XMEGA Timer High Resolution Extension

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

Hi,

I've a little problem with the HI-RES freq generator on XMEGA and also looking the forums I'mn not able to resolve it.

I need to swap the frequency from 20Khz to 32Khz usind two ports on PORTC PC6 and PC7 with DTI.

For do this I calculate the CCABUF have to be set from 3199 (20Khz) to 1999(32khz).
I use the 32Mhz internal osc and the PLL like this:

I set CLOCK sys:

CLKSYS_PLL_Config( OSC_PLLSRC_RC32M_gc, 16 ); // 32MHz/4 x16 = 128MHz 
CLKSYS_Enable( OSC_RC32MEN_bm); // enable 32MHz RC osc 
while ( CLKSYS_IsReady( OSC_RC32MRDY_bm ) == 0 ); 
CLKSYS_Enable( OSC_RC32MEN_bm + OSC_PLLEN_bm );  
while ( CLKSYS_IsReady( OSC_PLLRDY_bm ) == 0 ); 
CLKSYS_Prescalers_Config( CLK_PSADIV_1_gc, CLK_PSBCDIV_2_2_gc ); 
CLKSYS_Main_ClockSource_Select( CLK_SCLKSEL_PLL_gc ); 

then I set freq generator like this:

ConfigDTI_Freq_PC6_7( DEAD_TIME_CYCLES );
HIRES_Enable( &HIRESC, HIRES_HREN_TC0_gc );
TCC0.CTRLB =  TC_WGMODE_FRQ_gc; 
TCC0.CTRLA = TC_CLKSEL_DIV1_gc;

and I Update the Frequency so:

TCC0.CCABUF = 3199 
do { } while( TC_GetOverflowFlag( &TCC0 ) == 0 );
TC_ClearOverflowFlag( &TCC0 );

but Writing 3199 I have on output a Frequency of 5Kz that swaps
writing 3198 I've 10khz that swaps
writing 3197 I've 15khz that swaps
and finally writind 3196 I've a stable frequency of 20Khz but writing 3195 the swap start again and so on!

without enabling the highres all runs well but I've low resolution so I'd like to use it.

Someone can help me and tell me why my frequency swap and start from 5khz? and not to 20k and with steps of 5khz?
What I wrong?

Thanks
Davide