Conversion from Arduino Nano to Nano Every

I would like to use a sketch that was created for an Arduino Nano on a Nano Every, but some parts are not compatible due to the different microprocessors they use. Does anyone know the equivalent of the following Nano registers for a Nano Every:

TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
TCCR1A |= (1 << COM1A1) | (1 << WGM11);
TCCR1B |= (1 << WGM13) | (1 << CS10);
ICR1 = TCNT1_TOP;
OCR1A = (word) (duty * TCNT1_TOP) / 100;

Thanks

That code programs the timer to produce PWM of a certain frequency on some pin. Unless you need that certain frequency, use the builtin analogWrite() function to produce PWM.

I do need that frequency unfortunatly

There won't be a one-to-one translation for that code, no matter what you do. It is absolutely specific for a 16 bit timer on an ATmega328 or similar processor.

You will have to read the data sheet and learn how to program the timer to produce that required frequency. There may be a tutorial on line.

Thanks, I guess I'm going to order a "normal" Nano

Nano-Every.pdf

They do claim pin for pin compatibility...

I searched for TCC register and it's not documented... so it will take some figuring to get it to work...

:smiley_cat:

Undocumented by Arduino, perhaps (but TCCR1A wasn't documented by Arduino either.) It's in the Microchip datasheet for the ATmega4809.

How about: Blog Article about ATmega4809 timers?

I searched the MicroChip document on the micro...not the Arduino docs.

I see reference to it in the blog link you posted... Went back to the microchip and it still doesn't hit.. something smells...

:smiley_cat:

Timer setup on the ATmega4809 bears little resemblance to those on ATmega328 or similar, and there are some major drawbacks, e.g. "there is only one prescalar setting and it is shared across all timers".

Ah. You're right. It's the SAMD series that has TC and TCC timer.
Atmega4809 has TCA and TCB timers.
TCA looks quite powerful up to six 8-bit compare outputs, and separate "period" register. TCB, not so much - only one compare channel (but it still has a separate period register.) (the big "problem" with TCB is that it's tied to the same clock input as TCA, so you can't run them completely separately.) (well, you can also use a very fast clock - CLK_PER/2)

ATmega4809 has one TCA timer and 4 TCB timers.

TCCR1A |= (1 << COM1A1) | (1 << WGM11);
TCCR1B |= (1 << WGM13) | (1 << CS10);

So... that's "Phase correct PWM" with "Clear OC1A/OC1B on Compare Match when up- counting. Set OC1A/OC1B on Compare Match when downcounting." ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.