Function for pulseIn() in Arduino to obtain duty cycle from PWM

7 views (last 30 days)
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.
Syntax: pulseIn(pin, value)
pin: the number of the Arduino pin on which you want to read the pulse.
value: type of pulse to read: either HIGH or LOW
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.

Answers (0)

Categories

Find more on Arduino Hardware in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!