1.8V on GPIO High?

w3llschmidt
Posts: 8
Joined: Tue Jan 23, 2018 4:56 pm

1.8V on GPIO High?

Postby w3llschmidt » Tue Mar 30, 2021 8:42 pm

My ESP32 have a strange behavior.

With this code i read 3.3V on GPIO19 but 1.8V on GPIO18 :o

I have no idea what did this :cry:

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
PWM.C

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);

}
Last edited by w3llschmidt on Thu Apr 01, 2021 7:21 pm, edited 2 times in total.

ESP_Sprite
Posts: 9764
Joined: Thu Nov 26, 2015 4:08 am

Re: 1.8V on GPIO High?

Postby ESP_Sprite » Wed Mar 31, 2021 3:43 am

How do you define GPIO_OUTPUT_PIN_SEL ?

w3llschmidt
Posts: 8
Joined: Tue Jan 23, 2018 4:56 pm

Re: 1.8V on GPIO High?

Postby w3llschmidt » Thu Apr 01, 2021 4:34 pm

Sorry, i corrected my starting post.

This is how i configure them:

Code: Select all

#define GPIO_OUTPUT_PIN_SEL  ((1ULL<<GPIO_INA1_OUT) | (1ULL<<GPIO_INA2_OUT) | (1ULL<<GPIO_INB1_OUT) | (1ULL<<GPIO_INB2_OUT))

io_conf.pin_bit_mask = GPIO_OUTPUT_PIN_SEL  ;
I got a correct reply:

Code: Select all

I (550) cpu_start: App cpu up.
I (568) heap_init: Initializing. RAM available for dynamic allocation:
I (575) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (581) heap_init: At 3FFB9EF0 len 00026110 (152 KiB): DRAM
I (588) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (594) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (600) heap_init: At 40096DC0 len 00009240 (36 KiB): IRAM
I (607) cpu_start: Pro cpu start user code
I (624) spi_flash: detected chip: generic
I (625) spi_flash: flash io: dio
I (625) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
chip_info.revision: 1
chip_info.cores: 2
4MB external flash
I (649) gpio: GPIO[2]| InputEn: 1| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (649) gpio: GPIO[15]| InputEn: 1| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (659) gpio: GPIO[18]| InputEn: 1| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (669) gpio: GPIO[19]| InputEn: 1| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (679) pwm.c: ready
I (729) wifi:wifi driver task: 3ffc2a24, prio:23, stack:6656, core=0
I (729) system_api: Base MAC address is not set
I (729) system_api: read default base MAC address from EFUSE

w3llschmidt
Posts: 8
Joined: Tue Jan 23, 2018 4:56 pm

Re: 1.8V on GPIO High?

Postby w3llschmidt » Thu Apr 01, 2021 7:20 pm

Any ideas?

With this code i can read 3.3V on both pin's.

Code: Select all

//main.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#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>

#define GPIO_PWM0A_OUT  5	

#define GPIO_INA1_OUT 18	
#define GPIO_INA2_OUT 19	

#define GPIO_OUTPUT_PIN_SEL	((1ULL<<GPIO_INA1_OUT) | (1ULL<<GPIO_INA2_OUT));

void app_main() {

	gpio_config_t io_conf;

		//disable interrupt
		io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
		//set as output mode
		io_conf.mode = GPIO_MODE_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;

	gpio_config(&io_conf);

	mcpwm_config_t pwm_config;

		pwm_config.frequency = 22000;
		pwm_config.cmpr_a = 50;
		pwm_config.cmpr_b = 50;
		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);

	mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0A, GPIO_PWM0A_OUT);

	gpio_set_level(GPIO_INA1_OUT, 1);
	gpio_set_level(GPIO_INA2_OUT, 1);

}

Who is online

Users browsing this forum: No registered users and 118 guests