How to get a fixed repeat loop time.
BTX
Posts: 674
Hi all.
I've to get from a repeat loop the same time in each iteration.
But the time that·take·some job into the repeat loop is variable, and less than the time that I need in each iteration, so this is correct for me.
Some ideas ...how I could do this ?
I tried using cnt register but without luck in that case.
This don't work me correctly:
It seems that the time of each iteration that I get, is not the same everytime.
Thanks in advance !!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Regards.
Alberto.
I've to get from a repeat loop the same time in each iteration.
But the time that·take·some job into the repeat loop is variable, and less than the time that I need in each iteration, so this is correct for me.
Some ideas ...how I could do this ?
I tried using cnt register but without luck in that case.
This don't work me correctly:
It seems that the time of each iteration that I get, is not the same everytime.
repeat x:= cnt + constant_value (number of cicles in constant_value is greater tha the number of cicles of the 'job') . . do some variable job here. . repeat while cnt =< x
Thanks in advance !!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Regards.
Alberto.
Comments
PE Kit Labs: http://forums.parallax.com/showthread.php?p=617192
I/O and Timing Lab: http://www.parallax.com/dl/docs/prod/prop/PE-IOTimingBasics-v1.0.zip
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andy Lindsay
Education Department
Parallax, Inc.
I'll read that.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Regards.
Alberto.
I did this:
And this:
And this:
And it never works, the time involved in the pieces of my code (two waitpeq plus two outa) is less than 1/15 sec.
If I have so problem in this part of my code, a solution for me could be do some similar but into another assembly code.
How to do that ?? in asm. I could try....
Thanks in advance.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Regards.
Alberto.
waitcnt(clkfreq/1000 * t + cnt)· ' t = time in milliseconds
-Martin
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
StampPlot - GUI and Plotting, and XBee Wireless Adapters
Southern Illinois University Carbondale, Electronic Systems Technologies
This should work.
You need to remember that cnt is incrementing all the time in the background so you work out your target time, do stuff and then wait for the target time to come arround. Your examples do something and then add a fixed delay or wait a fixed time and do something which is not the same.
Graham
p.s. this assumes dT is a long enough time for the waitpeq's to occur.
Yes, I know this way... but in my case "t" is variable and unknown in each iteration inside the repeat loop.
Graham.
Yes , this should work... I tried with a different code into the repeat loop and all works fine, my problem is that those two 'waitpeq' sincronyze two differents COGs and one in a different Pchip.
Seems to be a problem with that when I add the waitcnt(T), if instead that, I add a waitcnt(clkfreq/n + cnt) it works fine ...but each iteration has a different execute time, dT and T variables are longs.
Perhaps I'm not explaining well in English what I want to say.
I just only copy the idea from "PE-IOTimingBasics-v1.0.zip" that Andy Lindsay suggest to me.
I need to try into a differents piece of my code, some that is in asm, the question is ...How could I do the same as Andy example but in asm ?
I attach here the page 20 of the pdf, where shows, when a code is correct and incorrect, see the example of "timekeeping aplications", ·take a look at that, is simple but awesome.
That's what I need·to insert in my·asm code.
Thanks all !!!!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Regards.
Alberto.
Did you notice that I had modified your code?
My version will work even when the waitpeq take different times.
You can do the same thing in assembly but using the assembly version of waitcnt.
Graham
If what you are doing is not working it is because the waitpeq do not happen in time, this means you may need to make dT larger.
Graham
I'll be testing your code later, to check if it works for me.
What I'm doing, is to send data from the master Pchip to the 16 slaves that I have.....
I'm sending a fixed quantity of data to each slave, and then they send the data to the display.
Like I send many frames to the display, and I've check that all the 'animation' take about a rate of 22fps and it is correct seeing it, I want to delay all the data, to get a frame rate of only 15 fps. Due the video that I'm playing was done at 15fps and if I leave the controller in 22fps I'm getting an image faster than the real video is. (Hope do you understand what I mean and doing....)
Due tehre are so many COGS and Pchis everywhere...it is a bit difficult for me, to get the correct place where to put the delay.
I'll try with your suggests and then I will post again with the results.
Thanks again !!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Regards.
Alberto.
The problem was solved.
The spin code wont work (still with your changes...but is not a code problem, it is some problem with my slaves that get hung with the delay introduced).
I solved that using the "delay" assembly code, into the Master code.
Thanks !!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Regards.
Alberto.
I used the counters and a fixed time length loop to get some really nice stepper drive stuff working, you just increment the counter frequency every loop for a certain number of loops, then keep it constant for a certain number of loops and then decrement it for a certain number of loops, the result is lovely trapizoidal pulse rates up to silly frequencies. You just need to be sure to scale the maximum frequency etc to make sure the "area under the graph" is the distance you wish to travel.
Oh, I got distracted.
Graham