Comments (4)
PWM input is supported on both the input pin and the enable/inhibit pin. However, the behavior is different, because the freewheeling current takes a different path. See page 4 and figure 7 of https://www.st.com/resource/en/application_note/cd00003776-applications-of-monolithic-bridge-drivers-stmicroelectronics.pdf for more details.
I've never really compared the behaviors of both modes, so I can't really tell you whether this is the cause of the issues you're facing.
That said, you shouldn't need to modify too much if you want to switch to a 3-pin drive mode.
What you need to know about the timers is that they generate a rectangular PWM wave on an output pin, the duty cycle of which is set by the value in the Output Compare register (OCRnX, where n is the timer number, and X is the channel, either A or B). The code uses two timers (Timer 0 and Timer 2), and each timer has two channels, A and B. Each channel is hard-wired to a specific pin, e.g. Timer 0 channel A drives pin 6. You can see this on page two of the full pinout: pin D6 is labeled OC0A
(Output Compare of Timer 0, channel A).
Besides OCRnX, another important register bit is the COMnX0 bit (Compare Output Mode for timer n channel X) in the TCCRnA register (Timer/Counter n Control Register A). When set to 1, this bit inverts the output pin. Toggling this bit has the effect of changing the duty cycle to its complement, e.g. from 25% to 75%.
As you probably know, to change the direction of the motor, you need to invert both input pins, i.e.
IN1 | IN2 | EN | |
---|---|---|---|
L | H | H | Forward |
H | L | H | Backward |
H | H | H | Free running stop |
L | L | H | Free running stop |
X | X | L | Faster stop |
The current code does the following to change direction: it inverts the output pin of IN2, and it changes the COMnX0 bit for the IN1 pin. This is done here for forward and backward operation, respectively:
Control-Surface-Motor-Fader/Motor-Controller/Motor.hpp
Lines 95 to 100 in 7bcd5aa
Control-Surface-Motor-Fader/Motor-Controller/Motor.hpp
Lines 134 to 139 in 7bcd5aa
To change this to 3-pin operation, you can do the following. Let's assume the following pinout, and we'll only look at one fader:
Arduino pin | Driver pin |
---|---|
2 (PD2) | IN1 |
3 (PD3/OC2B) | EN |
4 (PD4) | IN2 |
To initialize (Motors::begin()
), we just set all three pins as outputs:
if (Config::num_faders > 0) {
sbi(DDRD, 2); // PD2 output
sbi(DDRD, 3); // PD3/OC2B output
sbi(DDRD, 4); // PD4 output
}
To move in one direction (Motor::forward()
):
else if (Idx == 0)
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
cbi(PORTD, 2); // IN1 low
sbi(PORTD, 4); // IN2 high
OCR2B = speed;
}
And to move in the other (Motor::backward()
):
else if (Idx == 0)
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
sbi(PORTD, 2); // IN1 high
cbi(PORTD, 4); // IN2 low
OCR2B = speed;
}
Note that the COM2B0 bit is no longer used, it is always set to zero, regardless of direction.
from control-surface-motor-fader.
Success!!! It's buttery smooth now, apparently, the L298N should only receive pwm signals on it's ENA pin..
The code you provided worked on first try! Really a simple change, thanks to your great design :)
Thank you so much π
from control-surface-motor-fader.
Wow! Thanks so much for the detailed answer! I'll see to trying this out as soon as I can!
In the meantime, I'll also order some L293Ds, just in case.. they are truly cheap :D
Thanks again, I'll report back when I get some results π
from control-surface-motor-fader.
The L293Ds arrived, got an even smoother operation with them. I recommend any future readers to just use these.
from control-surface-motor-fader.
Related Issues (13)
- Problems using 8 motorized faders and Midi Interface HOT 12
- Motorized fader guidance HOT 7
- Sometimes a fader goes crazy, after hours working HOT 5
- How to connect linesοΌ
- Use on Arduino Uno HOT 4
- At start, at I2C control mode, the fader goes to zero, but the motor don't stop
- PID controller pre-calculated Ki_Ts not possible ?
- Use library without touch sensitive motor faders HOT 2
- Midi Controller and Motor Fader Controller on Teensy 4.1 HOT 1
- Multi controller example HOT 1
- Some DAW not output PB Value when I move real fader HOT 6
- Using a TB6612FNG HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from control-surface-motor-fader.