Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.0.1] MCPWM fault not work (IDFGH-3473) #5433

Closed
Wielebny666 opened this issue Jun 11, 2020 · 22 comments
Closed

[4.0.1] MCPWM fault not work (IDFGH-3473) #5433

Wielebny666 opened this issue Jun 11, 2020 · 22 comments
Labels
Status: Done Issue is done internally

Comments

@Wielebny666
Copy link
Contributor

Environment

  • IDF version 4.0.1
  • Compiler version xtensa-esp32-elf-gcc (crosstool-NG esp-2019r2) 8.2.0
  • Operating System: [Windows]
  • (Windows only) environment type: [ESP Command Prompt]
  • Using an IDE?: [Eclipse]
  • Power Supply: [USB]

Problem Description

Changing the fault signal has no effect on outputs A and B.

Code to reproduce this issue

	mcpwm_pin_config_t pin_config =
		{
			.mcpwm0a_out_num = output_a,
			.mcpwm0b_out_num = output_b,
			.mcpwm_fault0_in_num = GPIO_NUM_14,
		};

	ESP_ERROR_CHECK(mcpwm_set_pin(MCPWM_UNIT_0, &pin_config));

	mcpwm_config_t mcpwm_config =
		{
			.frequency = MOSFET_PWM_INIT_FREQ,
			.cmpr_a = 50.0,
			.cmpr_b = 50.0,
			.counter_mode = MCPWM_UP_DOWN_COUNTER,
		};

	ESP_ERROR_CHECK(mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_0, &mcpwm_config));
	ESP_ERROR_CHECK(mcpwm_stop(MCPWM_UNIT_0, MCPWM_TIMER_0));
	ESP_ERROR_CHECK(mcpwm_set_duty_type(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_A, MCPWM_DUTY_MODE_0));
	ESP_ERROR_CHECK(mcpwm_set_duty_type(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_B, MCPWM_DUTY_MODE_1));

	ESP_LOGI(TAG, "MCPWM Fault init...");
	gpio_pulldown_en(GPIO_NUM_14);
	ESP_ERROR_CHECK(mcpwm_fault_init(MCPWM_UNIT_0, MCPWM_HIGH_LEVEL_TGR, MCPWM_SELECT_F0));
	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_start(MCPWM_UNIT_0, MCPWM_TIMER_0));

I tried with mcpwm_basic_config_example.c and also not work.

@github-actions github-actions bot changed the title [4.0.1] MCPWM fault not work [4.0.1] MCPWM fault not work (IDFGH-3473) Jun 11, 2020
@Alvin1Zhang
Copy link
Collaborator

Thanks for reporting, we will look into.

@Wielebny666
Copy link
Contributor Author

Some conclusions?

@koobest
Copy link
Contributor

koobest commented Jun 15, 2020

Hi, @Wielebny666
I can not reproduce your issue with your test code.

image

I would suggest that you configure IO in this way:

    mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0A, 18);
    mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0A, 19);
    mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM_FAULT_0, 5);

@Wielebny666
Copy link
Contributor Author

This is strange.

#doesn't work

		mcpwm_pin_config_t pin_config =
			{
				.mcpwm0a_out_num = output_a,
				.mcpwm0b_out_num = output_b,
				.mcpwm1a_out_num = GPIO_NUM_NC,
				.mcpwm1b_out_num = GPIO_NUM_NC,
				.mcpwm2a_out_num = GPIO_NUM_NC,
				.mcpwm2b_out_num = GPIO_NUM_NC,
				.mcpwm_sync0_in_num = GPIO_NUM_NC,
				.mcpwm_sync1_in_num = GPIO_NUM_NC,
				.mcpwm_sync2_in_num = GPIO_NUM_NC,
				.mcpwm_fault0_in_num = input_shutdown,
				.mcpwm_fault1_in_num =  GPIO_NUM_NC,
				.mcpwm_fault2_in_num =  GPIO_NUM_NC,
				.mcpwm_cap0_in_num =  GPIO_NUM_NC,
				.mcpwm_cap1_in_num =  GPIO_NUM_NC,
				.mcpwm_cap2_in_num =  GPIO_NUM_NC,
			};

		ESP_ERROR_CHECK(mcpwm_set_pin(MCPWM_UNIT_0, &pin_config));

#work

	mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0A, output_a);
	mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0B, output_b);
	mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM_FAULT_0, input_shutdown);

@koobest
Copy link
Contributor

koobest commented Jun 15, 2020

Hi, @Wielebny666

mcpwm_pin_config_t contains other pins' configuration, if not used, you should set it to -1.

