µController

__Basic Parts used for the controller__

 * µController ATMega 16 (runs @ 4 Mhz)
 * Atmel AVR STK 500 Programming Board
 * Electroluminescent Inverter (approx. 120 V)
 * Relais

__Prgramming Language / Environment__

 * Programming language: C
 * Programming Environment: AVR Studio 4 with WinAVR Plug-In to enable C (includes avr-gcc compiler)

__Basic Principle__
The clock consists of 24 field / words, which have to be illuminated. Two of them ("The Times", "It's") are illuminated continuously and can be connected by one wire without the necessity of switching it on or off. This results in 22 field, which have to be turned on an off according to the related time. To realise this the µController will be connected to relais as shown in the following scheme. The clock will be realised using one of the provided timer of the controller. This is not as precise as an external clock module but is sufficient for the aim of the project displaying the time in steps of five minutes.



__**Port Declaration**__
The provided input/output ports of the µController have to be assigned to the various words, which will be illuminated. Due to the high amount of words the total number of ports (4) will be used. These ports are named PA, PB, PC and PD. Each of those ports has 8 pins which can be controlled separately using specific values in a 8 bit range. The respective pin of the port is depicted by a number in between 0 and 7, the specific values as Port Set Value. The depicted Status Variable is used for the program which can be seen in the next section.

For a better overview as well as sufficient programming the words have been separated into the parts hours, minutes and linker, which is in this case a used declaration for the words "past", "to" and "o'clock".


 *  **Part** ||  **Word**  ||  **Port**  ||  **Status Variable**  ||  **Port Set Value**  ||
 *  **Hours** || One ||  PA0  ||  1  ||  254  ||
 * || Two ||  PA1 ||  2  ||  253  ||
 * || Three ||  PA2 || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 3  || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 251  ||
 * || <span style="font: normal normal normal 10px/normal 'Helvetica Neue'; letter-spacing: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Four || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> PA3 || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 4  || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 247  ||
 * || <span style="font: normal normal normal 10px/normal 'Helvetica Neue'; letter-spacing: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Five || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> PA4 || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 5  || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 239  ||
 * || <span style="font: normal normal normal 10px/normal 'Helvetica Neue'; letter-spacing: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Six || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> PA5 || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 6  || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 223  ||
 * || <span style="font: normal normal normal 10px/normal 'Helvetica Neue'; letter-spacing: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Seven || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> PA6 || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 7  || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 191  ||
 * || <span style="font: normal normal normal 10px/normal 'Helvetica Neue'; letter-spacing: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Eight || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> PA7 || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 8  || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 127  ||
 * || <span style="font: normal normal normal 10px/normal 'Helvetica Neue'; letter-spacing: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Nine || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> PB0 || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 9  || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 254  ||
 * || <span style="font: normal normal normal 10px/normal 'Helvetica Neue'; letter-spacing: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Ten || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> PB1 || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 10  || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 253  ||
 * || <span style="font: normal normal normal 10px/normal 'Helvetica Neue'; letter-spacing: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Eleven || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> PB3 || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 11  || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 251  ||
 * || <span style="font: normal normal normal 10px/normal 'Helvetica Neue'; letter-spacing: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Twelve || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> PB4 || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 0  || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 247  ||
 * <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> **Minutes** || <span style="font: normal normal normal 10px/normal 'Helvetica Neue'; letter-spacing: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Five || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> PC0  || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 0  || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 254  ||
 * || <span style="font: normal normal normal 10px/normal 'Helvetica Neue'; letter-spacing: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Ten || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> PC1 || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 1  || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 253  ||
 * || <span style="font: normal normal normal 10px/normal 'Helvetica Neue'; letter-spacing: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Quarter || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> PC2 || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 2  || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 251  ||
 * || <span style="font: normal normal normal 10px/normal 'Helvetica Neue'; letter-spacing: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Twenty || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> PC3 || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 3  || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 247  ||
 * || <span style="font: normal normal normal 10px/normal 'Helvetica Neue'; letter-spacing: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Tewntyfive || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> PC4 || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 4  || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 239  ||
 * || <span style="font: normal normal normal 10px/normal 'Helvetica Neue'; letter-spacing: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Half || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> PC5 || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 5  || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 223  ||
 * || <span style="font: normal normal normal 10px/normal 'Helvetica Neue'; letter-spacing: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Thirtyfive || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> PC6 || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 6  || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 191  ||
 * <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> **Linker** || <span style="font: normal normal normal 10px/normal 'Helvetica Neue'; letter-spacing: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Past || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> PD0  || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 0  || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 254  ||
 * || <span style="font: normal normal normal 10px/normal 'Helvetica Neue'; letter-spacing: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">To || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> PD1 || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 1  || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 253  ||
 * || <span style="font: normal normal normal 10px/normal 'Helvetica Neue'; letter-spacing: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">O’Clock || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> PD2 || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 2  || <span style="display: block; font: 10.0px 'Helvetica Neue'; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;"> 251  ||

__**Program**__
A first draft of the program is shown below. As a function, to introduce the interval of a second to control the output behaviour, _delay_ms is used, which is provided by a standard library (delay.h). This function is sufficient for a first test of the circuitry and was tested using the debugging mode of the AVR Studio 4 as well as the provided LED's of the STK 500 <span style="font-family: arial,helvetica,sans-serif; font-size: 13px; line-height: 19px;">Programming Board.

