XMega 32E5 XCL Input Capture

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

Hi, I'm trying to use the 32E5 XCL 16bit timer to measure pulse widths and decode a RFID card that outputs manchester code.

The problem is that I simply can't get the XCL input capture working. Below is the code that I'm using to start the peripheral.

xcl_enable(XCL_SYNCHRONOUS);
xcl_port(PD);
xcl_tc_type(TC16);
ioport_set_pin_dir(ASK_FSK,IOPORT_DIR_INPUT);
ioport_set_pin_sense_mode(ASK_FSK,IOPORT_SENSE_BOTHEDGES);
xcl_tc_mode(XCL_TCMODE_CAPT_gc);
xcl_tc_set_compare_capture_interrupt_level(XCL_INT_LVL_HI);
EVSYS_SetEventSource(0,EVSYS_CHMUX_XCL_CC0_gc);
xcl_set_cc_interrupt_callback(CallbackTestFunc);
xcl_tc16_enable_cc_interrupt();
xcl_tc_source_clock(DIV1);

The CallbackTestFunc should blink an LED when an input capture happens and clear the interrupt flag.

void CallbackTestFunc(void)
{
	xcl_tc16_clear_cc_interrupt();
	ioport_toggle_pin_level(LED_GREEN);
}

Could someone help me ? What I'm missing ?

Thanks!

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

Quote:
What I'm missing ?
Someone who knows how to help you. :?

I have been using the E5 for about 6 months but only used the bare minimum I needed for my project.

There is possibly something in the ASF about it but I can't be bothered even trying to make any sense of it as it may have several dozens of files for something which only needs a dozen lines of code maybe.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Old thread, but I couldn't find any good solutions to Pulse Width capture with the xmegaE5 on the forum so I thought I'd post my solution.  I set up TCC4 to produce a pulse at 1.5ms period with pulse width set by TCC4.CCD so I could test the input capture on TCC5(externally wired output of TCC4 to input for TCC5 to test).  TCC5.CCA and TCC5.CCB output period and pulse width respectively of PortC/Pin2 input with setup below:

 

void pwm_init(){//TCC4
	
	  // Set up timer
	  TCC4.CTRLA = TC45_CLKSEL_DIV4_gc; // Prescaler
	  TCC4.CTRLB = TC45_WGMODE_SINGLESLOPE_gc;
	  PORTC.DIRSET = PIN3_bm;
	  TCC4.CTRLE = TC45_CCDMODE_COMP_gc;
	  TCC4.CCD = 6000;
	  TCC4.PER = 12000;//Div 4 prescaler and 12k TOP with 32Mhz clock gives 1.5ms period
	  TCC4.CNT = 0;	
	  
	  //TCC5
	  TCC5.CTRLA = TC45_CLKSEL_DIV4_gc;
	  TCC5.CTRLB = TC45_WGMODE_FRQ_gc;
	  TCC5.CTRLD = TC45_EVACT_PWF_gc | TC45_EVSEL_CH1_gc;
	  TCC5.CTRLE = TC45_CCAMODE_CAPT_gc | TC45_CCBMODE_CAPT_gc;
	  TCC5.CCA = 20000;
	  PORTC.PIN2CTRL = PORT_ISC_BOTHEDGES_gc;//input on PORTC pin 2
	  EVSYS.CH1MUX = EVSYS_CHMUX_PORTC_PIN2_gc;//increment counter on pin change portc/pin2
	  EVSYS.CH1CTRL = EVSYS_DIGFILT_gm;
	  
}