LED "get_duty" not retrieving correct data
Posted: Tue Jun 18, 2024 12:21 pm
Hi All,
I'm trying to get my secondary PWMs dutycycle out through the "LEDC_get_duty" command where my ledc_channel array is ledc_channel[2] making primary PWM in pos. 1 and secondary in pos. 2.
Primary register is 11bit and the secondary being 15bit as they are used for different frequencies.
What I see in the serial print in the while loop is the read out of the primary of any number from 0 to 2048; even when the starting value shouldn't be 0.
I've put the code part where the LEDC commands.
any help here would be greatly apreciated!
I'm trying to get my secondary PWMs dutycycle out through the "LEDC_get_duty" command where my ledc_channel array is ledc_channel[2] making primary PWM in pos. 1 and secondary in pos. 2.
Primary register is 11bit and the secondary being 15bit as they are used for different frequencies.
What I see in the serial print in the while loop is the read out of the primary of any number from 0 to 2048; even when the starting value shouldn't be 0.
I've put the code part where the LEDC commands.
Code: Select all
int PWM_primary = map_primary(65);
ledc_set_duty(ledc_channel[0].speed_mode, ledc_channel[0].channel, PWM_primary);
ledc_update_duty(ledc_channel[0].speed_mode, ledc_channel[0].channel);
vTaskDelay(50/portTICK_PERIOD_MS);
//Secondary pwm signal
PWM_Secondary_Time = ((65.0 - (float)Duty_cycle_prev)/abs((float)Duty_cycle_prev - (float)Duty_cycle)) * Total_Time;
int PWM_Secondary = map_secondary(65);
ledc_set_fade_with_time(LEDC_HIGH_SPEED_MODE,
LEDC_CHANNEL_1, PWM_Secondary, PWM_Secondary_Time);
ledc_fade_start(LEDC_HIGH_SPEED_MODE,
LEDC_CHANNEL_1, LEDC_FADE_NO_WAIT);
vTaskDelay(PWM_Secondary_Time/portTICK_PERIOD_MS);
while(secondary_Pres_Dc != 160){
secondary_Pres_Dc = ledc_get_duty(ledc_channel[1].speed_mode,ledc_channel[1].channel);
printf("%lu\n",secondary_Pres_Dc);
vTaskDelay(100/portTICK_PERIOD_MS); //100ms
}
//PWM_primary
PWM_primary = map_primary(Duty_cycle);
PWM_primary_Time = (((float)Duty_cycle - 65.0)/abs((float)Duty_cycle_prev - (float)Duty_cycle)) * Total_Time;
ledc_set_fade_with_time(LEDC_HIGH_SPEED_MODE,
LEDC_CHANNEL_0, PWM_primary, PWM_primary_Time);
ledc_fade_start(LEDC_HIGH_SPEED_MODE,
LEDC_CHANNEL_0, LEDC_FADE_NO_WAIT);