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 CCS Technical Support

Arrival Time - CCP

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



Joined: 25 Feb 2017
Posts: 6

View user's profile Send private message

Arrival Time - CCP
PostPosted: Sat Feb 25, 2017 12:20 pm     Reply with quote

Hello everyone,

I am looking into PIC & CCS to measure arrival time of two input signals.

Never did PIC before but coming in from much higher-level language. From my research into many posts on this forum along with source codes and CCS examples, seems CCP is the way to go. Choice of PIC probably will be one of the latest 18Fs, maybe K40s. Running internal 64Mhz. Compiler will be the latest.

The final output is deviation in degrees between the two signals. Two signals, coming in from two separate rotors. Rotation should be identical and synced. So rising edge in both pins should match, meaning happen at the same timer value. Time between rising edges should match and of course number of rising edges (pulses) per second are the same, Signals are between 5 & 50Hz

So plan is to setup CCP1 & 2 for RE, copy both captured values; keep older captured values so we can get the frequency; raise a flag that both interrupts serviced to indicate we have two valid timing signatures; compare both then convert to degrees (from 360) if more than the allowable error difference. Also, deal with the fact the clock is too fast for timer overflow.

Just to conclude the research that this can be done easily with CCP; so wanted to check with you guys if I am missing something or my plan above may lead to a surprise?!

My second part of the query is about SMT1/2. Looks like these chips have something called SMT (Signal Measurement Timer) already a 24-bit timer and comes with a Time-Of-Flight feature in hardware level. I couldn't find examples or source code to see for these timers, probably as being new features. So wanted to check if these already supported in CCS compilers and registers/settings are mapped!. Was hoping not to go even lower-level than CCS (no pun intended!)

Thanks for everyone's comments/suggestions and contribution.
temtronic



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

View user's profile Send private message

PostPosted: Sat Feb 25, 2017 1:04 pm     Reply with quote

Frankly almost ANY PIC will do the task as 50Hz is, well, sloooooooooooow.
The detail you need to work out is a CLEAN signal to the PIC from the rotors. Real good fast rise/fall times on the edges,aka signal conditioning.
Heck even a 16F84 at 4MHz would probably work for you.
One thing is to NOT use floating point math. It is a huge time killer and unecessary, just use unsigned long integers. Do comparisions on raw data NOT converted numbers. It's easy to 'scale' the integers to say 36000 is 360.00*.

There are several ways to accomplish your task, but first, choose a PIC, get the 1Hz LED program to run, then one rotor, then the other, then.....build upon small steps !


Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Sat Feb 25, 2017 3:01 pm     Reply with quote

Only a couple of PIC16's have the SMT.
Restricts massively the other features you have available.

Most of the PIC24/30's have CCP's, supporting up to 32bit operation, which makes this redundant. This is why they don't need/have such features.

Honestly as Temtronic has already said, almost any PIC could do what you describe. Personally choose one of the modern 'mid range' PIC18 chips with lots of extra features, then you'll find it easier to do whatever else you actually need. Something like a 18F25K22. Plenty of ROM, plenty of RAM, cheap, five CCP modules, supporting multiple timers (makes it easier if you want to go to more channels), couple of UARTs etc. etc..
temtronic



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

View user's profile Send private message

PostPosted: Sat Feb 25, 2017 3:25 pm     Reply with quote

Mr T's right.... I have to admit I now use the 18F46K22 as my 'Swiss Army Knife' of PICs. Seems to have more 'under the hood' than any project I can dream up needs. While it may cost a $1 or 2 more than a 'bare bones' PIC, you always need another I/O pin, timer, 6 more bytes of RAM,.... Having 2 HW UARTS is GREAT too !
Also if you standardize on one PIC, you'll soon develop your own libraries of WORKING code and NOT have to spend days trying to decide why this or that doesn't work on the new PIC ONLY to find out 'someone' reversed the bit logic.......argh.

Jay
Rob1955



Joined: 25 Feb 2017
Posts: 6

View user's profile Send private message

PostPosted: Sat Feb 25, 2017 7:48 pm     Reply with quote

Thanks guys. Appreciate the input.

Yes, agree about standardization. The one i mentioned above 18FxxK40 does have SMT, 5 UARTs, almost everything else! the lot really.

Glad this is easily done in PIC so i guess time to roll up the sleeves and get it done.
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Sun Feb 26, 2017 1:39 am     Reply with quote

I was assuming if this was a small unit, that something rather less 'big' might well be worth using. The K40, is very much an overkill for what you describe (nothing wrong with that), but 'beware' a lot of the relatively new PIC's have many errata, the key thing about the K22 family, is that they 99.9% 'work'...
Very Happy
NAR



Joined: 01 Dec 2016
Posts: 17
Location: IL, USA

View user's profile Send private message

PostPosted: Sun Feb 26, 2017 3:06 pm     Reply with quote

I think even if overkill; if the design can handle not having a DIP version for fast prototyping and changes; then go for the overkill. Also, having a 'big' RAM/ROM chip makes it more forgiving to less-experienced programmers towards variables and RAM management.

This is the chip I am using now. Design started with two K22 (4 HW UART needed) but then decided to test single 18F66K40 so field firmware update is easier. Lost most of my hair last month thinking issues are in my code (as usual) or the board design, but then CCS fixed compiler/programmer for this PIC family.

Now the PIC handles 4 HW UART, including one Bluetooth. I2C for external memory, SPI for MCP2515 CAN network, two CCP and one PWM out for control. I just finished Bluetooth boot loader. OTA firmware update for the PIC using an iPad is amazing to watch, its like geek's fantasy Laughing

Seeing it flash 40% of the that chip ROM in about 90 seconds is cool; makes you forget 90 seconds is some what slow compared to hard-wired!
Rob1955



Joined: 25 Feb 2017
Posts: 6

View user's profile Send private message

PostPosted: Mon Mar 13, 2017 12:00 am     Reply with quote

Thank you all for your contribution.

I did cover some grounds since. Got the prototype PCBs built and we are using 5.070 compiler now. Testing with both 18F26K22 and 18F65K40.

With the generous code being offered here, managed to get things almost working with CCP extended 24-bit timer1 per PCM Programmer code (Thank you).

Then i discovered CCS already have SMT example for the 65K40. They released it about two months ago!. SMT getting the period, duty cycle and time between rising edges (or falling) of two signals using one line code interrupt.

Just wanted to let anyone seeing this thread to consider SMT if they are looking for a standard or even sophisticated signal measurements options. CCS compiler now supports all options for SMT built-in.

And to be better for math, the 65K40 can use 500 kHz or 31.25 kHz secondary internal clock as the source for the 24-bit SMT timer! Truly overkill for my 50hz top requirements but better than when i was using CCP with 64Mhz clock, even with Div_by_8, its still 0.5 us per timer tick!
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