Professional Documents
Culture Documents
Abstract
Introduction
A control system monitors and regulates the behaviour of a plant by adjusting input parameters
to achieve a particular objective. The control system can operate in an opened or closed-loop;
however, the latter can ensure the desired goal is achieved by measuring the output parameter
that is being controlled. Electronics control systems are widely used in various industries;
therefore, engineering students need to develop the ability to conduct system modelling, system
analysis and controller design and analysis. These tasks can be implemented using state-of-the
art software such as MATLAB.
Results
LCD stop clock C program
sei();
lcd_init();
lcd_gotoxy(1,2);
itoa(l,str,10);
lcd_print("00");
lcd_gotoxy(4,2);
itoa(k,str2,10);
lcd_print("00");
lcd_gotoxy(8,2);
itoa(j,str3,10);
lcd_print("00");
lcd_gotoxy(12,2);
itoa(i,str4,10);
lcd_print("000");
while(1)
{
lcd_gotoxy(1, 2);
itoa(l/10, str, 10);
lcd_print(str);
itoa(l%10, str, 10);
lcd_print(str);
lcd_gotoxy(4,2);
itoa(k/10, str2, 10);
lcd_print(str2);
itoa(k%10, str2, 10);
lcd_print(str2);
lcd_gotoxy(8,2);
itoa(j/10, str3, 10);
lcd_print(str3);
itoa(j%10, str3, 10);
lcd_print(str3);
lcd_gotoxy(12,2);
itoa(i/10, str4, 10);
lcd_print(str4);
itoa(i%10, str4, 10);
lcd_print(str4);
}
}
ISR(INT0_vect){
if (!(PIND & (1<<2)))
{
count++;
if (count==2)
count=0;
_delay_ms(20);
}
}
ISR(INT1_vect){
if (!(PIND & (1<<3)))
{
i = 0;
j = 0;
k = 0;
l = 0;
count2++;
if (count2==2)
count2=0;
_delay_ms(20);
}
}
ISR(TIMER1_COMPA_vect){
if(count == 1) {
i++;
if (i == 1000){
j++;
i = 0;
}
if (j == 60){
k++;
j = 0;
}
if (k == 60){
l++;
k = 0;
}
if (l == 24)
{
l = 0;
k =0;
j =0 ;
i = 0;
}
if (count2 == 1){
lcd_gotoxy(1,2);
clear_lcd();
lcd_gotoxy(1, 2);
itoa((l=0), str, 10);
lcd_print("00");
lcd_gotoxy(4,2);
itoa((k=0), str2, 10);
lcd_print("00");
lcd_gotoxy(8,2);
itoa((j=0), str3, 10);
lcd_print("00");
lcd_gotoxy(12,2);
itoa((i=0), str4, 10);
lcd_print("000");
}
}
Discussion
In this code, there were 3 interrupts used; these were two external interrupts and a timer
interrupt. The two external interrupts (INT0 AND INT1) were used to program the debouncing
of a push button for different tasks on the stopclock. The timer interrupt
(TIMER1_COMPA_vect) was used in timing the stop clock.
INT0
When the button presses, it picks up the falling edge, and can start or stop the stop clock. The
program then waits for the button to be pressed again to start back the stop clock.
INT1
When the button presses, it picks up the falling edge, and resets the stop clock. This starts the
stop clock all over.
TIMER1(compare matching)
In compare mode a register called Output Compare Register is loaded with a value of choice and
the timer will compare the current value of timer with that of Output Compare Register
continuously and when they match it triggers an interrupt. The timer was configured to reset it
self to 0; this is called CTC - Clear Timer on Compare match. This is a 16 bits register, so a
prescaler was setup as prescribed. The output compare register used was OC1A (as
TIMER1_COMPA_vect was used) and it was configured to 30 timer cycles using the formula:
This value was used to achieve the wanted delay that the stop clock should run at.
Literature cited
No literature cited.