November 24, 2024, 06:17:37 AM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


Another Converting Prop-1 to Prop-2

Started by gadget-evilusions, September 10, 2007, 01:54:18 PM

Previous topic - Next topic

gadget-evilusions

Jon,

This is the program I asked about in the charlieplexing thread. I would like to use it on the prop-2 because instead of just the on/off that I was getting with the prop-1 and dc-16, i would like to be able to pwm the leds in some of my led patterns. If you get time could you help me out. No rush. This is my first time working with the prop-2, and it figures right after I just finally get the prop-1 down.


' =========================================================================
'
'   File...... Evilusions_led_motorcycle.BS1
'   Purpose...
'   Author.... Brian Warner
'   E-mail.... gadget@evilusions.com
'   Started...
'   Updated... 8-1-07
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
'



' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Dial            = 6
SYMBOL  Sio             = 7
' -----[ Constants ]-------------------------------------------------------

SYMBOL  Baud            = OT2400
SYMBOL  Addr            = %00

' -----[ Variables ]-------------------------------------------------------

SYMBOL  cmd             = B2


' -----[ Initialization ]--------------------------------------------------

Reset:
  DIRS = %001111111


' -----[ Program Code ]----------------------------------------------------

Main:
  POT Dial, 104, cmd
  cmd = cmd / 37
  BRANCH cmd, (Task0, Task1, Task2, Task3, Task4, Task5, Task6)
  GOTO Main

Task0:
  SEROUT Sio, Baud, ("!DC16", Addr, "S", %01001001, %00000000)
  PAUSE 100
  GOTO Main

Task1:
  SEROUT Sio, Baud, ("!DC16", Addr, "S", %10010010, %00000000)
  PAUSE 100
  GOTO Main

Task2:
  SEROUT Sio, Baud, ("!DC16", Addr, "S", %00100100, %00000001)
  PAUSE 100
  GOTO Main

Task3:
  SEROUT Sio, Baud, ("!DC16", Addr, "S", %01001001, %00000000)
  PAUSE 50
  SEROUT Sio, Baud, ("!DC16", Addr, "X")
  PAUSE 50
  GOTO Main

Task4:
  SEROUT Sio, Baud, ("!DC16", Addr, "S", %10010010, %00000000)
  PAUSE 50
  SEROUT Sio, Baud, ("!DC16", Addr, "X")
  PAUSE 50
  GOTO Main

Task5:
  SEROUT Sio, Baud, ("!DC16", Addr, "S", %00100100, %00000001)
  PAUSE 50
  SEROUT Sio, Baud, ("!DC16", Addr, "X")
  PAUSE 50
  GOTO Main

Task6:
  SEROUT Sio, Baud, ("!DC16", Addr, "S", %10100001, %00000000)
  PAUSE 250
  SEROUT Sio, Baud, ("!DC16", Addr, "S", %00001010, %00000001)
  PAUSE 250
  SEROUT Sio, Baud, ("!DC16", Addr, "S", %01010100, %00000000)
  PAUSE 250
  GOTO Main




' -----[ Subroutines ]-----------------------------------------------------


' -----[ EEPROM Data ]-----------------------------------------------------
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

September 10, 2007, 01:57:22 PM #1 Last Edit: September 10, 2007, 01:58:54 PM by JonnyMac
Are you wanting to replace the DC-16 by using the Prop-2?  If yes, you'll be limited to 15 outputs (one is used for the Prop-Pot) -- can you live with that?
Jon McPhalen
EFX-TEK Hollywood Office

gadget-evilusions

Most definetly. I am only using 9 right now but 15 would be a perfect number.

Thank you sir.
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

September 10, 2007, 02:16:19 PM #3 Last Edit: September 10, 2007, 02:19:10 PM by JonnyMac
Then here you go!

' =========================================================================
'
'   File...... Evilusions_Led_Motorcycle.BS2
'   Purpose...
'   Author.... Brian Warner (with an assist from Jon Williams, EFX-TEK)
'   E-mail.... gadget@evilusions.com
'   Started...
'   Updated... 8-1-07
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------

