Serial interface module for emergency power off

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.
DEIM installed in the Rack status panel

Information

With DEIM it's possible to trigger and reset the emergency shutdown from Serial Client, the voltage on the 12V emergency supply is also measured and shown in Serial Client. The module also registers if the emergency shutdown is triggered and gives the option of disabling the emergency strobe. DEIM has three LEDs and one two way switch on the Rack status panel, a yellow LED flashes when there is serial activity. Two LEDs are dual colored (green/red), the color can be controlled from the computer. The switch can be set up using triggers in Serial Server.

Commands

  • Inputs
    1. Value from emergency supply 12V
    2. Emergency shutdown status
    3. Status on switch 1
    4. Status on switch 2
  • Outputs
    1. Trigger emergency shutdown (1 sec auto off)
    2. Reset emergency shutdown (10 sec auto off)
    3. Deactivate strobe (on/off)
    4. LED 1
      • 0 Off
      • 1 Green
      • 2 Red
    5. LED 2
      • 0 Off
      • 1 Green
      • 2 Red

I/O

Inputs

  1. PC0 - Emergency supply 12V voltage for volt meter
  2. PC1 - Emergency shutdown active (Emergency shutdown unit)
  3. PC2 - Switch 1
  4. PC3 - Switch 2

Calculations

Voltage

Outputs

  1. PB0 - Trigger emergency shutdown (Emergency shutdown unit)
  2. PB1 - Reset emergency shutdown (Emergency shutdown unit)
  3. PB2 - Deactivate strobe
  4. PB3 - LED 1 Green
  5. PB4 - LED 1 Red
  6. PB5 - LED 2 Green
  7. PD6 - LED 2 Red
  8. PD7 - Activity LED
  9. PD5 - Lifesignal (to Module stability monitoring unit 2) (optoisolator)

D-Sub connector

See Rack status panel for D-Sub connector.

Communication

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

Serial settings

Baud
9600
Data bits
8
Parity
None
Stop bits
1
Start command
*
Module ID
004

Images

Schematic drawing

Deim circuit.png

Parts list

Qty. Part
1 AVR ATmega8-16PU, DIL-28, 16 MHz, 23 I/Os
5 Capacitor, aluminium electrolytic, 1 µF, 50V
1 Capacitor, aluminium electrolytic, 10 µF, 25V
2 Capacitor, aluminium electrolytic, 47 µF, 25V
2 Capacitor, ceramic, 1 nF, 100V
2 Capacitor, metallized polyester foil, 0.01 µF
1 DIL socket, 16-pin, 7.62mm
1 DIL socket, 28-pin, 7.62mm
1 DIL socket, 6-pin, 7.62mm
1 Diode, small signal, 1N4148/Ph
1 Heat conducting film for heatsink, Adhesive, TO220
1 Heatsink, 15K/W @ 4W, 28mm 7g, TO220
1 Optocoupler, single, CNY17F-3, DIL-6
32 cm2 PCB, stripboard, 100x160mm, 160cm2
4 Resistor, carbon film, 0.25W, 330 Ω, 5%
4 Resistor, carbon film, 0.25W, 4.7 kΩ, 5%
3 Resistor, carbon film, 0.25W, 10 kΩ, 5%
1 Resistor, carbon film, 0.25W, 100 kΩ, 5%
1 Resistor, metal film, 0.6W, 20 kΩ, 1%
1 RS232 interface, MAX232CPE, dual
1 Spacer, round unthreaded, 3mm, Ø6mm, Delrin
17 Straight pin header, female, Single row, 2.54mm
24 Straight pin header, male, Single row, 2.54mm
3 Transistor, NPN, 100 mA, 45V, 0.5W, BC547B
1 Voltage regulator +5V, 1 A, 7805PI

Source code

Template:Basic code

'--------------------------------------------------------------
' Thomas Jensen
'--------------------------------------------------------------
' file: AVR_DEIM_v.1.0
' date: 27/10/2007
'--------------------------------------------------------------
$regfile = "m8def.dat"
$crystal = 8000000
$baud = 9600
Config Portb = Output
Config Portd.5 = Output
Config Portd.6 = Output
Config Portd.7 = Output
Config Portc.1 = Input
Config Portc.2 = Input
Config Portc.3 = Input

Dim W1 As Word , Lifesignal As Integer
Dim Life As Integer , Send As String * 20
Dim Inn(4) As Integer , A As Byte , A2 As String * 1
Dim Serialcharwaiting As Byte , Serialchar As Byte
Dim Comminput As String * 15 , Input_nr As String * 3
Dim Input_com As String * 1 , Input_ut As String * 2
Dim Input_stat As String * 1 , Led As Byte , Ut(5) As Byte
Dim Ut_t(2) As Word , B As Byte

Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc

Const Id = "004"
Life = 1000

For A = 1 To 10
Portb.3 = 1
Portb.4 = 1
Portb.5 = 0
Portd.6 = 0
Waitms 250
Portb.3 = 0
Portb.4 = 0
Portb.5 = 1
Portd.6 = 1
Waitms 250
Next A
Portb = 0
Portd.6 = 0
Portd.7 = 0
Portd.5 = 0

Top:
Serialcharwaiting = Ischarwaiting()

If Serialcharwaiting = 1 Then
   Serialchar = Inkey()
      Goto Myroutine
   End If

Goto Main

Myroutine:
Select Case Serialchar
Case 42 '*
Goto Set_value
End Select

