Commit 7363cced authored by Pontus Giselsson's avatar Pontus Giselsson
Browse files

Added simulink file and matlab scripts

parent 91a6458f
avr-gcc -mmcu=atmega16 -g -Wall -o current_control current_control.c avr-gcc -mmcu=atmega16 -g -Wall -o current_control.o current_control.c
avr-objcopy -Osrec current_control current_control.sr avr-objcopy -Osrec current_control.o current_control.sr
uisp -dprog=stk200 --erase --upload if=current_control.sr uisp -dprog=stk200 --erase --upload if=current_control.sr
\ No newline at end of file
avr-gcc -mmcu=atmega16 -O -g -Wall -o vel_control vel_control.c pccom.c avr-gcc -mmcu=atmega16 -O -g -Wall -o vel_control.o vel_control.c pccom.c
avr-objcopy -Osrec vel_control vel_control.sr avr-objcopy -Osrec vel_control.o vel_control.sr
uisp -dprog=stk200 --erase --upload if=vel_control.sr uisp -dprog=stk200 --erase --upload if=vel_control.sr
\ No newline at end of file
/***************************************************************
Current regulation - Pontus Giselsson, Per-Ola Larsson 18/02/09
for LTH - reglerteknik
/***************************************************************
#include <avr/twi.h> #include <avr/twi.h>
#include <avr/io.h> #include <avr/io.h>
#include <avr/signal.h> #include <avr/signal.h>
...@@ -136,8 +143,6 @@ SIGNAL(SIG_OUTPUT_COMPARE0) { ...@@ -136,8 +143,6 @@ SIGNAL(SIG_OUTPUT_COMPARE0) {
sei(); // enable interrupts from encoder-counter sei(); // enable interrupts from encoder-counter
// Poll UART receiver // Poll UART receiver
uint8_t status = UCSRA; uint8_t status = UCSRA;
if (status & (1<<RXC)) { if (status & (1<<RXC)) {
...@@ -155,8 +160,6 @@ SIGNAL(SIG_OUTPUT_COMPARE0) { ...@@ -155,8 +160,6 @@ SIGNAL(SIG_OUTPUT_COMPARE0) {
if (toSend >= 0) UDR = (char)toSend; if (toSend >= 0) UDR = (char)toSend;
} }
TIFR = (1<<OCF0); // skip pending interrupts from serial comm, (but not from ctrl) TIFR = (1<<OCF0); // skip pending interrupts from serial comm, (but not from ctrl)
TIMSK |= (BV(OCIE0)|BV(OCIE1A)); // reenable communication and ctrl-interrupts TIMSK |= (BV(OCIE0)|BV(OCIE1A)); // reenable communication and ctrl-interrupts
...@@ -183,7 +186,6 @@ SIGNAL(SIG_OUTPUT_COMPARE1A) { ...@@ -183,7 +186,6 @@ SIGNAL(SIG_OUTPUT_COMPARE1A) {
// ref = ref*(1-brake); // emergency stop // ref = ref*(1-brake); // emergency stop
sei(); sei();
// control error // control error
e = refCtrl-((velEst+16)>>5); // mm/s e = refCtrl-((velEst+16)>>5); // mm/s
...@@ -225,15 +227,11 @@ SIGNAL(SIG_OUTPUT_COMPARE1A) { ...@@ -225,15 +227,11 @@ SIGNAL(SIG_OUTPUT_COMPARE1A) {
sei(); sei();
// TWI-communication to set current reference on the other atmel // TWI-communication to set current reference on the other atmel
// send start command // send start command
outp(BV(TWINT)|BV(TWEN)|BV(TWSTA),TWCR); outp(BV(TWINT)|BV(TWEN)|BV(TWSTA),TWCR);
while (!(TWCR&BV(TWINT))) {} while (!(TWCR&BV(TWINT))) {}
// Contact slave // Contact slave
outp(0x02,TWDR); // slave is 0x02 (sla+w) outp(0x02,TWDR); // slave is 0x02 (sla+w)
outp(BV(TWINT)|BV(TWEN),TWCR); outp(BV(TWINT)|BV(TWEN),TWCR);
...@@ -260,7 +258,6 @@ int main() ...@@ -260,7 +258,6 @@ int main()
PORTD = 0x40; // pull up on reset switch PORTD = 0x40; // pull up on reset switch
/* Timer section */ /* Timer section */
// Enable timer0, timer1, timer2 compare match interrupts // Enable timer0, timer1, timer2 compare match interrupts
outp(BV(OCIE0)|BV(OCIE1A)|BV(OCIE2),TIMSK); outp(BV(OCIE0)|BV(OCIE1A)|BV(OCIE2),TIMSK);
...@@ -296,8 +293,7 @@ int main() ...@@ -296,8 +293,7 @@ int main()
outp(0x18, UCSRB); // USART: RxEnable|TxEnable outp(0x18, UCSRB); // USART: RxEnable|TxEnable
outp(0x86, UCSRC); // USART: 8bit, no parity outp(0x86, UCSRC); // USART: 8bit, no parity
outp(0x00, UBRRH); // USART: 115200 @ 14.7456MHz 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 */ /* AREF (AREF is 5V) pin external capacitor, ADC3 for pendulum angle */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment