Intial commit

This commit is contained in:
Jimmy 2020-12-10 14:53:44 +13:00
parent 418e557a14
commit bcbb320289
5 changed files with 116 additions and 0 deletions

2
.gitignore vendored
View File

@ -32,3 +32,5 @@
*.out
*.app
.vscode/
bin/

31
makefile Normal file
View File

@ -0,0 +1,31 @@
MCU=atmega32
F_CPU=8000000
PROG=dragon_jtag
DEBUGGER = dragon
PORT=/dev/ttyUSB0
CC=avr-g++
OBJCOPY=avr-objcopy
CFLAGS=-Wall -g -mmcu=${MCU} -DF_CPU=${F_CPU} -I.
TARGET=main
SRCS=src/*.cpp
default: build flash
build:
${CC} ${CFLAGS} -o bin/${TARGET}.bin ${SRCS}
${CC} ${CFLAGS} -o bin/${TARGET}.elf ${SRCS}
${OBJCOPY} -j .text -j .data -O ihex bin/${TARGET}.bin bin/${TARGET}.hex
flash:
avrdude -p ${MCU} -c ${PROG} -U flash:w:bin/main.hex
clean:
rm -f bin/*
debug: flash avarice
sleep 1
avr-gdb -ex "target remote :4242" bin/main.elf
avarice:
avarice --file bin/main.elf --part ${MCU} --${DEBUGGER} :4242

59
src/main.cpp Normal file
View File

@ -0,0 +1,59 @@
#define F_CPU 8000000UL
#include<avr/io.h>
#include <util/delay.h>
#include "servo.h"
int main()
{
servo::init();
//Configure TIMER1
// TCCR1A|=(1<<COM1A1)|(1<<COM1B1)|(1<<WGM11); //NON Inverted PWM
// TCCR1B|=(1<<WGM13)|(1<<WGM12)|(1<<CS11)|(0<<CS10); //PRESCALER=1 MODE 14(FAST PWM)
// ICR1=19999; //fPWM=50Hz (Period = 20ms Standard).
// DDRD|=(1<<PD4)|(1<<PD5); //PWM Pins as Out
while(1)
{
// for(int i = 1000; i < 2000; i++) {
// OCR1A = i;
// _delay_ms(1);
// }
// for(int i = 2000; i > 999; i--) {
// OCR1A = i;
// _delay_ms(1);
// }
servo::pos(1000);
_delay_ms(1000);
servo::pos(2000);
_delay_ms(1000);
// OCR1A=0; //0 degree
// _delay_ms(1000);
// OCR1A=600; //45 degree
// _delay_ms(1000);
// OCR1A=950; //90 degree
// _delay_ms(1000);
// OCR1A=1425; //135 degree
// _delay_ms(1000);
// OCR1A=1900; //180 degree
// _delay_ms(1000);
// OCR1A=1425; //135 degree
// _delay_ms(1000);
// OCR1A=950; //90 degree
// _delay_ms(1000);
// OCR1A=650; //45 degree
// _delay_ms(1000);
}
return 0;
}

16
src/servo.cpp Normal file
View File

@ -0,0 +1,16 @@
#include "servo.h"
namespace servo
{
void init() {
//Configure TIMER1
TCCR1A|=(1<<COM1A1)|(1<<COM1B1)|(1<<WGM11); //NON Inverted PWM
TCCR1B|=(1<<WGM13)|(1<<WGM12)|(1<<CS11)|(0<<CS10); //PRESCALER=1 MODE 14(FAST PWM)
ICR1=19999; //fPWM=50Hz (Period = 20ms Standard).
DDRD|=(1<<PD4)|(1<<PD5); //PWM Pins as Out
}
void pos(int pos) {
OCR1A = pos;
}
} // namespace servo

8
src/servo.h Normal file
View File

@ -0,0 +1,8 @@
#pragma once
#include <avr/io.h>
namespace servo
{
void init();
void pos(int pos);
} // namespace servo