Main:
'input send off signal
For A = 2 To 4
   If Inn(a) = 1 Then
      Led = 103
      A2 = Str(a)
      If Len(a2) < 2 Then A2 = "0" + A2
      Send = Id + ":i:" + A2 + ":0:"
      Print Send ; Checksum(send)
      End If
Next A

'input send on signal
If Inn(1) = 1 Then 'input 1
   W1 = Getadc(0)
   If W1 > 999 Then W1 = 999
   Led = 103
   Send = Id + ":i:01:" + Str(w1) + ":"
   Print Send ; Checksum(send)
   Inn(1) = 0
End If

If Pinc.1 = 0 Then 'input 2
   If Inn(2) = 0 Then
   Led = 103
   Send = Id + ":i:02:1:"
   Print Send ; Checksum(send)
   End If
   Inn(2) = 2500
End If

If Pinc.2 = 0 Then 'input 3
   If Inn(3) = 0 Then
   Led = 103
   Send = Id + ":i:03:1:"
   Print Send ; Checksum(send)
   End If
   Inn(3) = 250
End If

If Pinc.3 = 0 Then 'input 4
   If Inn(4) = 0 Then
   Led = 103
   Send = Id + ":i:04:1:"
   Print Send ; Checksum(send)
   End If
   Inn(4) = 250
End If

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

'set output counters
For B = 1 To 2
   If Ut_t(b) > 0 Then Decr Ut_t(b)
Next B

'handle outputs
If Ut(1) = 1 And Ut_t(1) = 0 Then Ut_t(1) = 1000
If Ut(2) = 1 And Ut_t(2) = 0 Then Ut_t(2) = 10000

If Ut_t(1) = 1000 Then Portb.0 = 1
If Ut_t(1) = 1 Then
   Portb.0 = 0
   Ut(1) = 0
   Send = Id + ":o:01:" + Str(ut(1)) + ":"
   Print Send ; Checksum(send)
   End If

If Ut_t(2) = 10000 Then Portb.1 = 1
If Ut_t(2) = 1 Then
   Portb.1 = 0
   Ut(2) = 0
   Send = Id + ":o:02:" + Str(ut(2)) + ":"
   Print Send ; Checksum(send)
   End If

'led timer
If Led > 0 Then Decr Led
If Led = 100 Then Portd.7 = 1
If Led = 0 Then Portd.7 = 0

'lifestring
If Life > 0 Then Decr Life
If Life = 0 Then
   Led = 103
   Send = Id + ":s:01:1:"
   Print Send ; Checksum(send)
   Life = 20000
   End If

'lifesignal
If Lifesignal > 0 Then Decr Lifesignal
If Lifesignal = 500 Then Portd.5 = 1
If Lifesignal = 0 Then
   Portd.5 = 0
   Lifesignal = 2100
   End If

Waitms 1
Goto Top
End

Set_value:
Input Comminput Noecho 'read serialport

Input_nr = Left(comminput , 3) 'id check
Input_com = Mid(comminput , 5 , 1) 'command check
Input_ut = Mid(comminput , 7 , 2) 'output nr check
Input_stat = Mid(comminput , 10 , 1) 'output stat check

'output
If Input_nr = Id Then

If Input_com = "o" Then
Led = 103
Select Case Input_ut

Case "01" 'output 1
If Input_stat = "1" Then Ut(1) = 1
If Input_stat = "0" Then Ut(1) = 0
Send = Id + ":o:01:" + Str(ut(1)) + ":"
Print Send ; Checksum(send)

Case "02" 'output 2
If Input_stat = "1" Then Ut(2) = 1
If Input_stat = "0" Then Ut(2) = 0
Send = Id + ":o:02:" + Str(ut(2)) + ":"
Print Send ; Checksum(send)

Case "03" 'output 3
If Input_stat = "1" Then Portb.2 = 1
If Input_stat = "0" Then Portb.2 = 0
Send = Id + ":o:03:" + Str(portb.2) + ":"
Print Send ; Checksum(send)

Case "04" 'output 4
If Input_stat = "2" Then
   Portb.4 = 1
   Portb.3 = 0
   Ut(4) = 2
   End If
If Input_stat = "1" Then
   Portb.4 = 0
   Portb.3 = 1
   Ut(4) = 1
   End If
If Input_stat = "0" Then
   Portb.4 = 0
   Portb.3 = 0
   Ut(4) = 0
   End If
Send = Id + ":o:04:" + Str(ut(4)) + ":"
Print Send ; Checksum(send)

Case "05" 'output 5
If Input_stat = "2" Then
   Portd.6 = 1
   Portb.5 = 0
   Ut(5) = 2
   End If
If Input_stat = "1" Then
   Portd.6 = 0
   Portb.5 = 1
   Ut(5) = 1
   End If
If Input_stat = "0" Then
   Portd.6 = 0
   Portb.5 = 0
   Ut(5) = 0
   End If
Send = Id + ":o:05:" + Str(ut(5)) + ":"
Print Send ; Checksum(send)

End Select
End If

If Input_com = "i" Then
Select Case Input_ut

Case "01"
If Inn(1) = 0 Then Inn(1) = 1 'status input 1
Case "02"
If Inn(2) = 0 Then Inn(2) = 2 'status input 2
Case "03"
If Inn(3) = 0 Then Inn(3) = 2 'status input 3
Case "04"
If Inn(4) = 0 Then Inn(4) = 2 'status input 4

End Select
End If

End If
Goto Main
End