Society of Robots - Robot Forum

Software => Software => Topic started by: blackbeard on November 28, 2009, 10:31:01 AM

Title: arduino frequency detection?
Post by: blackbeard on November 28, 2009, 10:31:01 AM
so i managed to transmit a box wave from an a434 transmitter with it's data connected to a shmidtt trigger oscilator composed of a 74ls14 ic, a 1uf capacitor and a 1k resistor with a 1k pot. the problem is i have no idea how to make the arduino detect that. what i would need is something that counts the frequency every 100 ms or so it can choose which servo (there's one on each side) moves faster. i can do the servo selection but what i don't know is the syntax for reading a frequency. it's a square wave that gets transmitted so that's what i'd need . admittedly i was tainted by BASIC before moving to the arduino.
Title: Re: arduino frequency detection?
Post by: hopslink on November 28, 2009, 11:07:05 AM
Frequency is the reciprocal of the period of the signal. To calculate a frequency measure the time period T for one cycle of your signal and calculate 1/T.

Better yet do not calculate frequency at all and just use the measured time period. Microcontrollers have timer hardware and timing thing is trivial operation. The division calculation is a lot of work (relatively) for a micro.
Title: Re: arduino frequency detection?
Post by: blackbeard on November 28, 2009, 08:07:16 PM
i'm more in need of syntax then calculations but thanks
Title: Re: arduino frequency detection?
Post by: hopslink on November 29, 2009, 11:53:44 AM
Here >CLICKY< (http://diydrones.ning.com/profiles/blog/show?id=705844%3ABlogPost%3A39393&page=1#c_de2) is a link to some arduino code to measure servo input pulse width. This should do what you want. You might have to tweak the timer settings depending on the frequency you are using. HTH

EDIT - sorry that link may be a sledgehammer to crack a nut. Have a look at the PulseIn command - it also does what you need. >Here< (http://www.arduino.cc/en/Reference/PulseIn)
Title: Re: arduino frequency detection?
Post by: blackbeard on November 29, 2009, 06:28:41 PM
awesome. it's working great!