Showing posts with label avr notes. Show all posts
Showing posts with label avr notes. Show all posts

Monday, 28 September 2009

AVR notes

Just ignore this, it's a NOTE

PWM


Timer 0, atiny45
1. Set output DDRB

2. Select mode TCCR0A1 -- WGM02:00

3. Select
inverting/non-inverting TCCR0A1 -- COM0A1:0 (for OC0A); COM0B1:0 (for OC0B);
+
output OC0A/OC0B

4. Select timer prescale TCCR0B--CS02:00

5. Register OCR0A for OC0A; OCR0B for OC0B




ADC

Timer 0, atiny45
1. Set output DDRB

2 .Eenable ADC ADCSRA-- ADEN

3. Select channel
+ ADMUX--MU3..0
differential gain

4. Reference Voltage ADMUX--REFS2:0

5. Select timer prescale ADCSRA--ADPS2:0 **between 50k-250kHz**

6. Register ADCH **store hi bit**
ADCL ** store low bit**

7. Start ADC ADCSRA -- ADSC

extra
8. Mode ADCSRB-- ADTS2:0

9. Set to 8bit ADC ADMUX |= (1<<> ADLAR) ** note1**

10. Interrupt flag ADSCRA--ADIF


note 1
This 10 bit value is split across two 8 bit registers, ADCH and ADCL. By default, the lowest 8 bits of the ADC value are found in ADCL, with the upper two being the lowest two bits of ADCH. By setting the ADLAR bit in the ADMUX register, we can left align the ADC value. This puts the highest 8 bits of the measurement in the ADCH register, with the rest in the ADCL register. If we then read the ADCH register, we get an 8 bit value that represents our 0 to 5 volt measurement as a number from 0 to 255. We're basically turning our 10 bit ADC measurement into an 8 bit one

taken from AVR freaks