With this code i read 3.3V on GPIO19 but 1.8V on GPIO18
I have no idea what did this
PWM.H
Code: Select all
#ifndef MCPWM_H // Header wrapper
#define MCPWM_H // Header wrapper
#define GPIO_PWM0A_OUT 5
#define GPIO_INA1_OUT 18
#define GPIO_INA2_OUT 19
#define GPIO_FAULT0_IN 17
#define GPIO_PWM0B_OUT 4 //PWM0B - PWM B-Signal
#define GPIO_INB1_OUT 15 //INB1 - Direction
#define GPIO_INB2_OUT 2 //INB2 - Direction
#define GPIO_FAULT1_IN 16 //LO2 - Low on Motor Error
#include "driver/mcpwm.h"
#include "soc/mcpwm_reg.h"
#include "soc/mcpwm_struct.h"
//PWM initialisieren
void pwm_init();
//Drive the motor
void brushed_motor_forward(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num , float duty_cycle);
void brushed_motor_backward(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num , float duty_cycle);
void brushed_motor_coast(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num);
void brushed_motor_hard_stop(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num);
#endif // MCPWM_H // Header wrapper
Code: Select all
/*
https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/mcpwm.html
*/
static const char* TAG = "pwm.c";
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <driver/mcpwm.h>
#include <soc/mcpwm_reg.h>
#include <soc/mcpwm_struct.h>
#include <driver/gpio.h>
#include <esp_log.h>
#include <pwm.h>
#define GPIO_OUTPUT_PIN_SEL ((1ULL<<GPIO_INA1_OUT) | (1ULL<<GPIO_INA2_OUT) | (1ULL<<GPIO_INB1_OUT) | (1ULL<<GPIO_INB2_OUT))
void gpio_initialize() {
/*
https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/mcpwm.html#_CPPv418mcpwm_io_signals_t
*/
mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0A, GPIO_PWM0A_OUT);
mcpwm_gpio_init(MCPWM_UNIT_1, MCPWM0B, GPIO_PWM0B_OUT);
mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM_FAULT_0, GPIO_FAULT0_IN);
mcpwm_gpio_init(MCPWM_UNIT_1, MCPWM_FAULT_1, GPIO_FAULT1_IN);
gpio_config_t io_conf;
//disable interrupt
io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
//set as output mode
io_conf.mode = GPIO_MODE_INPUT_OUTPUT;
//bit mask of the pins that you want to set,e.g.GPIO18/19
io_conf.pin_bit_mask = GPIO_OUTPUT_PIN_SEL ;
//pull-down mode
io_conf.pull_down_en = 0;
//pull-up mode
io_conf.pull_up_en = 0;
//configure GPIO with the given settings
gpio_config(&io_conf);
gpio_set_level(GPIO_INA1_OUT, 1);
gpio_set_level(GPIO_INA2_OUT, 1);
}