Serial port IO module with 11 inputs

From uCtrl
This page is kept for historical interest. It may document projects or methods that are obsolete and/or no longer relevant. The information here is not kept up-to-date.

This module was part of the rack box project — which was terminated when I moved out of my first apartment.
Serial port IO module installed in the Rack box

Information

OMU is connected to the computer via the serial port. If the status on any of the 11 digital inputs change, OMU will send a command string containing module number, input number and new status. This also occurs on boot. OMU can not receive any commands, that makes it impossible to request a input status.

This module was later rebuilt to handle more inputs: Serial port IO module with 15 inputs

Noise and rebuild

Communication noise

OMU was originally designed for RS-485, but as the image shows the signals was drowned in noise. Later I found out that the cause of the noise was lack of stabilizing capacitors, mounted to great a distance from the AVR device. 0,0uF and 1nF was installed directly over the AVR and the problem was solved.

When the noise problem was solved the module was rebuild into RS-232, which is a bit easier to interact with then the RS-485. The source code was rewritten to suit the RS-232, all out of flash memory I had to remove input 12. Leaving the module with only 11 inputs.

I/O

Inputs

  1. PB0 Input 1
  2. PB1 Input 2
  3. PB2 Input 3
  4. PB3 Input 4
  5. PB4 Input 5
  6. PB5 Input 6
  7. PB6 Input 7
  8. PB7 Input 8
  9. PD5 Input 9
  10. PD6 Input 10
  11. PA0 Input 11

Outputs

  1. PD2 Lifesignal
  2. PD3 RS-485 Send enable (not in use)
  3. PD4 Link activity LED

Interface

  • PD0 RS-232 Rx
  • PD1 RS-232 Tx

Connectors

15-pin

  1. 5v
  2. 0v
  3. Input 1
  4. Input 2
  5. Input 3
  6. Input 4
  7. Input 5
  8. Input 6
  9. Input 7
  10. Input 8
  11. Input 9
  12. Input 10
  13. Input 11
  14. Lifesignal

9-pin

  • 2 Transmit
  • 3 Receive
  • 5 GND

Communication

Interfacing is done with RS-232, using MAX232 or MAX202.

001:s:00:1:125 'boot
001:i:02:1:116 'input 2 on                                                               
001:i:01:1:115 'input 1 on 
001:i:02:0:116 'input 2 off                                                                
001:i:01:0:115 'input 1 off
001:s:01:1:126 'lifesignal                                                                  

Serial settings

Baud
9600
Data bits
7
Parity
None
Stop bits
1
Start command
#n/a
Module ID
001

Images

Schematic drawing

Omu circuit.png

Parts list

Qty. Part
1 AVR ATtiny2313-20PU, DIL-20, 20 MHz, 18 I/Os
5 Capacitor, aluminium electrolytic, 1 µF, 50V
2 Capacitor, aluminium electrolytic, 10 µF, 25V
1 Capacitor, aluminium electrolytic, 47 µF, 25V
2 Capacitor, ceramic, 1 nF, 100V
2 Capacitor, metallized polyester foil, 0.01 µF
1 D-Sub soldering cups, 15 pin male
1 D-Sub soldering cups, 9 pin female
1 DIL socket, 16-pin, 7.62mm
1 DIL socket, 20-pin, 7.62mm
1 Enclosure, plastic (1591 FL), 120x65x40mm, flange
1 Fuse 5x20 mm, 200 mA, fast-acting
1 Fuse holder, open, PCB, 5x20mm
1 Fuse holder, open, PCB, Protective cover
1 LED 5mm clear, Yellow, 2.0V, 20mA, 250mcd, 6°
1 LED 5mm coloured clear, Green, 2.1V, 20mA, 30mcd, 10°
2 LED holder 5mm, RTC51, black plastic
2 Mounting bracket, DIN rail, Plastic
32 cm2 PCB, stripboard, 100x160mm, 160cm2
13 Resistor, carbon film, 0.25W, 330 Ω, 5%
2 Resistor, carbon film, 0.25W, 4.7 kΩ, 5%
11 Resistor, carbon film, 0.25W, 10 kΩ, 5%
1 RS232 interface, MAX232CPE, dual
11 Straight pin header, female, Single row, 2.54mm
14 Straight pin header, male, Single row, 2.54mm
1 Transistor, NPN, 100 mA, 45V, 0.5W, BC547B

Source code

Template:Basic code

