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

Help w/ precise frequency

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







Help w/ precise frequency
PostPosted: Wed Nov 27, 2002 10:34 pm     Reply with quote

I'm working on interfacing an accelerometer to an 876, and I need to get a very precise frequency in order to measure the specific acceleration on the axis that I'm looking at. The problem is, I've spent too much time already trying to figure this out and I could really use some pointers - please. I need to pulse the accelerometer with 10.000 to 10.035 Hz, with a variable duty cycle. The frequency is very critical according to the manufacturer, and the duty cycle length will determine the amount of time the acceleration reading is available on the output which is why I want to vary it.

My dilemma is that obviously the frequency is extremely slow for a PIC, and using the PWM seems out since I'd have to clock at a max. freq of somewhere around 150kHz to get down to the 10Hz range.

Should I just be using delay_us and delay_ms commands? Will these give me the constant accuracy I need compared to the PWM pins?
___________________________
This message was ported from CCS's old forum
Original Post ID: 9551
Laurent chouinard
Guest







Re: Help w/ precise frequency
PostPosted: Thu Nov 28, 2002 10:25 am     Reply with quote

How about this:

1- You setup a timer to fire an interrupt at every 100 ms precisely.
2- in the interrupt service routine, you output a port, wait a number of ms (your duty cycle), and then lower the port, and get out of the interrupt.

I think this would be pretty solid as far as frequency stability is concerned.
___________________________
This message was ported from CCS's old forum
Original Post ID: 9581
R.J.Hamlett
Guest







Re: Help w/ precise frequency
PostPosted: Thu Nov 28, 2002 3:58 pm     Reply with quote

:=I'm working on interfacing an accelerometer to an 876, and I need to get a very precise frequency in order to measure the specific acceleration on the axis that I'm looking at. The problem is, I've spent too much time already trying to figure this out and I could really use some pointers - please. I need to pulse the accelerometer with 10.000 to 10.035 Hz, with a variable duty cycle. The frequency is very critical according to the manufacturer, and the duty cycle length will determine the amount of time the acceleration reading is available on the output which is why I want to vary it.
:=
:=My dilemma is that obviously the frequency is extremely slow for a PIC, and using the PWM seems out since I'd have to clock at a max. freq of somewhere around 150kHz to get down to the 10Hz range.
:=
:=Should I just be using delay_us and delay_ms commands? Will these give me the constant accuracy I need compared to the PWM pins?

The big question is what else you need to do while timing?. The delays are accurate, _provided_ nothing interrupts them. Also you would have to allow for the latency time involved in the I/O, and the loop. I answered a similar question a while ago, with regards to reading an input bit at mSec intervals, by using a hardware timer, and interrupt, which is what another poster has suggested. This will give accurate overall times, but will have slight 'jitter' because of the latency changes.
The most accurate output, will be to add an external divider, then use the timer2 output, feeding this. If you use a single /128 counter (readily available in CMOS), then this requires an incoming clock at 1280Hz for 10Hz output. Setting Timer2, to use the /16 divider (assuming you are using a 20Mhz clock), with a count value of 243 (244 counts), gives a frequency of 10.00576Hz decreasing the count by one, speeds this to 10.04693Hz, To get a finer resolution than this, would require you to effectively be running a 'longer' timer, with finer adjustment therefore available. Unfortunately, timer2, is the only internal timer with it's output directly available, and only has 8 adjustable bits, making finer resolution than this hard. The solution then would become one of adjusting an external divider to get finer resolution.
The interrupt solution gives finer frequency control, but at the expense of absolute accuracy on the individual cycles. You 'pays your money'...

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 9601
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: Help w/ precise frequency
PostPosted: Fri Nov 29, 2002 7:16 pm     Reply with quote

:=I'm working on interfacing an accelerometer to an 876, and I need to get a very precise frequency in order to measure the specific acceleration on the axis that I'm looking at. The problem is, I've spent too much time already trying to figure this out and I could really use some pointers - please. I need to pulse the accelerometer with 10.000 to 10.035 Hz, with a variable duty cycle. The frequency is very critical according to the manufacturer, and the duty cycle length will determine the amount of time the acceleration reading is available on the output which is why I want to vary it.
:=
:=My dilemma is that obviously the frequency is extremely slow for a PIC, and using the PWM seems out since I'd have to clock at a max. freq of somewhere around 150kHz to get down to the 10Hz range.
:=
:=Should I just be using delay_us and delay_ms commands? Will these give me the constant accuracy I need compared to the PWM pins?

I would set a timer to overflow at a fixed rate thats the inverse of the minimum frequency you want. When the timer interupts toggle the output and set the counter with a value thats determined in main. In main determine the counter value needed for desired timing while running other task.
___________________________
This message was ported from CCS's old forum
Original Post ID: 9634
John Yaron
Guest







Re: Help w/ precise frequency
PostPosted: Sat Nov 30, 2002 4:03 pm     Reply with quote

:=I'm working on interfacing an accelerometer to an 876, and I need to get a very precise frequency in order to measure the specific acceleration on the axis that I'm looking at. The problem is, I've spent too much time already trying to figure this out and I could really use some pointers - please. I need to pulse the accelerometer with 10.000 to 10.035 Hz, with a variable duty cycle. The frequency is very critical according to the manufacturer, and the duty cycle length will determine the amount of time the acceleration reading is available on the output which is why I want to vary it.
:=
:=My dilemma is that obviously the frequency is extremely slow for a PIC, and using the PWM seems out since I'd have to clock at a max. freq of somewhere around 150kHz to get down to the 10Hz range.
:=
:=Should I just be using delay_us and delay_ms commands? Will these give me the constant accuracy I need compared to the PWM pins?

use a DDS
___________________________
This message was ported from CCS's old forum
Original Post ID: 9643
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