Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
and-re
PostPosted: Jun 03, 2012 - 08:09 PM
Rookie


Joined: Jan 28, 2012
Posts: 37


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
      
    }
}
 
 View user's profile Send private message  
Reply with quote Back to top
and-re
PostPosted: Jun 03, 2012 - 08:26 PM
Rookie


Joined: Jan 28, 2012
Posts: 37


Oh and I almost forgot, I am using the timer as PWM signal and overflow interrupt, but that shouldn't be an issue since the overflow frequency is the same as the PWM frequency...
 
 View user's profile Send private message  
Reply with quote Back to top
larryvc
PostPosted: Jun 03, 2012 - 08:51 PM
Raving lunatic


Joined: Dec 06, 2007
Posts: 2512
Location: Redmond, WA USA

and-re wrote:
Hi, I am using an Atmega168A and debugging with AVR Studio 5. For some reason, when I debug...

Are you using the simulator to debug?

I suggest that you upgrade to Atmel Studio 6. Studio 5 is very buggy.

_________________
Larry

Those afraid to embrace the future will quickly fade into the past. - larryvc
 
 View user's profile Send private message  
Reply with quote Back to top
and-re
PostPosted: Jun 04, 2012 - 02:00 PM
Rookie


Joined: Jan 28, 2012
Posts: 37


I'll try that but I already used a timer overflow interrupt before and the simulator worked fine (though it was with an Atmega8).
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits