Problem programming bare metal PWM
Posted: Tue Sep 10, 2024 2:11 pm
Hi, i'm trying to create a test pwm and route it throughout the gpio5, i'm currently waiting to get de JTAG to be able to debug my code in any way, right now i'm pretty much blind, i can only see what i get at the output pin and i'm not able to see what could i be doing wrong, it is also mi first post in this forum and i'm not sure how i should paste the code so forgive me if i commit any mistakes and thank you for your time.
I am also using a custom library where i defined all the names of the registers with their respective address, that is the reason of all the pointers.
I am also using a custom library where i defined all the names of the registers with their respective address, that is the reason of all the pointers.
- volatile uint32_t *gpio_enable_reg = (volatile uint32_t *)GPIO_ENABLE_REG;
- /*----------------------------HIGH SPEED TIMER-----------------------------------*/
- volatile uint32_t *ledc_hsch0_conf0_reg = (volatile uint32_t *)LEDC_HSCH0_CONF0_REG;
- volatile uint32_t *ledc_hsch0_hpoint_reg = (volatile uint32_t *)LEDC_HSCH0_HPOINT_REG;
- volatile uint32_t *ledc_hsch0_duty_reg = (volatile uint32_t *) LEDC_HSCH0_DUTY_REG;
- volatile uint32_t *ledc_hsch0_conf1_reg = (volatile uint32_t *) LEDC_HSCH0_CONF1_REG;
- volatile uint32_t *ledc_hsch0_duty_r_reg = (volatile uint32_t *) LEDC_HSCH0_DUTY_R_REG;
- /*----------------------------LOW SPEED PWM ------------------------------------*/
- volatile uint32_t *ledc_lsch0_conf0_reg = (volatile uint32_t *)LEDC_LSCH0_CONF0_REG;
- volatile uint32_t *ledc_lsch0_hpoint_reg = (volatile uint32_t *)LEDC_LSCH0_HPOINT_REG;
- volatile uint32_t *ledc_lsch0_duty_reg = (volatile uint32_t *) LEDC_LSCH0_DUTY_REG;
- volatile uint32_t *ledc_lsch0_conf1_reg = (volatile uint32_t *) LEDC_LSCH0_CONF1_REG;
- volatile uint32_t *ledc_lsch0_duty_r_reg = (volatile uint32_t *) LEDC_LSCH0_DUTY_R_REG;
- /*----------------------------LOW SPEED TIMER------------------------------------*/
- volatile uint32_t *ledc_lstimer0_conf_reg= (volatile uint32_t *)LEDC_LSTIMER0_CONF_REG;
- volatile uint32_t *ledc_lstimer0_value_reg = (volatile uint32_t *)LEDC_LSTIMER0_VALUE_REG;
- volatile uint32_t *ledc_conf_reg = (volatile uint32_t *) LEDC_CONF_REG;
- /*---------------------------GPIO MATRIX CONFIG----------------------------------*/
- //OUTPUT CONTROL
- volatile uint32_t *gpio_out_reg = (volatile uint32_t *) GPIO_OUT_REG; // REGISTRE QUE AFECTA ALS GPIO DEL 0 AL 31
- volatile uint32_t *gpio_out_w1ts_reg = (volatile uint32_t *) GPIO_OUT_W1TS_REG; // REGISTRE PER FICAR BITS A 1 DEL OUT_REG
- volatile uint32_t *gpio_out_w1tc_reg = (volatile uint32_t *) GPIO_OUT_W1TC_REG; // REGISTRE PER FICAR BITS A 0 DEL OUT_REG
- //OUTPUT ENABLE
- //volatile uint32_t *gpio_enable_reg = (volatile uint32_t *) GPIO_ENABLE_REG; // REGISTRE PER HABILITAR ELS GPIO DEL 0 AL 31
- volatile uint32_t *gpio_enable_w1ts_reg = (volatile uint32_t *) GPIO_ENABLE_W1TS_REG; // REGISTRE PER FICAR BITS A 1 DEL OUT_ENABLE
- volatile uint32_t *gpio_enable_witc_reg = (volatile uint32_t *) GPIO_ENABLE_W1TC_REG; // REGISTRE PER FICAR BITS A 0 DEL OUT_ENABLE
- //PIN CONFIGURATION
- volatile uint32_t *gpio_pin5_reg = (volatile uint32_t *) GPIO_PIN5_REG; // REGISTRE PER HABILITAR ELS GPIO DEL 0 AL 31
- volatile uint32_t *gpio_func5_out_sel_cfg_reg = (volatile uint32_t *) GPIO_FUNC0_OUT_SEL_CFG_REG; // REGISTRE PER FICAR BITS A 1 DEL OUT_ENABLE
- /*------------------------------IO MUX CONFIG-----------------------------------*/
- volatile uint32_t *io_mux_gpio5_reg = (volatile uint32_t *) IO_MUX_GPIO5_REG; // REGISTRE PER HABILITAR ELS GPIO DEL 0 AL 31
- void app_main()
- {
- *gpio_enable_reg = 0xFFFFFFFF;
- /*ACTIVACION PWM LEDC*/
- /*------------------------DESACTIVEM EL HIGH SPEED TIMER---------------------*/
- *ledc_hsch0_conf0_reg=0x00000000;
- *ledc_hsch0_hpoint_reg=0x00000000;
- *ledc_hsch0_duty_reg=0x00000000;
- *ledc_hsch0_conf1_reg=0x00000000;
- *ledc_hsch0_duty_r_reg=0x00000000;
- /*------------------------CONFIGUREM EL LOW SPEED PWM------------------------*/
- *ledc_lsch0_conf0_reg=0b00000000000000000000000000000100; // configuracio dels bits 4-0 on configurem el timer 0 i el output enable
- *ledc_lsch0_hpoint_reg=0b00000000000011111111111111111111; // configuracion del numero maximo al que llegara el timer
- *ledc_lsch0_duty_reg=0x0003FFFF; // configuracion del duty cycle
- *ledc_lsch0_conf1_reg=0x00000000; // registro utilizado para aplicar incrementos y decrementos graduales al duty cycle
- *ledc_lsch0_conf1_reg=0b10000000000000000000000000000000;//ejecutar esta linia para aplicar el incremento o decremento del duty cicle configurado en la linia anterior.
- *ledc_lsch0_duty_r_reg=0x00000000; // registre de lectura del duty cycle en remps real
- /*-----------------------CONFIGUREM EL TIMER 0-------------------------------*/
- *ledc_conf_reg= 0x00000001; // freq de 8 MHz
- *ledc_lstimer0_conf_reg=0b00000010010011100010000000001010;// registre que configura el preescaler del timer
- /*-------------CONFIGUREM LA MATRIU GPIO PER ENRUTAR LA SENYAL PWM-----------*/
- /*
- //OUTPUT CONTROL
- *gpio_out_reg = 0x00000000; // REGISTRE QUE AFECTA ALS GPIO DEL 0 AL 31
- *gpio_out_reg =
- *gpio_out_w1ts_reg = 0x00000000; // REGISTRE PER FICAR BITS A 1 DEL OUT_REG
- *gpio_out_w1ts_reg =
- *gpio_out_w1tc_reg = 0x00000000; // REGISTRE PER FICAR BITS A 0 DEL OUT_REG
- *gpio_out_w1tc_reg =
- */
- //OUTPUT ENABLE
- *gpio_enable_reg = 0x00000000; // REGISTRE PER HABILITAR ELS GPIO DEL 0 AL 31
- *gpio_enable_w1ts_reg = 0x00000000; // REGISTRE PER FICAR BITS A 1 DEL OUT_ENABLE
- *gpio_enable_w1ts_reg |=(1<<GPIO5);
- *gpio_enable_witc_reg = 0x00000000; // REGISTRE PER FICAR BITS A 0 DEL OUT_ENABLE
- //GPIO PIN CONFIGURATION
- *gpio_pin5_reg = 0x00000000; // REGISTRE PER HABILITAR ELS GPIO DEL 0 AL 31 (INTERRUPCIONS)
- *gpio_func5_out_sel_cfg_reg = 0x00000000; // REGISTRE PER FICAR BITS A 1 DEL OUT_ENABLE
- *gpio_func5_out_sel_cfg_reg = 0b00000000000000000000010001100010;
- //IO_MUX_CONFIGURATION
- *io_mux_gpio5_reg = 0x00000000;
- *io_mux_gpio5_reg = 0b00000000000000000000100000000000;
- }