Hello everyone
I'm going to share my experience with you, in case it helps someone:
I have entered the following code:
//KurtE's original code, modified by Jose555
#include <pwm.h>
PwmOut pwm0(0);
PwmOut pwm1(1);
PwmOut pwm2(2);
PwmOut pwm3(3);
PwmOut pwm4(4);
PwmOut pwm5(5);
PwmOut pwm6(6);
PwmOut pwm7(7);
PwmOut pwm8(8);
PwmOut pwm9(9);
PwmOut pwm10(10);
PwmOut pwm11(11);
PwmOut pwm12(12);
PwmOut pwm13(13);
uint32_t frequency = 50;
uint32_t duty = 2048;
void setup() {
while (!Serial) {};
Serial.begin(115200);
Serial.print("Quick and dirty PWM Test");
analogWriteResolution(12);
pwm5.begin(1000000 / frequency, 0);
analogWrite(5, duty); //GTIOC2B
analogWrite(6, 2048); // GTIOC0B
analogWrite(4, 2048); // GTIOC2A
}
void loop() {
Serial.println("Enter new frequency and duty:");
while (!Serial.available()) {};
uint32_t new_freq = 0;
uint32_t new_duty = 0;
int ch;
for (;;) {
ch = Serial.read();
if ((ch < '0') || (ch > '9')) break;
new_freq = new_freq * 10 + ch - '0';
}
while (ch == ' ') ch = Serial.read();
for (;;) {
if ((ch < '0') || (ch > '9')) break;
new_duty = new_duty * 10 + ch - '0';
ch = Serial.read();
}
while (Serial.read() != -1) {}
uint32_t period_us = 1000000 / new_freq;
Serial.print("New freq: ");
Serial.print(new_freq);
Serial.print(" period: ");
Serial.println(period_us);
pwm0.begin(period_us, 0);
period_us = 1000000 / (new_freq-1000);
pwm1.begin(period_us, 0);
period_us = 1000000 / (new_freq-2000);
pwm2.begin(period_us, 0);
period_us = 1000000 / (new_freq-3000);
pwm3.begin(period_us, 0);
period_us = 1000000 / (new_freq-4000);
pwm4.begin(period_us, 0);
period_us = 1000000 / (new_freq-5000);
pwm5.begin(period_us, 0);
period_us = 1000000 / (new_freq-6000);
pwm6.begin(period_us, 0);
period_us = 1000000 / (new_freq-7000);
pwm7.begin(period_us, 0);
period_us = 1000000 / (new_freq-8000);
pwm8.begin(period_us, 0);
period_us = 1000000 / (new_freq-9000);
pwm9.begin(period_us, 0);
period_us = 1000000 / (new_freq-10000);
pwm10.begin(period_us, 0);
period_us = 1000000 / (new_freq-11000);
pwm11.begin(period_us, 0);
period_us = 1000000 / (new_freq-12000);
pwm12.begin(period_us, 0);
period_us = 1000000 / (new_freq-13000);
pwm13.begin(period_us, 0);
period_us = 1000000 / (new_freq-14000);
Serial.print("duty: ");
Serial.println(new_duty);
analogWrite(0, new_duty);
analogWrite(1, new_duty);
analogWrite(2, new_duty);
analogWrite(3, new_duty);
analogWrite(4, new_duty);
analogWrite(5, new_duty);
analogWrite(6, new_duty);
analogWrite(7, new_duty);
analogWrite(4, new_duty);
analogWrite(5, new_duty);
analogWrite(6, new_duty);
analogWrite(7, new_duty);
analogWrite(8, new_duty);
analogWrite(9, new_duty);
analogWrite(10, new_duty);
analogWrite(11, new_duty);
analogWrite(12, new_duty);
analogWrite(13, new_duty);
}
I write in the serial 40000 300
Only output 5 (35.7kHz) is activated, the rest of the outputs 490hz
I write again 40000 300
It would be expected that at output 1, we would have 40kHz, at 2 - 39kHz, at 3 -38kHz.....
(my oscilloscope is very simple, and probably not very accurate)
Then yes:
I write the measured values:
0 - 40kHz - GTIOC4B
1 - 40kHz - GTIOC4A
2 - 28.5kHz - GTIOC1A
3 - 28.5kHz - GTIOC1B
4 - 80Hz ?? - GTIOC2A
5 - 35.7 kHz - GTIOC2B
6 - 33.3 kHz - GTIOC0B
7 - 33.3 kHz - GTIOC0A
8 - 31.2 kHz - GTIOC7A
9 - 31.2 kHz - GTIOC7B
10 - 27 kHz - GTIOC3B
11 - 28.5 kHz - GTIOC1A
12 - 28.5 kHz - GTIOC1B
13 - 27 kHz - GTIOC3A
Output 4 has strange behavior,
The rest behaves grouped in clocks:
0 and 1
2,3,11 and 12
6 and 7
8 and 9
10 and 13
the 5 alone
and number 4, which has not worked for me in this test
I hope the information is useful to someone
Thank you very much to all