Function for pulseIn() in Arduino to obtain duty cycle from PWM
7 views (last 30 days)
Show older comments
Hello,
I need to replicate the pulseIn() function from Arduino on Simulink model for my project.
I am using this function to convert the pwm feedback from the continuous servo to the anglular position of the motor. I do need to calculate the duty cycle in order to calculate the angle from the feedback, and obtaining tHigh and tLow (high time and low time from pulseIn(pin, HIGH) & pulseIn(pin, LOW)) would be necessary. The return variable is not specified as I would need to use tHigh and tLow to calculate the angle using the equation given in datasheet, which is not a part of the concern.
The pulseIn() in Arduino works as following: (https://www.arduino.cc/reference/en/language/functions/advanced-io/pulsein/)
Syntax: pulseIn(pin, value)
pin: the number of the Arduino pin on which you want to read the pulse.
Description: "Reads a pulse (either HIGH or LOW) on a pin. For example, if value is HIGH, pulseIn() waits for the pin to go from LOW to HIGH, starts timing, then waits for the pin to go LOW and stops timing. Returns the length of the pulse in microseconds or gives up and returns 0 if no complete pulse was received within the timeout."
I tried using tic & toc but Simulink returned million errors. Would there be a good way to approach this problem? Any help would be appreciated.
0 Comments
Answers (0)
See Also
Categories
Find more on Arduino Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!