code <span style="background-color: #eeeeee; border-bottom-color: #cccccc; border-bottom-style: solid; border-bottom-width: 1px; border-left-color: #cccccc; border-left-style: solid; border-left-width: 1px; border-right-color: #cccccc; border-right-style: solid; border-right-width: 1px; border-top-color: #cccccc; border-top-style: solid; border-top-width: 1px; font-size: 13px; overflow-x: auto; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px;"><span style="background-color: #eeeeee; border-bottom-color: #999999; border-bottom-style: solid; border-bottom-width: 1px; border-left-color: #999999; border-left-style: solid; border-left-width: 1px; border-right-color: #999999; border-right-style: solid; border-right-width: 1px; border-top-color: #999999; border-top-style: solid; border-top-width: 1px; font-family: 'Courier New',Courier,monospace; font-size: 0.9em; overflow-x: auto; overflow-y: auto; padding-bottom: 0.2em; padding-left: 0.2em; padding-right: 0.2em; padding-top: 0.2em;">#include <avr/io.h>


 * 1) ifndef F_CPU                       // Defines the uC clock in Hz for delay.h
 * 2) define F_CPU 4000000UL               // Clock of the uC = 4 MHz
 * 3) endif


 * 1) include <util/delay.h>               // Uses delay.h for a 1 second delay

//********************************** //       Set Outputs //**********************************

// SetTime defines the output pins for the respective time. // The linker words past, to and o'clock are defined within the respective minute state

int SetTime(unsigned int iHourStat, unsigned int iMinStat) {   // Defines output pins for hours

switch(iHourStat) {       case 0:  PORTB = 247; break; case 1: PORTA = 254; break; case 2: PORTA = 253; break; case 3: PORTA = 251; break; case 4: PORTA = 247; break; case 5: PORTA = 239; break; case 6: PORTA = 223; break; case 7: PORTA = 191; break; case 8: PORTA = 127; break; case 9: PORTB = 254; break; case 10: PORTB = 253; break; case 11: PORTB = 251; break; default: PORTB = 255; break; }

// Defines output pins for minutes

switch(iMinStat) {       case 0:  PORTD = 251;    // O'Clock break; case 1: PORTC = 254;    // Five PORTD = 254;   // Past break; case 2: PORTC = 253;    // Ten PORTD = 254;   // Past break; case 3: PORTC = 251;    // Quarter PORTD = 254;   // Past break; case 4: PORTC = 247;    // Twenty PORTD = 254;   // Past break; case 5: PORTC = 239;    // Twentyfive PORTD = 254;   // Past break; case 6: PORTC = 223;    // Half PORTD = 254;   // Past break; case 7: PORTC = 191;    // Thirtyfive PORTD = 254;   // Past break; case 8: PORTC = 247;    // Twenty PORTD = 253;   // To             break; case 9: PORTC = 251;    // Quarter PORTD = 253;   // To             break; case 10: PORTC = 253;   // Ten PORTD = 253;   // To             break; case 11: PORTC = 254;   // Five PORTD = 253; break; default: PORTC = 255; PORTD = 255; break; }

return 1; }

//********************************** //          Hauptprogramm //**********************************

int main(void) {   // Variables

unsigned char cSec = 0, cMin = 0, cHour = 0;

// Define ports A,B,C,D as outputs

DDRA = 0xFF; DDRB = 0xFF; DDRC = 0xFF; DDRD = 0xFF;

// Turn all ports off

PORTA = 255; PORTB = 255; PORTC = 255; PORTD = 255;

// Sets the respective time for the program start

SetTime(cHour, cMin);

while(1) {       //_delay_us(1);             // Waits 10 us for test reasons _delay_ms(980);                // Waits 1 s until executing next step

cSec++;                // Increases cSec by 1

if (cSec == 5)           // Executes following code segemnt after cSec = 300 seconds = 5 minutes {           cSec = 0;         // Sets cSec to 0 (

cMin++;            // Increases cMin (= minute state) by 1

if (cMin == 13)        // If cMin = 9, all minute states are done and the state is set back to 0 {               cMin = 0;    // Sets cMin back to 0

cHour++;    / / Increases cHour (= hour state) by 1

if (cHour == 12)    // If cHour = 12, all hour states are done and the state is set back to 0 {                   cHour = 0;   // Sets cHour back to 0 }           }        }

// Sets the respective time

SetTime(cHour, cMin);

}

return 1;               // Standard for C programs } code

__**Circuitry**__
Possible switches:


 * Transistor
 * Relais
 * Tyrac

The switches will be realised using relais. These have to be specified for a max. AC voltage of 120 V at a frequency of min. 400 Hz. Another important characteristic is the voltage to set in on or off as it has to fit to the output voltage of 5 V of the µC.

To be added...


 * Freilaufdiode
 * Schaltplan (zumindest ausschnitt, da Zeichnung mit 22 Relais sehr umfangreich wird)
 * erster Versuch mit Relais klappte -> Folie lies sich mehrmals nacheinander an und aus schalten, hohe Frequenzen scheinen keinen schlechten Einfluss auf Relais zu haben
 * Transitoren und Tyracs können nich genommen werden
 * Transistor zum schalten der Relais nicht nötig (siehe Schaltbild mikrocontroller.net) nicht nötig, da pro Port nur 1 Pin geschalten (d. h. nie 2 gleichzeitig) wird und demnach der Strom nicht verstärkt werden muss
 * 40 mA max. Ausgangsstrom des µC pro Pin zum schalten des Relais ausreichend -> extra so ausgewählt