-Bert
The glass is not half full or half empty, Its twice as big as needed for the job!
http://foamcasualty.com/ - Warbird R/C scratch building with foam!
Code:DEFINE OSC 4 @ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF CMCON=7 cnt VAR BYTE boton VAR GPIO.2 mosfet VAR GPIO.1 cnt = 0 CHECK: IF boton = 0 THEN TEST LOW mosfet GOTO CHECK TEST: IF cnt < 3 THEN OFF_MOSFET IF cnt => 3 THEN ON_MOSFET GOTO CHECK OFF_MOSFET: PAUSE 100 IF boton = 0 THEN low mosfet cnt = cnt + 1 ENDIF GOTO CHECK On_MOSFET: HIGH mosfet pause 1000 low mosfet cnt = 0 GOTO CHECK end
Dave
Always wear safety glasses while programming.
If you are setting the configs in code space comment that line out.
Dave
Always wear safety glasses while programming.
Hi Dave, yes thats it.
When I delete the first 2 lines "define ocs" and "@...", both codes compile ok.
Unfortunately, the behaviour is basicaly the same....they start with led off, and it should be on, more over, the counting is not regular, it depends in the speed of the click.
Some times, it goes off at 3, others at 5...etc....
I dont know....it is very over me.
I have tried to cut here and there taking ideas from both codes, but it does not work either.
I have to mention, that the clicks will be very fast, we could have posibly.......20 clicks per second, but we need to stop the mosfet after counting 3 clicks, hence the pause for 1 second.
I am sorry, my spanish brain is too tyre and can not speak properly.
Thanks for helping me guys.
Much appreciated.
Best regards.
You might not need the
DEFINE OSC 4
but it is a good idea to put it in. That is the line that tell PBP how fast the chip is running. I assume you are using the 4MHz internal.
The state of the mosfet/led depends on how you have the hardware setup. Just change the LOW/HIGH around to do what you want.
Like I said before. This will need a good denouncing routine to work correctly. Now that you say the button could be pressed at 20HZ even more so. What is going to press a button that fast?
Here are a couple of threads that might help you.
http://www.picbasic.co.uk/forum/showthread.php?t=13516
http://www.picbasic.co.uk/forum/showthread.php?t=2180
Read them all the way through.
Dave
Always wear safety glasses while programming.
Hi dave,
Thanks for your help, I will have a look at the links later.
Yes you are right, I am using the internal oscillator at 4 mhz.
The botton is pressed by a piston.
So I need to stop the piston after 3 pulses.
Thanks.
Bookmarks