View Single Post
  #6   Spotlight this post!  
Unread 30-07-2009, 19:48
RyanCahoon's Avatar
RyanCahoon RyanCahoon is offline
Disassembling my prior presumptions
FRC #0766 (M-A Bears)
Team Role: Engineer
 
Join Date: Dec 2007
Rookie Year: 2007
Location: Mountain View
Posts: 689
RyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond repute
Re: PWM signals from computer?

Quote:
Originally Posted by shadowraze View Post
I have a linux computer and I was trying to use the serial or parallel port as an output. However, I'm not really sure how to connect the PWM to those ports.
As has been stated, there are many products available that offload control of servos and can be interfaced over RS-232 (serial), IEEE-1284 (parallel), or USB.

Of the three, parallel is probably the best suited for an attempt at directly controlling a servo. And while this is physically/electrically possible, a stock Linux installation is not well equipped to be able to handle this kind of a task. The problem exists in the task scheduling mechanism of the OS, which typically runs on somewhere between a 1ms and 10ms clock.

Explanation of task scheduling:
One of the main jobs of an operating system is to schedule which programs get to use the CPU. The handoff between tasks occurs whenever a program calls any of the faciilities provided by the OS, such as hardware interface, timed delay, writing to the screen, communication between programs running on the system, etc. A scheduling clock of 1ms to 10ms means that a new task is switched into the processor at a minimum of 1ms to 10ms.

The problem that this generates for servo control is that standard servos require a control pulse that varies between 1ms and 2ms. So your program would look something like: turn on servo control output, wait for 1ms-2ms (depending on desired position), turn off servo control output. However, since timed waiting is one of the things provided by the OS, this means that when you call wait in your program, the OS will most likely let another task run on the CPU. This means that for most operating systems, asking your program to wait for 1.3ms doesn't actually mean it will wait for 1.3ms, but is more likely to wait somewhere between 10ms and 20ms.

There is a possible solutions to this. If you're particularly comfortable with Linux, there is a kernal patch available called PREEMPT_RT which enables an alternate scheduling algorithm called preemptive multitasking which basically allow the OS to wrench control away from any of the running programs whenever it wants to, allowing your program to request much more accurate timing intervals, but the process of patching and recompiling a Linux kernel can be painful. Once you have the support in the kernel however, it should be possible to do what you want, and there are a couple articles published by a someone who did something similar to what you are proposing.

All told, though, I think you'd be better off purchasing one of the controller modules, unless you're feeling especially adventurous.

--Ryan
__________________
FRC 2046, 2007-2008, Student member
FRC 1708, 2009-2012, College mentor; 2013-2014, Mentor
FRC 766, 2015-, Mentor