unexpected beaviour with eventsys routing

Hello everyone,

I’m tring to use nano-every board to make a small frequency meter and pulse meter. For this I’m using TCBn counters and EventSys to route input signal.
After some test I have some results, but tere is something I’m not able to understand, and I think it will be very uncomfortable if I try to make more complex program:

  • If I route PORTC pin 4 (4 and 6 works too), using CHANNEL3, I can use the signal on TCBn as USER 2
EVSYS_CHANNEL3 = 0x44;//EVSYS_GENERATOR_PORT0_PIN4_gc;  //0x44-46 portC 4-6 ; 0x4D-E port D 5-6
EVSYS_USERTCB0 = 1 << 2;
  • I’tried to route it in other channels and I’ve never been able to have something working. I think I’ve tried all combination CHANNEL/USER and the only one working is CHANNEL3/USER2

I’ve attached full code as .zip. It needs pulse generator to work (in my case it’s a RPi). I also use I2c to change EVSYS routes without reload program, but it’s not needed to make some tests, just change variable values at init and reload program.

TCB_EVSYS.zip (3.16 KB)

You shouldn’t be using EVSYS_USERTCB0 = 1 << 2; because that is misleading. Yes you need a value 4 for channel 3, but this makes it look like a bit field. EVSYS_USERTCB0 = EVSYS_CHANNEL_CHANNEL3_gc; is clearer.

You can only route PC4 to channel 2 or 3. I don’t know what you mean by “USER2”.

It’s admirable to configure the Event System via I2C instead of just statically assigning, but this could also be part of the problem if there is an error in that code.

OK. Checked the code. You are setting EVSYS_USERTCB0 to 1 << EvsysTCB0 (which is 2) and EVSYS_USERTCB1 to 1<<EvsysTCB1 (which is 4). Meanwhile EVSYS_CHANNEL3 is set to 0x44 and EVSYS_CHANNEL5 is set to 0x4D.

This means, for Event Generators, channel 3 is EVSYS_GENERATOR_PORT0_PIN4_gc and channel 5 is EVSYS_GENERATOR_PORT1_PIN5_gc. Further unwinding, that becomes PC4 (TX1 on board) and PF5 (D5 on board). My guess is these are correct for what you want.

EVSYS_USERTCB0 gets set to 1<<2, or 4, which is channel 3.
EVSYS_USERTCB1 gets set to 1<<4, or 16, which is out of range, thus no connection. HERE IS THE PROBLEM!

Hi, many thanks for your answer. Now it's working !!!

My mistake was that I was thinking I have to set bit n of USER to connect CHANNEL n. The good way is to set USER with the number of the channel (+1) as an [u]integer[/u].

For all who want to use it, take care with STROBE: The signal STROBE n is generated by set and unset bit n of STROBE register, but to read this signal you have to set USER with n value +1 as integer.