Page 1 of 1
dsPIC ECIO40P16 Timers, pulse counting, Gated Mode
Posted: Tue Jul 06, 2021 10:46 am
by jay_dee
Hi,
The matrix guys previously helped me to use a Pin interrupt, CCP and timer functions in a PIC18 to accuratly count the period between pulses on an external pin. Moving to the dsPIC things look decidedly more complex... and lots more registers to work through.
Step one: I'm looking to monitor a pulse train and measure the pulse frequency.
Would starting and stopping timer1, using a interrupt still be a good approach.
I see there is a Gated Timer Mode, is this potentially more suited to my needs?
Re: dsPIC ECIO40P16 Timers, pulse counting, Gated Mode
Posted: Tue Jul 06, 2021 11:43 am
by jay_dee
I've got a rough proof of concept running using timer1 ... the registers were not as bad as I though and also robbed a load of setting from the microchip documentation example.
Still not really sure if this is the 'best' solution or if the Gated is a better solution by off loading some work to peripherals.
will play a bit more on the bench.
Re: dsPIC ECIO40P16 Timers, pulse counting, Gated Mode
Posted: Mon Jul 12, 2021 12:04 pm
by jay_dee
Hi,
The Gated timer function look like a good feature for me and just working on a bench test using a ECIO dsPIC.
The timer periferal function returns the time of a pulse on the T1CK pin. This is pin 48 (RC14) on the chip, whilst this is not broken out on the ECIO, I have a patch wire to the pin.
Within flowcode what is a sensible way to work with this pin, just for On/Off testing, within an ECIO40P16 base project?
Do I need to set it On/Off using C code?
thanks, J.
Re: dsPIC ECIO40P16 Timers, pulse counting, Gated Mode
Posted: Mon Jul 12, 2021 3:02 pm
by jay_dee
Hi,
The attached example 'counts' the width of a pulse using the Gated Timer function in some PIC's
Its a bit clunky but I used the code example from Microchip developer documentation and direct connected an input wire to the Chips T1CK pin (RC14).
In this simple bench test it does seem to be quite good at reporting the pulse width, in number of clock counts.
I have tested it from around 1kHz to 10kHz.
If you have slower signals you may need to increase the pre scale values or the number of timer counts may roll over the unsigned integer limit.
Slow signals = big timer count values.
Fast signals = smaller timer count values.
I quite like this method as it makes a periferal do the accurate work and leaves the main micro routine to get on with other less timing critical jobs.