GPIO logical AND
Posted: Sat Nov 14, 2020 7:16 pm
by Wielebny
Hi,
Can you realize AND logical for 2 GPIO inputs and 1 GPIO output without interrupts and reading states in the loop?
Is the use of gpio_matrix_in and gpio_matrix_out the right direction?
regards
Re: GPIO logical AND
Posted: Sun Nov 15, 2020 3:24 am
by ESP_Sprite
No, sorry.
[SOLVED] GPIO logical AND
Posted: Mon Nov 16, 2020 8:42 pm
by Wielebny
Yes
Solution:
Code: Select all
mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0A, GPIO_PWM0A_OUT);
mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM_FAULT_0, INPUT_0);
mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM_FAULT_1, INPUT_1);
mcpwm_config_t mcpwm_config =
{
.frequency = 125000,
.cmpr_a = 100.0,
.counter_mode = MCPWM_UP_DOWN_COUNTER,
.duty_mode = MCPWM_DUTY_MODE_0,
};
ESP_ERROR_CHECK(mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_0, &mcpwm_config));
ESP_ERROR_CHECK(mcpwm_set_duty_type(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_B, MCPWM_DUTY_MODE_1));
ESP_ERROR_CHECK(mcpwm_fault_set_cyc_mode(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_SELECT_F0, MCPWM_FORCE_MCPWMXA_LOW, MCPWM_FORCE_MCPWMXB_LOW));
ESP_ERROR_CHECK(mcpwm_fault_set_cyc_mode(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_SELECT_F1, MCPWM_FORCE_MCPWMXA_LOW, MCPWM_FORCE_MCPWMXB_LOW));
ESP_ERROR_CHECK(mcpwm_fault_init(MCPWM_UNIT_0, MCPWM_LOW_LEVEL_TGR, MCPWM_SELECT_F0));
ESP_ERROR_CHECK(mcpwm_fault_init(MCPWM_UNIT_0, MCPWM_LOW_LEVEL_TGR, MCPWM_SELECT_F1));
Re: GPIO logical AND
Posted: Tue Nov 17, 2020 1:14 am
by ESP_Sprite
Okay, I guess that is a way I did not think of. Happy I was proven wrong
Re: GPIO logical AND
Posted: Fri Jun 23, 2023 11:53 am
by jamshiddastur
I'm trying to use MCPWM_UP_DOWN_COUNTER
and my frequency range is 10K - 100K, i know i have to provide double the frequency to generate the center aligned output. but the factor of twice the frequency changes when i above 12K, for instance if i want to generate 100K i'm providing 200K as frequency but the output is 125K instead. I've also tried to make a loop to see the linearity but by decreasing the value 200K then next jumps comes at around 83K and so on...., this only happens in MCPWM_UP_DOWN_COUNTER if i am using the other mode its fine. Say for instance I want to generate 50kHz and i provide 100000 as frequency it generate 55kHz.
The code snippet is attached below, any help would be appreciated. thanks
//MCPWM_UP_DOWN_COUNTER
mcpwm_config_t pwm_configA;
pwm_configA.frequency = 100000; // frequência = 500Hz,
pwm_configA.cmpr_a = 50.0; // Ciclo de trabalho (duty cycle) do PWMxA = 0
pwm_configA.cmpr_b = 50.0; // Ciclo de trabalho (duty cycle) do PWMxb = 0
pwm_configA.counter_mode = MCPWM_UP_DOWN_COUNTER; // Para MCPWM assimetrico
pwm_configA.duty_mode = MCPWM_DUTY_MODE_0; // Define ciclo de trabalho em nível alto
mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_0, &pwm_configA); // Define PWM0A & PWM0B com as configurações acima
mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0A, Pulse_Pin_1);
mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0B, Pulse_Pin_2);
delay(5000);
int DutyCycle = 40;
mcpwm_set_duty(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_A, DutyCycle);
mcpwm_set_duty(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_B, 100 - DutyCycle); // Configura a porcentagem do PWM no Operador B (Ciclo de trabalho)
mcpwm_set_duty_type(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_A, MCPWM_DUTY_MODE_0);
mcpwm_set_duty_type(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_B, MCPWM_DUTY_MODE_1);