Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Another Counter Question

Status
Not open for further replies.

Spasm

New Member
Hey all,

I have a question here regarding counting square waves or counting pulses program using a microcontroller. I need to the count the amount of changes (in this case it might be the transition of the wave signals from high to low ; low to high) for a microC input based on a one minute time. etc. pulses per minute. Therefore, has anyone done a similar counting program? How should the microC count the 1 minute and still able to receive the count of pulses in that period? Need some ideas on counting them precisely based on a 1 minute period.

Thanx
 
Timed pulse count

You need to set up the micro to give a 1minute period. This is easily done because any(?) micro has a built in timer counted down from its oscillator. It will also have a 'timer interrupt' facility. With this, you can enable the timer interrupt so that when the internal register loops round to zero it will cause the program to be halted and the diverted temporarily to an interrupt routine.

You can write this routine so that a register is decremented each time the routine is entered. When this register gets down to zero, a flag can be set. You arrange for the timer register(s) and multiplier so that the flag sets in precicely 1minute.

Your program would start by starting the 1minute timer. It then does a short loop of counting the pulses (seeing a 0 then a 1) at the input where you are applying the pulses, while checking to see if the timer flag is set. It counts pulses by incrementing a register (or cascaded registers if the count is more than 255).

At the end of the 1minute period, the registers are read to give the count.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top