I'm a switch mode power supply designer. I hope Espressif don't produce esp wroom 32 chips for only makers
Our traditional way is using arm mcu , if we need iot our way is arm mcu + ble or wifi mcu combined. But when we meet esp32 there are a lot of good things inside the chip. 2 core, 160 mhz, all peripherals what we need and wifi + ble all in one.
But we have some pwm issues. Pwm is most important thing for us
I'm using esp-idf + eclipse + windows 10 and mcpwm api on the esp-idf
1) We need higher pwm frequencies. Above 50kHz
2) Above the 1kHz esp output is not stable. Real pin frequency is not what I set in the software
3) mcpwm page is not good documented in the esp-idf programming guide
http://esp-idf.readthedocs.io/en/latest ... mcpwm.html
4) ESP32 Technical Reference Manual V3.0 page: 391
https://www.espressif.com/sites/default ... ual_en.pdf
160Mhz input clock frequency of mcpwm module. So it is very good in theory.
160Mhz clock pulse ----> 8 bit prescaler ----> 16 bit configurable timer ----> pwm_pin
5) In the ESP32 Technical Reference Manual V3.0 page: 397, there are registers for pwm. But how can we reach and edit this registers in safe way?
6) My basic code:
Code: Select all
void mcpwm_gpio_config (){
printf("PWM Module pin attachments......\n");
mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0A, PWM0A_PIN); //Set GPIO 15 as PWM0A
}
void mcpwm_internal_config (){
printf("Configuring Initial Parameters of mcpwm0......\n");
mcpwm_config_t pwm_config;
pwm_config.frequency = 1000; //frequency
pwm_config.cmpr_a = 0; //duty cycle of PWMxA = 0
pwm_config.cmpr_b = 0; //duty cycle of PWMxb = 0
pwm_config.counter_mode = MCPWM_UP_COUNTER;
pwm_config.duty_mode = MCPWM_DUTY_MODE_0;
mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_0, &pwm_config); //Configure PWM0A & PWM0B with above settings
}
Code: Select all
void app_main() {
mcpwm_gpio_config();
mcpwm_internal_config();
gpio_pad_select_gpio(GPIO_NUM_2);
gpio_set_direction(GPIO_NUM_2, GPIO_MODE_OUTPUT);
uint8_t i = 0;
float dutyCounter = 0.0;
while (1) {
for (i = 0; i < 100; i++){
gpio_set_level(GPIO_NUM_2, 1);
dutyCounter = i * 1.0;
mcpwm_set_duty(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_A, dutyCounter);
printf("Duty = %f",dutyCounter);
printf("\n");
vTaskDelay(10);
gpio_set_level(GPIO_NUM_2, 0);
}
}
}
Results:
pwm_config.frequency = 1000; real pin frequency = 999,01Hz
pwm_config.frequency = 25000; real pin frequency = 24.390Hz
pwm_config.frequency = 50000; real pin frequency = 47.619Hz
pwm_config.frequency = 75000; real pin frequency = 71.429Hz
pwm_config.frequency = 150000; real pin frequency = 142.857Hz
pwm_config.frequency = 225000; real pin frequency = 200.000Hz
pwm_config.frequency = 300000; real pin frequency = 250.000Hz
pwm_config.frequency = 500000; real pin frequency = 333.333,33Hz
pwm_config.frequency = 1000000; real pin frequency = nothing on the oscilloscope, and there is no compile error
I need help and advice and all kind of helpfull things
Best regards.