Hi, I am using an Atmega168A and debugging with AVR Studio 5. For some reason, when I debug, the overflow ISR never gets reached... Though, when I tested with a different ISR (a compare for example) instead it works.
Thanks.
Code:
/*
* myhexapod.c
*
* Created: 28/05/2012 4:10:47 PM
* Author: Team30
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdint.h>
#include <stdbool.h>
#include <util/delay.h>
#define F_CPU 8000000ul
#define MAX_SERVOS_MUX 6
#define PERIOD 2499
#define PERIOD_END 7499
volatile uint16_t servoBody[MAX_SERVOS_MUX] = {2000, 1000, 1500, 1500, 1500, 1500};
volatile uint16_t servoCoxa[MAX_SERVOS_MUX] = {1500, 1500, 1500, 1500, 1500, 1500};
volatile uint16_t servoTibia[MAX_SERVOS_MUX] = {1500, 1500, 1500, 1500, 1500, 1500};
volatile uint8_t j;
ISR(TIMER1_OVF_vect) {
//time the period of each selection
if (++j < 5) {
ICR1 = PERIOD;
//select demux
PORTD = j << 5;
OCR1A = servoBody[j];
}
else {
ICR1 = PERIOD_END;
//select demux
PORTD = j << 5;
OCR1A = servoBody[j];
j = 0;
}
}
void initialize() {
DDRB = 0b000000110;
DDRD = 0xff;
//setting PWM
TCCR1A = (1<<WGM11)|(0 <<WGM10)|(1<<COM1A1)|(1<<COM1A0);
TCCR1B = (1<<WGM13)|(1<<WGM12)|(1<<CS11);
ICR1 = PERIOD;
OCR1A = servoBody[j];
TIMSK1 |= (1<<TOIE1);
TCNT1= 0;
}
int main(void)
{
initialize();
sei();
while(1)
{
uint8_t k = 8;
//TODO:: Please write your application code
}
}
|