Avr Xmega128-A1 Frequency Measurement

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
kkkkkk
 
Posts: 3
Joined: Wed Mar 26, 2014 2:52 am

Avr Xmega128-A1 Frequency Measurement

Post by kkkkkk »

Hi all, this is my first time using the atmel avr xmega-128A1 board. At the same time, using the avr dragon as the development tool.

I am trying out the project application of frequency measurement by AVR1617 document application. I wonder if anyone has tried this before? i have some questions to ask regarding its code. Appreciate any help that can be given!

Its main void code is as shown below. the rest of the codes are unchanged after download. I am trying to vary the result with constant changing of frequency, and trigger the LEDs accordingly.
I noted from the point that the result is = 1/4 of the actual frequency. But, no matter how i vary the frequency from function generator, the output on LEDs always hang at PORTE = 0xF0 no matter what was my input frequency. i have tested from 1kHz to 30kHz.

Would anyone be able to help this frequency measurement? Sorry i am rather new in this.

Much thanks!

Code: Select all

int main(void){
   PORTE.DIR = 0xFF; //Set as ouput, the 8 MSB of the result is output here 
   PORTE.OUT = 0xFF; //Default off for LED 

/*
 * For the best possible resolution of the results, the XMEGA clock frequency changed to 32 MHz.  
 * The function xmega_freq_cntr_start_meas() starts the TCCA counter and 
 * connects the signal to be measured with TCCB.  When the Gate Interval Timer, TCCA, reaches OVF,
 * then Event Channel 1 triggers an Input Capture of TCCB and also triggers a TCCA interrupt,
 * terminating the frequency measurement\n
 */
	
	cpu_clk_to_32_mhz();				// Changes XMEGA frequency to 32 MHz


	// Initialize frequency counter system

	xmega_freq_cntr_init();				// Initializes XMEGA timer/counters and Event System

	xmega_tcca_clk_freq_sel(CLK_SEL); 	// Selects the clock divider of TCCA.  In this example to 1/64 of CLKcpu.

	
	// Enter main application loop
		
	while(1){

		/* User Application code  */ 

		xmega_freq_cntr_start_meas();	// take a frequency measurement

		/* More User Application code */ 

		result = xmega_get_result(); // result available here

	//while(xmega_get_result() ==0){

		/* More User Application code here, if desired */ 
		//}			
			if(result < 20000)
			{
				PORTE.OUT = 0xF0;       //4 LEDs On
			}
			else
			{
				PORTE.OUT = 0x00;       //All 8 LEDs On
			}
			
	
		/*
			 At this point in the application code ,'result' is the sum of both positive and negitave edges
			 being counted. This makes the result double the actual frequency.  However, since the counting 
			 time interval is 1/8 second (125 milliseconds),  * the result must be both multiplied by 8 and 
			 divided by two, for a resulting multiplation factor  of four.  The 'result', above, is 1/4 of the 
			 actual frequency.  Thus a 16 bit result(2^16 -1) will allow frequencies up to 262143 (2^18 -1)
			 to be measured.
			
		*/
			
			
			xmega_freq_cntr_clr_result();// clears result coming from driver

		}	// end while(1)	
			
}	// Bottom of main()   

User avatar
Franklin97355
 
Posts: 23911
Joined: Mon Apr 21, 2008 2:33 pm

Re: Avr Xmega128-A1 Frequency Measurement

Post by Franklin97355 »

Have you tried it with the original, unchanged code and did it work?

kkkkkk
 
Posts: 3
Joined: Wed Mar 26, 2014 2:52 am

Re: Avr Xmega128-A1 Frequency Measurement

Post by kkkkkk »

No it didnt work because the value is being stored to result, not displayed anywhere. Making use of my board's features, i thought of using LEDs to identify the result.

kkkkkk
 
Posts: 3
Joined: Wed Mar 26, 2014 2:52 am

Re: Avr Xmega128-A1 Frequency Measurement

Post by kkkkkk »

One other thing was i checked the hardware and it was connected correctly to PORTD PIN0 (PD0) on my xmega-128A1. This was defined from the code by default to be the input signal.

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”