PDA

View Full Version : Counter



brenda
- 26th October 2008, 19:01
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

Acetronics2
- 26th October 2008, 19:28
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

mackrackit
- 27th October 2008, 08:35
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


ON INTERRUPT GOTO MYINT

INTCON = %10010000

setup variables and other stuff then


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
'#############################################


PS.
What is that in your mouth?

Acetronics2
- 27th October 2008, 08:51
PS.
What is that in your mouth?


Ohoh, Dave

Did not recognize the strawberry ??? ...

yours to offer the Champagne, then

Alain

But keep cool , the photo surely is not Brenda's ...

mackrackit
- 27th October 2008, 08:57
Ohoh, Dave

Did not recognize the strawberry ??? ...

yours to offer the Champagne, then

Alain

But keep cool , the photo surely is not Brenda's ...

Now I see it.

Must be a sour one.