Hello Arduino Universe.
I'm figuring out how to use Assembly within the Arduino IDE... turns out the underlying libraries made some provisions to use Assembly directly.
Anyway, I'm trying to access the 16bit Timer1 PWM on the USBoarduino (from Adafruit) ATmega328P. I have the datasheet in front of me and I'm reading all the instructions on how to turn on this bit and turn off that bit...etc
I got the chip to do the following:
-read a potentiometer on A0,
-copy the value into OCR1A, and ICR1 registers
-TCNT1 seems to be counting up and down based on the OCR1A, ICR1 values..
however there is no State Change on the designated PWM pins (D8, D9 on the USBoarduino)
Do I really have to write an interrupt routine to toggle the appropriate pins every time there is a Compare Match happening?
what am I missing?
here's some fun code:
#include <avr/io.h> //added these libraries to make sure I can use predefined Assembly code... probably redundant.
byte PinA0 = A0;
word pot1 = 0x0003; //minimum resolution is 3.
byte PB1 = 8;
byte PB2 = 9;
cbi(TCCR1B,CS12); //set prescaler to 1 on Timer1
sbi(TCCR1B,WGM13); //enable PWM, Phase and Frequency Correct. using ICR1A
sbi(TCCR1A,COM1A1); //set OC1A on Compare Match when up-counting
sbi(TCCR1A,COM1B1); //set OC1B on Compare Match when up-counting
sbi(DDRB,DDB1); //extra redundant here
pinMode(PB1, OUTPUT); //arduino pin8 = PB1 = OC1A
sbi(DDRB,DDB2); //extra redundant here
pinMode(PB2, OUTPUT); //arduino pin9 = PB2 = OC1B
pot1 = analogRead(PinA0);
OCR1A = pot1;
ICR1 = pot1;