' Notes:
' -- remove all SETUP jumpers
' -- replace ULN2803A on P8..P15 with a ULN2003A
' -- use Prop-Pot Prop-2 position


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

Dial            PIN     15                      ' for Prop-Pot, no ULN
Leds            VAR     OUTS                    ' OUT0 - OUT14


' -----[ Constants ]-------------------------------------------------------


' -----[ Variables ]-------------------------------------------------------

potVal          VAR     Word                    ' raw pot value (0 to ~600)
cmd             VAR     Nib                     ' command selection


' -----[ Initialization ]--------------------------------------------------

Reset:
  OUTS = $0000
  DIRS = $7FFF                                  ' make P0-P14 outputs


' -----[ Program Code ]----------------------------------------------------

Main:
  HIGH Dial
  PAUSE 1
  RCTIME Dial, 1, potVal
  cmd = potVal / 87
  BRANCH cmd, [Task0, Task1, Task2, Task3, Task4, Task5, Task6]
  GOTO Main

Task0:
  Leds = %0000000001001001
  PAUSE 100
  GOTO Main

Task1:
  Leds = %0000000010010010
  PAUSE 100
  GOTO Main

Task2:
  Leds = %0000000100100100
  PAUSE 100
  GOTO Main

Task3:
  Leds = %0000000001001001
  PAUSE 50
  Leds = %0000000000000000
  PAUSE 50
  GOTO Main

Task4:
  Leds = %0000000010010010
  PAUSE 50
  Leds = %0000000000000000
  PAUSE 50
  GOTO Main

Task5:
  Leds = %0000000100100100
  PAUSE 50
  Leds = %0000000000000000
  PAUSE 50
  GOTO Main

Task6:
  Leds = %0000000010100001
  PAUSE 250
  Leds = %0000000100001010
  PAUSE 250
  Leds = %0000000001010100
  PAUSE 250
  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------


' -----[ User Data ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office

gadget-evilusions

Thanks. Dosent look like there is too much of a difference in code. Since I make up my own prop-pot replacements using a pot that can be panel mounted and a capacitor, with is the difference between what I would be making for the prop-2 vs the prop-1?
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

You can test your circuit with a small bit of code:

' {$STAMP BS2}
' {$PBASIC 2.5}

Dial            PIN     15

potVal          VAR     Word

Main:
  HIGH Dial
  PAUSE 1
  RCTIME Dial, 1, potVal
  DEBUG HOME, DEC potVal, CLREOL
  PAUSE 50
  GOTO Main


Rotate your pot to determine the maximum value, then divide that by 7 (you have seven segments), and round up to the next highest value for your divisor.  For example, on my test I got a max value of 597; that divided by 7 is 85.28 so I rounded up 87 (for additional safety with temp variations on components).
Jon McPhalen
EFX-TEK Hollywood Office

gadget-evilusions

Also I forgot to ask, is it possible for me to PWM multiple piins at the same time. For example in the above program, i wanted to take 5 outputs and take them from 0% to 100% in 2 seconds.
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

Note with the Prop-2; that would, however, be possible with the Prop-SX  (with a bit of tricky code).
Jon McPhalen
EFX-TEK Hollywood Office

gadget-evilusions

that's fine. I can handle one at a time. Is there a difference in coding it between a prop-1 and prop-2?
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

Well, SX/B is similar to PBASIC, but as it's a truly compiled language (the output is assembly code that is burned into the chip) it is different.  As an exercise during lunch yesterday I created a framework that would allow you to control 15 LEDs from 0% to 100% brightness -- the main loop code is not there, but everything to implement it is.

Here's the code -- some of it is a little advanced (interrupts).

' =========================================================================
'
'   File...... Motorcycle_LEDs.SXB
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
' =========================================================================


' -------------------------------------------------------------------------
' Program Description
' -------------------------------------------------------------------------


' -------------------------------------------------------------------------
' Conditional Compilation Symbols
' -------------------------------------------------------------------------


' -------------------------------------------------------------------------
' Device Settings
' -------------------------------------------------------------------------

DEVICE          SX28, OSCXT2, TURBO, STACKX, OPTIONX, BOR42
FREQ            20_000_000
ID              "MC_LEDS"


