Hello all,
Here is the thing:
I use the code below to switich between two different cases in the If statement, based on the value I am sending thru the serial.
The issue is that, when I set the PWMs to 30Hz and 60Hz the serial is freezing for a few seconds - works quite slow.
If I use the default PWM settings, no issues (or I cannot notice them). Everything works fine then!
Do you see any issues with the code or is ir normal to wait such amount of time in case PWMs Freq are set to 30 or 60hz?
Thanks!
void setup() {
Serial.begin(115200);
pinMode(measurePin, INPUT);
pinMode(SwitchZCD1, OUTPUT);
pinMode(SwitchZCD2, OUTPUT);
pinMode(SwitchZCD3, OUTPUT);
pinMode(SwitchIGBT, OUTPUT);
//Pins D5 and D6 - 7.8 kHz
// TCCR0B = 0b00000010; // x8
//TCCR0A = 0b00000011; // fast pwm
// TCCR0B =TCCR0B & B11111000 | B00000101;//60HZ
// TCCR0A = 0b00000011; // fast pwm
TCCR0B = TCCR0B & B11111000 | B00000101; // set timer 0 divisor to 1024 for PWM frequency of 61.04 Hz
TCCR1B = TCCR1B & B11111000 | B00000101; // set timer 1 divisor to 1024 for PWM frequency of 30.64 Hz
TCCR2B = TCCR2B & B11111000 | B00000111; // set timer 2 divisor to 1024 for PWM frequency of 30.64 Hz
analogWrite(SwitchZCD1, 0);
analogWrite(SwitchZCD2, 0);
analogWrite(SwitchZCD3, 0);
analogWrite(SwitchIGBT, 0);
}
void loop() {
if (Serial.available() > 0) { // Четене от серийния порт и задаване на нова стойност на границата за регулиране във Volt.
// read the incoming byte:
String red = Serial.readString();
Urefmin = red.toInt();
}
if(Urefmin == 1){
pwm_IGBT =22;
analogWrite(SwitchZCD1, 150);
analogWrite(SwitchZCD2, 0);
analogWrite(SwitchZCD3, 0);
analogWrite(SwitchIGBT, pwm_IGBT);
}else {
pwm_IGBT =0;
analogWrite(SwitchZCD1, 0);
analogWrite(SwitchZCD2, 0);
analogWrite(SwitchZCD3, 0);
analogWrite(SwitchIGBT, pwm_IGBT);
}
//Serial.print("Uin =");
// Serial.print("PWM =");
Serial.println(pwm_IGBT);
// Serial.println(" ");
//delay(5);
}