AT32UC3C2512, Timer TC, problem with running channel 1

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello

 

I have problem with run channel 1 in AVR32_TC0. Channel 0 working good, but if i want run channel 1, timer is frozen and channel 0 also not working.  Init for channel 1 i have the same like in channel 0. Also i tried run only channel 1, not work.  Thank and regards 
here init timer and channels

#define TIMER_0                 (&AVR32_TC0)
//! \note TC Channel 0 is used.
#define TIMER_0_CHANNEL         0
//! \note IRQ0 line of TC0 module channel 0 is used.
#define TIMER_0_IRQ             AVR32_TC0_IRQ0
//! \note IRQ Group of TC0 module
#define TIMER_0_IRQ_GROUP       AVR32_TC0_IRQ_GROUP
//! \note Interrupt priority 0 is used for TC in this example.
#define TIMER_0_IRQ_PRIORITY    AVR32_INTC_INT0

#define TIMER_1_CHANNEL         1
//! \note IRQ0 line of TC0 module channel 0 is used.
#define TIMER_1_IRQ             AVR32_TC0_IRQ1
//! \note IRQ Group of TC0 module
#define TIMER_1_IRQ_GROUP       AVR32_TC0_IRQ_GROUP
//! \note Interrupt priority 0 is used for TC in this example.
#define TIMER_1_IRQ_PRIORITY    AVR32_INTC_INT0

void tc_irq(void)
{
	// Clear the interrupt flag. This is a side effect of reading the TC SR.
	tc_read_sr(TIMER_0, TIMER_0_CHANNEL);
	if(call_tick_DL!=0)
	{
		call_tick_DL();
	}

}

void tc_irq_chanel_1(void)
{
	// Clear the interrupt flag. This is a side effect of reading the TC SR.
	tc_read_sr(TIMER_0, TIMER_1_CHANNEL);
//  	static bool tmp = false;
//
// 	LedSet(LED0, tmp);
//  	tmp=!tmp;
}

bool timer_init(func_tick callback)
{
	// start init timer
	volatile avr32_tc_t *tc = TIMER_0;
	sysclk_enable_peripheral_clock(TIMER_0);
	cpu_irq_disable();

	INTC_init_interrupts();
	// Register the RTC interrupt handler to the interrupt controller.
	INTC_register_interrupt(&tc_irq, TIMER_0_IRQ, TIMER_0_IRQ_PRIORITY);
	INTC_register_interrupt(&tc_irq_chanel_1, TIMER_1_IRQ, TIMER_1_IRQ_PRIORITY);
	cpu_irq_enable();
	tc_init(tc);
	//end init timer
	//rejestracja wskaznika funkcji timera z datalinku
	if(callback != NULL)
	{
		call_tick_DL=callback;
	}
	return true;
}

