From 7bb9b8f1df6cf6ecf6e3fc04b089d1603e735d81 Mon Sep 17 00:00:00 2001 From: pfrison Date: Mon, 4 Mar 2019 19:00:08 +0100 Subject: [PATCH] Tests d'avr sur atmega2560, de controle de servomoteur et de moteur pas à pas concluants --- tests/atmega2560/ledControl/ledControl.c | 27 +++++++++++++++++++++++++++ tests/atmega2560/ledControl/makefile | 36 ++++++++++++++++++++++++++++++++++++ tests/atmega2560/makefile | 7 +++---- tests/atmega2560/ordonanceur.c | 132 ------------------------------------------------------------------------------------------------------------------------------------ tests/atmega2560/ordonanceur/makefile | 36 ++++++++++++++++++++++++++++++++++++ tests/atmega2560/ordonanceur/ordonanceur.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/atmega2560/servoAndStepperControl/makefile | 36 ++++++++++++++++++++++++++++++++++++ tests/atmega2560/servoAndStepperControl/servoAndStepperControl.c | 16 ++++++++++++++++ tests/atmega2560/servoControl.c | 14 -------------- tests/atmega2560/stepperControl.c | 20 -------------------- 10 files changed, 286 insertions(+), 170 deletions(-) create mode 100644 tests/atmega2560/ledControl/ledControl.c create mode 100644 tests/atmega2560/ledControl/makefile delete mode 100644 tests/atmega2560/ordonanceur.c create mode 100644 tests/atmega2560/ordonanceur/makefile create mode 100644 tests/atmega2560/ordonanceur/ordonanceur.c create mode 100644 tests/atmega2560/servoAndStepperControl/makefile create mode 100644 tests/atmega2560/servoAndStepperControl/servoAndStepperControl.c delete mode 100644 tests/atmega2560/servoControl.c delete mode 100644 tests/atmega2560/stepperControl.c diff --git a/tests/atmega2560/ledControl/ledControl.c b/tests/atmega2560/ledControl/ledControl.c new file mode 100644 index 0000000..2177c39 --- /dev/null +++ b/tests/atmega2560/ledControl/ledControl.c @@ -0,0 +1,27 @@ +#include +#include + +int main(void){ + // SCLK PIN 37 + // SIN PIN 35 + DDRC = 0x03; + uint8_t LEDs = {10, 20, 30, 40, 50, 60, 70, 80, 90, + 100, 110, 120, 130, 140, 150, 160, 170, 180, 190 + 200, 210, 220, 230, 240}; + uint8_t ANDs = {0x001, 0x002, 0x004, 0x008, 0x010, 0x020, 0x040, 0x080, + 0x100, 0x200, 0x400, 0x800}; + + while(1){ + for(int i=0; i<24; i++){ + uint16_t n = LEDs[i] << 4; + int clkStatus = 0; + for(int j=0; j<12; j++){ + if(j == 6) + clkStatus = 1; + PORTC = (n & ANDs[j]) << 1 | clkStatus; + _delay_ms(1); + } + } + } + return 0; +} diff --git a/tests/atmega2560/ledControl/makefile b/tests/atmega2560/ledControl/makefile new file mode 100644 index 0000000..96923b6 --- /dev/null +++ b/tests/atmega2560/ledControl/makefile @@ -0,0 +1,36 @@ +export CC = avr-gcc + +export MCU = atmega2560 +export TARGET_ARCH = -mmcu=$(MCU) + +export CFLAGS = -Wall -I. -DF_CPU=16000000 -Os #-g +export LDFLAGS = -g $(TARGET_ARCH) -lm -Wl,--gc-sections # -Os + +TARGET = servoControl +TERM = /dev/ttyACM0 +CPPFLAGS = -mmcu=$(MCU) +PGMERISP = -c wiring -b 115200 -P $(TERM) -D +export DUDE = /usr/bin/avrdude -F -v -p $(MCU) + +C_SRC = $(wildcard *.c) +OBJS = $(C_SRC:.c=.o) + +all: $(TARGET).hex + +clean: + rm -f *.o *.hex *.elf + +%.o:%.c + $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@ + +$(TARGET).elf: $(OBJS) + $(CC) $(LDFLAGS) -o $@ $(OBJS) + +$(TARGET).hex: $(TARGET).elf + avr-objcopy -j .text -j .data -O ihex $(TARGET).elf $(TARGET).hex + avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex $(TARGET).elf eeprom.hex + +upload: $(TARGET).hex + stty -F $(TERM) hupcl # reset + $(DUDE) $(PGMERISP) -U flash:w:$(TARGET).hex + make clean diff --git a/tests/atmega2560/makefile b/tests/atmega2560/makefile index 2c414c6..96923b6 100644 --- a/tests/atmega2560/makefile +++ b/tests/atmega2560/makefile @@ -6,12 +6,11 @@ export TARGET_ARCH = -mmcu=$(MCU) export CFLAGS = -Wall -I. -DF_CPU=16000000 -Os #-g export LDFLAGS = -g $(TARGET_ARCH) -lm -Wl,--gc-sections # -Os -TARGET = usb +TARGET = servoControl TERM = /dev/ttyACM0 CPPFLAGS = -mmcu=$(MCU) -PGMERISP = -c stk500v2 -b 115200 -P $(TERM) -ARVDUDECONF= -C /usr/local/arduino/arduino-0022/hardware/tools/avrdude.conf -export DUDE = /usr/bin/avrdude -F -v -p $(MCU) $(AVRDUDECONF) +PGMERISP = -c wiring -b 115200 -P $(TERM) -D +export DUDE = /usr/bin/avrdude -F -v -p $(MCU) C_SRC = $(wildcard *.c) OBJS = $(C_SRC:.c=.o) diff --git a/tests/atmega2560/ordonanceur.c b/tests/atmega2560/ordonanceur.c deleted file mode 100644 index c102e98..0000000 --- a/tests/atmega2560/ordonanceur.c +++ /dev/null @@ -1,132 +0,0 @@ -#include -#include -#include - -#define NB_TICK 104 //1563 -#define CPU_FREQ 16000000L -#define QUANTUM_ms 10 - -#define SAVE_CONTEXT() \ -asm volatile ( \ -"push r0 \n\t" \ -"in r0, __SREG__ \n\t" \ -"cli \n\t" \ -"push r0 \n\t" \ -"push r1 \n\t" \ -"clr r1 \n\t" \ -"push r2 \n\t" \ -"push r3 \n\t" \ -"push r4 \n\t" \ -"push r5 \n\t" \ -"push r6 \n\t" \ -"push r7 \n\t" \ -"push r8 \n\t" \ -"push r9 \n\t" \ -"push r10 \n\t" \ -"push r11 \n\t" \ -"push r12 \n\t" \ -"push r13 \n\t" \ -"push r14 \n\t" \ -"push r15 \n\t" \ -"push r16 \n\t" \ -"push r17 \n\t" \ -"push r18 \n\t" \ -"push r19 \n\t" \ -"push r20 \n\t" \ -"push r21 \n\t" \ -"push r22 \n\t" \ -"push r23 \n\t" \ -"push r24 \n\t" \ -"push r25 \n\t" \ -"push r26 \n\t" \ -"push r27 \n\t" \ -"push r28 \n\t" \ -"push r29 \n\t" \ -"push r30 \n\t" \ -"push r31 \n\t" \ -); - -#define RESTORE_CONTEXT() \ -asm volatile ( \ -"pop r31 \n\t" \ -"pop r30 \n\t" \ -"pop r29 \n\t" \ -"pop r28 \n\t" \ -"pop r27 \n\t" \ -"pop r26 \n\t" \ -"pop r25 \n\t" \ -"pop r24 \n\t" \ -"pop r23 \n\t" \ -"pop r22 \n\t" \ -"pop r21 \n\t" \ -"pop r20 \n\t" \ -"pop r19 \n\t" \ -"pop r18 \n\t" \ -"pop r17 \n\t" \ -"pop r16 \n\t" \ -"pop r15 \n\t" \ -"pop r14 \n\t" \ -"pop r13 \n\t" \ -"pop r12 \n\t" \ -"pop r11 \n\t" \ -"pop r10 \n\t" \ -"pop r9 \n\t" \ -"pop r8 \n\t" \ -"pop r7 \n\t" \ -"pop r6 \n\t" \ -"pop r5 \n\t" \ -"pop r4 \n\t" \ -"pop r3 \n\t" \ -"pop r2 \n\t" \ -"pop r1 \n\t" \ -"pop r0 \n\t" \ -"out __SREG__, r0 \n\t" \ -"pop r0 \n\t" \ -); - -struct task{ - uint16_t sp_vise; - uint8_t state; -}; - -/** Démarre le timer pour l'ordonnancement */ -void init_timer(){ - TCCR1B |= _BV(WGM12); // CTC mode with value in OCR1A - TCCR1B |= _BV(CS12); // CS12 = 1; CS11 = 1; CS10 =1 => CLK/1024 prescaler - TCCR1B |= _BV(CS10); - OCR1A = NB_TICK; - TIMSK1 |= _BV(OCIE1A); -} - -/** Configure les ports */ -void init_ports(){ - //TODO DDRXs -} - -/** Alumme la LED 13 pour témoigné du bon fonctionnement de la carte */ -void temoin_allumage(){ - DDRA = 0x01; - PORTA = 0x01; - _delay_ms(500); - PORTA = 0x00; -} - -/** Reception de l'interruption généré par le timer (changement de contexte) */ -ISR(TIMER1_COMPA_vect){ - // TODO - sei(); -} - -int main(void){ - temoin_allumage(); - - // Initialisation - init_timer(); - init_port(); - sei(); - - while(1){} - return 0; -} - - diff --git a/tests/atmega2560/ordonanceur/makefile b/tests/atmega2560/ordonanceur/makefile new file mode 100644 index 0000000..96923b6 --- /dev/null +++ b/tests/atmega2560/ordonanceur/makefile @@ -0,0 +1,36 @@ +export CC = avr-gcc + +export MCU = atmega2560 +export TARGET_ARCH = -mmcu=$(MCU) + +export CFLAGS = -Wall -I. -DF_CPU=16000000 -Os #-g +export LDFLAGS = -g $(TARGET_ARCH) -lm -Wl,--gc-sections # -Os + +TARGET = servoControl +TERM = /dev/ttyACM0 +CPPFLAGS = -mmcu=$(MCU) +PGMERISP = -c wiring -b 115200 -P $(TERM) -D +export DUDE = /usr/bin/avrdude -F -v -p $(MCU) + +C_SRC = $(wildcard *.c) +OBJS = $(C_SRC:.c=.o) + +all: $(TARGET).hex + +clean: + rm -f *.o *.hex *.elf + +%.o:%.c + $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@ + +$(TARGET).elf: $(OBJS) + $(CC) $(LDFLAGS) -o $@ $(OBJS) + +$(TARGET).hex: $(TARGET).elf + avr-objcopy -j .text -j .data -O ihex $(TARGET).elf $(TARGET).hex + avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex $(TARGET).elf eeprom.hex + +upload: $(TARGET).hex + stty -F $(TERM) hupcl # reset + $(DUDE) $(PGMERISP) -U flash:w:$(TARGET).hex + make clean diff --git a/tests/atmega2560/ordonanceur/ordonanceur.c b/tests/atmega2560/ordonanceur/ordonanceur.c new file mode 100644 index 0000000..c102e98 --- /dev/null +++ b/tests/atmega2560/ordonanceur/ordonanceur.c @@ -0,0 +1,132 @@ +#include +#include +#include + +#define NB_TICK 104 //1563 +#define CPU_FREQ 16000000L +#define QUANTUM_ms 10 + +#define SAVE_CONTEXT() \ +asm volatile ( \ +"push r0 \n\t" \ +"in r0, __SREG__ \n\t" \ +"cli \n\t" \ +"push r0 \n\t" \ +"push r1 \n\t" \ +"clr r1 \n\t" \ +"push r2 \n\t" \ +"push r3 \n\t" \ +"push r4 \n\t" \ +"push r5 \n\t" \ +"push r6 \n\t" \ +"push r7 \n\t" \ +"push r8 \n\t" \ +"push r9 \n\t" \ +"push r10 \n\t" \ +"push r11 \n\t" \ +"push r12 \n\t" \ +"push r13 \n\t" \ +"push r14 \n\t" \ +"push r15 \n\t" \ +"push r16 \n\t" \ +"push r17 \n\t" \ +"push r18 \n\t" \ +"push r19 \n\t" \ +"push r20 \n\t" \ +"push r21 \n\t" \ +"push r22 \n\t" \ +"push r23 \n\t" \ +"push r24 \n\t" \ +"push r25 \n\t" \ +"push r26 \n\t" \ +"push r27 \n\t" \ +"push r28 \n\t" \ +"push r29 \n\t" \ +"push r30 \n\t" \ +"push r31 \n\t" \ +); + +#define RESTORE_CONTEXT() \ +asm volatile ( \ +"pop r31 \n\t" \ +"pop r30 \n\t" \ +"pop r29 \n\t" \ +"pop r28 \n\t" \ +"pop r27 \n\t" \ +"pop r26 \n\t" \ +"pop r25 \n\t" \ +"pop r24 \n\t" \ +"pop r23 \n\t" \ +"pop r22 \n\t" \ +"pop r21 \n\t" \ +"pop r20 \n\t" \ +"pop r19 \n\t" \ +"pop r18 \n\t" \ +"pop r17 \n\t" \ +"pop r16 \n\t" \ +"pop r15 \n\t" \ +"pop r14 \n\t" \ +"pop r13 \n\t" \ +"pop r12 \n\t" \ +"pop r11 \n\t" \ +"pop r10 \n\t" \ +"pop r9 \n\t" \ +"pop r8 \n\t" \ +"pop r7 \n\t" \ +"pop r6 \n\t" \ +"pop r5 \n\t" \ +"pop r4 \n\t" \ +"pop r3 \n\t" \ +"pop r2 \n\t" \ +"pop r1 \n\t" \ +"pop r0 \n\t" \ +"out __SREG__, r0 \n\t" \ +"pop r0 \n\t" \ +); + +struct task{ + uint16_t sp_vise; + uint8_t state; +}; + +/** Démarre le timer pour l'ordonnancement */ +void init_timer(){ + TCCR1B |= _BV(WGM12); // CTC mode with value in OCR1A + TCCR1B |= _BV(CS12); // CS12 = 1; CS11 = 1; CS10 =1 => CLK/1024 prescaler + TCCR1B |= _BV(CS10); + OCR1A = NB_TICK; + TIMSK1 |= _BV(OCIE1A); +} + +/** Configure les ports */ +void init_ports(){ + //TODO DDRXs +} + +/** Alumme la LED 13 pour témoigné du bon fonctionnement de la carte */ +void temoin_allumage(){ + DDRA = 0x01; + PORTA = 0x01; + _delay_ms(500); + PORTA = 0x00; +} + +/** Reception de l'interruption généré par le timer (changement de contexte) */ +ISR(TIMER1_COMPA_vect){ + // TODO + sei(); +} + +int main(void){ + temoin_allumage(); + + // Initialisation + init_timer(); + init_port(); + sei(); + + while(1){} + return 0; +} + + diff --git a/tests/atmega2560/servoAndStepperControl/makefile b/tests/atmega2560/servoAndStepperControl/makefile new file mode 100644 index 0000000..0d506a1 --- /dev/null +++ b/tests/atmega2560/servoAndStepperControl/makefile @@ -0,0 +1,36 @@ +export CC = avr-gcc + +export MCU = atmega2560 +export TARGET_ARCH = -mmcu=$(MCU) + +export CFLAGS = -Wall -I. -DF_CPU=16000000 -Os #-g +export LDFLAGS = -g $(TARGET_ARCH) -lm -Wl,--gc-sections # -Os + +TARGET = servoAndStepperControl +TERM = /dev/ttyACM0 +CPPFLAGS = -mmcu=$(MCU) +PGMERISP = -c wiring -b 115200 -P $(TERM) -D +export DUDE = /usr/bin/avrdude -F -v -p $(MCU) + +C_SRC = $(wildcard *.c) +OBJS = $(C_SRC:.c=.o) + +all: $(TARGET).hex + +clean: + rm -f *.o *.hex *.elf + +%.o:%.c + $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@ + +$(TARGET).elf: $(OBJS) + $(CC) $(LDFLAGS) -o $@ $(OBJS) + +$(TARGET).hex: $(TARGET).elf + avr-objcopy -j .text -j .data -O ihex $(TARGET).elf $(TARGET).hex + avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex $(TARGET).elf eeprom.hex + +upload: $(TARGET).hex + stty -F $(TERM) hupcl # reset + $(DUDE) $(PGMERISP) -U flash:w:$(TARGET).hex + make clean diff --git a/tests/atmega2560/servoAndStepperControl/servoAndStepperControl.c b/tests/atmega2560/servoAndStepperControl/servoAndStepperControl.c new file mode 100644 index 0000000..746fe1f --- /dev/null +++ b/tests/atmega2560/servoAndStepperControl/servoAndStepperControl.c @@ -0,0 +1,16 @@ +#include +#include + +int main(void){ + // pin 13 + DDRB = 0x80; + + while(1){ + PORTB = 0x80; + _delay_us(1000); + PORTB = 0x00; + _delay_us(1000); + } + return 0; +} + diff --git a/tests/atmega2560/servoControl.c b/tests/atmega2560/servoControl.c deleted file mode 100644 index b182287..0000000 --- a/tests/atmega2560/servoControl.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include - -int main(void){ - DDRC = 0x01; - - while(1){ - PORTC = 0x01; - _delay_ms(200); - PORTC = 0x00; - _delay_ms(200); - } - return 0; -} diff --git a/tests/atmega2560/stepperControl.c b/tests/atmega2560/stepperControl.c deleted file mode 100644 index b9cefee..0000000 --- a/tests/atmega2560/stepperControl.c +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include - -int vitesseToDelay(int vitesse){ - return ; -} - -int main(void){ - DDRC = 0x01; - PORTC |= 0x02; // Direction horraire ? - //PORTC &= 0xFD; // Direction anti-horraire ? - while(1){ - // 1 Step - PORTC |= 0x01; - _delay_ms(10); - PORTC &= 0xFE; - _delay_ms(10); - } - return 0; -} -- libgit2 0.21.2