Pwm pin frequency

Hello guys, I am looking for some knowledge on how to adjust the frequncy at which the PWM pins on the Nano Every(ATM4809) pulse at.

For reference, I am controlling an ESC, which I got working perfectly on an UNO pin 11 which has a frequency of around 480-490hz. When attaching this ESC to pin 5 or 6 of the UNO (960-ish Hz), or ANY PWM pin of the nano-every, the esc exhibits behavior that suggests it is unable to discern changes in throttle, and will not exceed 0% throttle (I'm really not sure how, the resultant V should be the same regardless of frequency, no? I suppose this is a question for antoher forum).

The frequency of the Nano-Every pins is confirmed with a scope, its around 1ms between pulses. I would like to cut this frequency in half, and I'm not sure how to do so. Is there a way to slow down an internal clock without affecting the rest of the board perhaps?
Again its a Nano-Every with the ATM4809, 20MHz clock speed.

Thanks guys! -Chad

If you use MegaCoreX

Then:

analogWriteFrequency(n);

sets the PWM frequency, where n is the frequency in kHz.

Better than that I don't know, and I realise you were after less than 1kHz.

You might have to dig into the datasheet for the 4809 and find out how to set the dividers to get a lower frequency.

2 Likes

There is a very good book from Tom Almy called "Far Inside The Arduino: Nano Every Supplement" He covers comprehensibly all the things you can do with it.

You can get the code from his examples here

Better still buy the book.

3 Likes

Isn't the default frequency for that 50Hz.
Does the ESC datasheet state a max frequency.
Leo..

1 Like

I do not think you can do this. Both the MegaCoreX and megaavr board packages use a default TCA timer CLKSEL of 64 which give the 980 hz pwm frequency. The next slower clock setting is with 256 divider. You can get a frequency of 245 but not 480. Most of the tutorials on pwm for the Nano Every deal with setting the TIMER A CLKSEL divider lower for faster pwm frequencies.

Hi,

if you are using the MegaCoreX package, then TCA is free because TCB3 is used for millis() etc..
You can freely configure TCA for your use.
If you still want to use a free TCB, you must at least configure TCA in Prescaler and assign it to TCBn. You would need Prescaler 256 because of the 8 bit PWM TCB timer mode. You can save yourself this trouble if you only use TCA.
The prescaler specifies the adjustable frequency range.
TOP value specifies the period duration and thus the frequency.
Duty is the duty cycle in relation to the period duration.

To get started, here is a .pdf - "Microchip TB3217 Getting Started with TCA"

If a duty of 50% is sufficient, use the “Frequency (FRQ) Waveform” mode.
If you want to set the duty, use the “Single-Slope PWM” or “Dual-Slope PWM” mode.

Yes, what are the specs on the ESC?

Most ESCs take a servo-like myServo.write(usecs) control signal rather than an analogWrite(127) PWM-like signal.

Thanks for all the help guys, awesome to see so many responses already.
To address some of the things I'm reading: my ESC is very vague Chinese component, the closest thing I found to a datasheet doesn't seem to list any input frequency, I would think the manufacturer correctly assumes that the users will be using standard RC protocols.
Additionaly, the MegaCoreX library looks like it would allow me in some way to modify the nano every to do what I need, slowing down the clock speed perhaps. However, a regular nano is about the same cost as getting a USB UDPI programming board, and will ship faster than I can figure out how to do it over USB, so I have chosen to order am official nano to get my desired PWM frequency :joy:. This is my solution just to get my project done, but I will definitely continue to learn about this topic, and dive into messing with AVR clock speeds in the future thanks to what you guys have sent me.

It seems you are trying to make things more difficult than they are.
Just use the servo library and the servo examples that come with the IDE.
Leo..

1 Like