Hi,
I'm programming an ATMEGA16 Microcontroller.
This what I am trying to do:
I need to output a 50Hz PWM Signal to control a servo. I want to vary the pulse width from 800uS to 2200 uS by using push buttons with deboucing. I also need to display the actual pulse width on 7 segments displays. Another feature is that if I keep the button pressed after 2 seconds (let's say) the pulse widh should start incrementing/decrementing by 1 until I unpress the button.
This is the code fragment I used to set the pwm signal:
TCCR1A |= 1<<WGM11 | 1<<COM1A1;
TCCR1B |= 1<<WGM12 | 1<<WGM13 | 1<<CS11;
ICR1=19999; //set ICR1 to produce 50Hz frequency
//(8000000 / 8 / 20000 = 50hz)
OCR1A = 1000; //set a position for the servo
I know how to display a certain value on displays. As I have four 7-segments displays (with just one port for data) I need to set a delay for Multiplexing the displays. In general, I know how to control peripherals.
My question is: When it comes to combine all the features (displays, debouncing, pwm signal, etc) in one main code, what should I take into account? Do I need interrupts or something special? Should I use interrupt instead of _delay_ms(ms) for the delay?
I am starting to learn how to program AVRs, and I do not have much experience in C programming. So I am trying to learn basic things first.
Thank you.
I'm programming an ATMEGA16 Microcontroller.
This what I am trying to do:
I need to output a 50Hz PWM Signal to control a servo. I want to vary the pulse width from 800uS to 2200 uS by using push buttons with deboucing. I also need to display the actual pulse width on 7 segments displays. Another feature is that if I keep the button pressed after 2 seconds (let's say) the pulse widh should start incrementing/decrementing by 1 until I unpress the button.
This is the code fragment I used to set the pwm signal:
TCCR1A |= 1<<WGM11 | 1<<COM1A1;
TCCR1B |= 1<<WGM12 | 1<<WGM13 | 1<<CS11;
ICR1=19999; //set ICR1 to produce 50Hz frequency
//(8000000 / 8 / 20000 = 50hz)
OCR1A = 1000; //set a position for the servo
I know how to display a certain value on displays. As I have four 7-segments displays (with just one port for data) I need to set a delay for Multiplexing the displays. In general, I know how to control peripherals.
My question is: When it comes to combine all the features (displays, debouncing, pwm signal, etc) in one main code, what should I take into account? Do I need interrupts or something special? Should I use interrupt instead of _delay_ms(ms) for the delay?
I am starting to learn how to program AVRs, and I do not have much experience in C programming. So I am trying to learn basic things first.
Thank you.