PDA

View Full Version : Help with example button program



keithv
- 22nd March 2014, 18:11
I've just downloaded PBP3 and I'm trying to use the example button program found here: http://melabs.com/samples/LABX4-12F675/BUTX4.htm but I get the following error message

[ASM ERROR] BUTTON TEST.ASM (110) : Illegal character (,)
[ASM WARNING] BUTTON TEST.ASM (110) : Found label after column 1 (intrc_osc_noclkout)

What am I missing here? Does this have something to do with the code being written for v2.6? Also, the compile button on the toolbar is grayed out. Although it still allows me to compile if I select it from the project drop down menu.

Darrel Taylor
- 22nd March 2014, 18:49
Read section 4.9 in the PBP3 manual, regarding how to set the configs in your code.

And I doubt the "Compile" button is greyed out, although it's likely that the "ICD Compile" button is, since you can't use the In-Circuit Debugger with a 12F675.

If you don't see the "Compile" button, go to View > Toolbars and check the "Compile and Program" option.

keithv
- 22nd March 2014, 22:52
Thanks, DT. That did the trick!

keithv
- 23rd March 2014, 00:27
OK. So I've got that working and now I'm trying to use the BUTTON command. I'm having trouble getting the switch debounced. Any suggestions for delay cycle, auto repeat and BUTTON_PAUSE settings?

keithv
- 23rd March 2014, 16:19
Any ideas how I can improve this code? I'm trying to use a push button switch to toggle between 2 LEDs. For the most part it works, but the switch does not debounce very well. I'm actually trying to toggle between turning an LED on and turning a relay off, which is why one of the variables is named LATCH1, but for testing purposes I'm just using 2 LEDs.



' Name : BUTTONTEST.pbp
' Compiler : PICBASIC PRO Compiler 3.0
' Assembler : PM
' Target PIC : 8-pin PIC12F675 or similar type
' Hardware : Kee
' Oscillator : 4MHz internal
' Keywords : HIGH, LOW
' Description : PICBASIC PRO program to show button press on LED.

#config
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _CPD_OFF
#endconfig

Define OSCCAL_1K 1 ' PIC12F675, Calibrate internal oscillatordefine MCLRE_OFF
define BUTTON_PAUSE 65

LED1 Con 0 ' Alias GPIO.0 to LED1
LATCH1 con 1 'Alias GPIO.1 to LATCH1
PB1 Var GPIO.2 ' Alias GPIO.2 to push button
B1 var byte 'Working buffer for switch1 button command

ANSEL = 0 ' Set all digital
CMCON = 7 ' Analog comparators off
clear
low LED1 'Begin program with LED1 off
high LATCH1 'Begin program with relay1 in bypass

main:
switch1:

button PB1, 0, 40, 5, B1, 0, main
toggle LATCH1
toggle LED1

Goto main ' Do it forever

End

HenrikOlsson
- 23rd March 2014, 16:33
Hi,
If it's really not debouncing properly - even with 65ms worth of "debounce time", you've got to have a really bouncy switch... :-)

Are you sure that it's not the autorepeat feature you're seeing? If you change the value 40 in your example to 255 it will still debounce but not autorepeat - according to the manual.

/Henrik.

Acetronics2
- 23rd March 2014, 17:53
Hi,

I'm not so sure of:

button PB1, 0, 40, 5, B1, 0, main


I'd try ...


...
B1 = 0 ; always think to place it just before " button " command ...
button PB1, 0, 255, 0, B1, 1,yes
no:
Pause 20 ; pace the scanning ... not compulsory
goto main
yes:
toggle LATCH1
toggle LED1
...


that's the way It works for me for years in such a use ... note I think ( and observed ) the debouncing only occurs if condition is true (1) ...
so, sometimes, you have to "twist" the test somewhat ...

Alain

keithv
- 24th March 2014, 17:57
Thanks for the help guys. The button and toggle commands just weren't working for what I needed. First of all, I couldn't get the button to debounce consistently, but mostly it wouldn't work even if it did because the toggle command did not toggle the two LEDs simultaneously. It would toggle the first LED upon the button press and then toggle the second upon button release. It also seemed to loop if you held the button down. I'm using a non-latching momentary switch thas intended to be activated with your foot, so it's incredibly bouncy. And it's activating a dual latching relay. I'm using LEDs now just to verify the program. So both LEDs need to toggle simultaneously upon pressing the switch and not do anything at all when you hold the switch down.

I wrote my own debounce/toggle program. It sorta works. here's the thread: http://www.picbasic.co.uk/forum/showthread.php?t=19114

HenrikOlsson
- 24th March 2014, 20:19
Hi,

> First of all, I couldn't get the button to debounce consistently, but mostly it wouldn't work even if it did because the toggle command did not toggle the two LEDs simultaneously.
Out of curiosity....and for a possible learing experience, try putting a PAUSE 10 between the two TOGGLE commands and see what happens.

> It also seemed to loop if you held the button down.
Well, that is clearly documented in the manual. It's the autorepeat feature of the button command. Did you try changing the 40 to 255 as suggested earlier, that should have disabled the autorepeat.

With that said, I don't think I've ever used the button command so I'm just going by what the manual says. I'll pop over to the other thread and see if there's something I can help with there.

/Henrik.