@Wielebny666
Copy link
Contributor Author

I know.
gpio.h:

    GPIO_NUM_NC = -1,    /*!< Use to signal not connected to S/W */

@wilhelmw201
Copy link

wilhelmw201 commented Jun 18, 2020

hi,
are you sure this doesn't work?
mcpwm_pin_config_t pin_config =
{
.mcpwm0a_out_num = output_a,
.mcpwm0b_out_num = output_b,
.mcpwm1a_out_num = GPIO_NUM_NC,
.mcpwm1b_out_num = GPIO_NUM_NC,
.mcpwm2a_out_num = GPIO_NUM_NC,
.mcpwm2b_out_num = GPIO_NUM_NC,
.mcpwm_sync0_in_num = GPIO_NUM_NC,
.mcpwm_sync1_in_num = GPIO_NUM_NC,
.mcpwm_sync2_in_num = GPIO_NUM_NC,
.mcpwm_fault0_in_num = input_shutdown,
.mcpwm_fault1_in_num = GPIO_NUM_NC,
.mcpwm_fault2_in_num = GPIO_NUM_NC,
.mcpwm_cap0_in_num = GPIO_NUM_NC,
.mcpwm_cap1_in_num = GPIO_NUM_NC,
.mcpwm_cap2_in_num = GPIO_NUM_NC,
};
ESP_ERROR_CHECK(mcpwm_set_pin(MCPWM_UNIT_0, &pin_config));

Here is a program that i used to test your code. It seems to run correctly on my board. I suspect you didn't call mcpwm_fault_set_cyc_mode to specify the bahavior when a fault is detected, in which the default is MCPWM_ACTION_NO_CHANGE.

mcpwm_config_t pwm_config;
pwm_config.frequency = 300;                        
pwm_config.cmpr_a = 25.0;                               
pwm_config.cmpr_b = 35.0;                               
pwm_config.counter_mode = MCPWM_UP_DOWN_COUNTER;       
pwm_config.duty_mode = MCPWM_DUTY_MODE_0;              
mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_0, &pwm_config);  

int output_a = 4;
int output_b = 2;
int input_shutdown = 25;

mcpwm_pin_config_t pin_config =
{
    .mcpwm0a_out_num = output_a,
    .mcpwm0b_out_num = output_b,
    .mcpwm1a_out_num = GPIO_NUM_NC,
    .mcpwm1b_out_num = GPIO_NUM_NC,
    .mcpwm2a_out_num = GPIO_NUM_NC,
    .mcpwm2b_out_num = GPIO_NUM_NC,
    .mcpwm_sync0_in_num = GPIO_NUM_NC,
    .mcpwm_sync1_in_num = GPIO_NUM_NC,
    .mcpwm_sync2_in_num = GPIO_NUM_NC,
    .mcpwm_fault0_in_num = input_shutdown,
    .mcpwm_fault1_in_num =  GPIO_NUM_NC,
    .mcpwm_fault2_in_num =  GPIO_NUM_NC,
    .mcpwm_cap0_in_num =  GPIO_NUM_NC,
    .mcpwm_cap1_in_num =  GPIO_NUM_NC,
    .mcpwm_cap2_in_num =  GPIO_NUM_NC,
};
ESP_ERROR_CHECK(mcpwm_set_pin(MCPWM_UNIT_0, &pin_config));


mcpwm_fault_set_cyc_mode(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_SELECT_F0, MCPWM_ACTION_FORCE_LOW, MCPWM_ACTION_FORCE_LOW);
ESP_ERROR_CHECK(mcpwm_fault_init(MCPWM_UNIT_0, MCPWM_HIGH_LEVEL_TGR, MCPWM_SELECT_F0));

for(;;)
{
    printf("Fault pin: %d\n", gpio_get_level(input_shutdown));
    vTaskDelay(pdMS_TO_TICKS(1000));
}

@Alvin1Zhang
Copy link
Collaborator

@Wielebny666 Would you please help share if any updates for this issue? Thanks.

@Wielebny666
Copy link
Contributor Author

Hi,

[...] I suspect you didn't call mcpwm_fault_set_cyc_mode to specify the bahavior when a fault is detected, in which the default is MCPWM_ACTION_NO_CHANGE.

Seriously?

my code:

[...]
ESP_ERROR_CHECK(mcpwm_fault_init(MCPWM_UNIT_0, MCPWM_HIGH_LEVEL_TGR, MCPWM_SELECT_F0)); 
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));
[...]

I changed nothing in the code except gpio initiation and it started working.

Difference between my and your code is in the order of calls mcpwm_fault_init and mcpwm_fault_set_cyc_mode.

