[TriLUG] C linux programming question

Jeff Jackowski jeffj1 at hiwaay.net
Sat May 24 17:54:41 EDT 2003


On Sat, 24 May 2003, Scott G. Hall wrote:

I'll add a few things to the discussion. I have messed with serial data
(PC <-> microcontroller) and a PC in my car, although not at the same
time.

>Please note that serial interfaces are not like simple input ports.
>A positive value (a '1') is defined as -12v, and a negative is +12v.
>The voltage of the value actually is anywhere from 3 to 15 volts; in
>other words a positive is -15v to -3v, and a negative is +3v to +15v.
>The -3v to +3v range is undefined and is specified to represent no
>value change.

Actually, PCs implement RS-574, not RS-232. While they are very similar,
RS-574 provides a 9-pin connector and defines a signal of 0 volts to be a
logic 1. This allows a microcontroller running on 5 volts to send data
directly to a PC serial port without any voltage level converter. It works
quite well.

Using this detail, you could connect the accessory power line to carrier 
detect or another line to sense the power state. You won't need voltage 
level conversion.

However, you will need to protect the serial port against noise on that
power line, else you serial port might not last a month. Unless you don't
run the car's engine, anyway. On a buzzer I made to alert me when I leave
my headlights on, I had to deal with the same basic problem. I used a
diode to let current flow only from the power line (a serial port
shouldn't need this), a 3.3K ohm resistor to limit the current, and a
small capacitor to eat the remaining low current noise. Its been working
fine for over two years.

>>> Hey all.  Is it possible, using C, to monitor voltage on one pin of a
>>> serial port when voltage is supplied from an outside source or do I
>>> have to knuckle under and learn some assembly for this task?  What I'm
>>> after here is with an embedded linux machine mounted in a car and I
>>> want to have power supplied by an always-on supply in the car.  I'd
>>> also like to have a pin on a serial port connected to a "only on when
>>> running" wire (somehow).  So when the voltage drops to zero on the
>>> "only on when running" pin the embedded device will shut itself down
>>> automatically (the device would be turned on manually via an "on"
>>> button).
>>>
>>> Is this theoretically possible using C?

The power supply itself cannot be done in C  :-)

Seriously, though, the power supply will also need to be protected from
noise on the car's power supply. If you're using a DC->AC converter, the
converter should solve the problem. I tried using a DC->DC power supply
(avoids issues with a 60Hz tone on audio output), but I didn't solve the
noise problem well enough. The power supply quit working properly after
two years and I haven't fixed it yet.

Another issue to consider if you haven't already, especially if a
DC->AC->DC power setup is used, is how much current will the supply draw
when the computer is off. It may only become a problem when the car is
parked for an extended period of time. I suppose with something like a
relay and a switch wired to an always on flip-flop, the supply could be
turned completely off by the computer until the user turns it back on.

Good luck!

-- 
Jeff Jackowski
        http://ro.com/~jeffj/




More information about the TriLUG mailing list