PDA

View Full Version : Counting Events PIC18F8722



Bill Legge
- 30th August 2009, 11:53
It's a weather station - and I'm measuring wind speed using an anemometer.

The anemometer counts the pulses that occur in 3.6 seconds and this gives the wind speed in kph.

I want to do this 'in the background' whilst the MCU gets on with other tasks.

I am already using an ASM interrupt 'INT0' to count 'bucket-tips' for rainfall as a background process.

The station runs on a PIC18F8722 mcu.

Any advice/ideas on making the count a background process?

Regards Bill Legge

Jumper
- 30th August 2009, 12:35
Setup a timer as a counter with an external clock input T*CKI pin. Then you just need to reset the counter to 0 and after 3.6 sec you stop the counter and read the value when you have time for it.

How to know 3.6 seconds have passed is an other problem. Maybe you already have a timer running as RTC or you set up a timer to overflow after 3.6 sec. When the 3.6 s timer overflows you get an interupt and then you disable the counter clock input. If you set a flag in the 3.6 s timer interupt you can easily know that you have new valid data to be read from the counter register.

Bill Legge
- 31st August 2009, 01:32
Jumper,

Thanks for the idea.

Is there a simple/easy way to see what MCU resources the PBP compiler is using so that I don't use timers/registers/etc that will conflict?

Regards Bill Legge

Jumper
- 31st August 2009, 02:17
As far as I know you ned to keep track of what HW timers and counters you use your self :-) One thig to keep in mind is that if you use the HPWM in your pic that also steals a timer, usually timer 2.

I hope you use DT's instant interupts since that is the only way in PBP to get the interupts to be performed when the happen and not as in PBP's usual way after the current command is executed.

I would set up a timer to overflow every 0,1 sec as a RTC timebase and use that one to get the 3.6 sec (by increasing a variable in the interupt routine). By doing this you can have many events with different times beeing executed.