' -------------------------------------------------------------------------
' I/O Pins
' -------------------------------------------------------------------------

Dial            PIN     RC.7 INPUT              ' PI5 (no SETUP or ULN)

LedsHi          PIN     RC                      ' use P8-P14/OUT8-OUT14
Led15           PIN     RC.6 OUTPUT             ' use P14/OUT14
Led14           PIN     RC.5 OUTPUT             ' use P13/OUT13
Led13           PIN     RC.4 OUTPUT             ' use P12/OUT12
Led12           PIN     RC.3 OUTPUT             ' use P11/OUT11
Led11           PIN     RC.2 OUTPUT             ' use P10/OUT10
Led10           PIN     RC.1 OUTPUT             ' use P9/OUT9
Led9            PIN     RC.0 OUTPUT             ' use P8/OUT8

LedsLo          PIN     RB                      ' use P0-P7/OUT0-OUT7
Led8            PIN     RB.7 OUTPUT             ' use P7/OUT7
Led7            PIN     RB.6 OUTPUT             ' use P6/OUT6
Led6            PIN     RB.5 OUTPUT             ' use P5/OUT5
Led5            PIN     RB.4 OUTPUT             ' use P4/OUT4
Led4            PIN     RB.3 OUTPUT             ' use P3/OUT3
Led3            PIN     RB.2 OUTPUT             ' use P2/OUT2
Led2            PIN     RB.1 OUTPUT             ' use P1/OUT1
Led1            PIN     RB.0 OUTPUT             ' use P0/OUT0

' -------------------------------------------------------------------------
' Constants
' -------------------------------------------------------------------------


' -------------------------------------------------------------------------
' Variables
' -------------------------------------------------------------------------

flags           VAR     Byte
tic            VAR     flags.0                 ' mark ISR

position        VAR     Byte                    ' from Prop-Pot (Prop-2)
cmd             VAR     Byte

tmpB1           VAR     Byte                    ' for subs/funcs
tmpB2           VAR     Byte
tmpW1           VAR     Word

dimmerLo        VAR     Byte (16)               ' bank 1 for dimmer vars
level1          VAR     dimmerLo (0)
level2          VAR     dimmerLo (1)
level3          VAR     dimmerLo (2)
level4          VAR     dimmerLo (3)
level5          VAR     dimmerLo (4)
level6          VAR     dimmerLo (5)
level7          VAR     dimmerLo (6)
level8          VAR     dimmerLo (7)
acc1            VAR     dimmerLo (8)
acc2            VAR     dimmerLo (9)
acc3            VAR     dimmerLo (10)
acc4            VAR     dimmerLo (11)
acc5            VAR     dimmerLo (12)
acc6            VAR     dimmerLo (13)
acc7            VAR     dimmerLo (14)
acc8            VAR     dimmerLo (15)

dimmerHi        VAR     Byte (16)               ' bank 2 for dimmer vars
level9          VAR     dimmerHi (0)
level10         VAR     dimmerHi (1)
level11         VAR     dimmerHi (2)
level12         VAR     dimmerHi (3)
level13         VAR     dimmerHi (4)
level14         VAR     dimmerHi (5)
level15         VAR     dimmerHi (6)
level16         VAR     dimmerHi (7)            ' not used
acc9            VAR     dimmerHi (8)
acc10           VAR     dimmerHi (9)
acc11           VAR     dimmerHi (10)
acc12           VAR     dimmerHi (11)
acc13           VAR     dimmerHi (12)
acc14           VAR     dimmerHi (13)
acc15           VAR     dimmerHi (14)
acc16           VAR     dimmerHI (15)           ' not used


' =========================================================================
  INTERRUPT NOCODE 100_000                      ' ISR every 10 uS
' =========================================================================

TickTock:
  ASM
    BANK  tic
    SETB  tic                                   ' mark ISR

Leds_Lo:                                        ' diming for P0 - P7
    BANK  dimmerLo
    ADD   acc1, level1
    MOVB  Led1, C
    ADD   acc2, level2
    MOVB  Led2, C
    ADD   acc3, level3
    MOVB  Led3, C
    ADD   acc4, level4
    MOVB  Led4, C
    ADD   acc5, level5
    MOVB  Led5, C
    ADD   acc6, level6
    MOVB  Led6, C
    ADD   acc7, level7
    MOVB  Led7, C
    ADD   acc8, level8
    MOVB  Led8, C