'--------------------------------------------------------------
' Thomas Jensen
'--------------------------------------------------------------
' file: AVR_OMU_v.1.1
' date: 16/04/2007
'--------------------------------------------------------------
$regfile = "attiny2313.dat"
$crystal = 8000000
$baud = 9600
Config Portb = Input
Config Portd.5 = Input
Config Portd.6 = Input
Config Porta.0 = Input
Config Porta.1 = Input
Config Portd.2 = Output
Config Portd.3 = Output
Config Portd.4 = Output
Config Watchdog = 1024

Dim Lifesignal As Byte , Life As Integer , Send As String * 15
Dim Inn(11) As Byte , A As Byte , A2 As String * 1

Const Id = "001"
Life = 200
Lifesignal = 21

Portd.2 = 1
Portd.4 = 1

Waitms 4000

Portd.3 = 1
Send = Id + ":s:00:1:"
Print Send ; Checksum(send)

Waitms 1000
Portd.2 = 0
Portd.4 = 0
Start Watchdog

Do
'send off signal
For A = 1 To 11
   If Inn(a) = 1 Then
      Portd.3 = 1
      A2 = Str(a)
      If Len(a2) < 2 Then A2 = "0" + A2
      Send = Id + ":i:" + A2 + ":0:"
      Print Send ; Checksum(send)
      End If
Next A

'send on signal
If Pinb.0 = 0 Then
   If Inn(1) = 0 Then
   Portd.3 = 1
   Send = Id + ":i:01:1:"
   Print Send ; Checksum(send)
   End If
   Inn(1) = 30
End If

If Pinb.1 = 0 Then
   If Inn(2) = 0 Then
   Portd.3 = 1
   Send = Id + ":i:02:1:"
   Print Send ; Checksum(send)
   End If
   Inn(2) = 30
End If

If Pinb.2 = 0 Then
   If Inn(3) = 0 Then
   Portd.3 = 1
   Send = Id + ":i:03:1:"
   Print Send ; Checksum(send)
   End If
   Inn(3) = 30
End If

If Pinb.3 = 0 Then
   If Inn(4) = 0 Then
   Portd.3 = 1
   Send = Id + ":i:04:1:"
   Print Send ; Checksum(send)
   End If
   Inn(4) = 30
End If

If Pinb.4 = 0 Then
   If Inn(5) = 0 Then
   Portd.3 = 1
   Send = Id + ":i:05:1:"
   Print Send ; Checksum(send)
   End If
   Inn(5) = 30
End If

If Pinb.5 = 0 Then
   If Inn(6) = 0 Then
   Portd.3 = 1
   Send = Id + ":i:06:1:"
   Print Send ; Checksum(send)
   End If
   Inn(6) = 30
End If

If Pinb.6 = 0 Then
   If Inn(7) = 0 Then
   Portd.3 = 1
   Send = Id + ":i:07:1:"
   Print Send ; Checksum(send)
   End If
   Inn(7) = 30
End If

If Pinb.7 = 0 Then
   If Inn(8) = 0 Then
   Portd.3 = 1
   Send = Id + ":i:08:1:"
   Print Send ; Checksum(send)
   End If
   Inn(8) = 30
End If

If Pind.5 = 0 Then
   If Inn(9) = 0 Then
   Portd.3 = 1
   Send = Id + ":i:09:1:"
   Print Send ; Checksum(send)
   End If
   Inn(9) = 30
End If '

If Pind.6 = 0 Then
   If Inn(10) = 0 Then
   Portd.3 = 1
   Send = Id + ":i:10:1:"
   Print Send ; Checksum(send)
   End If
   Inn(10) = 30
End If

If Pina.0 = 0 Then
   If Inn(11) = 0 Then
   Portd.3 = 1
   Send = Id + ":i:11:1:"
   Print Send ; Checksum(send)
   End If
   Inn(11) = 30
End If

'set input counters
For A = 1 To 11
   If Inn(a) > 0 Then Decr Inn(a)
Next A

'lifestring
If Life > 0 Then Decr Life
If Life = 0 Then
   Portd.3 = 1
   Send = Id + ":s:01:1:"
   Print Send ; Checksum(send)
   Life = 200
   End If

'lifesignal
If Lifesignal > 0 Then Decr Lifesignal
If Lifesignal = 5 Then Portd.2 = 1
If Lifesignal = 0 Then
   Portd.2 = 0
   Lifesignal = 21
   End If

'loop cycle
Reset Watchdog
Portd.4 = Portd.3
Portd.3 = 0
Waitms 100
Portd.4 = 0
Loop
End