GPIO logical AND

Wielebny
Posts: 5
Joined: Wed Mar 18, 2020 3:28 pm

GPIO logical AND

Postby Wielebny » Sat Nov 14, 2020 7:16 pm

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

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

Re: GPIO logical AND

Postby ESP_Sprite » Sun Nov 15, 2020 3:24 am

No, sorry.

Wielebny
Posts: 5
Joined: Wed Mar 18, 2020 3:28 pm

[SOLVED] GPIO logical AND

Postby Wielebny » Mon Nov 16, 2020 8:42 pm

ESP_Sprite wrote:
Sun Nov 15, 2020 3:24 am
No, sorry.
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));

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

Re: GPIO logical AND

Postby ESP_Sprite » Tue Nov 17, 2020 1:14 am

Okay, I guess that is a way I did not think of. Happy I was proven wrong :)

jamshiddastur
Posts: 1
Joined: Fri Jun 23, 2023 11:49 am

Re: GPIO logical AND

Postby jamshiddastur » Fri Jun 23, 2023 11:53 am

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

Who is online

Users browsing this forum: Bing [Bot] and 79 guests