From 7363cced82d2f358df0d1c9f72e95475935e1ec9 Mon Sep 17 00:00:00 2001 From: Pontus Giselsson <pontus.giselsson@control.lth.se> Date: Thu, 19 Feb 2009 13:59:17 +0000 Subject: [PATCH] Added simulink file and matlab scripts --- .../avr/compileUploadCurrentControl.sh | 4 ++-- .../avr/compileUploadVelControl.sh | 4 ++-- linear_pendulum_2009/avr/vel_control.c | 20 ++++++++----------- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/linear_pendulum_2009/avr/compileUploadCurrentControl.sh b/linear_pendulum_2009/avr/compileUploadCurrentControl.sh index e97cfdf..dda8aeb 100755 --- a/linear_pendulum_2009/avr/compileUploadCurrentControl.sh +++ b/linear_pendulum_2009/avr/compileUploadCurrentControl.sh @@ -1,3 +1,3 @@ -avr-gcc -mmcu=atmega16 -g -Wall -o current_control current_control.c -avr-objcopy -Osrec current_control current_control.sr +avr-gcc -mmcu=atmega16 -g -Wall -o current_control.o current_control.c +avr-objcopy -Osrec current_control.o current_control.sr uisp -dprog=stk200 --erase --upload if=current_control.sr \ No newline at end of file diff --git a/linear_pendulum_2009/avr/compileUploadVelControl.sh b/linear_pendulum_2009/avr/compileUploadVelControl.sh index 7a26573..bad2b4b 100755 --- a/linear_pendulum_2009/avr/compileUploadVelControl.sh +++ b/linear_pendulum_2009/avr/compileUploadVelControl.sh @@ -1,3 +1,3 @@ -avr-gcc -mmcu=atmega16 -O -g -Wall -o vel_control vel_control.c pccom.c -avr-objcopy -Osrec vel_control vel_control.sr +avr-gcc -mmcu=atmega16 -O -g -Wall -o vel_control.o vel_control.c pccom.c +avr-objcopy -Osrec vel_control.o vel_control.sr uisp -dprog=stk200 --erase --upload if=vel_control.sr \ No newline at end of file diff --git a/linear_pendulum_2009/avr/vel_control.c b/linear_pendulum_2009/avr/vel_control.c index ca125ae..39122ae 100644 --- a/linear_pendulum_2009/avr/vel_control.c +++ b/linear_pendulum_2009/avr/vel_control.c @@ -1,3 +1,10 @@ +/*************************************************************** + + Current regulation - Pontus Giselsson, Per-Ola Larsson 18/02/09 + for LTH - reglerteknik + +/*************************************************************** + #include <avr/twi.h> #include <avr/io.h> #include <avr/signal.h> @@ -136,8 +143,6 @@ SIGNAL(SIG_OUTPUT_COMPARE0) { sei(); // enable interrupts from encoder-counter - - // Poll UART receiver uint8_t status = UCSRA; if (status & (1<<RXC)) { @@ -155,8 +160,6 @@ SIGNAL(SIG_OUTPUT_COMPARE0) { if (toSend >= 0) UDR = (char)toSend; } - - TIFR = (1<<OCF0); // skip pending interrupts from serial comm, (but not from ctrl) TIMSK |= (BV(OCIE0)|BV(OCIE1A)); // reenable communication and ctrl-interrupts @@ -183,7 +186,6 @@ SIGNAL(SIG_OUTPUT_COMPARE1A) { // ref = ref*(1-brake); // emergency stop sei(); - // control error e = refCtrl-((velEst+16)>>5); // mm/s @@ -225,15 +227,11 @@ SIGNAL(SIG_OUTPUT_COMPARE1A) { sei(); - // TWI-communication to set current reference on the other atmel // send start command outp(BV(TWINT)|BV(TWEN)|BV(TWSTA),TWCR); - while (!(TWCR&BV(TWINT))) {} - - // Contact slave outp(0x02,TWDR); // slave is 0x02 (sla+w) outp(BV(TWINT)|BV(TWEN),TWCR); @@ -260,7 +258,6 @@ int main() PORTD = 0x40; // pull up on reset switch - /* Timer section */ // Enable timer0, timer1, timer2 compare match interrupts outp(BV(OCIE0)|BV(OCIE1A)|BV(OCIE2),TIMSK); @@ -296,8 +293,7 @@ int main() outp(0x18, UCSRB); // USART: RxEnable|TxEnable outp(0x86, UCSRC); // USART: 8bit, no parity outp(0x00, UBRRH); // USART: 115200 @ 14.7456MHz - outp(7,UBRRL); // USART: 115200 @ 14.7456MHz - + outp(7,UBRRL); // USART: 115200 @ 14.7456MHz /* AREF (AREF is 5V) pin external capacitor, ADC3 for pendulum angle */ -- GitLab