Poll
Question: is it possible to use two timers of arduino at different frequency at the same time?
-- - 1 (100%)
-- - 0 (0%)
Total Voters: 1

Pages: [1]   Go Down
Author Topic: arduino timing problem  (Read 563 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My problem is this:


my ultrasonic transmitter is connected to the arduino I/o pin which outputs a pulse of 40 kHZ high and low by simple:

      digitalWrite (transmitterPin, HIGH); //sets the transmitter to 5 V
      delayMicroseconds (9); //first half cycle of 40kHz
      digitalWrite (transmitterPin, LOW); //sets the transmitter to 0 V
      delayMicroseconds (9); //second half cycle of 40kHz


my adc for the receiver needs a clock pulse of 4 MHz which I want to get from arduino also..


the problem is they have to run simultaneously... meaning while the transmitter is pulsing high and low of 40 kHz, the arduino should also ouptut 4 MhZ clock pulse to drive my ADC IC. WHat should i do?


Thank you
Logged

Ontario
Offline Offline
God Member
*****
Karma: 20
Posts: 835
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I would look at generating the 40 kHz signal with a hardware timer.  If you monkey with the pre-scaler you can probably get the tone library up in that range.  You can definitely get the AVR counter/timer hardware to do it.

To get a 4Mhz clock, I think you're going to have to use an external divider to divide down the 16 MHz system clock. If the 40 kHz and 4 Mhz clocks have to be synchronized, you might consider doing it all with a counter.  If the 40 kHz clock may be free running, you can use a 555 timer circuit to generate that without creating any load on the Arduino.
Logged

0
Offline Offline
Shannon Member
****
Karma: 162
Posts: 10496
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
To get a 4Mhz clock, I think you're going to have to use an external divider to divide down the 16 MHz system clock. If the 40 kHz and 4 Mhz clocks have to be synchronized, you might consider doing it all with a counter.  If the 40 kHz clock may be free running, you can use a 555 timer circuit to generate that without creating any load on the Arduino.

You can configure a 328 timer to generate the 4MHz - it needs to be set up with a prescaler of divide-by-1, TOP = 3, OCR=1 (or perhaps 2?) - but you'll need to mug-up on the timer control registers in the ATmega328p datasheet to do this.  I've a few notes that might help:

http://www.mythic-beasts.com/~markt/ATmega-timers.html
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thank you very much for the information .. smiley-grin
I appreciate it...
another follow up question....


what is the max frequency at which the gpio ports could read digital data?...

I just need to know because as I said, I need 1 MHz pulses for my 12-bit ADC which will return 12-bits digital output to be stored by the arduino?...

thanks..
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

another thing is that I will just need 1 MHz pulse instead of 4 MHz...  smiley

I think that would be easier. is there any way to directly output 1 MHz pulse from digital pin? I mean something like a function or library that could help me do it?...

So what i just need would be 1 MHz clock where I will use a counter to create 40 kHz

thank you
Logged

Pages: [1]   Go Up
Jump to: