Silicon ChipA Speed Alarm For Cars; Pt.1 - November 1999 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: DC power in the home; it could be made to work
  4. Feature: USB: Hassle-Free Connections To Your PC by Peter Smith
  5. Project: A Speed Alarm For Cars; Pt.1 by John Clarke
  6. Book Store
  7. Serviceman's Log: Price isn't everything by The TV Serviceman
  8. Project: Multi-Colour LED Christmas Tree by Les Grant
  9. Feature: Electric Lighting; Pt.15 by Julian Edgar
  10. Product Showcase
  11. Feature: Setting Up An Email Server by Peter Smith
  12. Project: Build An Intercom Station Expander by Paul Hoad
  13. Vintage Radio: The case of the disappearing TV sets by Rodney Champness
  14. Project: Foldback Loudspeaker System For Musicians by John Clarke
  15. Project: Railpower Model Train Controller; Pt.2 by John Clarke & Leo Simpson
  16. Order Form
  17. Notes & Errata
  18. Market Centre
  19. Advertising Index
  20. Outer Back Cover

This is only a preview of the November 1999 issue of Silicon Chip.

You can view 34 of the 96 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Items relevant to "A Speed Alarm For Cars; Pt.1":
  • PIC16F84(A)-04/P programmed for the Speed Alarm for Cars [SPEED254.HEX] (Programmed Microcontroller, AUD $10.00)
  • PIC16F84 firmware and source code for the Speed Alarm for Cars [SPEED254.HEX] (Software, Free)
  • Speed Alarm for Cars PCB patterns (PDF download) [05310991/2] (Free)
  • Speed Alarm for Cars panel artwork (PDF download) (Free)
Articles in this series:
  • A Speed Alarm For Cars; Pt.1 (November 1999)
  • A Speed Alarm For Cars; Pt.1 (November 1999)
  • Speed Alarm For Cars, Pt.2 (December 1999)
  • Speed Alarm For Cars, Pt.2 (December 1999)
Articles in this series:
  • Understanding Electric Lighting; Pt.1 (November 1997)
  • Understanding Electric Lighting; Pt.1 (November 1997)
  • Understanding Electric Lighting; Pt.2 (December 1997)
  • Understanding Electric Lighting; Pt.2 (December 1997)
  • Understanding Electric Lighting; Pt.3 (January 1998)
  • Understanding Electric Lighting; Pt.3 (January 1998)
  • Understanding Electric Lighting; Pt.4 (February 1998)
  • Understanding Electric Lighting; Pt.4 (February 1998)
  • Understanding Electric Lighting; Pt.5 (March 1998)
  • Understanding Electric Lighting; Pt.5 (March 1998)
  • Understanding Electric Lighting; Pt.6 (April 1998)
  • Understanding Electric Lighting; Pt.6 (April 1998)
  • Understanding Electric Lighting; Pt.7 (June 1998)
  • Understanding Electric Lighting; Pt.7 (June 1998)
  • Understanding Electric Lighting; Pt.8 (July 1998)
  • Understanding Electric Lighting; Pt.8 (July 1998)
  • Electric Lighting; Pt.9 (November 1998)
  • Electric Lighting; Pt.9 (November 1998)
  • Electric Lighting; Pt.10 (January 1999)
  • Electric Lighting; Pt.10 (January 1999)
  • Electric Lighting; Pt.11 (February 1999)
  • Electric Lighting; Pt.11 (February 1999)
  • Electric Lighting; Pt.12 (March 1999)
  • Electric Lighting; Pt.12 (March 1999)
  • Electric Lighting; Pt.13 (April 1999)
  • Electric Lighting; Pt.13 (April 1999)
  • Electric Lighting, Pt.14 (August 1999)
  • Electric Lighting, Pt.14 (August 1999)
  • Electric Lighting; Pt.15 (November 1999)
  • Electric Lighting; Pt.15 (November 1999)
  • Electric Lighting; Pt.16 (December 1999)
  • Electric Lighting; Pt.16 (December 1999)
Items relevant to "Railpower Model Train Controller; Pt.2":
  • Railpower PCB pattern (PDF download) [09308991] (Free)
  • Railpower panel artwork (PDF download) (Free)
Articles in this series:
  • Build The Railpower; Pt.1 (October 1999)
  • Build The Railpower; Pt.1 (October 1999)
  • Railpower Model Train Controller; Pt.2 (November 1999)
  • Railpower Model Train Controller; Pt.2 (November 1999)
  • Railpower Model Train Controller; Pt.3 (December 1999)
  • Railpower Model Train Controller; Pt.3 (December 1999)

Purchase a printed copy of this issue for $10.00.

Speed Alar Is your driver’s licence looking a bit dodgy? This easy-tobuild speed alarm can help prevent a fine and save you from losing any more demerit points. As a bonus, it can also function as a digital speedometer while still maintaining the speed alert function. Pt.1: By JOHN CLARKE A NYONE WHO DRIVES a car inevitably exceeds the posted speed limit on occasions, either deliberately or due to lack of atten­ tion. But these days, it’s really not a good idea to speed. Apart from the obvious safety considerations, there are lots of speed cameras about and it’s all too easy to cop a heavy fine and maybe even lose your licence. You don’t have to be a speed demon either. On a long trip, your speed can gradually creep up as you become used to the road conditions. It’s also 16  Silicon Chip quite difficult to stick to the speed limit in a 60km/h zone after you have been driving at high speed on the open road – 60km/h seems agonisingly slow after driving at 100km/h. In this situation, a speed alarm can keep you on your toes and ensure that you stick within the posted limit. Another situation where it’s easy to inadvertently exceed the speed limit is if you using a cruise control. Now while cruise controls are a great help when it comes to maintaining a set speed, they do have one inher- ent limitation – the speed of the car can increase beyond the set limit on downhill stretches. Once again, a speed alarm can instantly warn you when you’ve over­stepped the mark. Main features Our new Speed Alarm is quite compact and fits neatly into the smallest available jiffy/zippy box. By contrast, our previous Speed Alarm (described in the December 1997 issue) used a case this size just for the display circuitry. The rest of the circuit was rm All the parts fit on two small PC boards which are housed in a compact plastic case. Note the black cardboard sleeve around the 7-segment displays in the photo at left. This prevents light leakage from the LEDs adjacent to the pushbutton switches from spoiling the appearance of the readout. housed in a separate instrument case and while it was OK for large vehicles, it wasn’t all that easy to squeeze into the average family sedan. So how have we managed to shrink the circuitry so dramati­ cally? The answer is that we have replaced all the discrete control circuitry with a low-cost PIC microprocessor and come up with the necessary software to control the internal “smarts” of this device. The resulting circuitry all fits on two small PC boards which are stacked inside the case. It’s also just as easy to drive as before. As shown, the front panel carries a 3-digit LED display, a LED indicator and three pushbutton switches. Two of these pushbuttons let you set the alarm speed in 5km increments between 0km/h and 155km/h (one switch increases the speed; the other reduces it). As soon as you exceed the preset speed, the indicator LED lights and an internal piezo alarm briefly sounds at 10-second intervals to provide a warning. The third switch selects between three display modes: (1) the alarm speed value; (2) the actual vehicle speed (ie, the unit functions as a digital speedometer); and (3) the alarm off mode. Each press of the switch cycles the unit to the next operating mode – it really is that easy to operate. The alarm off mode is indicated by three dashes (---) on the display. In this mode, the alarm is off and there is no overspeed indication (either audible or visual). The speedometer mode displays the vehicle speed with a resolution of 1km/h over the range from 0-159km/h. If you exceed 159km/h, the display shows 888 to indicate overrange so the circuit is not suitable for use on a racetrack. By the way, the speed alert function continues to operate when the digital speedometer mode is selected. You can even adjust the alarm speed while the unit is in the speedometer mode by pressing the up and down buttons. Each time one of these buttons is pressed, the piezo alarm and the LED both give brief “blips” to let you know that the alarm speed has increased or decreased by 5km/h. If power to the Speed Alarm is interrupted (ie, if the ignition is turned off), the unit “remembers” its current speed alarm and operating mode settings. These settings are then au­ tomatically restored the next time the engine is started. Options OK, so that’s the basic operation of the unit and most drivers will be content with just those features. However, this design uses a microprocessor and that means we can easily include lots of options just by programming them into the soft­ware. And that’s just what we’ve done, to make this unit as versatile as possible. These options are as follows: (1) Disable repeat alarm: this is done by pressing the Up button at the same time as the ignition is turned on. The righthand display will show a dash (-) until the button is released. The Speed Alarm then resumes normal operation but with the repeat alarm feature disabled (ie, the audible alarm now sounds only once when you exNovember 1999  17 Main Features • • • • • • Overspeed indication range of 0-155km/h in 5km/h steps. • • • • • • • • • Speedometer indication from 0-159km/h. Audible and visual alarm indication. Visual alarm stays on during overspeed. Repeat audible alarm sounds every 10 seconds during overspeed. 3-digit LED display. Unit can be switched to display alarm speed or vehicle speed (ie, speedometer mode), or switched off. Overspeed alarm works for both alarm speed and speedometer modes. Audible and visual acknowledgement when a switch is pressed. Repeat alarm and speedometer mode functions can be switched off. Two selectable alarm speed threshold points. Display brightness automatically adjusts to suit ambient light conditions. Illuminated switches for night-time operation. Automatic calibration. All selected settings restored when power switched on by igni­tion. ceed the preset speed limit). The repeat alarm feature now remains disabled even if the ignition is turned off and on again. It is re-enabled by again holding down the Up button as the ignition is turned on. In this case, the display will show an “r” to indicate that the repeat alarm has been reactivated. (2) Disable speedometer mode: this is done by pressing the Mode switch as the ignition is turned on). A dash (-) is indicated on the lefthand display until the button is re­ leased, after which the speedo­meter mode can no longer be select­ed. The Mode switch now simply toggles the unit between off and the speed alarm mode. The speedometer mode is reactivated by again pressing the Mode switch at power up. This time, the lefthand display shows an “S” to indicate that the speedometer option has been enabled. (3). High or low alarm threshold: if the “low” threshold is selected, the alarm sounds as soon as the set speed is reached and stays on until the speed drops by 1.25km/h. Alternatively, if the “high” threshold is selected, the alarm sounds when the speed is 1.25km/h above the set limit and stays on until the speed drops back to this limit. The upper threshold mode is useful if you normally use the speedo-meter setting. It will allow you to travel at the set alarm speed without the alarm sounding. The high or low threshold is selected by pressing the Down button during power up. If the centre display Specifications • • • Overspeed detection accuracy better than 1% above 65km/h. • • • • Hysteresis (alarm on to alarm off speed) 1.25km/h. Speedometer linearity and repeatability to within 1km/h. Speedometer and overspeed detection update time typically 0.5-3 seconds (depends on calibration). Operating current typically less than 300mA. Calibration accuracy typically .002% (depends on oscillator drift). Memory storage endurance typically 10 million times. 18  Silicon Chip shows an “L”, the low threshold is selected. Conversely, if the display shows an “H”, the high threshold is selected. Saving the settings All settings made using the Up, Down and Mode switches are stored in an EEPROM (Electrically Erasable and Programmable Read Only Mem­ ory), so that they are saved when the power is switched off via the ignition. This type of memory can tolerate about 10 million write operations per bit, which means that it will never wear out (at least not in this design). Note that during normal program operation, the Speed Alarm utilises standard RAM which does not suffer from a limited life­time. Both the EEPROM and RAM are included in the PIC microcon­troller, so we don’t have to use separate ICs for this memory. When it is first built, the Speed Alarm contains a set of default values as follows: alarm speed = 60km/h; repeat alarm on; speed­ometer mode enabled; low threshold selected; and calibration = 100Hz per 100km/h. The display will be in the alarm speed mode and so it will show 60km/h. Circuit details Refer now to Fig.1 for the complete circuit details of the Speed Alarm circuit. It’s dominated by IC1, a PIC16F84 microcon­ troller which forms the basis of the circuit. This device takes its inputs from a speed sensor and from the various switches and drives the LED displays and the piezo alarm element. Let’s start with the speed sensor. It consists of a coil which mounts on the chassis, plus two magnets which mount on a drive shaft (or tail shaft). As the magnets spin past, they induce a voltage into the coil and this is detected by comparator stage IC2a. The top of the coil connects to a 2.5V supply, derived from a voltage divider consisting of two 2.2kΩ resistors between the +5V rail and ground. This 2.5V rail is decoupled using a 47µF capacitor and biases pin 3 (the non-inverting input) of IC2a via a 22kΩ resistor. It also biases the pin 2 inverting input of IC2a via the coil and a series 1kΩ resistor. Diodes D3 & D4 clamp the input signal from the coil to ±0.6V, while the 0.1µF capacitor filters the pickup signal. IC2a functions as an inverting com- parator. The output signal from the coil is a 250mV peak-to-peak pulse waveform as shown by the top trace in Fig.2. This is fed to the inverting input (pin 2) of IC2a and each time the input swings negative, the output of IC2a (pin 1) goes high (ie, to about 10V). Note, however, that the output from IC2a is fed to pin 6 (RB0) of IC1 via a 2.2kΩ limiting resistor. This is done to convert the 10V pulse train on pin 1 of IC2a to a +5V pulse train at the RB0 input of IC1. So how does it do this? The answer November 1999  19 ZD1 16V 1W 10 1W 47F 16VW S 1k D3 LED4  LED3  LED2  +5V D4 47F 16VW +5V 22k 0.1 3 2 4 8 +5V 15pF 1M IC2a LM358 47F 16VW OUT +12V 7805 REG1 GND IN 2.2k +5V 0.1 4 14 15 16 6  LED1 10k 5 RB7 RB4 RB3 RB2 RB1 RB6 RB5 13 10 a  g f d e c b a B IC2b 7 E c b a B B B C +5V A K Q1 BC328 3,8 C E E C DISPLAY 1 HDSP5301 Q4 BC338 2 d 1 e 9 f 10 g 4 6 7 680 Q2 BC328 3,8 C E DIMMER 6 5 LDR1 DISPLAY 2 HDSP5301 OUT 10 9 2 1 4 6 7 GND IN 7805 b DISPLAY 3 HDSP5301 c Q3 BC328 680 560 VR1 100k 3,8 C E f g 2 d 1 e e 9 d f 10 g 9 c b a 8 6 7 B CAL 4 680 1k DOWN MODE 7 x 150 1k UP 7 12 11 RA2 1 RA1 18 RA0 17 RA3 RA4 3 2 IC1 PIC16F84 RB0 PIEZO ALARM ELEMENT D1 D2 SPEED ALARM 15pF 3.58MHz XTAL1 1 0.1 0.1 2 x 1N914 Fig.1: the circuit is based on IC1, a PIC16F84P microprocessor. This processes the pulses from the speed sensor on its RB0 (pin 6) input and drives three 7-segment LED displays in multiplex fashion. LDR1, IC2b and Q4 automatically dim the LED displays so that they are not too bright at night. SWITCH LIGHT INDICATORS 680 680 2.2k 2.2k 2x 1N914 680 SPEED SENSOR AND COMPARATOR N L1 L1: 500T 0.18mm ENAMELLED COPPER WIRE ON 8mm DIA FORMER +12V VIA IGNITION SWITCH Fig.2: the output signal from the sensor coil is a 250mV peak-to-peak pulse waveform, as shown by the top trace in this scope shot. The bottom trace shows the processed speed sensor waveform that’s fed to pin 6 of IC1. is that the RB0 input includes internal diodes which clamp the voltage on pin 6 to a maximum of 5.8V. The resulting processed speed sensor waveform into pin 6 of IC1 is shown as the bottom trace in Fig.2. Note how the waveform has been squared up and limited to 5.8V. The 1MΩ positive feedback resistor sets the hysteresis of the Schmitt trigger and prevents false triggering due to noise. Switch inputs The pushbutton switches are all monitored at the RA4 input. The other sides of the Up, Down and Mode switches also connect to the RA0, RA1 & RA2 outputs respectively, while the Cal switch connects to ground. Normally, the RA4 input is pulled high (ie, to +5V) via a 10kΩ resistor. However, when a switch is closed, it initially pulls the RA4 input low. The microcontroller then tests which switch is closed by first taking the RA0, RA1 & RA2 outputs all high. If RA4 is still low, then it must be the Cal switch that is closed. If the Cal switch hasn’t been pressed, the RA0-RA3 outputs are taken low in turn until RA4 also goes low. In this way, the microcontroller quickly determines which switch has been pressed. For example, if RA4 goes low when RA0 is low, then it’s the Mode switch that’s been pressed. The 1kΩ resistors in series with the Mode and Up switches are there to ensure that the RA0, RA1 & RA2 outputs can not be shorted if more 20  Silicon Chip Fig.3: the top trace on this shot shows the RA0 output (2V/div) from the microcontroller, while the lower traces (on 5V/div scales) are for the RA1 and RA2 outputs respectively. These outputs drive transistors Q1-Q3. than one switch is pressed at the same time. While this is not a major problem for the microcontroller outputs for a short time, it can produce strange display results. We haven’t included 1kΩ resistors in series with the Down and Calibrate (Cal) switches, since these are unnecessary. Note that the Calibrate switch is only accessible with a small probe and it is unlikely that this switch will be pressed at the same time as any of the other switches. Pressing the Cal switch places the unit in calibration mode. This switch is accessed through a small hole in the Speed Alarm front panel using a pen or a similar probe. Basically, the unit counts the pulses from the speed sensor over a fixed time period to calculate the road speed. During calibration, this time period is automatically extended until the number of pulses counted equals 8 per 5km/h. This time period becomes the calibration number and is permanently stored in the EEPROM. In practice, this means that if you are travelling at 100km/h, the counter period is long enough to receive 160 pulses from the speed sensor. And because of the way the software oper­ ates, the unit is virtually self-calibrating, as we shall see later on. LED displays The three 7-segment LED displays are driven by IC1 in multiplex fashion. As shown, the individual segments are driven directly from the RB1-RB7 outputs via 150Ω current limiting resistors, while the RA0-RA2 outputs drive the individual dis­plays via switching transistors Q1-Q3. To drive one of the displays the microcontroller must bring the corresponding RA0, RA1 or RA2 line low. When RA0 is brought low, for example, Q1 turns on and applies power to the common anode connection of display 1. Any low outputs on RB1RB7 will thus light the corresponding segment(s) of that display. After this display is lit for a short time, the RA0 output is taken high and display 1 turns off. The RA1 line is then brought low to drive Q2 and display 2. The new 7-segment data on the RB1-RB7 outputs is then presented to this new display, after which RA2 is taken low to drive display 3. Because the displays are switched on and off at 944Hz, they appear to be continuously lit. Fig.3 shows the RA0 output on the top trace (2V/ div), while the lower traces (on 5V/ div scales) show the RA1 and RA2 outputs respectively. Alarm output The alarm output from IC1 appears at RA3 (pin 2) and per­forms two functions. First, it drives the alarm LED to produce a visual alarm output. Second, it provides a modulated 1.4kHz tone to drive the piezo element with a characteristic “beep, beep” sound. In practice, the RA3 output goes high and low at a 1.4kHz rate for about 80ms, then the output stays high for 80ms. The 1.4kHz tone is then pro- duced for another 80ms, after which the output goes low for 10 seconds and the cycle repeats (assum­ing that the repeat alarm feature is enabled). As well as the piezo alarm, the RA3 output also drives the alarm LED (LED1). This means that when the alarm speed is ex­ceeded, LED1 flashes twice (because it is driven by the two 1.4kHz 80ms pulses). The LED then stays lit until the vehicle’s speed drops below the alarm speed. The two parallel diodes in series with the piezo element prevent any low volume tone from being produced due to modulation of the RA3 output as the display is multiplexed. By including the diodes, the modulation must exceed 600mV p-p before any sound is heard from the piezo element. Display brightness IC2b is used to control the display brightness. This op amp is wired as a voltage follower and drives a transistor buffer stage (Q4) which is inside the negative feedback loop. Light dependent resistor LDR1 controls the voltage on the pin 5 input of IC2b according to the ambient light level. The op amp, in turn, controls Q4 and thus the voltage applied to the emitters of the display drivers (Q1-Q4). During daylight hours, the voltage on pin 5 is close to +5V because the LDR has a low resistance in strong light. IC2b controls Q4 so that the voltage on pin 6 is equal to the voltage on pin 5, so Q4’s emitter will also be close to +5V. This voltage is applied to the emitters of Q1-Q3 and to the 560Ω resistor in series with LED1. This lights the displays at full brilliance, so that they can be seen during daylight hours. Conversely, as the light level falls, the resistance of the LDR increases and the voltage on pin 5 of IC2b decreases. In fact, when it’s completely dark, the voltage on pin 5 is deter­ mined by the setting of trimpot VR1. As before, this voltage appears at Q4’s emitter and so the displays are all driven at reduced brightness. In practice, VR1 is adjusted to give the requisite display brightness at night. LEDs2-4 are the switch indicator lights. They shine light through translucent rings fitted to the holes surrounding the switches, so that their positions can be seen at night. Parts List For Speed Alarm 1 display PC board, code 05310991, 78 x 50mm 1 processor PC board, code 15310992, 78 x 50mm 1 plastic utility case, 83 x 54 x 30mm 1 front panel label, 80 x 51mm 1 dark red transparent Perspex or Acrylic window, 50 x 20 x 2.5 1 piezo transducer, 13.5mm OD x 3.5mm (Kingstate KPE-165); use KPE-827 (30mm dia.) or equivalent if a louder external alarm is required 1 3.579545MHz parallel resonant crystal (X1) 1 LDR (Jaycar RD-3480 or equivalent) 3 9.5 x 11.5 x 2mm translucent rings (optional – see text) 4 or 6 button magnets 1 coil former, 15mm OD x 8mm ID x 7mm 1 20m length of 0.18mm enamelled copper wire 1 6mm x 25mm steel bolt, washer and nut 6 PC stakes 1 8-way pin header launcher 2 7-way pin header launchers 1 DIP-16 IC socket with wiper contacts (cut for 1 x 8-way single in-line socket) 1 DIP-14 IC socket with wiper contacts (cut for 2 x 7-way single in-line sockets) 1 small rubber grommet 3 PC-mount click action push-on switches (black) (S1-S3) 1 tactile switch (S4) (Jaycar SP0730 or equiv.) 1 500kΩ horizontal trimpot (VR1) 3 6mm tapped spacers 2 M3 x 6mm countersunk screws 1 M3 x 15mm Nylon screw 1 M3 x 15mm brass screw Clock signals for IC1 are provided by an internal oscilla­tor circuit which operates in conjunction with crystal XTAL1 (3.58MHz) and two 15pF capacitors. The two capacitors are in­clud­ed to provide the correct loading for the crystal and to ensure reliable starting. The crystal frequency is divided down internally to produce separate clock signals for the microcontroller 2 M3 nuts 2 M3 plastic washers 1mm thick (insulating bush and washer with bushing cut off) or 1 x M3 plastic washer 2mm thick 1 400mm length of 0.8mm tinned copper wire 1 2m length of single core shielded cable 1 2m length of red automotive wire 1 2m length of black or green automotive wire (ground wire) Semiconductors 1 PIC16F84P microprocessor programmed with SPEED.HEX program (IC1) 1 LM358 dual op amp (IC2) 1 7805, LM340T5 5V 1A 3-terminal regulator (REG1) 3 BC328 PNP transistors (Q1-Q3) 1 BC338 NPN transistor (Q4) 3 HDSP5301, LTS542A common anode 7-segment LED displays 1 5mm high-intensity red LED (LED1) 3 3mm red LEDs (LED2-4) 4 1N914, 1N4148 diodes (D1-D4) 1 16V 1W zener diode (ZD1) Capacitors 3 47µF 16VW PC electrolytic 4 0.1µF MKT polyester 2 15pF ceramic Resistors (0.25W, 1%) 1 1MΩ 3 1kΩ 1 22kΩ 6 680Ω 1 10kΩ 1 560Ω 3 2.2kΩ 1 10Ω 1W Miscellaneous Automotive connectors, aluminium bracket for sensor, heatshrink tubing, long cable ties, Silicone sealant, super glue, thin black cardboard. operation and for the alarm tone and display multiplexing. The crystal frequency is also used to give a precise time period over which to count the incoming speed signals at RB0. The number of pulses within a set period indicates the speed. That’s all we have space for this month. Next month, we will describe the power supply circuit and give the SC full construction details. November 1999  21