In looking at the documentation for the EZ-3 I found that by soldering across the jumpers that it can be configured for working with the SX controller. I have a need bor the pre and post delay pots of the EZ3 but the run time POT can be ignored. I'm using the SX to controll 5 servos and am running it with the 50,000,000 resonator. I was wondering if the TURBO instruction works with all the resonators as a 5X multiplier and if so what is the upper limit for clock speed for the SX. There is samplw code in th EZ-3 documentation for using it with a prop-1 but I need some example of using it with an SX - one that is controlling servos and thus dealing with interrupts. Thanks. ps Trying to get it for the big H and it seems to be coming a day early this year! Arrg.
Please attached your present program so I can see how you have the servo pins assigned -- need to know that so there are no conflicts.
You will need to put the EZ-3 into BS2 mode and remove the ULN influence from the pins. It's not easy to add a pot to a program running interrupts, but it can be done (I helped a friend create an adjustable flame controller with the FC-4 last year, so I have done it).
The TURBO option (which is default in SX/B 2.x) allows the SX to run in its native mode. Non-turbo allowed for PIC compatibility which is why there was a dust-up between Microchip and Scenix which, ultimately, has led to the demise of the SX. This is why Parallax spent so much time and money creating the Propeller: they didn't want to get caught in another crossfire and they wanted to maintain control of their own destiny.
Here is the code:
I didn't include all the subroutines because they are all very similar. Is there a way to attach a larger file to this FORUM?
D "S5+D11"
DEVICE SX28, OSCHS2, BOR42
FREQ 50_000_000
' DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX, BOR42
' DEVICE SX28, OSC4MHZ, BOR42
' FREQ 4_000_000
' -------------------------------------------------------------------------
' I/O Pins
' -------------------------------------------------------------------------
' SERO PIN RC.7 INPUT ' Reserved for Serial I/O v-music
' SERI PIN RC.6 INPUT ' Reserved for Serial I/O v-music
PrePot PIN RC.5 INPUT ' Pre Delay POT
GrnLED PIN RC.4 OUTPUT ' PreDelay Green LED
PostPot PIN RC.3 INPUT ' Post Delay POT
YelLED PIN RC.2 OUTPUT ' PostDelay Yellow LED
C_Out1 PIN RC.1 OUTPUT ' unused P9/C_Out1
Trigger PIN RC.0 INPUT ' P3 - PIR or Switch
UpSol PIN RB.7 OUTPUT ' solenoid UP coil
DownSol PIN RB.6 OUTPUT ' solenoid DOWN coil
B_Out5 PIN RB.5 ' unused P5/B_OUT5
ServoCtrl PIN RB OUTPUT ' servo control pins
Servo4 PIN RB.4 ' use P4
Servo3 PIN RB.3 ' use P3
Servo2 PIN RB.2 ' use P2
Servo1 PIN RB.1 ' use P1
Servo0 PIN RB.0 ' use P0
'TX PIN RA.3 OUTPUT ' to PC
'RX PIN RA.2 INPUT ' from PC
'SCL PIN RA.1 INPUT ' EE clock line (I2C)
'SDA PIN RA.0 INPUT ' EE data line (I2C)
' Note: TX, SCL, and SDA lines are not used by this program
' -------------------------------------------------------------------------
' Constants
' -------------------------------------------------------------------------
IsOn CON 1
IsOff CON 0
Yes CON 1
No CON 0
LO_LIMIT CON 64 ' to prevent servo burn-up
MID CON 155 ' limint trave min and max
HI_LIMIT CON 245
' Bit dividers for 3.255 uS interrupt
' -- ISR actually runs at 3.333 uS for better servo timing
Baud2400 CON 128
Baud4800 CON 64
Baud9600 CON 32
Baud19K2 CON 16
Baud38K4 CON 8
Baud1x0 CON Baud38K4 ' 1 bit period (ISR counts)
Baud1x5 CON Baud1x0 * 3 / 2 ' 1.5 bit periods
' -------------------------------------------------------------------------
' Variables
' -------------------------------------------------------------------------
flags VAR Byte ' (keep global)
isrFlag VAR flags.0
rxReady VAR flags.1 ' rx byte waiting
sync VAR Byte
chan VAR Byte
value VAR Byte
mask VAR Byte
potVal VAR Word
tmpW1 VAR Word
tmpB1 VAR Byte
tmpB2 VAR Byte
waitTime VAR Byte
UpDwnLim VAR Byte
RgtLftLim VAR Byte
TiltLim VAR Byte
EyeRgtLftLim VAR Byte
EyeUpDwnLim VAR Byte
rxSerial VAR Byte (16)
rxBuf VAR rxSerial(0) ' 8-byte buffer
rxCount VAR rxSerial(8) ' rx bit count
rxDivide VAR rxSerial(9) ' bit divisor timer
rxByte VAR rxSerial(10) ' recevied byte
rxHead VAR rxSerial(11) ' buffer head (write to)
rxTail VAR rxSerial(12) ' buffer tail (read from)
rxBufCnt VAR rxSerial(13) ' # bytes in buffer
svoData VAR Byte (16) ' bank servo data
pos VAR svoData(0) ' position table
pos0 VAR svoData(0)
pos1 VAR svoData(1)
pos2 VAR svoData(2)
pos3 VAR svoData(3)
pos4 VAR svoData(4)
pos5 VAR svoData(5)
pos6 VAR svoData(6)
pos7 VAR svoData(7)
svoTix VAR svoData(8) ' isr divider
svoFrame_LSB VAR svoData(9) ' frame timer
svoFrame_MSB VAR svoData(10)
svoIdx VAR SvoData(11) ' active servo pointer
svoTimer VAR svoData(12) ' pulse timer
svoPin VAR svoData(13) ' active servo pin
dbTimer VAR Byte
' =========================================================================
INTERRUPT NOPRESERVE 300_000 ' (4) run every 3.333 uS
' =========================================================================
Mark_ISR:
\ SETB isrFlag ' (1)
'
' ----------------
' Servo Processing
' ----------------
'
Test_Servo_Tix:
ASM
BANK svoData ' (1)
INC svoTix ' (1) update divider
CJB svoTix, #3, Servo_Done ' (4/6) done?
CLR svoTix ' (1) yes, reset for next
' Code below this point runs every 10 uS
Check_Frame_Timer:
CJNE svoFrame_LSB, #2000 & 255, Inc_FrTmr ' (4/6) svoFrame = 2000 (20 ms)?
CJNE svoFrame_MSB, #2000 >> 8, Inc_FrTmr ' (4/6)
CLR svoFrame_LSB ' (1) yes, reset
CLR svoFrame_MSB ' (1)
MOV svoPin, #%0000_0001 ' (2) start servo sequence
CLR svoIdx ' (1) point to servo 0
MOV FSR, #pos ' (2)
MOV svoTimer, IND ' (2)
JMP Refesh_Servo_Outs ' (3)
Inc_FrTmr:
INC svoFrame_LSB ' (1) DEC svoFrame
ADDB svoFrame_MSB, Z ' (2)
Check_Servo_Timer:
TEST svoPin ' (1) any servos on?
SNZ ' (1)
JMP Servo_Done ' (1) no, exit
DEC svoTimer ' (1) yes, update timer
SZ ' (1) still running?
JMP Servo_Done ' (1) yes, exit
Reload_Servo_Timer:
INC svoIdx ' (1) point to next servo
MOV W, #pos ' (1) get pulse timing
ADD W, svoIdx ' (1)
MOV FSR, W ' (1)
MOV W, IND ' (1)
MOV svoTimer, W ' (1) move to timer
Select_Next_Servo:
CLC ' (1)
RL svoPin ' (1)
AND svoPin, #%0001_1111 ' (2) limit servo channels
Refesh_Servo_Outs:
AND ServoCtrl, #%1110_0000 ' (2) clear last
OR ServoCtrl, svoPin ' (2) update outputs
Servo_Done:
ENDASM
ISR_Exit:
RETURNINT ' (4)
' -------------------------------------------------------------------------
' Subroutine / Function Declarations
' -------------------------------------------------------------------------
' RX_BYTE FUNC 1, 0 ' receive a byte
' POT_DELAY FUNC 1, 1, 2 ' POT Pin to test, POT return value
DELAY_MS SUB 2, 2, Word, Word ' shell for PAUSE
NOD_DWN SUB 2, 2
NOD_UP SUB 2, 2
NOD_MID SUB 1, 1
TURN_LEFT SUB 2, 2
TURN_RIGHT SUB 2, 2
TURN_MID SUB 1, 1
TILT_LEFT SUB 2, 2
TILT_RIGHT SUB 2, 2
TILT_MID SUB 1, 1
LEFT_DWN SUB 3, 3
RIGHT_DWN SUB 3, 3
LEFT_UP SUB 3, 3
RIGHT_UP SUB 3, 3
CENTER_LR_UD SUB 1, 1
EYES_LEFT SUB 2, 2
EYES_RIGHT SUB 2, 2
EYES_RL_MID SUB 1, 1
EYES_DWN SUB 2, 2
EYES_UP SUB 2, 2
EYES_UD_MID SUB 1, 1
EYES_CENTER SUB 1, 1
' =========================================================================
PROGRAM Start
' =========================================================================
Start:
' TX = 1 ' set TX line to idle
' center servos
PUT pos, MID, MID, MID, MID, MID
PLP_A = %0000 ' Set pull-ups for inputs Chan A
TRIS_C = %1110_1001 ' make RC.1, RC.2, RC.4 outputs
Main:
dbTimer = 0
Check_Trigger: ' de-bounce the triger input
INC dbTimer
IF Trigger = IsOff THEN Main
IF dbTimer < 100 THEN Check_Trigger
' ELSE StartPreDelay
StartPreDelay:
HIGH GrnLED ' Turn ON indicator LED
HIGH prePot ' Charge the Capacitor
PAUSEUS 200 ' Pause for 20 microseconds
RCTIME prePot,1,potVal,3 ' Read POT, 6uS units
potVal = potVal ** $717C ' x 0.44 (MAX = 100)
' potVal = potVal + 5 ' Set (MIN = 5)
DELAY_MS potVal ' wait POT time
LOW GrnLED ' Turn OFF indicator LED
LOW DownSol
HIGH UpSol
DELAY_MS 60
LOW UpSol
DELAY_MS 600
MoveHead:
NOD_UP 15, 190 'sp HI
NOD_DWN 15, 90 'sp LO
NOD_MID 20 'sp
LEFT_DWN 40, 200, 90 'sp HI LO
RIGHT_UP 40, 80, 200 'sp LO HI
CENTER_LR_UD 30 'sp
' TILT_RIGHT 15, 100 'sp LO
' TILT_LEFT 15, 195 'sp HI
' TILT_MID 20 'sp
DELAY_MS 5000
' LEFT_UP 40, 210, 190 'sp HI HI
' RIGHT_DWN 40, 90, 90 'sp LO LO
' TURN_LEFT 40, 220 'sp HI
' TURN_RIGHT 40, 90 'sp LO
LEFT_DWN 40, 220, 90 'sp HI LO
EYES_RIGHT 10, 250 'sp HI
EYES_LEFT 10, 70 'sp LO
MoveHeadDone:
CENTER_LR_UD 30 'sp
EYES_RL_MID 10 'sp
LOW UpSol
HIGH DownSol
DELAY_MS 60
LOW DownSol
StartPostDelay:
HIGH YelLED ' Turn ON indicator LED
HIGH postPot ' Charge the Capacitor
PAUSEUS 200 ' Pause for 20 microseconds
RCTIME postPot,1,potVal,3 ' Read POT, 6uS units
potVal = potVal ** $717C ' x 0.44 (MAX = 100)
' potVal = potVal + 5 ' Set (MIN = 5)
DELAY_MS potVal ' wait POT time
LOW YelLED ' Turn OFF indicator LED
GOTO Main
' -------------------------------------------------------------------------
' Subroutine / Function Code
' -------------------------------------------------------------------------
SUB DELAY_MS
PAUSE __wparam12
ENDSUB
' FUNC POT_DELAY
' tmpB1 = __param1
' HIGH tmpB1 ' Charge the Capacitor
' PAUSEUS 20 ' Pause for 20 microseconds
' RCTIME tmpB1,1,tmpW1,3 ' Read POT, 6uS units
' tmpW1 = tmpW1 ** $717C ' x 0.44 (MAX = 100)
' tmpW1 = tmpW1 + 5 ' Set (MIN = 5)
' RETURN tmpW1
' ENDFUNC
SUB NOD_DWN ' Subroutines to control servos
waitTime = __param1
UpDwnLim = __param2
IF UpDwnLim < LO_LIMIT THEN
UpDwnLim = LO_LIMIT
ENDIF
tmpB1 = pos(0)
DO WHILE tmpB1 > UpDwnLim
DEC tmpB1
pos(0) = tmpB1
DELAY_MS waitTime
LOOP
ENDSUB
Here's a new framework for you program that uses the EZ-3. You do not need to add solder jumpers to the EZ-3; I wrote the code to imitate the Prop-1 POT function.
IMPORTANT: Copy your functions into this template, not the other way around. The ISR timing has changed and affects pot readings. I've also taken care of all the pin assignments to simplify program setup. Finally, use RC.6 as the trigger input as that exists on the EZ-3; you have a button on the board and a connector you can use for a mat switch, etc. I've also provided proper debouncing code for the trigger in this template.
When you read a pot it will return a value from 2 to 70ish. On my EZ-3 two of the pots returned 71-72, the other about 80 -- this is due to component variances. In your code you might want to do this:
tmpB1 = RD_DLYPOT
tmpB1 = tmpB1 MAX 70
This will keep the max value at 70. You can scale from there.
' =========================================================================
'
' File......
' Purpose...
' Author....
' E-mail....
' Started...
' Updated...
'
' =========================================================================
' -------------------------------------------------------------------------
' Program Description
' -------------------------------------------------------------------------
' -------------------------------------------------------------------------
' Conditional Compilation Symbols
' -------------------------------------------------------------------------
' -------------------------------------------------------------------------
' Device Settings
' -------------------------------------------------------------------------
ID "Svo_6+10"
DEVICE SX28, OSCHS2, BOR42
FREQ 50_000_000
' -------------------------------------------------------------------------
' I/O Pins
' -------------------------------------------------------------------------
EZ3Port PIN RC ' EZ-3 addon
Sio PIN RC.7 ' SETUP = UP; NO ULN
Trigger PIN RC.6 ' SETUP = DN; NO ULN
DelayPot PIN RC.5 ' SETUP = OUT; NO ULN
OnPot PIN RC.4 ' SETUP = OUT; NO ULN
OffPot PIN RC.3 ' NO ULN
Out5 PIN RC.2 OUTPUT ' use P10/OUT10
Out4 PIN RC.1 OUTPUT ' use P9/OUT9
Out3 PIN RC.0 OUTPUT ' use P8/OUT8
OutsLo PIN RB
Out2 PIN RB.7 OUTPUT ' use P7/OUT7
Out1 PIN RB.6 OUTPUT ' use P6/OUT6
Out0 PIN RB.5 OUTPUT ' use P5/OUT5
ServoCtrl PIN RB ' servo control pins
Servo4 PIN RB.4 OUTPUT ' use P4
Servo3 PIN RB.3 OUTPUT ' use P3
Servo2 PIN RB.2 OUTPUT ' use P2
Servo1 PIN RB.1 OUTPUT ' use P1
Servo0 PIN RB.0 OUTPUT ' use P0
TX PIN RA.3 INPUT PULLUP ' to PC
RX PIN RA.2 INPUT PULLUP ' from PC
SCL PIN RA.1 INPUT ' EE clock line (I2C)
SDA PIN RA.0 INPUT ' EE data line (I2C)
' -------------------------------------------------------------------------
' Constants
' -------------------------------------------------------------------------
IsOn CON 1
IsOff CON 0
Yes CON 1
No CON 0
LO_LIMIT CON 60 ' to prevent servo burn-up
CENTER CON 150
HI_LIMIT CON 240
' -------------------------------------------------------------------------
' Variables
' -------------------------------------------------------------------------
flags VAR Byte ' (keep global)
isrFlag VAR flags.0
tmpB1 VAR Byte
tmpB2 VAR Byte
tmpB3 VAR Byte
tmpB4 VAR Byte
tmpW1 VAR Word
tmpW2 VAR Word
' define arrays after simple variables
svoData VAR Byte (16) ' bank servo data
pos VAR svoData(0) ' position table
pos0 VAR svoData(0)
pos1 VAR svoData(1)
pos2 VAR svoData(2)
pos3 VAR svoData(3)
pos4 VAR svoData(4)
pos5 VAR svoData(5)
pos6 VAR svoData(6)
pos7 VAR svoData(7)
svoTix VAR svoData(8) ' isr divider
svoFrame_LSB VAR svoData(9) ' frame timer
svoFrame_MSB VAR svoData(10)
svoIdx VAR SvoData(11) ' active servo pointer
svoTimer VAR svoData(12) ' pulse timer
svoPin VAR svoData(13) ' active servo pin
' =========================================================================
INTERRUPT NOPRESERVE 100_000 ' (4) run every 10 uS
' =========================================================================
Mark_ISR:
\ SETB isrFlag ' (1)
' ----------------
' Servo Processing
' ----------------
'
Test_Servo_Tix:
ASM
BANK svoData ' (1)
Check_Frame_Timer:
CJNE svoFrame_LSB, #2000 & 255, Inc_FrTmr ' (4/6) svoFrame = 2000 (20 ms)?
CJNE svoFrame_MSB, #2000 >> 8, Inc_FrTmr ' (4/6)
CLR svoFrame_LSB ' (1) yes, reset
CLR svoFrame_MSB ' (1)
MOV svoPin, #%0000_0001 ' (2) start servo sequence
CLR svoIdx ' (1) point to servo 0
MOV FSR, #pos ' (2)
MOV svoTimer, IND ' (2)
JMP Refesh_Servo_Outs ' (3)
Inc_FrTmr:
INC svoFrame_LSB ' (1) DEC svoFrame
ADDB svoFrame_MSB, Z ' (2)
Check_Servo_Timer:
TEST svoPin ' (1) any servos on?
SNZ ' (1)
JMP Servo_Done ' (1) no, exit
DEC svoTimer ' (1) yes, update timer
SZ ' (1) still running?
JMP Servo_Done ' (1) yes, exit
Reload_Servo_Timer:
INC svoIdx ' (1) point to next servo
MOV W, #pos ' (1) get pulse timing
ADD W, svoIdx ' (1)
MOV FSR, W ' (1)
MOV W, IND ' (1)
MOV svoTimer, W ' (1) move to timer
Select_Next_Servo:
CLC ' (1)
RL svoPin ' (1)
AND svoPin, #%0001_1111 ' (2) limit servo channels
Refesh_Servo_Outs:
AND ServoCtrl, #%1110_0000 ' (2) clear last
OR ServoCtrl, svoPin ' (2) update outputs
Servo_Done:
ENDASM
ISR_Exit:
RETURNINT ' (4)
' =========================================================================
' Subroutine / Function / Task Declarations
' =========================================================================
DELAY_MS SUB 2, 2, Word, Word ' shell for PAUSE
RD_DLYPOT FUNC 1, 0 ' read delay pot
RD_ONPOT FUNC 1, 0 ' read on time pot
RD_OFFPOT FUNC 1, 0 ' read off time pot
' =========================================================================
PROGRAM Start
' =========================================================================
Start:
PUT pos, CENTER, CENTER, CENTER, CENTER, CENTER
Main:
tmpB1 = 0
Check_Trigger:
DELAY_MS 1
INC tmpB1
IF Trigger = IsOff THEN Main
IF tmpB1 < 100 THEN Check_Trigger
Program_Code:
tmpB1 = RD_DLYPOT ' how to read a pot
' program code here
GOTO Main
' -------------------------------------------------------------------------
' Subroutine / Function / Task Code
' -------------------------------------------------------------------------
' Use: DELAY_MS milliseconds
' -- replaces PAUSE
SUB DELAY_MS
'{$IFUSED DELAY_MS}
ms VAR __WPARAM12
msTix VAR __PARAM3
DO WHILE ms > 0
msTix = 100 ' set for 1ms
DO WHILE msTix > 0 ' run 1ms timer
\ CLRB isrFlag ' clear flag
\ JNB isrFlag, @$ ' wait for next
\ DEC msTix ' update msTix count
LOOP
DEC ms ' update ms count
LOOP
'{$ENDIF}
ENDSUB
' -------------------------------------------------------------------------
' Use: value = RD_DLYPOT
' -- duplicates BS1 POT function
' -- remove ULN influence and SETUP jumpers from pin
FUNC RD_DLYPOT
'{$IFUSED RD_DLYPOT}
potTix VAR __PARAM1
HIGH DelayPot ' charge RC circuit
DELAY_MS 10
potTix = 0 ' clear measurement
DO
LOW DelayPot ' discharge a little
\ CLRB isrFlag ' clear flag
\ JNB isrFlag, @$ ' wait for next
\ DEC msTix ' update msTix count
INPUT DelayPot ' release to check
INC potTix
IF potTix = 0 THEN EXIT ' abort if stuck
LOOP UNTIL DelayPot = 0 ' wait until discharged
RETURN potTix
'{$ENDIF}
ENDFUNC
' -------------------------------------------------------------------------
' Use: value = RD_ONPOT
' -- duplicates BS1 POT function
' -- remove ULN influence and SETUP jumpers from pin
FUNC RD_ONPOT
'{$IFUSED RD_ONPOT}
potTix VAR __PARAM1
HIGH OnPot ' charge RC circuit
DELAY_MS 10
potTix = 0 ' clear measurement
DO
LOW OnPot ' discharge a little
\ CLRB isrFlag ' clear flag
\ JNB isrFlag, @$ ' wait for next
\ DEC msTix ' update msTix count
INPUT OnPot ' release to check
INC potTix
IF potTix = 0 THEN EXIT ' abort if stuck
LOOP UNTIL OnPot = 0 ' wait until discharged
RETURN potTix
'{$ENDIF}
ENDFUNC
' -------------------------------------------------------------------------
' Use: value = RD_OFFPOT
' -- duplicates BS1 POT function
' -- remove ULN influence and SETUP jumpers from pin
FUNC RD_OFFPOT
'{$IFUSED RD_OFFPOT}
potTix VAR __PARAM1
HIGH OffPot ' charge RC circuit
DELAY_MS 10
potTix = 0 ' clear measurement
DO
LOW OffPot ' discharge a little
\ CLRB isrFlag ' clear flag
\ JNB isrFlag, @$ ' wait for next
\ DEC msTix ' update msTix count
INPUT OffPot ' release to check
INC potTix
IF potTix = 0 THEN EXIT ' abort if stuck
LOOP UNTIL OffPot = 0 ' wait until discharged
RETURN potTix
'{$ENDIF}
ENDFUNC
' =========================================================================
' User Data
' =========================================================================
If I've already modified the EZ-3 by soldering the jumpers, I guess I'll have to try and undo those jumpers. I was just doing what the EZ-3 documentation suggested for the Prop-2 and PropSX. I also noticed that you didn't include the turning on and off of the three LED that show what stage the timer is currently running. I would assume that I could put another variable into the function to pass the bit value of the LED to be turned on or off but I'm not sure exactly how to pass a bit value to a function? I guess I could just turn the LED on before calling the FUNCtion and the turn it off when the FUNCtion returns. PS you might want to include the code example with the EZ-3 documentation but you'll need to change the instruction to solder over the bridges which changes the RC from a series to a parallel circuit.
I had a tough time getting solder to stick on my EZ-3, but then, it's an early prototype. I also thought I'd save you some trouble. If you want the other code, I can show you.
You can use HIGH and LOW to turn on the LED outputs -- and they're defined in the code so it's easy to do.
I'd like to see the other code if it's not too much trouble. From your statement I assune that I should set the LED's HIGH before calling the FUNC and set them LOW following the subroutine return.
Here's one of the routines, modified for the BS2-style circuit. The differences are a bit subtle: this version sets the pin to input mode and allows the cap to discharge through the parallel resistor.
' Use: value = RD_DLYPOT
' -- duplicates BS1 POT function
' -- remove ULN influence and SETUP jumpers from pin
FUNC RD_DLYPOT
'{$IFUSED RD_DLYPOT}
potTix VAR __PARAM1
HIGH DelayPot ' charge RC circuit
DELAY_MS 2
potTix = 0 ' clear measurement
INPUT DelayPot ' release to check
DO
\ CLRB isrFlag ' clear flag
\ JNB isrFlag, @$ ' wait for next
\ DEC msTix ' update msTix count
INC potTix
IF potTix = 0 THEN EXIT ' abort if stuck
LOOP UNTIL DelayPot = 0 ' wait until discharged
RETURN potTix
'{$ENDIF}
ENDFUNC
I don't know what you want your LEDs to mean. When you want one to be on -- for whatever that means to your program -- use HIGH. When you want it off, use LOW.
The LED's each indicate when each of the delay times are running. Since the POT function gets a byte value between 2 and 71~80, the LED associated with the PRE-Delay will turn on before the read pot function is called and then turned off after the the scaled delay time has been met. I was thinking that the FUNCTIONS could get a scaling WORD value to use in calling the DELAY_MS function from within the POT read function. I was thinking also that if the BIT parameter value were to be able to be passed to the POT read function there could be only one copy of the code which would read the specified POT RC value. What I was looking for was a way to pass the DelayPot, OnPot and and OffPot values to a single FUNC. Am I dreaming about things that are not possible with the SX environment?
QuoteAm I dreaming about things that are not possible with the SX environment?
Well, not dreaming, but not possible using friendly coding techniques that are easy to read. You have to use a pin mask on a known port and reading the R/C value -- some will have trouble following the code.
Here's an untested, off-the-top of my head shot -- works only on the RC port (P8..P15 on the Prop-SX).
' Use: value = RD_POT portBit
' -- portBit is 0 to 7
' -- duplicates BS2 RCTIME on RC port of SX
' -- remove ULN influence and SETUP jumpers from pin
FUNC RD_POT
'{$IFUSED RD_POT}
portBit VAR __PARAM1
rcMask VAR __PARAM2
potTix VAR __PARAM3
rcMask = 1 << portBit ' create mask for pin
TRIS_C = TRIS_C &~ rcMask ' make pin output
RC = RC | rcMask ' make pin high
DELAY_MS 2 ' allow time to charge
potTix = 0 ' clear measurement
TRIS_C = TRIS_C | rcMask ' make pin an input
DO
\ CLRB isrFlag ' clear flag
\ JNB isrFlag, @$ ' wait for next
\ DEC msTix ' update msTix count
INC potTix
IF potTix = 0 THEN EXIT ' abort on rollover
portBit = RC & rcMask ' check the bit
IF portBit = 0 THEN EXIT ' exit when discharged
LOOP
RETURN potTix
'{$ENDIF}
ENDFUNCRemember, SX/B was never intended to be as easy as PBASIC, it was designed as a bridge between BASIC and Assembly (this is why you can only have one operator per line, just like in Assembly). PBASIC masks a lot of technicalities from the user that SX/B does not.
As might be expected I'm having a litle trouble understanding the pin mask code. I played with it a little without any success. Can't seem to get any delay out of the code. I tried the other code that was for the BS2 configuration of parrallel resistor- cap and couldn't get any delay there either. I air kluged a circuit of a pot and a cap in series without any current limiting resistor in series with them and was able to get some delay but it only varies from 7 to 11 seconds. not much of a selection! I took the return value from the function and multiplied it by 100 (tmpW1 = tmpB1 * 100) then used the tmpB1 value to call the DELAY_MS subroutine.
I tried to play with the bit mask code and was able to modify it to turn an LED ON and OFF using the mask and "|" or "&~" with the RC value. I guess that I need to have an SX KEY insted of the Blitz to allow trouble shooting of the kinds of thing I'm trying to do. Trouble shooting code when you are blind just doesn't work.
One final question - you didn't show the function declaration for the bit mask function nor does it make sense to me why you used __Param2 as a variable for rcMask? Is something supposed to be pass to the function in __Param2 which is immediatly modified by shifting a 1 through it bit offset times.
QuoteI need to have an SX KEY insted of the Blitz to allow trouble shooting of the kinds of thing I'm trying to do
That is true -- mostly. You could install a serial routine and send data out the DB-9 to a PC but that is another layer of complexity.
QuoteAs might be expected I'm having a litle trouble understanding the pin mask code.
Then why attempt to use it? Pin masking is fundamental to embedded programming. Your responsibility to yourself is to dig in and learn to program the SX; this includes using pin masks.
Quoteyou didn't show the function declaration for the bit mask function
My mistake -- I thought you understood the SX and SX/B. It's obvious now that you're still working your way up the learning curve. I've said this more than once: SX/B is not PBASIC and requires the programmer to do some serious study to master. There's no way around that.
Once you spend more time with SX/B it will make sense that I'm using __PARAM2 and __PARAM3 in that function to save variable space in the program. I did show how the function is used (in the preceding comment section) -- here's the declaration:
RD_POT FUNC 1, 1, 1This states that one byte will be returned, and that one byte is passed (min and max bytes passed are set to 1).