dsPIC ECIO40P16 Timers, pulse counting, Gated Mode

For general Flowcode discussion that does not belong in the other sections.
Post Reply
jay_dee
Posts: 229
http://meble-kuchenne.info.pl
Joined: Sun Dec 20, 2020 6:06 pm
Has thanked: 92 times
Been thanked: 58 times

dsPIC ECIO40P16 Timers, pulse counting, Gated Mode

Post 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?

jay_dee
Posts: 229
Joined: Sun Dec 20, 2020 6:06 pm
Has thanked: 92 times
Been thanked: 58 times

Re: dsPIC ECIO40P16 Timers, pulse counting, Gated Mode

Post 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.

jay_dee
Posts: 229
Joined: Sun Dec 20, 2020 6:06 pm
Has thanked: 92 times
Been thanked: 58 times

Re: dsPIC ECIO40P16 Timers, pulse counting, Gated Mode

Post 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.

jay_dee
Posts: 229
Joined: Sun Dec 20, 2020 6:06 pm
Has thanked: 92 times
Been thanked: 58 times

Re: dsPIC ECIO40P16 Timers, pulse counting, Gated Mode

Post 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).
dsPIC_Gated_Timer_Test_Simple.fcfx
(32.24 KiB) Downloaded 249 times
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.

Post Reply