[reason:hardware connection is not stable] EVSYS config on ATTINY814(don't work)

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

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?  

 

This topic has a solution.
Last Edited: Thu. Aug 15, 2019 - 02:41 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

have you checked this application note:

 

http://ww1.microchip.com/downloa...

 

and here is an example for using TCB with EVSYS:

 

https://github.com/MicrochipTech...

 

I also suggest you to take a look at this thread:

 

https://www.avrfreaks.net/forum/...

 

Regards,

Moe

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

Xiao wrote:

	//for test
	PORTMUX_CTRLA |= 1;//evout0 /PA2  
	EVSYS_ASYNCUSER8 = EVSYS_ASYNCUSER0_ASYNCCH0_gc;
	//PORTA.PIN2CTRL |= 0x80;
	PORTA.DIRSET |= (1<<2);

 

Are you seeing the copy of PA4 on PA2?

 

Also, see these threads:

https://www.avrfreaks.net/forum/...

https://www.avrfreaks.net/forum/...

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

Thank you for your info.

Actually, I used START to create the codes and then copy it to my case.

I have read those topics, but don't find the key :).

For my case, I can use interrupt of pin to realise the function instead, as freaker we must do thing another way.

 

I have studied the appnote on EVSYS & TCB, that is really complex.

 

 

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

Are you seeing the copy of PA4 on PA2?

No.

And the appearance is a little strange.

TSOP4840 data -> PIN4(input pullup) -> EVSYS -> PIN2 (output) 

The LED on PIN2 is ON forever, that means HIGH level on PIN2,

Even when I connect the PIN4 to GND.

The pulses to PIN4 looks like this:

----------------------_______--__--____--__--------------------

The width is hundreds us, it is long enough to captured by TCB.

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

There are other interrupts in my code, those works fine.

 

Maybe I did not init the EVSYS correctlly?

 

 

EVSYS_ASYNCCH0 = EVSYS_ASYNCCH0_PORTA_PIN4_gc;
EVSYS.ASYNCUSER0 = EVSYS_ASYNCUSER0_ASYNCCH0_gc;

Any other works to do except these?

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

I have tried to find something to do, but,NO...

There is a question , What is the EVENT ?

The pulses feeded into PIN4 will be transfered to TCB exact same?

And what's the meaning of this sentence: "The timer will automatically switch between rising and fallingedge detection, but a minimum edge separation of two clock cycles is required for correct behavior." (ATTINY814 datasheet,21.3.3.1.5 Input Capture Pulse Width Measurement Mode)

I thought that means " at least 2 clock cycles between two edges,from rising to falling or versa versa." 

/* Event System */
typedef struct EVSYS_struct
{
    register8_t ASYNCSTROBE;  /* Asynchronous Channel Strobe */
    register8_t SYNCSTROBE;  /* Synchronous Channel Strobe */
    register8_t ASYNCCH0;  /* Asynchronous Channel 0 Generator Selection */
    register8_t ASYNCCH1;  /* Asynchronous Channel 1 Generator Selection */
    register8_t ASYNCCH2;  /* Asynchronous Channel 2 Generator Selection */
    register8_t ASYNCCH3;  /* Asynchronous Channel 3 Generator Selection */
    register8_t reserved_0x06;
    register8_t reserved_0x07;
    register8_t reserved_0x08;
    register8_t reserved_0x09;
    register8_t SYNCCH0;  /* Synchronous Channel 0 Generator Selection */
    register8_t SYNCCH1;  /* Synchronous Channel 1 Generator Selection */
    register8_t reserved_0x0C;
    register8_t reserved_0x0D;
    register8_t reserved_0x0E;
    register8_t reserved_0x0F;
    register8_t reserved_0x10;
    register8_t reserved_0x11;
    register8_t ASYNCUSER0;  /* Asynchronous User Ch 0 Input Selection - TCB0 */
    register8_t ASYNCUSER1;  /* Asynchronous User Ch 1 Input Selection - ADC0 */
    register8_t ASYNCUSER2;  /* Asynchronous User Ch 2 Input Selection - CCL LUT0 Event 0 */
    register8_t ASYNCUSER3;  /* Asynchronous User Ch 3 Input Selection - CCL LUT1 Event 0 */
    register8_t ASYNCUSER4;  /* Asynchronous User Ch 4 Input Selection - CCL LUT0 Event 1 */
    register8_t ASYNCUSER5;  /* Asynchronous User Ch 5 Input Selection - CCL LUT1 Event 1 */
    register8_t ASYNCUSER6;  /* Asynchronous User Ch 6 Input Selection - TCD0 Event 0 */
    register8_t ASYNCUSER7;  /* Asynchronous User Ch 7 Input Selection - TCD0 Event 1 */
    register8_t ASYNCUSER8;  /* Asynchronous User Ch 8 Input Selection - Event Out 0 */
    register8_t ASYNCUSER9;  /* Asynchronous User Ch 9 Input Selection - Event Out 1 */
    register8_t ASYNCUSER10;  /* Asynchronous User Ch 10 Input Selection - Event Out 2 */
    register8_t reserved_0x1D;
    register8_t reserved_0x1E;
    register8_t reserved_0x1F;
    register8_t reserved_0x20;
    register8_t reserved_0x21;
    register8_t SYNCUSER0;  /* Synchronous User Ch 0 Input Selection - TCA0 */
    register8_t SYNCUSER1;  /* Synchronous User Ch 1 Input Selection - USART0 */
    register8_t reserved_0x24;
    register8_t reserved_0x25;
    register8_t reserved_0x26;
    register8_t reserved_0x27;
    register8_t reserved_0x28;
    register8_t reserved_0x29;
    register8_t reserved_0x2A;
    register8_t reserved_0x2B;
    register8_t reserved_0x2C;
    register8_t reserved_0x2D;
    register8_t reserved_0x2E;
    register8_t reserved_0x2F;
    register8_t reserved_0x30;
    register8_t reserved_0x31;
    register8_t reserved_0x32;
    register8_t reserved_0x33;
    register8_t reserved_0x34;
    register8_t reserved_0x35;
    register8_t reserved_0x36;
    register8_t reserved_0x37;
    register8_t reserved_0x38;
    register8_t reserved_0x39;
    register8_t reserved_0x3A;
    register8_t reserved_0x3B;
    register8_t reserved_0x3C;
    register8_t reserved_0x3D;
    register8_t reserved_0x3E;
    register8_t reserved_0x3F;
} EVSYS_t;

/* Asynchronous Channel 0 Generator Selection select */
typedef enum EVSYS_ASYNCCH0_enum
{
    EVSYS_ASYNCCH0_OFF_gc = (0x00<<0),  /* Off */
    EVSYS_ASYNCCH0_CCL_LUT0_gc = (0x01<<0),  /* Configurable Custom Logic LUT0 */
    EVSYS_ASYNCCH0_CCL_LUT1_gc = (0x02<<0),  /* Configurable Custom Logic LUT1 */
    EVSYS_ASYNCCH0_AC0_OUT_gc = (0x03<<0),  /* Analog Comparator 0 out */
    EVSYS_ASYNCCH0_TCD0_CMPBCLR_gc = (0x04<<0),  /* Timer/Counter D0 compare B clear */
    EVSYS_ASYNCCH0_TCD0_CMPASET_gc = (0x05<<0),  /* Timer/Counter D0 compare A set */
    EVSYS_ASYNCCH0_TCD0_CMPBSET_gc = (0x06<<0),  /* Timer/Counter D0 compare B set */
    EVSYS_ASYNCCH0_TCD0_PROGEV_gc = (0x07<<0),  /* Timer/Counter D0 program event */
    EVSYS_ASYNCCH0_RTC_OVF_gc = (0x08<<0),  /* Real Time Counter overflow */
    EVSYS_ASYNCCH0_RTC_CMP_gc = (0x09<<0),  /* Real Time Counter compare */
    EVSYS_ASYNCCH0_PORTA_PIN0_gc = (0x0A<<0),  /* Asynchronous Event from Pin PA0 */
    EVSYS_ASYNCCH0_PORTA_PIN1_gc = (0x0B<<0),  /* Asynchronous Event from Pin PA1 */
    EVSYS_ASYNCCH0_PORTA_PIN2_gc = (0x0C<<0),  /* Asynchronous Event from Pin PA2 */
    EVSYS_ASYNCCH0_PORTA_PIN3_gc = (0x0D<<0),  /* Asynchronous Event from Pin PA3 */
    EVSYS_ASYNCCH0_PORTA_PIN4_gc = (0x0E<<0),  /* Asynchronous Event from Pin PA4 */
    EVSYS_ASYNCCH0_PORTA_PIN5_gc = (0x0F<<0),  /* Asynchronous Event from Pin PA5 */
    EVSYS_ASYNCCH0_PORTA_PIN6_gc = (0x10<<0),  /* Asynchronous Event from Pin PA6 */
    EVSYS_ASYNCCH0_PORTA_PIN7_gc = (0x11<<0),  /* Asynchronous Event from Pin PA7 */
    EVSYS_ASYNCCH0_UPDI_gc = (0x12<<0),  /* Unified Program and debug interface */
} EVSYS_ASYNCCH0_t;

 

Last Edited: Wed. Aug 14, 2019 - 03:13 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, here is a program that outputs the input from PA1 to EVOUT0 (PA2):

 

#include <avr/io.h>

inline void event_init();

int main(void) {
    event_init();
     while (1);
}


void event_init() {
    EVSYS.ASYNCCH0 = EVSYS_ASYNCCH0_PORTA_PIN1_gc;
    EVSYS.ASYNCUSER8 = EVSYS_ASYNCUSER8_ASYNCCH0_gc;	// -> EVOUT0
    PORTMUX.CTRLA |= PORTMUX_EVOUT0_bm;
    //PORTA.DIRSET = 1 << 2;
}

 

Not that the EVOUT0 pin becomes output automatically, so you don't need to set the direction. I already tested this and it's working, so if it doesn't work in your case you have some hardware problem.

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

Thank EI & Moe for your help.

 

I have created the code using START, that didn't work still, if you select PORTA.PIN4 as input.

 

When I change to other pin, suddenlly, everything getting right.

 

I checked PORTMUX & <Table 5-1. PORT Function Multiplexing> ,  no finds.

 

So, for ATTINY814, if you want to use EVSYS, don't select PORTA.PIN4 as event generator.

 

Maybe, there is some limits not listed in datasheet.

Or, ATMEL technical support can check this, pls?

 

 

Last Edited: Thu. Aug 15, 2019 - 06:36 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Xiao wrote:
Or, ATMEL technical support can check this, pls?
You need to raise a support ticket in the microchip.com site to get input from Microchip/Atmel.

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

Xiao wrote:
So, for ATTINY814, if you want to use EVSYS, don't select PORTA.PIN4 as event generator.

 

Weird. Actually, I just used PA1 in my test code because ATM I'm working with a tiny412 (PA4 is not present). Now I'm curious, I need to find a chip to test that PA4 bug.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry to disturb you.

 

I thought of the reasons  related to hardware this afternoon,  and checked again, the problem comes from hardware:

1) maybe the connection is not stable;

or

2)damaged to chips(PIN4) while soldering.

 

I used a little PCB as adaptor to breadboard.

The connection is not stable :  chip - adaptor PCB - breadboard - dupont line .

When I measure the resist between chip(pin4) and dupont line, the resist is very low, less than 1 ohm, so I thought the connection is OK.

But, after power up, the chip doesn't sense anything if you try to change level through dupont line:

           GND - dupond line - breadboard - adaptor PCB - chip.pin4

And chip will work fine if do like this:

           GND - dupond line - chip.pin4 (include  the pad on PCB)

 

It is absolutlly deceitful, hard to notice it.

But how can that happened?

 

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

no bug for PIN4, check my update pls.

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

It's ok. I figured it should be some hardware problem, maybe a burned protection diode in PA4?