Need a micro-second timer
LoopyByteloose
Posts: 12,537
Hi all,
I know that that SimpleIDE provides mstimer.h for millisecond delays, but in porting Arduino code over to the Propeller I have run into problems as the code uses the Arduino library that include a microsecond timer.
I have created a good timer for micro second delays in pfth Forth that worked very linearly down to about 25 microseconds. Under that, system call overhead begain to distort the timing. I have looked at the mstimer.h library and the c code, but I am not finding much to indicate how to create my own micro-second timer library.
Any suggestions before I plod along on my own?
I know that that SimpleIDE provides mstimer.h for millisecond delays, but in porting Arduino code over to the Propeller I have run into problems as the code uses the Arduino library that include a microsecond timer.
I have created a good timer for micro second delays in pfth Forth that worked very linearly down to about 25 microseconds. Under that, system call overhead begain to distort the timing. I have looked at the mstimer.h library and the c code, but I am not finding much to indicate how to create my own micro-second timer library.
Any suggestions before I plod along on my own?
Comments
The PropGCC C library already has a usleep() function that sleeps for a given number of microseconds. The prototype is in <unistd.h>, if I remember correctly.
I am not sure that a delay, a sleep, and a timer are the same thing.
Sleep mode in a BasicStamp actually puts the microcontroller into a low power suspended state.
Delay mode in anything is generally a delay
Timer mode could be a lot of things and more complex.
I have to study both the Propeller GCC and the Arduino libraries to sort out whether they are trying to do the same thing or something completely different or similar things in different ways.
Propelleruino library is attempting to mimic Arduino libraries, but it is only partally completed at this point.
If the function is "doSomeKindOfSleep(T);" where T is seconds, milliseconds, microseconds then do you really care if the processor goes into some low power mode of not? As far as you program is concerned that function returns after whatever time and you continue on your merry way.
Timers generally look a bit different, perhaps "setTimeout(someFunction, 1000);" Which returns immediately but "someFunction" will be called a thousand whatever units later.
attachInterrupt(function, period)
Calls a function at the specified interval in microseconds. Be careful about trying to execute too complicated of an interrupt at too high of a frequency, or the CPU may never enter the main loop and your program will 'lock up'. Note that you can optionally set the period with this function if you include a value in microseconds as the last parameter when you call it.
You surely wouldn't be needing an INTERRUPT?????
Discussing it here does help. Why so?
Well, I look at 'timers' and think of just the Propeller context. The code may be an Arduino context and trying to do a PWM or a sleep funciton. These things have to be sorted out in different ways or just eliminated.
I do learn a lot by the comparison and contrast processes. But there is a bit of confusion along the way. Thanks to all.
At this point, I am trying to eliminate all sleep functions and watchdog timer calls... they are distracting.
Hope this helps