Reputation: 1
From
http://www.electronicsplanet.ch/mikrocontroller/source-code/ATMega16/ATmega16-ADC-Interrupt.htm
I tried the initialisation of the AD of the mega16. It works, but the line
ADCSRA |= (1<<ADEN)|(1<<ADPS2) // Enable ADC, set prescaler to 16
|(1<<ADIE); // Fadc=Fcpu/prescaler=1000000/16=62.5kHz
// Fadc should be between 50kHz and 200kHz
// Enable ADC conversion complete interrupt
is not clear to me. Where does the 1000000 come from and what des it means?
thanks!
Upvotes: 0
Views: 178
Reputation: 111
1000000 Hz is the clock frequency of the device running.
By default, the mega's will run on an internal 8 MHz RC oscillator with clk/8 fuse set, making the default frequency as 8MHz/8 = 1MHz
Hence you are seeing FCPU as 1000000.
Upvotes: 1
Reputation: 4893
The prescaler means how is the main clock divided, to provide the clock for the ADC. The clock for the ADC is provided from the main clock, with an optional prescaler. In the example, the 1000000 means that the main clock frequency of the microcontroller is 1 MHz. If the prescaler is set to 16, the frequency of the ADC will be 1000000/16 = 62.5kHz.
Of course, if your main clock is different, you have to calculate your own frequency for the ADC.
Upvotes: 1