Set Number of Pulses from MCPWM?

Greg-R
Posts: 18
Joined: Mon Nov 20, 2017 1:01 am

Set Number of Pulses from MCPWM?

Postby Greg-R » Mon Nov 20, 2017 1:07 am

Hello-

I am controlling a small stepper motor with the MCPWM module.
I need a function which will cause the PWM to emit a fixed number of pulses.

My first code uses the Capture module to count pulses, and then an if statement shuts down the PWM output when
the desired number of steps is reached. The capture module is firing an ISR at each pulse. This is creating a large number of interrupts!

I would like a way to configure the PWM to emit "n" number of pulses where n is an integer.
Hopefully this can be done such that the PWM does this autonomously without requiring many interrupts.

Your suggestions are appreciated!

Regards,
Greg

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

Re: Set Number of Pulses from MCPWM?

Postby ESP_Sprite » Mon Nov 20, 2017 11:01 am

What you may be able to do is connect the pulse counter peripheral to the output pin of the MCPWM pin and generate an interrupt after n cycles that way. However, note that depending on your pulse frequency and what the ESP32 is doing, you may run the risk of getting to the ISR too late and accidentally sending out an extra pulse. Have you looked into using other ways to do this? I'd personally grab the RMT peripheral; depending on your exact requirements, this may solve your issue well.

Greg-R
Posts: 18
Joined: Mon Nov 20, 2017 1:01 am

Re: Set Number of Pulses from MCPWM?

Postby Greg-R » Mon Nov 20, 2017 2:01 pm

Thank you, I am going to try both approaches. There is so much functionality on the ESP32, impressive!

Regards,
Greg

Who is online

Users browsing this forum: No registered users and 93 guests