I am controlling an ADC with my Arduino Uno. I would like the clock of the ADC to be the same frequency of the Arduino. Is there any way that I can have a constant clock output from one of the Arduino pin ?
Thanks,
Liam
I am controlling an ADC with my Arduino Uno. I would like the clock of the ADC to be the same frequency of the Arduino. Is there any way that I can have a constant clock output from one of the Arduino pin ? Thanks, Liam |
|||||
|
This outputs 8 MHz on pin 9:
You change the prescaler bits. You can look at the datasheet or my cheat sheet here: You may not need a prescaler, depending on the frequency. Change OCR1A to some number between 0 and 65535 to slow it down.
Registers like TCCR1A and so on are defined in files which are automatically included by the Arduino IDE. If you use another toolchain they may be also automatically included. The start point is:
Inside that file it checks your processor type (from a symbol passed to the compiler) and then includes an appropriate sub-file. Inside those files are defines which relate the register names to their address in the address-space of that particular chip. For example:
The _SFR_MEM8 basically generates a pointer to a Notice that the number 0x80 in that define agrees with the number shown on my chart. Underneath that define in the appropriate file are also the bit positions for the bits in that register, like this:
Yes, in effect. The datasheet says that if you set the appropriate bits in TCCR1A (note the spelling) then OC1A (board pin 9 on the Uno) or OC1B (board pin 10 on the Uno) will be unchanged/toggled/cleared/set depending on the bits. You can find these names on the datasheet for the Atmega328P (and other devices) and then use the Arduino schematic to find which processor pins are connected to which board pins. Atmega328P datasheet snippet:Uno datasheet snippet:
Because every time the counter matches I want to flip the pin. That is, on/off/on/off etc.
Clear Timer on Compare. What this means is that (unlike other modes) once the compare match is made, the timer is cleared, thus it starts counting up from zero again. |
|||||||||||||||||||||
|
You can use one of the PWM pins on Arduino to output a PWM signal. If you want a constant clock, you need to set the duty cycle of the PWM to be 0.5, i.e. 50%. Syntax: analogWrite(pin, value) where the parameter "value" is the duty cycle ranges from 0 (always off) to 255 (always on) since it is a 8-bit PWM generator inside Arduino. If you need a PWM wave with duty cycle of 0.5, you need to set the "value" above to be 127, which is exactly in middle of 0 and 255:
|
|||||||||
|