void tc_init(volatile avr32_tc_t *tc)
{
	// Options for waveform generation.
	static tc_waveform_opt_t waveform_opt = {
		// Channel selection.
		.channel  = TIMER_0_CHANNEL,
		// Software trigger effect on TIOB.
		.bswtrg   = TC_EVT_EFFECT_NOOP,
		// External event effect on TIOB.
		.beevt    = TC_EVT_EFFECT_NOOP,
		// RC compare effect on TIOB.
		.bcpc     = TC_EVT_EFFECT_NOOP,
		// RB compare effect on TIOB.
		.bcpb     = TC_EVT_EFFECT_NOOP,
		// Software trigger effect on TIOA.
		.aswtrg   = TC_EVT_EFFECT_NOOP,
		// External event effect on TIOA.
		.aeevt    = TC_EVT_EFFECT_NOOP,
		// RC compare effect on TIOA.
		.acpc     = TC_EVT_EFFECT_NOOP,
		/*
		 * RA compare effect on TIOA.
		 * (other possibilities are none, set and clear).
		 */
		.acpa     = TC_EVT_EFFECT_NOOP,
		/*
		 * Waveform selection: Up mode with automatic trigger(reset)
		 * on RC compare.
		 */
		.wavsel   = TC_WAVEFORM_SEL_UP_MODE_RC_TRIGGER,
		// External event trigger enable.
		.enetrg   = false,
		// External event selection.
		.eevt     = 0,
		// External event edge selection.
		.eevtedg  = TC_SEL_NO_EDGE,
		// Counter disable when RC compare.
		.cpcdis   = false,
		// Counter clock stopped with RC compare.
		.cpcstop  = false,
		// Burst signal selection.
		.burst    = false,
		// Clock inversion.
		.clki     = false,
		// Internal source clock 3, connected to fPBA / 8.
		.tcclks   = TC_CLOCK_SOURCE_TC3
	};
	// Options for waveform generation.
	static tc_waveform_opt_t waveform_opt2 = {
		// Channel selection.
		.channel  = TIMER_1_CHANNEL,
		// Software trigger effect on TIOB.
		.bswtrg   = TC_EVT_EFFECT_NOOP,
		// External event effect on TIOB.
		.beevt    = TC_EVT_EFFECT_NOOP,
		// RC compare effect on TIOB.
		.bcpc     = TC_EVT_EFFECT_NOOP,
		// RB compare effect on TIOB.
		.bcpb     = TC_EVT_EFFECT_NOOP,
		// Software trigger effect on TIOA.
		.aswtrg   = TC_EVT_EFFECT_NOOP,
		// External event effect on TIOA.
		.aeevt    = TC_EVT_EFFECT_NOOP,
		// RC compare effect on TIOA.
		.acpc     = TC_EVT_EFFECT_NOOP,
		/*
		 * RA compare effect on TIOA.
		 * (other possibilities are none, set and clear).
		 */
		.acpa     = TC_EVT_EFFECT_NOOP,
		/*
		 * Waveform selection: Up mode with automatic trigger(reset)
		 * on RC compare.
		 */
		.wavsel   = TC_WAVEFORM_SEL_UP_MODE_RC_TRIGGER,
		// External event trigger enable.
		.enetrg   = false,
		// External event selection.
		.eevt     = 0,
		// External event edge selection.
		.eevtedg  = TC_SEL_EACH_EDGE,
		// Counter disable when RC compare.
		.cpcdis   = false,
		// Counter clock stopped with RC compare.
		.cpcstop  = false,
		// Burst signal selection.
		.burst    = false,
		// Clock inversion.
		.clki     = false,
		// Internal source clock 3, connected to fPBA / 8.
		.tcclks   = TC_CLOCK_SOURCE_TC3
	};
	// Options for enabling TC interrupts
	static const tc_interrupt_t tc_interrupt = {
		.etrgs = 0,
		.ldrbs = 0,
		.ldras = 0,
		.cpcs  = 1, // Enable interrupt on RC compare alone
		.cpbs  = 0,
		.cpas  = 0,
		.lovrs = 0,
		.covfs = 0
	};

	// Initialize the timer/counter.
	tc_init_waveform(tc, &waveform_opt);
	tc_write_rc(tc, TIMER_0_CHANNEL, (sysclk_get_pbb_hz() / 8 / TIMER_FREQUENCY)); // 10kHz
	tc_configure_interrupts(tc, TIMER_0_CHANNEL, &tc_interrupt);
	tc_start(tc, TIMER_0_CHANNEL);
	delay_ms(2);

	tc_init_waveform(tc, &waveform_opt2);
	tc_write_rc(tc, TIMER_1_CHANNEL, (sysclk_get_pbb_hz() / 8 / 100)); // 10Hz
	tc_configure_interrupts(tc, TIMER_1_CHANNEL, &tc_interrupt);
	tc_start(tc, TIMER_1_CHANNEL);
}

 

edit:
if this line is commented  
 

tc_init_waveform(tc, &waveform_opt2);

channel 0 working o_O

Last Edited: Thu. Jan 26, 2017 - 10:28 AM