working, refactured a bit, optimised for size

This commit is contained in:
Lucas Pleß 2013-06-12 15:31:48 +02:00
parent ee0f2a921d
commit 147a6d8e25
10 changed files with 341 additions and 508 deletions

View File

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CppTools.Loader" reportImplicitCastToBool="false" reportNameReferencedOnce="false" warnedAboutFileOutOfSourceRoot="true" version="3" currentProject="$PROJECT_DIR$/displayboard/Makefile" compilerSelect="AUTO" />
<component name="CppTools.Loader" reportImplicitCastToBool="false" reportNameReferencedOnce="false" warnedAboutFileOutOfSourceRoot="true" version="3" currentProject="$PROJECT_DIR$/displayboard/Makefile" additionalPreprocessorDefs="" compilerSelect="GCC" javaIncludes="false">
<system-include-dir path="/usr/lib/avr/include" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true">
<output url="file://$PROJECT_DIR$/out" />
</component>

View File

@ -2,14 +2,22 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="9fad4545-a424-4a82-86dc-76602cf3eef3" name="Default" comment="">
<change type="DELETED" beforePath="$PROJECT_DIR$/powerboard/src/asciiart.h" afterPath="" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/powerboard/Makefile" afterPath="$PROJECT_DIR$/powerboard/Makefile" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/powerboard/src/main.c" afterPath="$PROJECT_DIR$/powerboard/src/main.c" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/powerboard/src/main.h" afterPath="$PROJECT_DIR$/powerboard/src/main.h" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/misc.xml" afterPath="$PROJECT_DIR$/.idea/misc.xml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/powerboard/powerboard.iml" afterPath="$PROJECT_DIR$/powerboard/powerboard.iml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/powerboard/src/uart.c" afterPath="$PROJECT_DIR$/powerboard/src/uart.c" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/powerboard/src/utils.c" afterPath="$PROJECT_DIR$/powerboard/src/utils.c" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/powerboard/src/utils.h" afterPath="$PROJECT_DIR$/powerboard/src/utils.h" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
</list>
<ignored path="bikegenerator.iws" />
<ignored path=".idea/workspace.xml" />
<file path="/Makefile" changelist="9fad4545-a424-4a82-86dc-76602cf3eef3" time="1370979337668" ignored="false" />
<file path="/Dummy.txt" changelist="9fad4545-a424-4a82-86dc-76602cf3eef3" time="1370989840314" ignored="false" />
<file path="/main.c" changelist="9fad4545-a424-4a82-86dc-76602cf3eef3" time="1370991964646" ignored="false" />
<file path="/Makefile" changelist="9fad4545-a424-4a82-86dc-76602cf3eef3" time="1371032328243" ignored="false" />
<file path="/Dummy.txt" changelist="9fad4545-a424-4a82-86dc-76602cf3eef3" time="1371043806331" ignored="false" />
<file path="/main.c" changelist="9fad4545-a424-4a82-86dc-76602cf3eef3" time="1371032185953" ignored="false" />
<option name="TRACKING_ENABLED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -73,7 +81,7 @@
<file leaf-file-name="Makefile" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/powerboard/Makefile">
<provider selected="true" editor-type-id="text-editor">
<state line="44" column="5" selection-start="1201" selection-end="1201" vertical-scroll-proportion="0.0">
<state line="63" column="34" selection-start="1644" selection-end="1644" vertical-scroll-proportion="-17.678572">
<folding />
</state>
</provider>
@ -82,7 +90,34 @@
<file leaf-file-name="main.c" pinned="false" current="true" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/powerboard/src/main.c">
<provider selected="true" editor-type-id="text-editor">
<state line="122" column="12" selection-start="2842" selection-end="2842" vertical-scroll-proportion="1.8497758">
<state line="169" column="0" selection-start="4305" selection-end="4305" vertical-scroll-proportion="0.66820276">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="main.h" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/powerboard/src/main.h">
<provider selected="true" editor-type-id="text-editor">
<state line="24" column="34" selection-start="646" selection-end="646" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="utils.c" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/powerboard/src/utils.c">
<provider selected="true" editor-type-id="text-editor">
<state line="30" column="0" selection-start="649" selection-end="649" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="utils.h" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/powerboard/src/utils.h">
<provider selected="true" editor-type-id="text-editor">
<state line="6" column="33" selection-start="185" selection-end="185" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
@ -106,18 +141,23 @@
<component name="IdeDocumentHistory">
<option name="changedFiles">
<list>
<option value="$PROJECT_DIR$/powerboard/src/uart.c" />
<option value="$PROJECT_DIR$/powerboard/src/uart.h" />
<option value="$PROJECT_DIR$/powerboard/src/asciiart.h" />
<option value="$PROJECT_DIR$/powerboard/src/adc.h" />
<option value="$PROJECT_DIR$/powerboard/src/adc.c" />
<option value="$PROJECT_DIR$/powerboard/src/utils.c" />
<option value="$PROJECT_DIR$/powerboard/src/utils.h" />
<option value="$PROJECT_DIR$/powerboard/src/main.h" />
<option value="$PROJECT_DIR$/powerboard/Makefile" />
<option value="$PROJECT_DIR$/powerboard/src/main.c" />
</list>
</option>
</component>
<component name="ProjectFrameBounds">
<option name="x" value="-4" />
<option name="y" value="25" />
<option name="width" value="1608" />
<option name="height" value="853" />
<option name="x" value="1596" />
<option name="width" value="1928" />
<option name="height" value="1058" />
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true">
<OptionsSetting value="true" id="Add" />
@ -198,7 +238,7 @@
<property name="options.splitter.main.proportions" value="0.3" />
<property name="MemberChooser.sorted" value="false" />
<property name="recentsLimit" value="5" />
<property name="options.lastSelected" value="project.propVCSSupport.Mappings" />
<property name="options.lastSelected" value="project.propCompiler" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/../.." />
<property name="MemberChooser.copyJavadoc" value="false" />
<property name="GoToClass.toSaveIncludeLibraries" value="false" />
@ -343,14 +383,22 @@
<created>1370989849092</created>
<updated>1370989849092</updated>
</task>
<option name="localTasksCounter" value="2" />
<task id="LOCAL-00002" summary="added first draft of overvoltage protection by using dump load">
<created>1370994654693</created>
<updated>1370994654693</updated>
</task>
<task id="LOCAL-00003" summary="optimisations in adc code">
<created>1371043815539</created>
<updated>1371043815539</updated>
</task>
<option name="localTasksCounter" value="4" />
<servers />
</component>
<component name="ToolWindowManager">
<frame x="-4" y="25" width="1608" height="853" extended-state="6" />
<frame x="1596" y="0" width="1928" height="1058" extended-state="6" />
<editor active="false" />
<layout>
<window_info id="Changes" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.328125" sideWeight="0.5" order="11" side_tool="false" content_ui="tabs" />
<window_info id="Changes" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.25412542" sideWeight="0.5" order="11" side_tool="false" content_ui="tabs" />
<window_info id="Palette" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
@ -365,7 +413,7 @@
<window_info id="Maven Projects" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="SLIDING" type="SLIDING" visible="false" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Application Servers" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="10" side_tool="false" content_ui="tabs" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.3011583" sideWeight="0.671875" order="0" side_tool="false" content_ui="combo" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.2497332" sideWeight="0.7458746" order="0" side_tool="false" content_ui="combo" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
@ -379,8 +427,8 @@
</component>
<component name="VcsManagerConfiguration">
<option name="OFFER_MOVE_TO_ANOTHER_CHANGELIST_ON_PARTIAL_COMMIT" value="true" />
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="true" />
<option name="CHECK_NEW_TODO" value="true" />
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
<option name="CHECK_NEW_TODO" value="false" />
<option name="myTodoPanelSettings">
<value>
<are-packages-shown value="false" />
@ -416,7 +464,7 @@
<option name="WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN" value="false" />
<option name="FORCE_NON_EMPTY_COMMENT" value="false" />
<option name="CLEAR_INITIAL_COMMIT_MESSAGE" value="false" />
<option name="LAST_COMMIT_MESSAGE" value="- added 3rd party uart lib&#10;- added measurements for voltage and current" />
<option name="LAST_COMMIT_MESSAGE" value="optimisations in adc code" />
<option name="MAKE_NEW_CHANGELIST_ACTIVE" value="false" />
<option name="OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT" value="false" />
<option name="CHECK_FILES_UP_TO_DATE_BEFORE_COMMIT" value="false" />
@ -431,6 +479,8 @@
<option name="SHOW_FILE_HISTORY_AS_TREE" value="false" />
<option name="FILE_HISTORY_SPLITTER_PROPORTION" value="0.6" />
<MESSAGE value="- added 3rd party uart lib&#10;- added measurements for voltage and current" />
<MESSAGE value="added first draft of overvoltage protection by using dump load" />
<MESSAGE value="optimisations in adc code" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager />
@ -461,20 +511,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/powerboard/src/adc.h">
<provider selected="true" editor-type-id="text-editor">
<state line="3" column="22" selection-start="52" selection-end="52" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/powerboard/src/utils.h">
<provider selected="true" editor-type-id="text-editor">
<state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/displayboard/Makefile">
<provider selected="true" editor-type-id="text-editor">
<state line="19" column="28" selection-start="429" selection-end="429" vertical-scroll-proportion="0.06942393">
@ -482,46 +518,67 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/powerboard/Makefile">
<provider selected="true" editor-type-id="text-editor">
<state line="44" column="5" selection-start="1201" selection-end="1201" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/powerboard/src/utils.c">
<provider selected="true" editor-type-id="text-editor">
<state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/powerboard/src/uart.h">
<provider selected="true" editor-type-id="text-editor">
<state line="63" column="24" selection-start="2405" selection-end="2421" vertical-scroll-proportion="-1.971935">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/powerboard/src/uart.c">
<provider selected="true" editor-type-id="text-editor">
<state line="233" column="37" selection-start="8699" selection-end="8700" vertical-scroll-proportion="-0.38403615">
<state line="81" column="32" selection-start="2066" selection-end="3000" vertical-scroll-proportion="0.0">
<folding>
<element signature="n#!!doc" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/powerboard/src/uart.h">
<provider selected="true" editor-type-id="text-editor">
<state line="9" column="35" selection-start="301" selection-end="480" vertical-scroll-proportion="0.20737328">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/powerboard/src/adc.c">
<provider selected="true" editor-type-id="text-editor">
<state line="2" column="0" selection-start="21" selection-end="21" vertical-scroll-proportion="0.0">
<state line="8" column="39" selection-start="169" selection-end="169" vertical-scroll-proportion="0.1843318">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/powerboard/src/adc.h">
<provider selected="true" editor-type-id="text-editor">
<state line="4" column="11" selection-start="73" selection-end="73" vertical-scroll-proportion="0.0921659">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/powerboard/src/utils.h">
<provider selected="true" editor-type-id="text-editor">
<state line="6" column="33" selection-start="185" selection-end="185" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/powerboard/Makefile">
<provider selected="true" editor-type-id="text-editor">
<state line="63" column="34" selection-start="1644" selection-end="1644" vertical-scroll-proportion="-17.678572">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/powerboard/src/utils.c">
<provider selected="true" editor-type-id="text-editor">
<state line="30" column="0" selection-start="649" selection-end="649" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/powerboard/src/main.h">
<provider selected="true" editor-type-id="text-editor">
<state line="24" column="34" selection-start="646" selection-end="646" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/powerboard/src/main.c">
<provider selected="true" editor-type-id="text-editor">
<state line="122" column="12" selection-start="2842" selection-end="2842" vertical-scroll-proportion="1.8497758">
<state line="169" column="0" selection-start="4305" selection-end="4305" vertical-scroll-proportion="0.66820276">
<folding />
</state>
</provider>

