Multi-purpose AVR module

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.
MPM1 installed in the Rack box

Information

Tasks:

  1. Monitor the Rack status panel.
    • Connected: green flashing LED.
    • Disconnected: red flashing LED.
    • Alarm: If the Rack status panel has been connected and is disconnected the alarm is triggered, the LED will flash both red and green. This condition must be reset using the reset switch.
  2. Monitor the movement (IR) sensor and porch door.
    • Open porch door: slow yellow flashing LED. A signal is also sent to Oven and signal unit, a unit that controls the living room heating.
    • Movement detected: fast red flashing LED.
    • If the porch door is closed and no movement is detected a "all-ok" signal is sent to Alarm unit, this is the alarm input signal.
  3. Turn of lights in the living room using signals from the Light control unit.
    • The living room lights can be turned off instantly or after 45 seconds. It's however not possible to turn the lights back on again, this is caused by the digital regulator on the lamp. It does not turn it self back on when power is restored.

I/O

Inputs

  1. Panel OK (to Rack status panel)
  2. IR Sensor
  3. Porch door
  4. Lights out (from Light control unit)
  5. Lights out 45 sec (from Light control unit)
  6. Reset panel error (N.C)

Outputs

  1. Panel OK
  2. Panel NOK
  3. Signal to Alarm unit (N.C)
  4. Living room lights off relay
  5. Porch door LED
  6. IR Sensor LED
  7. Panel error (to Signal and lights controlling unit)
  8. Lifesignal (to Module stability monitoring unit 2)

D-Sub 15-pin

  1. +5V
  2. 0v
  3. Lifesignal
  4. In: Panel OK +
  5. In: Panel OK -
  6. In: IR Sensor (N.C)
  7. In: Porch door + (N.C)
  8. In: Lights out
  9. In: Lights out 45 sec
  10. Out: Signal to ALU (N.C)
  11. Out: Living room lights off relay
  12. Out: Porch door LED
  13. Out: IR LED
  14. Out: Panel error

Images

Schematic drawing

Mpm1 circuit.png

Parts list

Qty. Part
1 AVR ATtiny2313-20PU, DIL-20, 20 MHz, 18 I/Os
1 Capacitor, aluminium electrolytic, 10 µF, 25V
1 Capacitor, ceramic, 1 nF, 100V
1 D-Sub soldering cups, 15 pin male
1 DIL socket, 20-pin, 7.62mm
2 DIL socket, 6-pin, 7.62mm
1 Enclosure, plastic (1591 FL), 112x62x31mm, flange
1 LED 5mm coloured clear, Green, 2.1V, 20mA, 30mcd, 10°
1 LED 5mm, Red, 2.0V, 20mA
1 LED 5mm, Red/Green, 2.0 2.1V, 10mA, 100 63mcd, 30°
1 LED 5mm, Yellow, 2.0V, 25mA
1 LED holder 5mm, RTC51, black plastic
1 LED lens 5mm, CLF 280, Clear
1 LED lens 5mm, CLF 280, Red
1 LED lens 5mm, CLF 280, Yellow
2 Optocoupler, single, CNY17F-3, DIL-6
64 cm2 PCB, stripboard, 100x160mm, 160cm2
11 Resistor, carbon film, 0.25W, 330 Ω, 5%
7 Resistor, carbon film, 0.25W, 4.7 kΩ, 5%
6 Resistor, carbon film, 0.25W, 10 kΩ, 5%
2 Resistor, metal film, 0.6W, 1 kΩ, 1%
18 Straight pin header, female, Single row, 2.54mm
18 Straight pin header, male, Single row, 2.54mm
1 Switch, push-button, 1-pole, 1A, 50VAC, on-(off)
6 Transistor, NPN, 100 mA, 45V, 0.5W, BC547B

Source code

Template:Basic code

'--------------------------------------------------------------
' Thomas Jensen
'--------------------------------------------------------------
' file: AVR_MPM1
' date: 06/12/2006
'--------------------------------------------------------------
$crystal = 8000000
Config Portd = Input
Config Portb = Output
Config Watchdog = 1024

Dim A As Byte , Lifesignal As Integer , Dorled As Integer
Dim Stuelys As Integer , Rspledg As Integer , Rspledr As Integer
Dim Rspactive As Integer , Rspledgr As Integer , Rspalarm As Integer
Dim Rspalert As Integer , Irled As Integer

Lifesignal = 21
Dorled = 0
Stuelys = 0
Rspledg = 0
Rspledr = 0
Rspactive = 0
Rspalarm = 0
Rspalert = 0

Portb = 0
Portb.0 = Not Portb.0

For A = 1 To 15
    Portb.0 = Not Portb.0
    Portb.1 = Not Portb.1
    Portb.4 = Not Portb.4
    Portb.5 = Not Portb.5
    Waitms 200
Next A

Waitms 500

Start Watchdog
Portb = 0

Main:
'IR LED
If Pind.1 = 1 And Irled = 0 Then Irled = 2
'Dør LED
If Pind.2 = 1 And Dorled = 0 Then Dorled = 21

'Flash porch LED
If Dorled = 20 Then Portb.4 = 1
If Dorled = 10 Then Portb.4 = 0
If Dorled > 0 Then Dorled = Dorled - 1

'Flash IR sensor LED
If Irled = 2 Then Portb.5 = 1
If Irled = 1 Then Portb.5 = 0
If Irled > 0 Then Irled = Irled - 1

'ALU signal on (NC)
If Pind.1 = 1 Or Pind.2 = 1 Then Portb.2 = 0
'ALU signal off (NC)
If Pind.1 = 0 And Pind.2 = 0 Then Portb.2 = 1

'Lights livingroom off
If Pind.3 = 0 Then Stuelys = 21
If Pind.4 = 0 Then Stuelys = 461
If Stuelys = 10 Then Portb.3 = 1
If Stuelys = 0 Then Portb.3 = 0
If Stuelys > 0 Then Stuelys = Stuelys - 1

'Panel test
If Pind.0 = 0 And Rspledg = 0 And Rspalarm = 0 Then
   'Activate green LED
   Rspledg = 21
   'Arm alarm
   Rspactive = 1
   End If

If Pind.0 = 1 And Rspalarm = 0 Then Rspalert = 1

If Rspalert = 1 And Rspactive = 1 And Rspledr = 0 And Rspledg = 0 Then
   'Activate green and red LED
   Rspledg = 11
   Rspledr = 11
   'Panel faulted
   Rspalarm = 1
   'Activate lighttower/sound
   Portb.6 = 1
   End If

'Reset panel fault
If Pind.5 = 1 Then
   Rspactive = 0
   Rspalarm = 0
   Rspalert = 0
   'Deactivate lighttower/sound
   Portb.6 = 0
   End If

'Activate red LED
If Pind.0 = 1 And Rspalarm = 0 And Rspledr = 0 Then Rspledr = 21

'Green panel LED
If Rspledg = 11 Then Portb.0 = 1
If Rspledg = 6 Then Portb.0 = 0
If Rspledg > 0 Then Rspledg = Rspledg - 1

'Red panel LED
If Rspledr = 6 Then Portb.1 = 1
If Rspledr = 1 Then Portb.1 = 0
If Rspledr > 0 Then Rspledr = Rspledr - 1

'Lifesignal
If Lifesignal > 0 Then Lifesignal = Lifesignal - 1
If Lifesignal = 6 Then Portb.7 = 1
If Lifesignal = 1 Then Portb.7 = 0
If Lifesignal = 0 Then Lifesignal = 21

'Loop cycle
Reset Watchdog
Waitms 100
Goto Main
End