What can be a good solution for a very low speed counter? 2 pulse per sec.
loop:
If flagA=1 then goto check_low_pulse
If porta.o = 1 then flagA = 1
goto loop
check_low_pulse:
If porta.0 = 0 then
flagA=0
count1=count1 + 1
endif
goto loop
What can be a good solution for a very low speed counter? 2 pulse per sec.
loop:
If flagA=1 then goto check_low_pulse
If porta.o = 1 then flagA = 1
goto loop
check_low_pulse:
If porta.0 = 0 then
flagA=0
count1=count1 + 1
endif
goto loop
Hi,
The dawback of the "event counter" method is a very, very, very bad resolution ...
Sooo, the best would be to measure the period, and then convert it to speed.
Depends on your skills ... but a 16 Bits timer looks compulsory. The TMR1 of a 16F628a gives a 524288 µs period ( 1.907 Hz) with 1:8 prescaler enabled.
may be a bit "short" for what you intend to do; you should then have to increment a counter for each overflow ( interrupt ) ... and truncate some bits of TMR1 result, just to keep a 16bits word for your calculations.
a more precise explanation of what you're looking for will surely help ( Freq. range and precision required ... at least )
Alain
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
This might get you started.
I use this for counting parts passing on a conveyor where the parts hit a mechanical switch.
16F873A is used.
Near the top of your code
setup variables and other stuff thenCode:ON INTERRUPT GOTO MYINT INTCON = %10010000
PS.Code:LOOP: 'DO STUFF GOTO LOOP '############################################# 'PART COUNT '############################################ DISABLE MYINT: IF PORTB.0 = 1 THEN PC = PC + 1 WRITE 3,PC.BYTE0 WRITE 4,PC.BYTE1 READ 3,PCNT.BYTE0 READ 4,PCNT.BYTE1 pause 100 ELSE PC = PC ENDIF INTCON.1 = 0 RESUME ENABLE 'THE ABOVE WILL ALSO DEBOUNCE THE SWITCH '#############################################
What is that in your mouth?
Dave
Always wear safety glasses while programming.
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
Bookmarks