View File

@ -1,48 +1,17 @@
# Hey Emacs, this is a -*- makefile -*-
#
# WinAVR makefile written by Eric B. Weddington, J<>rg Wunsch, et al.
# Released to the Public Domain
# Please read the make user manual!
#
# Additional material for this makefile was submitted by:
# Tim Henigan
# Peter Fleury
# Reiner Patommel
# Sander Pool
# Frederik Rouleau
# Markus Pfaff
#
# On command line:
#
# make all = Make software.
#
# make clean = Clean out built project files.
#
# make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB).
#
# make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio
# 4.07 or greater).
#
# make program = Download the hex file to the device, using avrdude. Please
# customize the avrdude settings below first!
#
# make filename.s = Just compile filename.c into the assembler code only
#
# To rebuild project do "make clean" then "make all".
#
# mth 2004/09
# Differences from WinAVR 20040720 sample:
# - DEPFLAGS according to Eric Weddingtion's fix (avrfreaks/gcc-forum)
# - F_OSC Define in CFLAGS and AFLAGS
# MCU name
MCU = atmega8
# Main Oscillator Frequency
# This is only used to define F_OSC in all assembler and c-sources.
F_OSC = 8000000
F_CPU = 8000000
# Output format. (can be srec, ihex, binary)
FORMAT = ihex
@ -50,32 +19,14 @@ FORMAT = ihex
# Target file name (without extension).
TARGET = main
# List C source files here. (C dependencies are automatically generated.)
SRC = src/$(TARGET).c src/adc.c src/utils.c src/uart.c
# List Assembler source files here.
# Make them always end in a capital .S. Files ending in a lowercase .s
# will not be considered source files but generated files (assembler
# output from the compiler), and will be deleted upon "make clean"!
# Even though the DOS/Win* filesystem matches both .s and .S the same,
# it will preserve the spelling of the filenames, and gcc itself does
# care about how the name is spelled on its command-line.
ASRC =
# Optimization level, can be [0, 1, 2, 3, s].
# 0 = turn off optimization. s = optimize for size.
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
OPT = s
# Debugging format.
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
#DEBUG = stabs
DEBUG = dwarf-2
# List any extra directories to look for include files here.
# Each directory must be seperated by a space.
@ -97,13 +48,11 @@ CINCS =
# Compiler flags.
# -g*: generate debugging information
# -O*: optimization level
# -f...: tuning, see GCC manual and avr-libc documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns...: create assembler listing
CFLAGS = -g$(DEBUG)
CFLAGS += $(CDEFS) $(CINCS)
CFLAGS += -O$(OPT)
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
@ -111,112 +60,30 @@ CFLAGS += -Wall -Wstrict-prototypes
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
CFLAGS += $(CSTANDARD)
CFLAGS += -DF_OSC=$(F_OSC)
CFLAGS += -DF_CPU=$(F_CPU) -DDEBUG
# Assembler flags.
# -Wa,...: tell GCC to pass this to the assembler.
# -ahlms: create listing
# -gstabs: have the assembler create line number information; note that
# for use in COFF files, additional information about filenames
# and function names needs to be present in the assembler source
# files -- see avr-libc docs [FIXME: not yet described there]
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
ASFLAGS += -DF_OSC=$(F_OSC)
#Additional libraries.
# Minimalistic printf version
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
# Floating point printf version (requires MATH_LIB = -lm below)
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
PRINTF_LIB =
# Minimalistic scanf version
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
SCANF_LIB =
MATH_LIB = -lm
# External memory options
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
# used for variables (.data/.bss) and heap (malloc()).
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
# only used for heap (malloc()).
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
EXTMEMOPTS =
# Linker flags.
# -Wl,...: tell GCC to pass this to linker.
# -Map: create map file
# --cref: add cross reference to map file
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
LDFLAGS += $(EXTMEMOPTS)
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
# Programming support using avrdude. Settings and variables.
# Programming hardware: alf avr910 avrisp bascom bsd
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
#
# Type: avrdude -c ?
# to get a full listing.
#
AVRDUDE_PROGRAMMER = usbasp
# com1 = serial port. Use lpt1 to connect to parallel port.
AVRDUDE_PORT = usb
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
# Uncomment the following if you want avrdude's erase cycle counter.
# Note that this counter needs to be initialized first using -Yn,
# see avrdude manual.
#AVRDUDE_ERASE_COUNTER = -y
# Uncomment the following if you do /not/ wish a verification to be
# performed after programming the device.
#AVRDUDE_NO_VERIFY = -V
# Increase verbosity level. Please use this when submitting bug
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
# to submit bug reports.
#AVRDUDE_VERBOSE = -v -v
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
AVRDUDE_FLAGS = -p $(MCU) -c $(AVRDUDE_PROGRAMMER)
# ---------------------------------------------------------------------------
# Define directories, if needed.
DIRAVR = c:/winavr
DIRAVRBIN = $(DIRAVR)/bin
DIRAVRUTILS = $(DIRAVR)/utils/bin
DIRINC = .
DIRLIB = $(DIRAVR)/avr/lib
# Define programs and commands.
SHELL = sh
CC = avr-gcc
@ -266,10 +133,6 @@ GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
# Default target.
@ -322,29 +185,6 @@ program: $(TARGET).hex $(TARGET).eep
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
--change-section-address .data-0x800000 \
--change-section-address .bss-0x800000 \
--change-section-address .noinit-0x800000 \
--change-section-address .eeprom-0x810000
coff: $(TARGET).elf
@echo
@echo $(MSG_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
extcoff: $(TARGET).elf
@echo
@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
@echo

View File

@ -2,7 +2,9 @@
<module type="C++" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="Cpp SDK" jdkType="CppSdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>

View File

@ -1,138 +0,0 @@
#ifndef _asciiart_h
#define _asciiart_h
#define NUM_ROWS 10
#define ASCII_OFFSET 0
const uint8_t characters[128][10] PROGMEM = {
{255,255,255,255,255,255,255,255,255,255}, // gefuellt
{66,165,24,0,0,0,0,0,0,0}, // smiley 1
{56,68,130,170,130,130,146,130,68,56}, // smiley 2
{56,68,130,170,130,130,186,130,68,56}, // smiley 3
{56,68,130,170,130,130,186,198,68,56}, // smiley 4
{56,68,130,170,130,130,170,146,68,56}, // smiley 5
{255,255,255,255,255,255,255,255,255,255}, // gefuellt
{255,255,255,255,255,255,255,255,255,255}, // gefuellt
{255,255,255,255,255,255,255,255,255,255}, // gefuellt
{255,255,255,255,255,255,255,255,255,255}, // gefuellt
{255,255,255,255,255,255,255,255,255,255}, // gefuellt
{255,255,255,255,255,255,255,255,255,255}, // gefuellt
{255,255,255,255,255,255,255,255,255,255}, // gefuellt
{255,255,255,255,255,255,255,255,255,255}, // gefuellt
{255,255,255,255,255,255,255,255,255,255}, // gefuellt
{255,255,255,255,255,255,255,255,255,255}, // gefuellt
{255,255,255,255,255,255,255,255,255,255}, // gefuellt
{255,255,255,255,255,255,255,255,255,255}, // gefuellt
{255,255,255,255,255,255,255,255,255,255}, // gefuellt
{255,255,255,255,255,255,255,255,255,255}, // gefuellt
{255,255,255,255,255,255,255,255,255,255}, // gefuellt
{255,255,255,255,255,255,255,255,255,255}, // gefuellt
{255,255,255,255,255,255,255,255,255,255}, // gefuellt
{255,255,255,255,255,255,255,255,255,255}, // gefuellt
{255,255,255,255,255,255,255,255,255,255}, // gefuellt
{255,255,255,255,255,255,255,255,255,255}, // gefuellt
{255,255,255,255,255,255,255,255,255,255}, // gefuellt
{255,255,255,255,255,255,255,255,255,255}, // gefuellt
{255,255,255,255,255,255,255,255,255,255}, // gefuellt
{255,255,255,255,255,255,255,255,255,255}, // gefuellt
{255,255,255,255,255,255,255,255,255,255}, // gefuellt
{255,255,255,255,255,255,255,255,255,255}, // gefuellt
{0,0,0,0,0,0,0,0,0,0}, // leer
{56,254,254,124,124,56,56,16,0,16}, // !
{36,36,0,0,0,0,0,0,0,0}, // "
{0,72,72,254,72,72,238,72,72,0}, // #
{16,60,80,80,48,24,20,20,120,16}, // $
{0,100,100,8,8,16,19,35,0,0}, // %
{24,68,68,68,24,40,69,66,70,57}, // &
{0,32,32,32,0,0,0,0,0,0}, // '
{16,32,32,32,32,32,32,32,32,16}, // (
{32,16,16,16,16,16,16,16,16,32}, // )
{0,0,0,24,60,60,24,0,0,0}, // *
{0,0,16,16,16,254,16,16,16,0}, // +
{0,0,0,0,0,0,0,48,48,64}, // ,
{0,0,0,0,0,126,0,0,0,0}, // -
{0,0,0,0,0,0,0,0,24,24}, // .
{2,4,4,12,8,16,16,32,32,64}, // /
{59,68,130,130,130,130,130,130,68,56}, // 0
{24,40,72,136,8,8,8,8,8,8}, // 1
{56,68,132,4,8,16,32,64,128,252}, // 2
{56,68,130,2,4,4,2,130,68,56}, // 3
{8,24,40,72,252,8,8,8,8,8}, // 4
{254,128,128,184,196,2,2,130,68,56}, // 5
{56,68,128,128,176,200,132,132,72,48}, // 6
{254,2,4,8,124,32,32,64,64,128}, // 7
{56,68,130,68,56,68,130,130,68,56}, // 8
{60,66,130,130,64,62,2,130,68,56}, // 9
{0,0,48,48,0,0,48,48,0,0}, // :
{0,48,48,0,0,48,48,64,64,0}, // ;
{0,0,24,32,64,64,32,24,0,0}, // <
{0,0,0,60,0,60,0,0,0,0}, // =
{0,0,32,16,8,8,16,32,0,0}, // >
{56,68,130,2,2,4,8,16,0,16}, // ?
{126,153,153,165,133,157,164,166,125,60},// @
{16,40,68,130,130,254,130,130,130,130}, // A
{248,132,132,132,248,132,130,130,130,252},// B
{60,66,128,128,128,128,128,128,66,60}, // C
{248,132,130,130,130,130,130,130,132,248},// D
{124,64,64,64,124,64,64,64,64,124}, // E
{124,64,64,64,124,64,64,64,64,64}, // F
{56,64,128,128,128,140,130,130,132,120},// G
{130,130,130,130,254,130,130,130,130,130},// H
{124,16,16,16,16,16,16,16,16,124}, // I
{2,2,2,2,2,2,2,2,68,56}, // J
{132,136,144,160,192,192,160,144,136,132},// K
{128,128,128,128,128,128,128,128,128,248},// L
{130,198,170,170,146,130,130,130,130,130},// M
{130,194,162,162,146,146,138,138,134,130},// N
{56,68,130,130,130,130,130,130,68,56}, // O
{252,130,130,130,252,128,128,128,128,128},// P
{56,68,130,130,130,130,130,138,68,58}, // Q
{252,130,130,130,252,136,132,130,130,130},// R
{62,64,128,128,96,24,4,2,2,252}, // S
{254,16,16,16,16,16,16,16,16,16}, // T
{130,130,130,130,130,130,130,130,68,56},// U
{130,130,130,130,130,130,130,68,40,16}, // V
{130,130,130,130,146,170,170,198,198,130},// W
{130,68,68,40,16,16,40,68,68,130}, // X
{130,130,130,68,56,16,16,16,16,16}, // Y
{254,4,8,8,16,16,32,32,64,254}, // Z
{56,32,32,32,32,32,32,32,32,56}, // [
{128,64,64,64,32,32,16,16,8,12}, // backslash
{112,16,16,16,16,16,16,16,16,112}, // ]
{16,16,40,68,0,0,0,0,0,0}, // ^
{0,0,0,0,0,0,0,0,0,124}, // _
{24,4,0,0,0,0,0,0,0,0}, // `
{0,0,0,112,136,8,120,136,136,248}, // a
{0,0,0,128,128,128,240,136,136,240},
{0,0,0,0,112,128,128,128,128,112},
{0,0,0,8,8,8,120,136,136,120},
{0,0,0,0,112,136,248,128,128,120},
{0,0,0,16,32,32,112,32,32,32},
{0,0,0,120,136,136,120,8,8,240},
{0,0,0,128,128,128,240,136,136,136},
{0,0,0,32,0,32,32,32,32,32},
{0,0,0,16,0,16,16,16,144,96},
{0,0,0,128,128,144,160,192,160,144},
{0,0,0,32,32,32,32,32,32,32},
{0,0,0,0,108,84,84,84,84,84},
{0,0,0,0,240,136,136,136,136,136},
{0,0,0,0,112,136,136,136,136,112},
{0,0,0,0,120,68,68,120,64,64},
{0,0,0,0,120,136,136,120,8,8},
{0,0,0,0,176,192,128,128,128,128},
{0,0,0,0,112,128,64,32,16,224},
{0,0,0,64,64,224,64,64,64,48},
{0,0,0,0,136,136,136,136,136,112},
{0,0,0,0,136,136,136,136,80,32},
{0,0,0,0,146,146,146,84,84,40},
{0,0,0,0,136,80,32,32,80,136},
{0,0,0,0,136,136,80,32,32,64},
{0,0,0,0,248,16,32,64,128,248}, // z
{24,24,24,24,56,56,24,24,24,24}, // {
{0,32,32,32,32,32,32,32,32,0}, // |
{24,24,24,24,28,28,24,24,24,24}, // }
{0,0,0,0,50,76,0,0,0,0}, // ~
{0,0,0,0,126,98,98,98,126,0}, // kasten
};
#endif

View File

@ -1,45 +1,22 @@
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <utils.h>
#include "utils.h"
#include "main.h"
#include "adc.h"
#include "uart.h"
#define AD_I_LOAD 0
#define AD_I_GEN 1
#define AD_V 2
#define LOADSW PB0
#define GENSW PB1
#define DUMPSW PB2
#define PORT_SW PORTB
#define DDR_SW DDRB
#define LOAD_ON PORT_SW |= _BV(LOADSW)
#define LOAD_OFF PORT_SW &= ~_BV(LOADSW)
#define GEN_ON PORT_SW |= _BV(GENSW)
#define GEN_OFF PORT_SW &= ~_BV(GENSW)
#define DUMP_ON PORT_SW |= _BV(DUMPSW)
#define DUMP_OFF PORT_SW &= ~_BV(DUMPSW)
#define OVERVOLTAGE1 144
#define OVERVOLTAGE2 150
#define OVERVOLTAGE_TIMEOUT1 20
#define OVERVOLTAGE_TIMEOUT2 20
#define CURRENT_OFFSET 511
#define CURRENT_PER_TICK 72
#define TICKS_PER_VOLTAGE 6.6
volatile uint16_t syscounter = 0;
uint16_t voltage = 0;
int16_t current_in = 0;
int16_t current_out = 0;
uint16_t overvoltage_counter = 0;
uint16_t overvoltage_off_counter = 0;
uint16_t overvoltage_counter1 = 0;
uint16_t overvoltage_off_counter1 = 0;
uint16_t overvoltage_counter2 = 0;
uint16_t overvoltage_off_counter2 = 0;
uint16_t undervoltage_counter = 0;
uint16_t undervoltage_off_counter = 0;
void timer_init(void) {
@ -56,14 +33,15 @@ void ports_init(void) {
}
void measure(void) {
voltage = adc_read_avg(AD_V, 4) / TICKS_PER_VOLTAGE;
voltage = adc_read_avg(AD_V, 4);
voltage *= VOLTAGE_PER_TICK;
current_in = adc_read_avg(AD_I_GEN, 4);
current_in -= VOLTAGE_OFFSET;
current_in -= CURRENT_OFFSET;
current_in *= CURRENT_PER_TICK;
current_out = adc_read_avg(AD_I_LOAD, 4);
current_out -= VOLTAGE_OFFSET;
current_out -= CURRENT_OFFSET;
current_out *= CURRENT_PER_TICK;
}
@ -71,20 +49,116 @@ uint8_t get_power(uint16_t voltage, int16_t currents) {
return (voltage * (currents/100)) / 100;
}
void pretty_print_all_values() {
uart_puts_P("Voltage: ");
uart_print_voltage(voltage);
uart_puts_P("V\r\n");
uart_puts_P("Load: ");
uart_print_current(current_out);
uart_puts_P("mA ");
uart_print_uint16( get_power(voltage, current_out));
uart_puts_P("W\r\n");
uart_puts_P("Generator: ");
uart_print_current(current_in);
uart_puts_P("mA ");
uart_print_uint16(get_power(voltage, current_in));
uart_puts_P("W\r\n");
}
void handle_over_and_undervoltage() {
if(voltage > OVERVOLTAGE1) {
overvoltage_off_counter1 = 0;
if(overvoltage_counter1<OVERVOLTAGE_TIMEOUT1) overvoltage_counter1++;
} else {
overvoltage_counter1 = 0;
if(overvoltage_off_counter1<OVERVOLTAGE_TIMEOUT1) overvoltage_off_counter1++;
}
if(voltage > OVERVOLTAGE2) {
overvoltage_off_counter2 = 0;
if(overvoltage_counter2<OVERVOLTAGE_TIMEOUT2) overvoltage_counter2++;
} else {
overvoltage_counter2 = 0;
if(overvoltage_off_counter2<OVERVOLTAGE_TIMEOUT2) overvoltage_off_counter2++;
}
if(voltage < UNDERVOLTAGE) {
undervoltage_off_counter = 0;
if(undervoltage_counter<UNDERVOLTAGE_TIMEOUT) undervoltage_counter++;
} else {
undervoltage_counter = 0;
if(undervoltage_off_counter<UNDERVOLTAGE_TIMEOUT) undervoltage_off_counter++;
}
if(overvoltage_counter1 >= OVERVOLTAGE_TIMEOUT1) {
overvoltage_off_counter1 = 0;
DUMP_ON;
}
if(overvoltage_off_counter1 >= OVERVOLTAGE_TIMEOUT1) {
overvoltage_counter1 = 0;
DUMP_OFF;
}
if(overvoltage_counter2 >= OVERVOLTAGE_TIMEOUT2) {
overvoltage_off_counter2 = 0;
GEN_OFF;
}
if(overvoltage_off_counter2 >= OVERVOLTAGE_TIMEOUT2) {
overvoltage_counter2 = 0;
GEN_ON;
}
if(undervoltage_counter >= UNDERVOLTAGE_TIMEOUT) {
undervoltage_off_counter = 0;
LOAD_OFF;
}
if(undervoltage_off_counter >= UNDERVOLTAGE_TIMEOUT) {
undervoltage_counter = 0;
LOAD_ON;
}
#ifdef DEBUG
uart_puts_P("overvoltage_counter1=");
uart_print_uint16(overvoltage_counter1);
uart_puts_P(" overvoltage_off_counter1=");
uart_print_uint16 (overvoltage_off_counter1);
uart_puts_P("\r\n");
uart_puts_P("overvoltage_counter2=");
uart_print_uint16(overvoltage_counter2);
uart_puts_P(" overvoltage_off_counter2=");
uart_print_uint16 (overvoltage_off_counter2);
uart_puts_P("\r\n");
uart_puts_P("undervoltage_counter=");
uart_print_uint16(undervoltage_counter);
uart_puts_P(" undervoltage_off_counter=");
uart_print_uint16(undervoltage_off_counter);
uart_puts_P("\r\n");
#endif
}
int main(void) {
ports_init();
LOAD_OFF;
GEN_ON;
DUMP_OFF;
adc_init();
timer_init();
uart_init(UART_BAUD_SELECT(9600,F_OSC));
uart_init(UART_BAUD_SELECT(9600,F_CPU));
char s[10];
LOAD_ON;
GEN_ON;
DUMP_OFF;
while(1) {
@ -92,50 +166,9 @@ int main(void) {
measure();
uart_puts_P("Voltage: ");
uart_puts ( itoa ( voltage, s, 10 ) );
uart_puts_P("dV\r\n");
uart_puts_P("Load: ");
uart_puts ( itoa ( current_out, s, 10 ) );
uart_puts_P("mA ");
uart_puts ( itoa ( get_power(voltage, current_out), s, 10 ) );
uart_puts_P("W\r\n");
uart_puts_P("Generator: ");
uart_puts ( itoa ( current_in, s, 10 ) );
uart_puts_P("mA ");
uart_puts ( itoa ( get_power(voltage, current_in), s, 10 ) );
uart_puts_P("W\r\n");
if(voltage > OVERVOLTAGE1) {
overvoltage_off_counter = 0;
overvoltage_counter++;
} else {
overvoltage_counter = 0;
overvoltage_off_counter++;
}
uart_puts_P("overvoltage_counter=");
uart_puts ( itoa ( overvoltage_counter, s, 10 ) );
uart_puts_P(" overvoltage_off_counter=");
uart_puts ( itoa ( overvoltage_off_counter , s, 10 ) );
if(overvoltage_counter >= OVERVOLTAGE_TIMEOUT1) {
overvoltage_off_counter = 0;
DUMP_ON;
}
if(overvoltage_off_counter >= OVERVOLTAGE_TIMEOUT1/2) {
overvoltage_counter = 0;
DUMP_OFF;
}
pretty_print_all_values();
handle_over_and_undervoltage();
}
}

View File

@ -1,26 +1,35 @@
#ifndef _main_h
#define _main_h
// count of lines on display
#define NUM_ROWS 10
#define AD_I_LOAD 0
#define AD_I_GEN 1
#define AD_V 2
enum tower_mode_t {
NONE,
ROTATE_CCW,
ROTATE_CW,
BLINK,
};
#define LOADSW PB0
#define GENSW PB1
#define DUMPSW PB2
#define PORT_SW PORTB
#define DDR_SW DDRB
enum display_mode_t {
NORMAL,
SCROLL
};
#define LOAD_ON PORT_SW |= _BV(LOADSW)
#define LOAD_OFF PORT_SW &= ~_BV(LOADSW)
#define GEN_ON PORT_SW |= _BV(GENSW)
#define GEN_OFF PORT_SW &= ~_BV(GENSW)
#define DUMP_ON PORT_SW |= _BV(DUMPSW)
#define DUMP_OFF PORT_SW &= ~_BV(DUMPSW)
struct message_t {
enum display_mode_t mode;
uint8_t speed;
char *text;
};
#define IS_LOAD_ON PIND &= _BV(LOADSW);
#define UNDERVOLTAGE 112
#define OVERVOLTAGE1 141
#define OVERVOLTAGE2 150
#define OVERVOLTAGE_TIMEOUT1 20
#define OVERVOLTAGE_TIMEOUT2 20
#define UNDERVOLTAGE_TIMEOUT 20
#define CURRENT_OFFSET 511
#define CURRENT_PER_TICK 72
#define VOLTAGE_PER_TICK 15
#endif

View File

@ -1,6 +1,6 @@
#include <avr/io.h>
#include <util/delay.h>
#include "uart.h"
void wait(uint8_t count) {
uint8_t i;
@ -10,5 +10,30 @@ void wait(uint8_t count) {
}
}
void uart_print_voltage(uint16_t x) {
uart_putc(48 + (x / 10000));
uart_putc(48 + (x % 10000 /1000));
uart_putc(48 + (x % 1000 / 100 ));
uart_putc(48 + (x % 100 / 10 ));
uart_putc('.');
uart_putc(48 + (x % 10));
}
void uart_print_current(int16_t x) {
if(x <0) uart_putc('-');
uart_putc(48 + (x / 10000));
uart_putc(48 + (x % 10000 /1000));
uart_putc(48 + (x % 1000 / 100 ));
uart_putc(48 + (x % 100 / 10 ));
uart_putc(48 + (x % 10));
}
void uart_print_uint16(uint16_t x) {
uart_putc(48 + (x / 10000));
uart_putc(48 + (x % 10000 /1000));
uart_putc(48 + (x % 1000 / 100 ));
uart_putc(48 + (x % 100 / 10 ));
uart_putc(48 + (x % 10));
}

View File

@ -1,7 +1,10 @@
#ifndef _utils_h
#define _utils_h
void wait(uint8_t count);
extern void wait(uint8_t count);
extern void uart_print_voltage(uint16_t);
extern void uart_print_current(int16_t);
extern void uart_print_uint16(uint16_t);
#endif