I'm trying to use EVSYS to guide input signal to TCB, till now,not work.
Anyone can give some advice?
Target:
TSOP4840 data -> PORTA.PIN4 -> EVSYS -> TCB (pulse width measure mode)
init for EVSYS:
void EVENT_Init(void){ //EVSYS.SYNCCH0 = EVSYS_SYNCCH0_PORTA_PIN4_gc; /* Synchronous Event from Pin PA4 */ EVSYS_ASYNCCH0 = EVSYS_ASYNCCH0_PORTA_PIN4_gc; EVSYS.ASYNCUSER0 = EVSYS_ASYNCUSER0_ASYNCCH0_gc; /* Asynchronous Event Channel 0 */ //for test PORTMUX_CTRLA |= 1;//evout0 /PA2 EVSYS_ASYNCUSER8 = EVSYS_ASYNCUSER0_ASYNCCH0_gc; //PORTA.PIN2CTRL |= 0x80; PORTA.DIRSET |= (1<<2); }
init for TCB
void TCB_init(void) { // TCB0.CCMP = 0x0; /* Compare or Capture: 0x0 */ // TCB0.CNT = 0x0; /* Count: 0x0 */ TCB0.CTRLB |= TCB_CNTMODE_PW_gc; /* Input Capture Pulse-Width measurement */ //1 << TCB_ASYNC_bp /* Asynchronous Enable: enabled */ // 0 << TCB_CCMPEN_bp /* Pin Output Enable: disabled */ //| 0 << TCB_CCMPINIT_bp /* Pin Initial State: disabled */ TCB0.DBGCTRL = 1 << TCB_DBGRUN_bp; /* Debug Run: enabled */ TCB0.EVCTRL |= (1 << TCB_CAPTEI_bp /* Event Input Enable: enabled */ | 1 << TCB_EDGE_bp //Negative Edge : Initialize,Positive Edge : Capture = count, interrupt | 1 << TCB_FILTER_bp); /* Input Capture Noise Cancellation Filter: enabled */ TCB0.INTCTRL = 1 << TCB_CAPT_bp; /* Capture or Timeout: enabled */ TCB0.CTRLA |= (TCB_CLKSEL_CLKDIV2_gc /* CLK_PER/2 */ | 1 << TCB_ENABLE_bp /* Enable: enabled */ | 1 << TCB_RUNSTDBY_bp); /* Run Standby: enabled */ //| 0 << TCB_SYNCUPD_bp; /* Synchronize Update: disabled */ }
init for PIN4
PORTA.DIRCLR = (1<<PIN_IR_RCV_1); //input //PORTA.OUTCLR = (1<<PIN_IR_RCV_1); PORTA.PIN4CTRL |= (0x08); //pullup
ISR for TCB
ISR(TCB0_INT_vect) { IRreceiving(); /** * The interrupt flag is cleared by writing 1 to it, or when the Capture register * is read in Capture mode */ TCB0.INTFLAGS = TCB_CAPT_bm; }
I monitered the PIN4 input, pulses presented indeed.
But no interrupt triggered (TCB0_INT_vect).
And I don't master EVSYS indeed, I don't understand the difference of ASYNC / SYNC, how to make the choice.
I manually chage the input of PIN4, hope to see the action in PIN2 as test (defined in EVSYS init codes), but nothing happed, the LED on PIN2 ON always.
Anyone can post some sample code execute successfully?