CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PIC24 Capture Input Capability/Gotchas

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
demedeiros



Joined: 27 Dec 2013
Posts: 69

View user's profile Send private message

PIC24 Capture Input Capability/Gotchas
PostPosted: Thu Dec 21, 2023 2:48 pm     Reply with quote

Hi all,

I have an application where I need to measure the amount of time between 3 or 4 sequenced signals. They are all digital, rising edge signals, time between rising edges to be approximately 5-50uS.

I did some initial experimentation and was able to measure fairly reliably using the CCP inputs (2 of them) on a PIC16F1829. If I understand the datasheet correctly, the capture module is using Fosc/4 (20MHz/4) for the timing values.

If I move to a PIC24 or dsPIC it seems as though I can operate at up to 32MHz and that the capture modules on these use Fosc/2. Is that correct?

Using 32MHz/2 = 16MHz, that gives me a time value of 62.5nS per count. This gives me approximately 80counts at my worst case of 5uS.

We had initially thought about using a small FPGA, but we think this is well within the wheelhouse for a microcontroller.

First, is my math right, and second, is this a reasonable way to go about this? Is there anything specific I should worry about with this approach?
temtronic



Joined: 01 Jul 2010
Posts: 9117
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Dec 21, 2023 3:09 pm     Reply with quote

just 'randoml' thoughts...

the 1829 can go 32MHz, which may help you....

you might have the 1829 JUST do the 'front end' capture and signal a bigger PIC to do all the rest. PICs are cheap today and 'offloading' could be better ?

A lot of cycles can get used up when doing ISR (overhead...etc)

possible options.......
newguy



Joined: 24 Jun 2004
Posts: 1903

View user's profile Send private message

PostPosted: Thu Dec 21, 2023 3:30 pm     Reply with quote

The PIC24 or dsPICs do indeed run with 2 oscillator cycles per internal instruction cycle, so yes Fosc/2 as opposed to the 8 bits PICs which are 4 oscillator cycles per instruction cycle.

It sounds like you have a good grasp on what's required - you should be fine when you attempt to port your experiment to the 16 bit family. Only word of caution is that you should be very explicit with variables, down to explicitly declaring all variables as either signed or unsigned. That's a bit of a gotcha with CCS: for 8 bit processors the types by default are unsigned, but for 16 bit processors the types are signed by default.

I learned this the hard way when I too migrated a proof of concept from an 8 to a 16 bit processor - and nothing worked. Once I figured out why, every line of code I've written since always has the type explicitly spelled out....just in case I ever need to migrate from one to the other ever again.
demedeiros



Joined: 27 Dec 2013
Posts: 69

View user's profile Send private message

PostPosted: Thu Dec 21, 2023 7:09 pm     Reply with quote

temtronic wrote:

you might have the 1829 JUST do the 'front end' capture and signal a bigger PIC to do all the rest. PICs are cheap today and 'offloading' could be better ?


Thats a good idea that I hadn't thought about. Although, with the 1829 i'd at best get 125nS/cnt vs 62.5nS/cnt. Will evaluate and see if this will suffice. The current work with the 1829 was just a proof of concept, still much left to decide.
demedeiros



Joined: 27 Dec 2013
Posts: 69

View user's profile Send private message

PostPosted: Thu Dec 21, 2023 7:12 pm     Reply with quote

newguy wrote:
The PIC24 or dsPICs do indeed run with 2 oscillator cycles per internal instruction cycle, so yes Fosc/2 as opposed to the 8 bits PICs which are 4 oscillator cycles per instruction cycle.

It sounds like you have a good grasp on what's required - you should be fine when you attempt to port your experiment to the 16 bit family. Only word of caution is that you should be very explicit with variables, down to explicitly declaring all variables as either signed or unsigned. That's a bit of a gotcha with CCS: for 8 bit processors the types by default are unsigned, but for 16 bit processors the types are signed by default.

I learned this the hard way when I too migrated a proof of concept from an 8 to a 16 bit processor - and nothing worked. Once I figured out why, every line of code I've written since always has the type explicitly spelled out....just in case I ever need to migrate from one to the other ever again.


Thanks, I appreciate the heads up. Thankfully there was little reusable code written on the 1829. It was just a quick and dirty test.
Ttelmah



Joined: 11 Mar 2010
Posts: 19231

View user's profile Send private message

PostPosted: Fri Dec 22, 2023 1:21 am     Reply with quote

Consider doing a search for TDC chips.
These do exactly this. They give a digital readout of time between two
signals. Some give nSec reolutions.
It really does depend on how much accuracy you need. As others have
said, you can switch to faster chips, and gain another factor of 2* with
the DsPIC's. However if theseare not accurate enough, the dedicated
TDC will surpass either.
temtronic



Joined: 01 Jul 2010
Posts: 9117
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Dec 22, 2023 7:00 am     Reply with quote

Mr T has a better solution !
Sounds like you need a 4 channel TDC 'chip' as the 'front end'.
If this is for a 'home use' then time/money isn't a factor BUT if for a commercial product you need to 'do the math'.
My rough math...
Say it take 40 hours to get a PIC to be a TDC. 40hr x $100 = $4000 in R&D costs. If and 'off the shelf' 4ch TDC costs $10, you can buy 400 pieces of known ,working chips. Even at $20/unit, it's still better. Even if you add in R&D for the TDC unit at 1/4 of 'roll your own' , you'd get 100 pieces WORKING.
You'll also probably save a LOT of time( and time IS money ), 'free' time to do other stuff !!

just an option you should consider
demedeiros



Joined: 27 Dec 2013
Posts: 69

View user's profile Send private message

PostPosted: Fri Dec 22, 2023 11:06 am     Reply with quote

Thanks all, I really appreciate the help!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group