Write a program that implements the feedback controller desc

Write a program that implements the feedback controller described in the block diagram which is shown below. Put the feedback loop in an interrupt subroutine, and use the main program for keyboard I/O. Do not forget to consider the numberlimitation of the chosen data types (i.e., 2?s compliment integers).

Solution

program:

#include<avr/io.h>

#include<avr/signal.h>

#include<avr/interrupt.h>

#include\"$io.c\"

//input commands//

int count=0;

void io_setup()

{

ddrb=0*FF;

}

void io_update()

{

PORTB=count;

}

//\"clock interrupt\"//

#define clk_ms 10

unsigned int cnt_timer1;

volatile unsigned int clk_ticks=0;

volatile unsigned int clk_seconds=0;

signal{sig_overflow1}

{

clk_ticks+=clk_ms;

if(clk_ticks>=1000)

{

clk_ticks=clk_ticks-1000;

clk_seconds++;

io_update();

}

tont1=cnt_timer1;

}

void clk_setup()

{

tocr1a=(0<<co0mia1)|(0<<com1a0)|(0<<com1b1)|(0<<com1b0)|(0<<wgm11)|(0<<wgm10)|(0<<foc1a)|(0<<foc1b);

tocr1b=(0<<wgm12)|(0<<wgm13)|(0<<icnc1)|(0<<ices1|(0<<cs12)|(0<<cs11)|(0<<cs10);

cnt_timer1=0xFFF-clk_ms*8;

tcnt1+cnt_timer1;

//sfior6=psr10;

tifr6=~(1<<tov1);

timsk=(1<<toie1);

sei();

//the main program loop

int main()

{

int c;

sio_init();

io_setup();

clk_setup();

for(;;)

{

while(c=input()=-1)()

if(c==\'+\')

{

if(++count>255)

count=255;

outin(\"counter incremented\");

}

else if(c==\'-\')

{

if(--count<0)

count=0;

outin(\"count decremented);

}

else if(c==\'p\')

{

outin(count);

}

else if(c==\'h\')

{

outin(\"help: +, -, p, q\");

}

else if(c==\'q\')

{

break;

}

}

sio_cleanup();

return1;

Write a program that implements the feedback controller described in the block diagram which is shown below. Put the feedback loop in an interrupt subroutine, a
Write a program that implements the feedback controller described in the block diagram which is shown below. Put the feedback loop in an interrupt subroutine, a
Write a program that implements the feedback controller described in the block diagram which is shown below. Put the feedback loop in an interrupt subroutine, a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site