I will check it again today...

@Wielebny666
Copy link
Contributor Author

OK, i admit mea culpa.

This work

	mcpwm_pin_config_t pin_config =
		{
			.mcpwm0a_out_num = output_a,
			.mcpwm0b_out_num = output_b,
			.mcpwm1a_out_num = GPIO_NUM_NC,
			.mcpwm1b_out_num = GPIO_NUM_NC,
			.mcpwm2a_out_num = GPIO_NUM_NC,
			.mcpwm2b_out_num = GPIO_NUM_NC,
			.mcpwm_sync0_in_num = GPIO_NUM_NC,
			.mcpwm_sync1_in_num = GPIO_NUM_NC,
			.mcpwm_sync2_in_num = GPIO_NUM_NC,
			.mcpwm_fault0_in_num = input_pwm,
			.mcpwm_fault1_in_num =  GPIO_NUM_NC,
			.mcpwm_fault2_in_num =  GPIO_NUM_NC,
			.mcpwm_cap0_in_num =  GPIO_NUM_NC,
			.mcpwm_cap1_in_num =  GPIO_NUM_NC,
			.mcpwm_cap2_in_num =  GPIO_NUM_NC,
		};

	ESP_ERROR_CHECK(mcpwm_set_pin(MCPWM_UNIT_0, &pin_config));

	mcpwm_config_t mcpwm_config =
		{
			.frequency = MOSFET_PWM_INIT_FREQ,
			.cmpr_a = 50.0,
			.cmpr_b = 50.0,
			.counter_mode = MCPWM_UP_DOWN_COUNTER, };

	ESP_ERROR_CHECK(mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_0, &mcpwm_config));

	ESP_ERROR_CHECK(mcpwm_stop(MCPWM_UNIT_0, MCPWM_TIMER_0));
	ESP_ERROR_CHECK(mcpwm_set_duty_type(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_A, MCPWM_DUTY_MODE_0));
	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_init(MCPWM_UNIT_0, MCPWM_LOW_LEVEL_TGR, MCPWM_SELECT_F0));
	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_start(MCPWM_UNIT_0, MCPWM_TIMER_0));

but, not work

	mcpwm_pin_config_t pin_config =
		{
			.mcpwm0a_out_num = output_a,
			.mcpwm0b_out_num = output_b,
			.mcpwm1a_out_num = GPIO_NUM_NC,
			.mcpwm1b_out_num = GPIO_NUM_NC,
			.mcpwm2a_out_num = GPIO_NUM_NC,
			.mcpwm2b_out_num = GPIO_NUM_NC,
			.mcpwm_sync0_in_num = GPIO_NUM_NC,
			.mcpwm_sync1_in_num = GPIO_NUM_NC,
			.mcpwm_sync2_in_num = GPIO_NUM_NC,
			.mcpwm_fault0_in_num =  GPIO_NUM_NC,
			.mcpwm_fault1_in_num = input_shutdown,
			.mcpwm_fault2_in_num =  GPIO_NUM_NC,
			.mcpwm_cap0_in_num =  GPIO_NUM_NC,
			.mcpwm_cap1_in_num =  GPIO_NUM_NC,
			.mcpwm_cap2_in_num =  GPIO_NUM_NC,
		};

	ESP_ERROR_CHECK(mcpwm_set_pin(MCPWM_UNIT_0, &pin_config));

	mcpwm_config_t mcpwm_config =
		{
			.frequency = MOSFET_PWM_INIT_FREQ,
			.cmpr_a = 50.0,
			.cmpr_b = 50.0,
			.counter_mode = MCPWM_UP_DOWN_COUNTER, };

	ESP_ERROR_CHECK(mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_0, &mcpwm_config));

	ESP_ERROR_CHECK(mcpwm_stop(MCPWM_UNIT_0, MCPWM_TIMER_0));
	ESP_ERROR_CHECK(mcpwm_set_duty_type(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_A, MCPWM_DUTY_MODE_0));
	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_init(MCPWM_UNIT_0, MCPWM_LOW_LEVEL_TGR, MCPWM_SELECT_F1));
	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_start(MCPWM_UNIT_0, MCPWM_TIMER_0));

