« Phishing: DON'T CLICK THAT LINK! | Main | Tech support: Motor positioning »

Tech Support: Servo pulses

Nathan wrote:

Hello, For a device I am developing I need to be able to output a PWM signal (for servo control) in fractions between 1 and 2 mS. I have seen that there is a command which can output a signal in whole units of mSecs, but is there a way to break it down into finer incremements?

You would be able to generate servo pulses using what's known as a software timing loop. I am at home right now, without an oscilloscope or an MS12, so I can't experiment to get the right parameters.

A software timing loop simple wastes time by executing meaningless instructions endlessly, inside a counting loop. We don't publish instruction execution times, so some experimentation is required. Be also aware that different boards have different speeds. For example, the MS120, which replaces the MS12 you have, is *about* 2x as fast.

The best resolution you will get is the time of one instruction. From memory, for the MS12 that's about 170uS.

You can also do a time wasting "chain", i.e. lists of instructions carefully constructed to waste a certain amount of time. You construct one chain for each delay you wish to generate. You may for example decide to have 20 chains, for 1.0, 1.05, 1.1, ... 1.9, 1.95 and 2.0mS. To do that you need to know the execution times of several instructions and then juggle them around to create the chains. This can be done ... I once designed a microcontroller tone decoder chip that could detect any arbitrary frequency in 1uS steps from about 300Hz to 3kHz for Selcall decoding - all done in firmware. In that processor, the 3870 , 1µS was the smallest difference in execution times. The SPLat works very differently, so 10-50µS would be a good result.

I checked out servo pulses with Google. It seems OK if you generate one pulse every 20-30mS. On that basis I strongly suggest you use MultiTrack programming, and have the servo pulse generation as a single task that runs every (say) 20mS (experiment!) That will leave plenty of processor time for other jobs.

The following program will allow you to determine instruction times for your board.

        LaunchTask      TimeIt
LaunchTask DoIt
RunTasksForever

xx defByte

DoIt
YieldTask
; MMi201

;*** vvvv One instruction below here gets timed vvvvvvvv

; dmgnz xx,y1 ;172
; Pop ;140.3
; And ;144.2
; ON 5 ;206.7
; swap ;136.4
; GoTo Y1 ;148.1
recall xx ;163.75

Y1 GoTo DoIt



InstTimer defTIME24
CounterLo defBYTE
CounterHi defBYTE


TimeIt:
STStart InstTimer
SetMem CounterHi,10
TimeIt1:
YieldTask
DMGNZ CounterLo,TimeIt1
DMGNZ CounterHi,TimeIt1


fSTTimeSince InstTimer
fLoadQ 3.90625
fMUL
fLoadQ -805 ;<<<< adjust for 0 when nothing in the DoIt loop

fAdd
OBLCD_SetCur 0,0
OBLCD_fDispW 8,2
OBLCD_Text 228,"S"
on 15
pause 10
off 15
GoTo TimeIt

TrackBack

TrackBack URL for this entry:
http://www.splatco.com/cgi-sys/cgiwrap/microcon/managed-mt/mt-tb.cgi/39

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)


About

This page contains a single entry from the blog posted on June 18, 2007 6:58 PM.

The previous post in this blog was Phishing: DON'T CLICK THAT LINK!.

The next post in this blog is Tech support: Motor positioning.

Many more can be found on the main index page or by looking through the archives.

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by
Movable Type 3.33