Leds_Hi:                                        ' dimming for P8 - P14
    BANK  dimmerHi
    ADD   acc9, level9
    MOVB  Led9, C
    ADD   acc10, level10
    MOVB  Led10, C
    ADD   acc11, level11
    MOVB  Led11, C
    ADD   acc12, level12
    MOVB  Led12, C
    ADD   acc13, level13
    MOVB  Led13, C
    ADD   acc14, level14
    MOVB  Led14, C
    ADD   acc15, level15
    MOVB  Led15, C

ISR_Done:
    BANK  0
  ENDASM
  RETURNINT


' =========================================================================
  PROGRAM Start
' =========================================================================


' -------------------------------------------------------------------------
' Subroutine / Function Declarations
' -------------------------------------------------------------------------

DELAY_MS        SUB     1, 2                    ' delay in milliseconds
SET_LEDS        SUB     2                       ' set LEDs (digital)

READ_DIAL       FUNC    1                       ' read dial value


' -------------------------------------------------------------------------
' Program Code
' -------------------------------------------------------------------------

Start:


Main:


  GOTO Main


' -------------------------------------------------------------------------
' Subroutine / Function Code
' -------------------------------------------------------------------------

' Use: DELAY_MS ms
' -- delays program in milliseconds
' -- uses ISR timer

SUB DELAY_MS
  IF __PARAMCNT = 1 THEN
    tmpW1 = __PARAM1                            ' save byte value
  ELSE
    tmpW1 = __WPARAM12                          ' save word value
  ENDIF
  DO WHILE tmpW1 > 0
    tmpB1 = 100                                 ' set for 1 ms
    DO WHILE tmpB1 > 0                          ' wait
      \ CLRB tic                                ' clear tic marker
      \ JNB  tic, $                             ' wait for next marker
      \ DEC  tmpB1                              ' update tic counter
    LOOP
    DEC tmpW1                                   ' decrement ms counter
  LOOP
  ENDSUB

' -------------------------------------------------------------------------

' Use: SET_LEDS ledBits
' -- "ledBits" is word variable or two bytes (low byte first)
' -- set LEDs on (100%) or off (0%)

SUB SET_LEDS
  tmpW1 = __WPARAM12                            ' get led bits
  FOR tmpB1 = 0 TO 7
    dimmerLo(tmpB1) = 0 - tmpW1.0               ' make 0 or 255
    dimmerHi(tmpB1) = 0 - tmpW1.8
    tmpW1 = tmpW1 >> 1                          ' get next bit
  NEXT
  ENDSUB

' -------------------------------------------------------------------------

' Use: value = READ_DIAL
' -- used to replace POT command (due to use of ISR)
' -- timing expressed in 10 uS units (ISR period)
' -- max value of ~115 with Prop-Pot using Prop-2 side

FUNC READ_DIAL
  HIGH Dial                                     ' charge cap
  DELAY_MS 1
  tmpB1 = 0
  INPUT Dial                                    ' allow discharge
  DO
    \ CLRB tic                                  ' clear tic marker
    \ JNB  tic, $                               ' wait for next marker
    INC tmpB1
    IF tmpB1 = 0 THEN EXIT
  LOOP UNTIL Dial = 0
  RETURN tmpB1
  ENDFUNC


' -------------------------------------------------------------------------
' User Data
' -------------------------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office

gadget-evilusions

That's definetly above my ability for now, but thanks. I will store that away until the day I get up to the sx.

Can you give me an example of code for PWM that I can use with the code you gave me above, or would it be the same as if I was programming a prop-1?
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

You would do something like this:

Main:
  FOR idx = 0 TO 255
    level1 = idx
    DELAY_MS 4
  NEXT


This loop would fade-up the P0/OUT0 pin from of to on in about one second (4 ms x 256 = 1.024 s).  The background process takes care of the PWM; you just set the level and when ramping up or down, a delay between changes.
Jon McPhalen
EFX-TEK Hollywood Office