First project: BS1: loop timing estimates
I am a new user. I have been asked to implement part of a project that will go up in a balloon (30,000+ m) within the next week. The project calls for a BS1, which will be delivered within a few days. I have dowloaded the docs and written this program.
a. Does it look like it is likely to work?
b. Because there is no clock, I must estimate the loop times to begin with, and modify them as we test the program. I have read that the BS1 will execute ~2k instructions/sec. I haven't seen a table relating "instructions" to PBASIC. Any thoughts?
'
[noparse][[/noparse] I/O Definitions ]
dirs = %00000100 ' pin 5 is an output pin that can be toggled during execution to measure loop timing
'
[noparse][[/noparse] Constants ]
symbol DebounceOnly = 255
symbol DontCare0 = 0
symbol K2645OneShot = 0 ' pin P0
symbol K2645DownState = 1
symbol K2645OSPulse = 100 ' 100 ms - need to measure this and adjust
symbol KPC3PLoByte = 3 ' pin 3
symbol KPC3PHiByte = 7 ' pin 7
symbol PWMCycles = 20 ' 5 * RC = 50 ms. @ 5 ms/PWM cycle for the BS1, we need 10 cycles; double it to be conservative
'
[noparse][[/noparse] Variables ]
symbol PreviousCounterLo = B0 ' Note that these bytes are mapped to PreviousCounter = W0
symbol PreviousCounterHi = B1
symbol K2645Work = B3
symbol PreviousCounter = W0
symbol CurrentCounter = W1
'
[noparse][[/noparse] EEPROM Data ]
'
[noparse][[/noparse] Initialization ]
'
[noparse][[/noparse] Main Code ]
Main:
CheckK2645OneShot:
' look for K2645 one-shot
' BUTTON Pin, DownState, Delay, Rate, Workspace, TargetState, Address
button K2645OneShot, K2645DownState, DebounceOnly, DontCare0, K2645Work, K2645DownState, NoK2645Event
CurrentCounter = CurrentCounter + 1
pause K2645OSPulse
'update clock to account for pause
NoK2645Event:
update clock counters
if Clock = a minute then
reset the clock
' move the counter data to the output buffer area and reset the counter
PreviousCounter = CurrentCounter
CurrentCounter = 0
endif
' send the data to the output ports for the KPC-3+
' refresh every second
' PWM Pin, Duty, Cycles
PWM KPC3PLoByte, PreviousCounterLo, PWMCycles
PWM KPC3PHiByte, PreviousCounterHi, PWMCycles
' for testing loop cycle times
pin5 = pin5
toggle 5
goto CheckK2645OneShot
END
a. Does it look like it is likely to work?
b. Because there is no clock, I must estimate the loop times to begin with, and modify them as we test the program. I have read that the BS1 will execute ~2k instructions/sec. I haven't seen a table relating "instructions" to PBASIC. Any thoughts?
'
[noparse][[/noparse] I/O Definitions ]
dirs = %00000100 ' pin 5 is an output pin that can be toggled during execution to measure loop timing
'
[noparse][[/noparse] Constants ]
symbol DebounceOnly = 255
symbol DontCare0 = 0
symbol K2645OneShot = 0 ' pin P0
symbol K2645DownState = 1
symbol K2645OSPulse = 100 ' 100 ms - need to measure this and adjust
symbol KPC3PLoByte = 3 ' pin 3
symbol KPC3PHiByte = 7 ' pin 7
symbol PWMCycles = 20 ' 5 * RC = 50 ms. @ 5 ms/PWM cycle for the BS1, we need 10 cycles; double it to be conservative
'
[noparse][[/noparse] Variables ]
symbol PreviousCounterLo = B0 ' Note that these bytes are mapped to PreviousCounter = W0
symbol PreviousCounterHi = B1
symbol K2645Work = B3
symbol PreviousCounter = W0
symbol CurrentCounter = W1
'
[noparse][[/noparse] EEPROM Data ]
'
[noparse][[/noparse] Initialization ]
'
[noparse][[/noparse] Main Code ]
Main:
CheckK2645OneShot:
' look for K2645 one-shot
' BUTTON Pin, DownState, Delay, Rate, Workspace, TargetState, Address
button K2645OneShot, K2645DownState, DebounceOnly, DontCare0, K2645Work, K2645DownState, NoK2645Event
CurrentCounter = CurrentCounter + 1
pause K2645OSPulse
'update clock to account for pause
NoK2645Event:
update clock counters
if Clock = a minute then
reset the clock
' move the counter data to the output buffer area and reset the counter
PreviousCounter = CurrentCounter
CurrentCounter = 0
endif
' send the data to the output ports for the KPC-3+
' refresh every second
' PWM Pin, Duty, Cycles
PWM KPC3PLoByte, PreviousCounterLo, PWMCycles
PWM KPC3PHiByte, PreviousCounterHi, PWMCycles
' for testing loop cycle times
pin5 = pin5
toggle 5
goto CheckK2645OneShot
END