and also not work:

	mcpwm_pin_config_t pin_config =
		{
			.mcpwm0a_out_num = output_a,
			.mcpwm0b_out_num = output_b,
			.mcpwm1a_out_num = GPIO_NUM_NC,
			.mcpwm1b_out_num = GPIO_NUM_NC,
			.mcpwm2a_out_num = GPIO_NUM_NC,
			.mcpwm2b_out_num = GPIO_NUM_NC,
			.mcpwm_sync0_in_num = GPIO_NUM_NC,
			.mcpwm_sync1_in_num = GPIO_NUM_NC,
			.mcpwm_sync2_in_num = GPIO_NUM_NC,
			.mcpwm_fault0_in_num = input_pwm,
			.mcpwm_fault1_in_num = input_shutdown,
			.mcpwm_fault2_in_num =  GPIO_NUM_NC,
			.mcpwm_cap0_in_num =  GPIO_NUM_NC,
			.mcpwm_cap1_in_num =  GPIO_NUM_NC,
			.mcpwm_cap2_in_num =  GPIO_NUM_NC,
		};

	ESP_ERROR_CHECK(mcpwm_set_pin(MCPWM_UNIT_0, &pin_config));

	mcpwm_config_t mcpwm_config =
		{
			.frequency = MOSFET_PWM_INIT_FREQ,
			.cmpr_a = 50.0,
			.cmpr_b = 50.0,
			.counter_mode = MCPWM_UP_DOWN_COUNTER, };

	ESP_ERROR_CHECK(mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_0, &mcpwm_config));

	ESP_ERROR_CHECK(mcpwm_stop(MCPWM_UNIT_0, MCPWM_TIMER_0));
	ESP_ERROR_CHECK(mcpwm_set_duty_type(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_A, MCPWM_DUTY_MODE_0));
	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_init(MCPWM_UNIT_0, MCPWM_LOW_LEVEL_TGR, MCPWM_SELECT_F0));
	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_init(MCPWM_UNIT_0, MCPWM_LOW_LEVEL_TGR, MCPWM_SELECT_F1));
	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_start(MCPWM_UNIT_0, MCPWM_TIMER_0));

when init via mcpwm_gpio_init
all configuration work correctly.

@Wielebny666
Copy link
Contributor Author

This problem is in all ver from 2.1 to master

@Wielebny666
Copy link
Contributor Author

Why nobody approved pull requests?
Is 4.0 branch still alive?

@costaud
Copy link
Collaborator

costaud commented Jul 9, 2020

fixed in master branch, will be backported to 4.0 soon.

@Wielebny666
Copy link
Contributor Author

fixed in master branch, will be backported to 4.0 soon.

are you sure?

espressif-bot pushed a commit that referenced this issue Jul 25, 2020
Signed-off-by: wubowen <wubowen@espressif.com>

Merges #5491
Closes #5433
@Wielebny666
Copy link
Contributor Author

Wielebny666 commented Jul 29, 2020

fixed in master branch, will be backported to 4.0 soon.

20 days have passed and there is still no patch in branch 4.0

@Wielebny666
Copy link
Contributor Author

Please reopen.

espressif-bot pushed a commit that referenced this issue Aug 1, 2020
Signed-off-by: wubowen <wubowen@espressif.com>

Merges #5491
Closes #5433
@Alvin1Zhang
Copy link
Collaborator

Thanks for reporting, and reopened the ticket, will update once the fix on release/4.0 is available on GitHub. Thanks.

@Alvin1Zhang Alvin1Zhang reopened this Aug 3, 2020
@Alvin1Zhang
Copy link
Collaborator

Thanks for reporting and sorry for slow turnaround. Fix on release/4.0 is available at fcb0206, feel free to reopen if the issue still happens.

@Wielebny666
Copy link
Contributor Author

Wielebny666 commented Aug 5, 2020

This problem is in all ver from 2.1 to master

Reopen, please check other versions.

@Wielebny666
Copy link
Contributor Author

Relase v4.1 stable have this same problem.
REOPEN

@Alvin1Zhang Alvin1Zhang reopened this Sep 8, 2020
@Ethan-CYQ
Copy link
Contributor

Hi, @Wielebny666
Release/v4.1 have solved this problem in our internal gitlab,
but have no synchronize to github yet. We will do that as soon as possible.

espressif-bot pushed a commit that referenced this issue Sep 10, 2020
Signed-off-by: wubowen <wubowen@espressif.com>

Merges #5491
Closes #5433
espressif-bot pushed a commit that referenced this issue Oct 30, 2020
Signed-off-by: wubowen <wubowen@espressif.com>

Merges #5491
Closes #5433
@Alvin1Zhang
Copy link
Collaborator

Fix on release/4.0 is fcb0206, feel free to reopen. Thanks.

@espressif-bot espressif-bot added the Status: Done Issue is done internally label Mar 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Done Issue is done internally
Projects
None yet
Development

No branches or pull requests

7 participants