Borrar filtros
Borrar filtros

Time flowing during loop cycle

1 visualización (últimos 30 días)
Niccolò de Cesare
Niccolò de Cesare el 13 de Jul. de 2016
Editada: Niccolò de Cesare el 13 de Jul. de 2016
Hi everybody,
i've a question: i'm developing a GUI that controls a servo-motor using Arduino, the used servo is a Savox 1268SG but doesn't matter, the servo data sheet report that it spends 0.11s (at 7.4V) to move from 0°->60° and viceversa; i've to do, for example, 90 beats per minute thus for me a beats is composed of 120° roundtrip, hence to do a beat i send this sequence: moving servo 0°->60°, waiting 0.11s, moving servo 60°->0°, waiting 0.11s, like this:
tic
while toc<=60
writePosition(s,0);
pause(ts);
writePosition(s,1);
pause(ts);
pause(ta-2*tc);
end
now, as you see into the loop i use tic/toc for define a minute (60s), theoretically the total amount of pause is composed by: 2*0.11s (one beat) = 0.22s, 0.22s*90 bpm = 19.8s, the remaining time 60s-19.8s = 40.2s must be divided for 90 bpm, 40.2s/90 = 0.447s, and added into the loop (variable ta); this way should produce theoretically 90 bpm, but it doesn't because the other commands subtract time (i.e. writePosition(x,y)), therefore i've previously recorded time spent for execute writePosition(x,y) and subtracting it (variable tc) into the pause period.
tic
writePosition(s,1);
tc = toc;
This solution doesn't work all times because the time recorded by tic/toc for the command writePosition(x,y) varies, therefor sometimes cycle produces 88 bpm, sometimes 89, and so on.
My question is: is there a method to produce an exact amount of time that allows me to produce exactly 90 bpm whenever?

Respuestas (0)

Categorías

Más información sobre MATLAB Support Package for Arduino Hardware en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by