Advanced serial interface module

From uCtrl.net

Jump to: navigation, search
Symbols-Delete-256x256.png
Rack fullsize plan.png
The Rack box project is being discontinued!
I am moving to a new location, and therefor terminating the Rack box project, my plan is to build an even bigger system based on slot-in cards in a full size rack. I'll keep you posted. Feel tree to leave a comment if you have any question.
ASIM installed in the Rack box.

ASIM, driven by AVR ATMega8.

Contents

Information

ASIM provides 6 analog and 2 digital inputs, and 9 digital outputs for the computer serial port. The outputs give GND when activated, max load pr. channel: 100mA. The digital inputs are triggered when they are connected to GND, the analog inputs need to be queried for the value. The A/D converter is 10-bit, so 0-5 volt is reported back as 0-999. For sensors outside the Rack box, a 1uF capacitor is connected between GND and the signal input, this removed noise and allows for a stable input signal.

This module measures the voltage of the 5, 13.8 and 24 volt supply and the Rack box temperature (LM35). The two auxiliary analog inputs can be connected to any 0-5V voltage sensor, currently connected to two external LM35 temperature sensors.

By sending commands to the module one can change the status of the outputs, the module will confirm when the action is carried out. It's possible to ask for the current status of any in- or output, this is done by not sending a set value. All commands from the module is sent with a checksum.

I/O

Inputs

Formula to calculate voltage.
Formula to calculate temperature.

Outputs

D-sub 25-pin

  1. 13.8V
  2. 0V
  3. Input 5V (Analog)
  4. Input 24V (Analog)
  5. 5V to analog sensor
  6. 0V to analog sensor
  7. Input 5 (Analog)
  8. Input 6 (Analog)
  9. Input 7
  10. Input 8
  11. Output 1
  12. Output 2
  13. Output 3
  14. Output 4
  15. Output 5
  16. Output 6
  17. Output 7
  18. Output 8
  19. Output 9
  20. Lifesignal

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
0
Module ID
005

Parts list

Quantity Supplier Part number Description
1 Elfa 73-672-04 AVR-RISC, ATmega8-16PI
1 Elfa 50-197-40 Plastic Enclosure (1591 FL), 150x80x50mm fixed install.
1 Elfa 44-055-77 D-Sub soldering cups, 25 pin male
1 Elfa 44-055-28 D-Sub soldering cups, 25 pin female
1 Elfa 44-055-02 D-Sub soldering cups, 9 pin female
1 Elfa 48-161-38 DIL socket, 16-pin, 7,62mm
1 Elfa 48-161-87 DIL socket, 28-pin, 7,62mm
1 Elfa 48-884-18 Unthreaded round spacer, 3mm, Ø6mm
1 Elfa 25-530-71 D-sub cable, pin-to-pin 3m, 9-pin male-female
1 Elfa 75-612-36 Heatsink, 27.3 K/W, 19mm, attachable, TO220
1 Elfa 67-008-01 Aluminium electrolytic capacitor, 10uF 25V
5 Elfa 67-013-12 Aluminium electrolytic capacitor, 1uF 50V
2 Elfa 67-008-68 Aluminium electrolytic capacitor, 47uF 25V
2 Elfa 65-851-94 Ceramic Disc Capacitor, 1 nF 100V
2 Elfa 65-550-64 Foil capacitor, 0,01uF
2 Elfa 48-326-06 Laboratory card, 100x160mm (1/5)
1 Elfa 75-016-79 LED 5mm clear, Green, 2.1V, 20mA, 385mcd, 6°
1 Elfa 75-016-95 LED 5mm clear, Yellow, 2.0V, 20mA, 250mcd, 6°
2 LED1.de 805082 LED holder 5mm, Black plastic
1 Elfa 73-023-26 MAX232, CPE RSR232double
3 Elfa 60-737-46 Metal film resistor 1% 0,6W, 20 K
2 Elfa 60-106-15 Carbon film resistor 5% 1/4W, 10 K
3 Elfa 60-107-30 Carbon film resistor 5% 1/4W, 100 K
4 Elfa 60-104-33 Carbon film resistor 5% 1/4W, 330 Ohm
11 Elfa 60-105-73 Carbon film resistor 5% 1/4W, 4,7 K
33 Elfa 43-708-05 Socket connector 2,54, 1×36, female
33 Elfa 43-702-19 Straight pin header 2,54, 1×36, PCB
1 Elfa 33-167-59 Fuse 5x20 mm, 1.0A, quick-acting
1 Elfa 33-160-49 Fuse Holder, panel, 5x20mm, PTF30
1 Elfa 73-095-60 Voltage regulator +5V, L78S05CV 2.0A
1 Elfa 73-090-57 Temperature sensor LM35DZ, 0 to +100°C, +-0,6°C
10 Elfa 71-027-59 Transistor BC547B, NPN, 45V 0.1A 0.625W

Images

Schematic drawing

Asim circuit.png

Source code

The program is written in basic, using Bascom-AVR.

'--------------------------------------------------------------
'                         Thomas Jensen
'--------------------------------------------------------------
'  file: AVR_ASIM_v.1.0
'  date: 20/03/2008
'--------------------------------------------------------------
$regfile = "m8def.dat"
$crystal = 8000000
$baud = 9600
Config Portb = Output
Config Portd.2 = Output
Config Portd.3 = Output
Config Portd.4 = Output
Config Portd.5 = Input
Config Portd.6 = Input
Config Portd.7 = Input
 
