Basic button/indicator problem... Stumped at the moment.
Chicago Mike
Posts: 88
I've been building a Nixie Alarm clock for the last 2 years. I'm almost done after 6 PCB rev's, a child, and significant frustration and fun.
Most of the·parts are old Soviet parts... Except for the SX that is the heart of it. Everything works. Except for one stupid thing. Would someone please look at my code snippet below. There is something dumb here that I'm overlooking that has had me stuck for a month (in the 15 minutes here and there I've had)
[noparse][[/noparse]code]
DEVICE·SX28, OSCHS2,TURBO,STACKX,OPTIONX
IRC_CAL IRC_FAST
FREQ·50_000_000
o_statusled··Pin ·RB.0 OUTPUT··' Status o_statusled On Circuit Board
i_sw_alarm··Pin·RB.1 INPUT CMOS··' Used to toggle monitoring of the alarm time. Used to turn the alarm on and off.
o_nixierelay··Pin·RB.2 OUTPUT··' 12V Relay Power to Supply Nixie Tubes Power
o_colontriac··Pin·RB.3 OUTPUT··' 120V TRIAC Driver for neom seperator indicator colons
o_alarmtriac··Pin·RB.4 OUTPUT··' 120V TRIAC Driver for neon alarm on indicator
o_nixrck··Pin·RB.5 OUTPUT ··' Nixie Data Driver Line. rck Pin (Latch Pin)
o_nixsck··Pin·RB.6 OUTPUT ··' Nixie Data Driver Line. sck Pin (Clock Pin)
o_nixser··Pin·RB.7 OUTPUT ··' Nixie Data Driver Line. ser Pin (Data Pin)
Stack 8
' Constants
True··CON ·1····' True
False··CON·0····' False
' Variables
alarm_enabled·· VAR·Bit····'Tells if the Alarm is on or off
Program Setup_Time
Setup_Time:
·LOW rb······' Setup everything low
·pause 250
goto Mainloop·····' Proceed to main clock operation
Mainloop:
·if i_sw_alarm = true then
··Toggle alarm_enabled
··do
···pause 100
··loop while i_sw_alarm = true
·endif
· o_alarmtriac = alarm_enabled
goto Mainloop
[noparse][[/noparse]/code]
So here is my delema. In 'Mainloop', i_sw_alarm is a button. When pressed it toggles alarm_enabled variable, its then followed by a wait to avoid bouncing. If the alarm_enabled variable is true, it assigns o_alarmtriac to true... Which is a triac type device that drives ON an neon indicator. So basiclly, this doesn't work. I never can turn on this neon when the button is pressed. However, in a test program, the following WILL work.
[noparse][[/noparse]code]
Setup_Time:
if i_sw_alarm = True then
··high o_alarmtriac
else
·low o_alarmtriac
endif
goto Setup_Time
[noparse][[/noparse]/code]
If I replace mainloop with the above, if I press the i_sw_alarm, the o_alarm triac comes on.... Which confirms that the hardware is working.
Can anyone see something I'm missing. I'm just stumped at the moment.
Thanks,
Most of the·parts are old Soviet parts... Except for the SX that is the heart of it. Everything works. Except for one stupid thing. Would someone please look at my code snippet below. There is something dumb here that I'm overlooking that has had me stuck for a month (in the 15 minutes here and there I've had)
[noparse][[/noparse]code]
DEVICE·SX28, OSCHS2,TURBO,STACKX,OPTIONX
IRC_CAL IRC_FAST
FREQ·50_000_000
o_statusled··Pin ·RB.0 OUTPUT··' Status o_statusled On Circuit Board
i_sw_alarm··Pin·RB.1 INPUT CMOS··' Used to toggle monitoring of the alarm time. Used to turn the alarm on and off.
o_nixierelay··Pin·RB.2 OUTPUT··' 12V Relay Power to Supply Nixie Tubes Power
o_colontriac··Pin·RB.3 OUTPUT··' 120V TRIAC Driver for neom seperator indicator colons
o_alarmtriac··Pin·RB.4 OUTPUT··' 120V TRIAC Driver for neon alarm on indicator
o_nixrck··Pin·RB.5 OUTPUT ··' Nixie Data Driver Line. rck Pin (Latch Pin)
o_nixsck··Pin·RB.6 OUTPUT ··' Nixie Data Driver Line. sck Pin (Clock Pin)
o_nixser··Pin·RB.7 OUTPUT ··' Nixie Data Driver Line. ser Pin (Data Pin)
Stack 8
' Constants
True··CON ·1····' True
False··CON·0····' False
' Variables
alarm_enabled·· VAR·Bit····'Tells if the Alarm is on or off
Program Setup_Time
Setup_Time:
·LOW rb······' Setup everything low
·pause 250
goto Mainloop·····' Proceed to main clock operation
Mainloop:
·if i_sw_alarm = true then
··Toggle alarm_enabled
··do
···pause 100
··loop while i_sw_alarm = true
·endif
· o_alarmtriac = alarm_enabled
goto Mainloop
[noparse][[/noparse]/code]
So here is my delema. In 'Mainloop', i_sw_alarm is a button. When pressed it toggles alarm_enabled variable, its then followed by a wait to avoid bouncing. If the alarm_enabled variable is true, it assigns o_alarmtriac to true... Which is a triac type device that drives ON an neon indicator. So basiclly, this doesn't work. I never can turn on this neon when the button is pressed. However, in a test program, the following WILL work.
[noparse][[/noparse]code]
Setup_Time:
if i_sw_alarm = True then
··high o_alarmtriac
else
·low o_alarmtriac
endif
goto Setup_Time
[noparse][[/noparse]/code]
If I replace mainloop with the above, if I press the i_sw_alarm, the o_alarm triac comes on.... Which confirms that the hardware is working.
Can anyone see something I'm missing. I'm just stumped at the moment.
Thanks,
Comments
How about if you explain what it is that you figure this --
is supposed to do.
Your code is fine, the problem is the SX is faster than you... In your code, you turn the alarm on when the button is pushed, then you loop to wait for a debounce. Your wait is to short and in the process of debounce it comes out of the loop. As a test, remove the GOTO MainLoop at the bottom and see if the light stays on. I expect that it will be. To fix it, increase your PAUSE inside the loop to 700.
Also, just from the small bit of code you gave, it looks like you could just directly toggle o_alarmtriac and skip using alarm_enabled.
Let me know if this fixes it!
Dan
if rb.1 = 1 then
Toggle alarm_enabled
do
pause 1000
high o_buzzer
loop while rb.1 <> 0
endif
basicly, if rb.1 switch is HIGH then toggle an LED. The do is a bebounce to wait for rb.1 to go low again before continuing the program.
There is something odd here. Ther ehas to be. I'd post the whole program, but its really long. Its so odd becasue I know the hardware works as that if I start a new program and do:
setuptime:
if rb.1 = 1 then
high o_alarmtriac
else
low o_alarmtriac
endif
goto Setup_Time
This is·a routine in·P·Basic·What·would this·routine· be in SX
···· P = P + 1 *· Chg_P·············· ' This line is to check if state of pin
····· IF (P = 6 ) THEN GOSUB P_resetData······ ·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 10/30/2009 11:28:39 PM GMT