Hi, I need to control 3 DC Gear motors independently I'm using l298n modules but struggeling with high frequencies for days now. I would like to use either 328P or samd21g chips .. depents which is easier. In total I need 6 pwm channels. Is there any example code out there?
Not sure what your problem is. Is it that you want to change PWM frequency? Is it that you don't know how to control a L298 motor driver?
And Uno or Nano (328 chip) has 6 PWM outputs. I would think that the 328 is easier. Much better chance of finding libraries and example code for what you whatever it is that you want to do.
Is there any example code out there?
Example code for what, exactly?
Why 6 PWM channels for only 3 motors? Please describe how the motors will work.
The L298 is old technology and inefficient but it does allow you to control the speed and direction of a DC motor using a single PWM output applied to the Enable pin. The In1 and In2 pins are then used to control direction. Some of the more efficient drivers such as the DRV8833 do require a separate PWM signal for each direction unless you build an external circuit to route the PWM signal.
my main issue is getting higher pwm frequencies to control a driver. As far as I understood almost all motor drivers rely on a pwm input to set speed.
The usual pwm frequency when using analogWrite is to low and you hear a sound. To avoid this I need to control a driver with a higher frequency.
Right now I'm using this module. It has inouts IN1 IN2. When applying a pwm to IN1 the motor turns right, when apply to IN2 it turns left.
That works so far. My Issue here is to generate higher frequencies. When using your suggested solution I need only generate 3 separate pwm frequencis
If you Google "arduino pwm frequency" there is no shortage of examples of how to change it.
One thing to keep in mind is that hardware Timer0 is used to produce micros() and millis() and it also produces the PWM on pins 5 and 6. If you want to change the PWM frequency on those pins without upsetting millis() and micros() you may have fewer options. Sorry, but I don't retain the details for that sort of info in my head.
Yeah that's the thing when changing it. Maybe I should use a 328P alone to drive the motors and send the signals from another µController with i2c. When 3 pwm Signals are enough for 3 motors I can use a 328P for it. Will try it tomorrow, thanks.
Can you provide a general context of your project? Are you trying to make a robot to move something heavy in 3 dimensions, or ??