Different GPIO PWM outputs with different frequencies at the same time #1372
Replies: 2 comments
-
Hi,
|
Beta Was this translation helpful? Give feedback.
-
Yes, you have to use pins which belong to different slices a.k.a. channels. Use the A pins in the slice.
bit-banging PWM when you have a subsystem which is capable of MHz operations is like driving 15Kph in a Ferarri.
Well, I'd suggest you start with something like khoih-prog/RP2040_PWM From personal experience the following may apply to you: PWM on the PICO/2040 can be frustrating as it has a lot of shall we say odd and unexpected behavior. Stay away from phase-corrected mode until you are very well versed in the inns and outs of PWM on PICO/2040. Inverting the phase has it's own "charm" shall we say so again, save it for later. If you need to synchronized the PWM signals you are getting into a whole other area of complications... this PI forum post can give you an idea, but get a stiff drink in hand before you delve in lol. Be mindful when reading the spec-sheets, marketing people love to pepper them with fancy terminology hoping they sell more chips, e.g. Delta-Sygma bla, bla,... completely irrelevant to most use cases most programmers are likely to deal with. PWM is likely going to be a steep learning curve, strap in and good luck :)) Cheers. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi! I was wondering if it was possible to drive two different devices at the same time but while using two different PWM frequencies.
I needed to run a solenoid which needs a frequency range from 11 Hz up to 80 Hz, while i need to simultaneously control a dc motor, but this motor has to work from 3000 Hz up to 6000 Hz. I managed to lower the limit of the analogWriteFreq to 10 Hz by modifying the function inside wiring_analog.cpp . I did a simple test with a potentiometer and two leds, where i tried to use AnalogWriteFreq(11) on a LED which runs on the first core, and then analogWriteFreq(3000) on another led which runs on the second core, however this doesn't work (both leds won't turn on) and i honestly have no idea why, because i'm new in electronics and i'm still learning. Can someone help me out? Thanks in advance!
Here's the code:
`void setup() {
pinMode(LED_BUILTIN, OUTPUT);
pinMode(0, OUTPUT);
pinMode(28, INPUT);
Serial.begin(38400);
}
void loop() {
analogWriteFreq(11);
analogWrite(LED_BUILTIN, map(analogRead(28), 0, 1024, 0, 256));
Serial.print("pot: ");
Serial.println(map(analogRead(28), 0, 1024, 0, 256));
Serial.println("\n");
}
void setup1() {
}
void loop1() {
analogWriteFreq(3000);
analogWrite(0, map(analogRead(28), 0, 1024, 0, 256));
}`
Beta Was this translation helpful? Give feedback.
All reactions