How can I generate PWM on 8 pins on my arduino mega using bare metal programming such that all the pwm are independent that is that i must be able to change the frequency and dutycycle of pwm signal on each pin independently
Depending on the frequencies required,you could write a software PWM implementation.
Write nice tight code, and it works well
I have written a code but the issue is that if I change the frequency of lets say pin 6 on mega then the frequency on pin 7 and 8 also changes because they all are connected to the same timer4 and are using a single timer counter
What frequency do you need the PWM outputs to run at ?
16.6Hz
You can't, it only has two 8bit counters and four 16bit coumters, that's six counters, you need 8 counters.
is there any other method of approaching this problem
Why the need to go "bare metal" at such a low frequency ?
- See post #2
- Use a processor with 8 timers.
- Build external circuits for generating PWM
because i am using avr sow pwm library and it is giving me 16.4hz
Thats a wonderful idea by the way, how can i do that can you teach me ?
have a look at the ESP32 Motor Control Pulse Width Modulator (MCPWM)
e.g. 16 independent PWM Channels, divided into group of two with 8 channels per group.
It's fairly complicated. Trying to teach by chatting on this forum is very difficult and time consuming and I don't have the time.
Unmark the topic as solved and maybe someone else will come along and teach you.
`The RP2040 has a PWM block with 8 identical slices. Each slice can drive two PWM output signals, the frequency of each slice can be adjusted independently.
You can also just add on a PWM shield like this one: Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface [PCA9685] : ID 815 : Adafruit Industries, Unique & fun DIY electronics and kits
The PCA9685 has a fixed frequency for all 16 channels.
With a minimum of 40 Hz.
Leo..