Go Down

Topic: Frequency in, modify, Frequency back out (Read 2306 times) previous topic - next topic


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. :) 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.. :) And if what I want to do is completely impossible with an Arduino, tell me that too.. ;) hehe.. Thanks guys.
Brian from Tacoma, WA
Arduino evangelist - since Dec, 2010.


Jan 21, 2011, 04:45 pm Last Edit: Jan 21, 2011, 04:50 pm by graynomad Reason: 1
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 Gray aka the GRAYnomad www.robgray.com


That makes sense. Thanks for the tips, gives me a good direction to look in. :)
Brian from Tacoma, WA
Arduino evangelist - since Dec, 2010.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131