Pages: [1]   Go Down
Author Topic: Frequency in, modify, Frequency back out  (Read 1057 times)
0 Members and 1 Guest are viewing this topic.
Tacoma, WA
Offline Offline
Full Member
***
Karma: 4
Posts: 192
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm still a newb, so let me start with what I'd like to do, and then I'll move onto my guess as to how I need to do it (it's a real rough guess..)
What I want to do is read in a frequency, divide that frequency by 1000, then multiply it by a user definable amount, something like 923, and then output the new frequency on another pin.
Both the incoming and outgoing signals would be a fixed 50% duty cycle. The frequency would be between 2hz and 200hz, I'd prefer .1hz resolution on both the input and output.
I found a library that uses Timer2 to get the incoming frequency. Much of how it works is well over my head, but as I understand it, the timer just causes a recurring interrupt on a time specific table, so that you can accurately time the high and low input events on a pin. Do I have that right?
Now for the output, would I use Timer1? Can I use Timer1 and Timer2 at the same time? Or would I just schedule the output along with checking the input on the same Timer1?
I believe the kind of output I'd be doing at this point would be referred to as bit-banging, because I'd be manually changing the pin state based on the timer, rather than using a PWM output. Sounds like the PWM outputs are not what I need, because I only need 50% duty cycle, and the Frequency selection is very limited.
What am I trying to build? Electronic speedometer correction device.. If your tires are 7.3% too tall, put this in between the speedo and the speed sensor, and it'll correct the speed. It's an 8000pulse per mile sensor, so that's where I get the 2-200hz (2.2hz=1mph and 222hz is 100mph). If someone has already written something like this, point me to it please. smiley If there's a library for the kind of output I'm trying to get (something like an analogWrite(frequency) rather than analogWrite(duty cycle)) point me to that too.. smiley And if what I want to do is completely impossible with an Arduino, tell me that too.. smiley-wink hehe.. Thanks guys.
Logged

Brian from Tacoma, WA
Arduino evangelist - since Dec, 2010.

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8461
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

2-200 Hz is pretty slow so you could bit bang the OP as you say.

You don't have to know the frequency, it's easier to measure the period.

Every say 1/2 second you could use pulseIn() to get the IP period, do your maths, and use the result to periodically toggle the OP pin.

I would hang the OP pulse generation off a timer interrupt and have the pulsIn() in the main loop.

______
Rob

« Last Edit: January 21, 2011, 10:50:38 am by graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

Tacoma, WA
Offline Offline
Full Member
***
Karma: 4
Posts: 192
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

That makes sense. Thanks for the tips, gives me a good direction to look in. smiley
Logged

Brian from Tacoma, WA
Arduino evangelist - since Dec, 2010.

Pages: [1]   Go Up
Jump to: