Compare commits
3 Commits
77afb9d4cf
...
1fee740458
| Author | SHA1 | Date | |
|---|---|---|---|
| 1fee740458 | |||
| c5fc30dfb3 | |||
| 1c2d799d8c |
12
Firmware/compile_flags.txt
Normal file
12
Firmware/compile_flags.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
--target=avr
|
||||
-D
|
||||
__AVR_ATmega324PA__
|
||||
-D
|
||||
F_CPU=16000000UL
|
||||
-I
|
||||
/usr/lib/avr/include
|
||||
-I
|
||||
./include
|
||||
-I
|
||||
../../dmm-libs/include
|
||||
|
||||
59
Firmware/makefile
Normal file
59
Firmware/makefile
Normal file
@@ -0,0 +1,59 @@
|
||||
TARGET = main
|
||||
SRCS := $(shell find ../../dmm-libs/src/ -name '*.c') $(shell find src/ -name '*.c')
|
||||
FILES = $(SRCS:%.c=%) #main uart avrIOhelper/io-helper #uart#hier alle c-Datein reinschreiben, trennung durch " " und ohne .c-Endung
|
||||
MCU = atmega324pa
|
||||
PROGC = m324pa
|
||||
CC = avr-gcc
|
||||
#TOOL = stk500 -P /dev/ttyUSB0
|
||||
TOOL = atmelice
|
||||
#TOOL = avrispmkii
|
||||
#TOOL = usbasp-clone
|
||||
|
||||
BUILDDIR = Builds
|
||||
|
||||
DEFINES = -DF_CPU=16000000UL -I include/ -I ../../dmm-libs/include/
|
||||
|
||||
CFLAGS =-mmcu=$(MCU) -O2 -Wall -Wpedantic $(DEFINES) -std=c99 -ffunction-sections -fdata-sections
|
||||
LDFLAGS =-mmcu=$(MCU) -Wl,--gc-sections
|
||||
|
||||
LDFILES = $(foreach FILE,$(FILES),$(BUILDDIR)/$(FILE).o)
|
||||
|
||||
all: clean $(BUILDDIR)/$(TARGET).elf
|
||||
|
||||
$(BUILDDIR)/%.o: %.c
|
||||
mkdir -p $(dir $@)
|
||||
$(CC) $(CFLAGS) -c $< -o $(BUILDDIR)/$*.o
|
||||
|
||||
$(BUILDDIR)/$(TARGET).elf: $(LDFILES)
|
||||
mkdir -p $(dir $@)
|
||||
$(CC) $(LDFLAGS) $(LDFILES) -o $(BUILDDIR)/$(TARGET).elf
|
||||
|
||||
$(BUILDDIR)/$(TARGET).hex : $(BUILDDIR)/$(TARGET).elf
|
||||
avr-objcopy -j .data -j .text -O ihex $< $@
|
||||
|
||||
fuse:
|
||||
avrdude -p $(PROGC) -c $(TOOL) -U lfuse:w:0xE8:m -U hfuse:w:0xD1:m
|
||||
|
||||
load: $(BUILDDIR)/$(TARGET).hex
|
||||
avrdude -p $(PROGC) -c $(TOOL) -U flash:w:$(BUILDDIR)/$(TARGET).hex -v -B 4MHz
|
||||
|
||||
program: clean load
|
||||
|
||||
reset:
|
||||
avrdude -p $(PROGC) -c $(TOOL)
|
||||
|
||||
size: $(BUILDDIR)/$(TARGET).elf
|
||||
avr-size -C --mcu=$(MCU) $(BUILDDIR)/$(TARGET).elf
|
||||
|
||||
.PHONY=clean
|
||||
clean:
|
||||
rm -rf $(BUILDDIR)
|
||||
|
||||
|
||||
#Fuse m1284p external Osz. Long startuptime
|
||||
# avrdude -c usbasp-clone -p m1284p -U lfuse:w:0xff:m -U hfuse:w:0xd9:m -U efuse:w:0xff:m
|
||||
|
||||
#Fuse m1284p internal Osz. Long startuptime
|
||||
# avrdude -c usbasp-clone -p m1284p -U lfuse:w:0xe2:m -U hfuse:w:0xd9:m -U efuse:w:0xff:m
|
||||
|
||||
|
||||
@@ -80,30 +80,49 @@ void pwm_init (void)
|
||||
TCCR1B = _BV(CS10) | _BV(WGM12); //fast PWM (8 bit), clk/1 source
|
||||
|
||||
//setup sample timer (CTC Mode)
|
||||
#if defined(__AVR_ATmega1284P__)
|
||||
TCCR3A = 0;
|
||||
TCCR3B = _BV(CS30) | _BV(WGM32); // clk/1
|
||||
#elif defined(__AVR_ATmega324PA__)
|
||||
TCCR0A = _BV(WGM01);
|
||||
TCCR0B = _BV(CS01); // clk/8
|
||||
#endif
|
||||
}
|
||||
|
||||
void pwm_deinit (void)
|
||||
{
|
||||
TCCR1A = 0;
|
||||
TCCR1B = 0;
|
||||
#if defined(__AVR_ATmega1284P__)
|
||||
TCCR3A = 0;
|
||||
TCCR3B = 0;
|
||||
#elif defined(__AVR_ATmega324PA__)
|
||||
TCCR0A = 0;
|
||||
TCCR0B = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void pwm_gen(uint16_t tone, uint16_t periods)
|
||||
{
|
||||
//calculate single sine sample duration
|
||||
#if defined(__AVR_ATmega1284P__)
|
||||
OCR3A = F_CPU / tone / sizeof(sine_lookup) - 1;
|
||||
|
||||
#elif defined(__AVR_ATmega324PA__)
|
||||
OCR0A = F_CPU / 8 / tone / sizeof(sine_lookup) - 1;
|
||||
#endif
|
||||
|
||||
for (uint16_t period=0; period < periods; ++period) {
|
||||
for (uint8_t spl=0; spl < sizeof(sine_lookup); ++spl) {
|
||||
//wait for timer ready for next spl
|
||||
#if defined(__AVR_ATmega1284P__)
|
||||
loop_until_bit_is_set(TIFR3, OCF1A);
|
||||
TIFR3 = _BV(OCF1A); //clear OCF
|
||||
#elif defined(__AVR_ATmega324PA__)
|
||||
loop_until_bit_is_set(TIFR0, OCF0A);
|
||||
TIFR0 = _BV(OCF0A); //clear OCF
|
||||
#endif
|
||||
|
||||
OCR1A = pgm_read_byte(sine_lookup + spl) + 0x70;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user