Getting stuck at while

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

#define F_CPU 1000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "tc.h"
#include "led.h"

 

static void ticktimer_callback(void);

 

int main(void)
{
    tc_enable(&TCC0);
    tc_set_overflow_interrupt_callback(&TCC0, ticktimer_callback);
    tc_set_wgm(&TCC0, TC_WG_NORMAL);
    tc_write_period(&TCC0, 1000);
    tc_set_overflow_interrupt_level(&TCC0, TC_INT_LVL_LO);
    tc_write_clock_source(&TCC0, TC_CLKSEL_DIV1_gc);
 

    while (1){}
    
}

static void ticktimer_callback()
{
    LED_Toggle(LED1_GPIO);
    
}

 

The program is not coming out of while loop

Nitin Shenoy

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It will come out of the while loop when the 1 changes to 0.  Seriously, what did you expect to happen?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tried all that just here in this code I didn't mention it. The code automatically goes into the disassembly and gets stuck there.

Nitin Shenoy

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are you actually saying "the interrupt never triggers"?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Missing

cpu_irq_enable(); 

when comparing with http://asf.atmel.com/docs/latest...

/Lars

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yeah..basically thats what is happening

#include <avr/io.h>
#include "tc.h"
static void my_callback(void);

int main(void)
{
   pmic_init();
   sysclk_init();
   tc_enable(&TCC0);

   tc_set_overflow_interrupt_callback(&TCC0, my_callback);
   tc_set_wgm(&TCC0, TC_WG_NORMAL);
   tc_write_period(&TCC0, 624);
   tc_set_overflow_interrupt_level(&TCC0, TC_INT_LVL_LO);
   cpu_irq_enable();
   tc_write_clock_source(&TCC0, TC_CLKSEL_DIV256_gc);
   
   PORTR_DIRSET= 0x02;
                
    while (1) 
    {
    }
}

static void my_callback()
{
    
    if(TCC0.CNT == 624)
    {
        PORTR_OUTSET=0x02;
    }
    
    // User code to execute when the overflow occurs here
    //Important to clear Interrupt Flag
    tc_clear_overflow(&TCC0);
}

 

this is my new program

Nitin Shenoy

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

#include <avr/io.h>
#include "tc.h"
static void my_callback(void);

int main(void)
{
   pmic_init();
   sysclk_init();
   tc_enable(&TCC0);

   tc_set_overflow_interrupt_callback(&TCC0, my_callback);
   tc_set_wgm(&TCC0, TC_WG_NORMAL);
   tc_write_period(&TCC0, 624);
   tc_set_overflow_interrupt_level(&TCC0, TC_INT_LVL_LO);
   cpu_irq_enable();
   tc_write_clock_source(&TCC0, TC_CLKSEL_DIV256_gc);
   
   PORTR_DIRSET= 0x02;
                
    while (1) 
    {
    }
}

static void my_callback()
{
    
    if(TCC0.CNT == 624)
    {
        PORTR_OUTSET=0x02;
    }
    
    // User code to execute when the overflow occurs here
    //Important to clear Interrupt Flag
    tc_clear_overflow(&TCC0);
}

 

 

Still the same..

Nitin Shenoy