Dim W1 As Word , W2 As Word , W3 As Word , W4 As Word , W5 As Word , W6 As Word
Dim Lifesignal As Integer , Life As Integer , Send As String * 15
Dim Inn(8) As Byte , 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 , B As Byte , Led As Byte
 
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc
 
Const Id = "005"
Life = 1000
 
Waitms 5000
 
Top:
 
Serialcharwaiting = Ischarwaiting()
 
If Serialcharwaiting = 1 Then
   Serialchar = Inkey()
      Goto Myroutine
   End If
 
Goto Main
 
Myroutine:
Select Case Serialchar
Case 48                                                     '0
Goto Set_value
End Select
 
Main:
'input send off signal
For A = 7 To 8
   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 Inn(2) = 1 Then                                          'input 2
   W2 = Getadc(1)
   If W2 > 999 Then W2 = 999
   Led = 103
   Send = Id + ":i:02:" + Str(w2) + ":"
   Print Send ; Checksum(send)
   Inn(2) = 0
   End If
 
If Inn(3) = 1 Then                                          'input 3
   W3 = Getadc(2)
   If W3 > 999 Then W3 = 999
   Led = 103
   Send = Id + ":i:03:" + Str(w3) + ":"
   Print Send ; Checksum(send)
   Inn(3) = 0
   End If
 
If Inn(4) = 1 Then                                          'input 4
   W4 = Getadc(3)
   If W4 > 999 Then W4 = 999
   Led = 103
   Send = Id + ":i:04:" + Str(w4) + ":"
   Print Send ; Checksum(send)
   Inn(4) = 0
   End If
 
If Inn(5) = 1 Then                                          'input 5
   W5 = Getadc(4)
   If W5 > 999 Then W5 = 999
   Led = 103
   Send = Id + ":i:05:" + Str(w5) + ":"
   Print Send ; Checksum(send)
   Inn(5) = 0
   End If
 
If Inn(6) = 1 Then                                          'input 6
   W6 = Getadc(5)
   If W6 > 999 Then W6 = 999
   Led = 103
   Send = Id + ":i:06:" + Str(w6) + ":"
   Print Send ; Checksum(send)
   Inn(6) = 0
   End If
 
If Pind.5 = 0 Then                                          'input 7
   If Inn(7) = 0 Then
   Led = 103
   Send = Id + ":i:07:1:"
   Print Send ; Checksum(send)
   End If
   Inn(7) = 250
End If
 
If Pind.6 = 0 Then                                          'input 8
   If Inn(8) = 0 Then
   Led = 103
   Send = Id + ":i:08:1:"
   Print Send ; Checksum(send)
   End If
   Inn(8) = 250
End If
 
'set input counters
For A = 7 To 8
   If Inn(a) > 0 And B = 0 Then Decr Inn(a)
Next A
 
'led timer
If Led > 0 Then Decr Led
If Led = 100 Then Portd.4 = 1
If Led = 0 Then Portd.4 = 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.3 = 1
If Lifesignal = 0 Then
   Portd.3 = 0
   Lifesignal = 2100
   End If
 
Waitms 1
Goto Top                                                    'loop cycle
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 Portb.0 = 1
If Input_stat = "0" Then Portb.0 = 0
Send = Id + ":o:01:" + Str(portb.0) + ":"
Print Send ; Checksum(send)
 
Case "02"                                                   'output 2
If Input_stat = "1" Then Portb.1 = 1
If Input_stat = "0" Then Portb.1 = 0
Send = Id + ":o:02:" + Str(portb.1) + ":"
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 = "1" Then Portb.3 = 1
If Input_stat = "0" Then Portb.3 = 0
Send = Id + ":o:04:" + Str(portb.3) + ":"
Print Send ; Checksum(send)
Case "05"                                                   'output 5
If Input_stat = "1" Then Portb.4 = 1
If Input_stat = "0" Then Portb.4 = 0
Send = Id + ":o:05:" + Str(portb.4) + ":"
Print Send ; Checksum(send)
 
Case "06"                                                   'output 6
If Input_stat = "1" Then Portb.5 = 1
If Input_stat = "0" Then Portb.5 = 0
Send = Id + ":o:06:" + Str(portb.5) + ":"
Print Send ; Checksum(send)
 
Case "07"                                                   'output 7
If Input_stat = "1" Then Portb.6 = 1
If Input_stat = "0" Then Portb.6 = 0
Send = Id + ":o:07:" + Str(portb.6) + ":"
Print Send ; Checksum(send)
 
Case "08"                                                   'output 8
If Input_stat = "1" Then Portb.7 = 1
If Input_stat = "0" Then Portb.7 = 0
Send = Id + ":o:08:" + Str(portb.7) + ":"
Print Send ; Checksum(send)
 
Case "09"                                                   'output 9
If Input_stat = "1" Then Portd.2 = 1
If Input_stat = "0" Then Portd.2 = 0
Send = Id + ":o:09:" + Str(portd.2) + ":"
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) = 1                               'status input 2
Case "03"
If Inn(3) = 0 Then Inn(3) = 1                               'status input 3
Case "04"
If Inn(4) = 0 Then Inn(4) = 1                               'status input 4
Case "05"
If Inn(5) = 0 Then Inn(5) = 1                               'status input 5
Case "06"
If Inn(6) = 0 Then Inn(6) = 1                               'status input 6
Case "07"
If Inn(7) = 0 Then Inn(7) = 2                               'status input 7
Case "08"
If Inn(8) = 0 Then Inn(8) = 2                               'status input 8
 
End Select
End If
 
End If
Goto Main
End
Personal tools
Namespaces
Variants
Actions
Navigation
Categories
projects
Toolbox