mirror of
https://github.com/caperren/school_archives.git
synced 2025-11-09 21:51:15 +00:00
Added old firmware and pcb design files
These are all design documents that I thought I had lost. It's may make me cringe, but it's still cool to use it to see how far I've come.
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Atmel Studio Solution File, Format Version 11.00
|
||||
Project("{E66E83B9-2572-4076-B26E-6BE79FF3018A}") = "DechorionatorV1.1", "DechorionatorV1.1.cppproj", "{C0A89A51-65B6-4173-AE27-4E91C9089ABF}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|AVR = Debug|AVR
|
||||
Release|AVR = Release|AVR
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{C0A89A51-65B6-4173-AE27-4E91C9089ABF}.Debug|AVR.ActiveCfg = Debug|AVR
|
||||
{C0A89A51-65B6-4173-AE27-4E91C9089ABF}.Debug|AVR.Build.0 = Debug|AVR
|
||||
{C0A89A51-65B6-4173-AE27-4E91C9089ABF}.Release|AVR.ActiveCfg = Release|AVR
|
||||
{C0A89A51-65B6-4173-AE27-4E91C9089ABF}.Release|AVR.Build.0 = Release|AVR
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
Binary file not shown.
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* DechorionatorV1.cpp
|
||||
*
|
||||
* Created: 7/30/2014 4:55:13 PM
|
||||
* Author: corwin
|
||||
*/
|
||||
#define F_CPU 16000000UL
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
#include "DefineMacrosAndPinDefs.h"
|
||||
#include "SoftLCD.h"
|
||||
#include "StepperClass.h"
|
||||
#include "PumpClass.h"
|
||||
#include "EncoderClass.h"
|
||||
#include "InterruptServiceRoutines.h"
|
||||
|
||||
SoftLCD LCD(&LCD_TX_PORT, &LCD_TX_DDR, P_LCD_TX, &LCD_PWR_PORT, &LCD_PWR_DDR, P_LCD_PWR);
|
||||
StepperClass Stepper(&STEPPER_EN_PORT, &STEPPER_EN_DDR, P_STEPPER_EN,
|
||||
&STEPPER_DIR_PORT, &STEPPER_DIR_DDR, P_STEPPER_DIR,
|
||||
&STEPPER_STEP_PORT, &STEPPER_STEP_DDR, P_STEPPER_STEP,
|
||||
&STEPPER_FAULT_PORT, &STEPPER_FAULT_DDR, P_STEPPER_FAULT,
|
||||
&STEPPER_M0_PORT, &STEPPER_M0_DDR, P_STEPPER_M0,
|
||||
&STEPPER_M1_PORT, &STEPPER_M1_DDR, P_STEPPER_M1,
|
||||
&STEPPER_M2_PORT, &STEPPER_M2_DDR, P_STEPPER_M2
|
||||
);
|
||||
|
||||
char TopTemp[17];
|
||||
char BottomTemp[17];
|
||||
|
||||
void TemporaryInit(){
|
||||
//////////Pump Initialization//////////
|
||||
PUMP_PWR_INIT();
|
||||
//////////End Pump Initialization//////////
|
||||
|
||||
//////////Rotary Encoder Initialization//////////
|
||||
ENCODER_A_INIT();
|
||||
|
||||
ENCODER_B_INIT();
|
||||
|
||||
ENCODER_BUTTON_INIT();
|
||||
//////////End Rotary Encoder Initialization//////////
|
||||
|
||||
|
||||
//////////Hardware Serial Initialization//////////
|
||||
UART_TX_INIT();
|
||||
UART_RX_INIT();
|
||||
//////////End Hardware Serial Initialization//////////
|
||||
|
||||
|
||||
//////////Control Switch Initialization//////////
|
||||
SWITCH_TOP_INIT();
|
||||
SWITCH_BOTTOM_INIT();
|
||||
//////////End Control Switch Initilization//////////
|
||||
|
||||
}
|
||||
|
||||
int TimeCount = 0;
|
||||
|
||||
int i = 0;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
TemporaryInit();
|
||||
TCCR2A = 0;
|
||||
TCCR2B = ((1 << CS22) | (1 << CS21) | (1 << CS20));
|
||||
TCNT2 = 0;
|
||||
TIMSK2 = (1 << TOIE0);
|
||||
|
||||
sei(); //Enable all system interrupts
|
||||
|
||||
//////////Startup Display and System Initialization//////////
|
||||
LCD.showNameScreen();
|
||||
|
||||
LCD.setTopText(" Time ");
|
||||
STEPPER_EN_SET();
|
||||
while(1)
|
||||
{
|
||||
for(int i = 2000 ; i > 1200 ; i--){
|
||||
LCD.show();
|
||||
snprintf(BottomTemp, 16, "%d", TimeCount);
|
||||
LCD.setBottomText(BottomTemp);
|
||||
OCR1A = i;
|
||||
_delay_us(2000);
|
||||
if(SWITCH_TOP_GET() || SWITCH_BOTTOM_GET()){
|
||||
STEPPER_EN_SET();
|
||||
}else{
|
||||
STEPPER_EN_CLR();
|
||||
}
|
||||
}
|
||||
for(int i = 1200 ; i < 2000 ; i++){
|
||||
LCD.show();
|
||||
snprintf(BottomTemp, 16, "%d", TimeCount);
|
||||
LCD.setBottomText(BottomTemp);
|
||||
OCR1A = i;
|
||||
_delay_us(2000);
|
||||
if(SWITCH_TOP_GET() || SWITCH_BOTTOM_GET()){
|
||||
STEPPER_EN_SET();
|
||||
}else{
|
||||
STEPPER_EN_CLR();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectVersion>6.2</ProjectVersion>
|
||||
<ToolchainName>com.Atmel.AVRGCC8.CPP</ToolchainName>
|
||||
<ProjectGuid>{c0a89a51-65b6-4173-ae27-4e91c9089abf}</ProjectGuid>
|
||||
<avrdevice>ATmega328</avrdevice>
|
||||
<avrdeviceseries>none</avrdeviceseries>
|
||||
<OutputType>Executable</OutputType>
|
||||
<Language>CPP</Language>
|
||||
<OutputFileName>$(MSBuildProjectName)</OutputFileName>
|
||||
<OutputFileExtension>.elf</OutputFileExtension>
|
||||
<OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
|
||||
<AssemblyName>DechorionatorV1.1</AssemblyName>
|
||||
<Name>DechorionatorV1.1</Name>
|
||||
<RootNamespace>DechorionatorV1.1</RootNamespace>
|
||||
<ToolchainFlavour>Native</ToolchainFlavour>
|
||||
<KeepTimersRunning>true</KeepTimersRunning>
|
||||
<OverrideVtor>false</OverrideVtor>
|
||||
<CacheFlash>true</CacheFlash>
|
||||
<ProgFlashFromRam>true</ProgFlashFromRam>
|
||||
<RamSnippetAddress>0x20000000</RamSnippetAddress>
|
||||
<UncachedRange />
|
||||
<OverrideVtorValue>exception_table</OverrideVtorValue>
|
||||
<BootSegment>2</BootSegment>
|
||||
<eraseonlaunchrule>0</eraseonlaunchrule>
|
||||
<AsfFrameworkConfig>
|
||||
<framework-data xmlns="">
|
||||
<options />
|
||||
<configurations />
|
||||
<files />
|
||||
<documentation help="" />
|
||||
<offline-documentation help="" />
|
||||
<dependencies>
|
||||
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.18.1" />
|
||||
</dependencies>
|
||||
</framework-data>
|
||||
</AsfFrameworkConfig>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<ToolchainSettings>
|
||||
<AvrGccCpp>
|
||||
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
|
||||
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
|
||||
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
||||
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
||||
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
|
||||
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcc.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>NDEBUG</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.symbols.DefSymbols>
|
||||
<avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
|
||||
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
|
||||
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
|
||||
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
|
||||
<avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcccpp.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>NDEBUG</Value>
|
||||
</ListValues>
|
||||
</avrgcccpp.compiler.symbols.DefSymbols>
|
||||
<avrgcccpp.compiler.optimization.level>Optimize for size (-Os)</avrgcccpp.compiler.optimization.level>
|
||||
<avrgcccpp.compiler.optimization.PackStructureMembers>True</avrgcccpp.compiler.optimization.PackStructureMembers>
|
||||
<avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>
|
||||
<avrgcccpp.compiler.warnings.AllWarnings>True</avrgcccpp.compiler.warnings.AllWarnings>
|
||||
<avrgcccpp.linker.libraries.Libraries>
|
||||
<ListValues>
|
||||
<Value>libm</Value>
|
||||
</ListValues>
|
||||
</avrgcccpp.linker.libraries.Libraries>
|
||||
</AvrGccCpp>
|
||||
</ToolchainSettings>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<ToolchainSettings>
|
||||
<AvrGccCpp>
|
||||
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
|
||||
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
|
||||
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
||||
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
||||
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
|
||||
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcc.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>DEBUG</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.symbols.DefSymbols>
|
||||
<avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
|
||||
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
|
||||
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
|
||||
<avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
|
||||
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
|
||||
<avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcccpp.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>DEBUG</Value>
|
||||
</ListValues>
|
||||
</avrgcccpp.compiler.symbols.DefSymbols>
|
||||
<avrgcccpp.compiler.optimization.level>Optimize (-O1)</avrgcccpp.compiler.optimization.level>
|
||||
<avrgcccpp.compiler.optimization.PackStructureMembers>True</avrgcccpp.compiler.optimization.PackStructureMembers>
|
||||
<avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>
|
||||
<avrgcccpp.compiler.optimization.DebugLevel>Default (-g2)</avrgcccpp.compiler.optimization.DebugLevel>
|
||||
<avrgcccpp.compiler.warnings.AllWarnings>True</avrgcccpp.compiler.warnings.AllWarnings>
|
||||
<avrgcccpp.linker.libraries.Libraries>
|
||||
<ListValues>
|
||||
<Value>libm</Value>
|
||||
</ListValues>
|
||||
</avrgcccpp.linker.libraries.Libraries>
|
||||
<avrgcccpp.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcccpp.assembler.debugging.DebugLevel>
|
||||
</AvrGccCpp>
|
||||
</ToolchainSettings>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DechorionatorV1.1.cpp">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="DefineMacrosAndPinDefs.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="EncoderClass.cpp">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="EncoderClass.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="InterruptServiceRoutines.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="MegaUART.cpp">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="MegaUART.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="PumpClass.cpp">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="PumpClass.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="SoftLCD.cpp">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="SoftLCD.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="StepperClass.cpp">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="StepperClass.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
|
||||
</Project>
|
||||
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* DefineMacrosAndPinDefs.h
|
||||
*
|
||||
* Created: 7/30/2014 4:56:56 PM
|
||||
* Author: corwin
|
||||
*/
|
||||
|
||||
|
||||
#ifndef DEFINEMACROSANDPINDEFS_H_
|
||||
#define DEFINEMACROSANDPINDEFS_H_
|
||||
|
||||
//////////LCD Definitions//////////
|
||||
#define P_LCD_TX PORTB0 //Pin B0 runs tx pin for serial lcd
|
||||
#define LCD_TX_PORT PORTB //Port that the tx lcd pin is on
|
||||
#define LCD_TX_DDR DDRB //Direction port that the tx lcd pin is on
|
||||
#define LCD_TX_BM (1 << P_LCD_TX) //Bit mask for pin
|
||||
#define LCD_TX_INIT() DDRB |= LCD_TX_BM //Sets tx pin to output
|
||||
#define LCD_TX_SET() PORTB |= LCD_TX_BM //Macro for setting pin high
|
||||
#define LCD_TX_CLR() PORTB &= ~LCD_TX_BM //Macro for setting pin low
|
||||
|
||||
|
||||
#define P_LCD_PWR PORTC5 //Pin C5 controls the power to the lcd through a mosfet
|
||||
#define LCD_PWR_PORT PORTC //Port that the lcd power pin is on
|
||||
#define LCD_PWR_DDR DDRC //Direction port that the lcd power pin is on
|
||||
#define LCD_PWR_BM (1 << P_LCD_PWR) //Bit mask for pin
|
||||
#define LCD_PWR_INIT() DDRC |= LCD_PWR_BM //Sets lcd power control pin to an output
|
||||
#define LCD_PWR_SET() PORTC |= LCD_PWR_BM //Macro for setting pin high
|
||||
#define LCD_PWR_CLR() PORTC &= ~LCD_PWR_BM //Macro for setting pin low
|
||||
//////////End LCD Definitions
|
||||
|
||||
//////////Pump Definitions//////////
|
||||
#define P_PUMP_PWR PORTD5 //Pin D5 controls power to the water pump through a mosfet
|
||||
#define PUMP_PWR_BM (1 << P_PUMP_PWR) //Bit mask for pin
|
||||
#define PUMP_PWR_INIT() DDRD |= PUMP_PWR_BM //Sets pump power control pin to an output
|
||||
#define PUMP_PWR_SET() PORTD |= PUMP_PWR_BM //Macro for setting pin high
|
||||
#define PUMP_PWR_CLR() PORTD &= ~PUMP_PWR_BM //Macro for setting pin low
|
||||
//////////End Pump Definitions//////////
|
||||
|
||||
//////////DRV8825 Stepper Motor Driver Definitions//////////
|
||||
#define P_STEPPER_DIR PORTD6 //Pin D6 controls the direction of the stepper motor
|
||||
#define STEPPER_DIR_PORT PORTD
|
||||
#define STEPPER_DIR_DDR DDRD
|
||||
#define STEPPER_DIR_BM (1 << P_STEPPER_DIR) //Bit mask for pin
|
||||
#define STEPPER_DIR_INIT() DDRD |= STEPPER_DIR_BM //Sets stepper direction pin to an output
|
||||
#define STEPPER_DIR_SET() PORTD |= STEPPER_DIR_BM //Macro for setting pin high
|
||||
#define STEPPER_DIR_CLR() PORTD &= ~STEPPER_DIR_BM //Macro for setting pin low
|
||||
|
||||
|
||||
#define P_STEPPER_STEP PORTD7 //Pin D7 controls the step pin of the driver
|
||||
#define STEPPER_STEP_PORT PORTD
|
||||
#define STEPPER_STEP_DDR DDRD
|
||||
#define STEPPER_STEP_BM (1 << P_STEPPER_STEP) //Bit mask for pin
|
||||
#define STEPPER_STEP_INIT() DDRD |= STEPPER_STEP_BM //Sets the step pin to an output
|
||||
#define STEPPER_STEP_SET() PORTD |= STEPPER_STEP_BM //Macro for setting pin high
|
||||
#define STEPPER_STEP_CLR() PORTD &= ~STEPPER_STEP_BM //Macro for setting pin low
|
||||
|
||||
|
||||
#define P_STEPPER_EN PORTC1 //Pin C1 controls whether the stepper motor is enabled and running or not
|
||||
#define STEPPER_EN_PORT PORTC
|
||||
#define STEPPER_EN_DDR DDRC
|
||||
#define STEPPER_EN_BM (1 << P_STEPPER_EN) //Bit mask for pin
|
||||
#define STEPPER_EN_INIT() DDRC |= STEPPER_EN_BM //Sets stepper enable control pin to an output
|
||||
#define STEPPER_EN_SET() PORTC &= ~STEPPER_EN_BM //Macro for setting pin high (Note inverted logic!!!)
|
||||
#define STEPPER_EN_CLR() PORTC |= STEPPER_EN_BM //Macro for setting pin low (Note inverted logic!!!)
|
||||
|
||||
|
||||
#define P_STEPPER_FAULT PORTC0 //Pin C0 senses whether the stepper driver is in a fault state due to over current or over temp conditions
|
||||
#define STEPPER_FAULT_PORT PORTC
|
||||
#define STEPPER_FAULT_DDR DDRC
|
||||
#define STEPPER_FAULT_BM (1 << P_STEPPER_FAULT) //Bit mask for pin
|
||||
#define STEPPER_FAULT_INIT() DDRC &= ~STEPPER_FAULT_BM //Sets stepper fault check pin to an input (May need to enable internal pull up?)
|
||||
#define STEPPER_FAULT_GET() !(PINC & STEPPER_FAULT_BM) //Returns true if in fault state (0 is fault, 1 is non-fault)
|
||||
|
||||
|
||||
|
||||
#define P_STEPPER_M0 PORTC2 //Pin C2 sets the lowest bit of the driver micro-stepping
|
||||
#define STEPPER_M0_PORT PORTC
|
||||
#define STEPPER_M0_DDR DDRC
|
||||
#define STEPPER_M0_BM (1 << P_STEPPER_M0) //Bit mask for pin
|
||||
#define STEPPER_M0_INIT() DDRC |= STEPPER_M0_BM //Sets the micro-step pin to an output
|
||||
#define STEPPER_M0_SET() PORTC |= STEPPER_M0_BM //Macro for setting pin high
|
||||
#define STEPPER_M0_CLR() PORTC &= ~STEPPER_M0_BM //Macro for setting pin low
|
||||
|
||||
|
||||
#define P_STEPPER_M1 PORTC3 //Pin C3 sets the middle bit of the driver micro-stepping
|
||||
#define STEPPER_M1_PORT PORTC
|
||||
#define STEPPER_M1_DDR DDRC
|
||||
#define STEPPER_M1_BM (1 << P_STEPPER_M1) //Bit mask for pin
|
||||
#define STEPPER_M1_INIT() DDRC |= STEPPER_M1_BM //Sets the micro-step pin to an output
|
||||
#define STEPPER_M1_SET() PORTC |= STEPPER_M1_BM //Macro for setting pin high
|
||||
#define STEPPER_M1_CLR() PORTC &= ~STEPPER_M1_BM //Macro for setting pin low
|
||||
|
||||
|
||||
#define P_STEPPER_M2 PORTC4 //Pin C4 sets the upper bit of the driver micro-stepping
|
||||
#define STEPPER_M2_PORT PORTC
|
||||
#define STEPPER_M2_DDR DDRC
|
||||
#define STEPPER_M2_BM (1 << P_STEPPER_M2) //Bit mask for pin
|
||||
#define STEPPER_M2_INIT() DDRC |= STEPPER_M2_BM //Sets the micro-step pin to an output
|
||||
#define STEPPER_M2_SET() PORTC |= STEPPER_M2_BM //Macro for setting pin high
|
||||
#define STEPPER_M2_CLR() PORTC &= ~STEPPER_M2_BM //Macro for setting pin low
|
||||
//////////End DRV8825 Stepper Motor Driver Definitions//////////
|
||||
|
||||
//////////Rotary Encoder Definitions//////////
|
||||
#define P_ENCODER_A PORTD2 //Pin D2 senses the state for channel A on the rotary encoder
|
||||
#define ENCODER_A_BM (1 << P_ENCODER_A) //Bit mask for pin
|
||||
#define ENCODER_A_INIT() {DDRD &= ~ENCODER_A_BM; PORTD |= ENCODER_A_BM;} //Sets channel A pin to an input and enables the internal pull up resistor
|
||||
#define ENCODER_A_GET() !(PIND & ENCODER_A_BM) //Returns state of the pin (Note inverted logic!!! Makes gray code logic less confusing...)
|
||||
|
||||
|
||||
#define P_ENCODER_B PORTD3 //Pin D3 sense the state for channel B on the rotary encoder
|
||||
#define ENCODER_B_BM (1 << P_ENCODER_B) //Bit mask for pin
|
||||
#define ENCODER_B_INIT() {DDRD &= ~ENCODER_B_BM; PORTD |= ENCODER_B_BM;} //Sets channel B pin to an input and enables the internal pull up resistor
|
||||
#define ENCODER_B_GET() !(PIND & ENCODER_B_BM) //Returns state of the pin (Note inverted logic!!! Makes gray code logic less confusing...)
|
||||
|
||||
|
||||
#define P_ENCODER_BUTTON PORTD4 //Pin D4 senses whether the tactile button on the rotary encoder has been pushed
|
||||
#define ENCODER_BUTTON_BM (1 << P_ENCODER_BUTTON) //Bit mask for pin
|
||||
#define ENCODER_BUTTON_INIT() {DDRD &= ~ENCODER_BUTTON_BM; PORTD |= ENCODER_BUTTON_BM;} //Sets encoder button pin to an input and enables the internal pull up resistor
|
||||
#define ENCODER_BUTTON_GET() !(PIND & ENCODER_BUTTON_BM) //Returns whether the button has been pushed (Note inverted logic!!!)
|
||||
//////////End Rotary Encoder Definitions//////////
|
||||
|
||||
//////////Hardware Serial Definitions//////////
|
||||
#define P_UART_TX PORTD1 //Pin D1 is the transmit line for the hardware uart
|
||||
#define UART_TX_BM (1 << P_UART_TX) //Bit mask for pin
|
||||
#define UART_TX_INIT() DDRD |= UART_TX_BM //Sets the transmit line to an output
|
||||
|
||||
|
||||
#define P_UART_RX PORTD0 //Pin D0 is the receive line for the hardware uart
|
||||
#define UART_RX_BM (1 << P_UART_RX) //Bit mask for pin
|
||||
#define UART_RX_INIT() DDRD &= ~UART_RX_BM //Sets the receive line to an input
|
||||
//////////End Hardware Serial Definitions//////////
|
||||
|
||||
//////////Control Switch Definitions//////////
|
||||
#define P_SWITCH_TOP PORTB2 //Pin B1 senses whether the top button on the control switch has been pushed (RINSE)
|
||||
#define SWITCH_TOP_BM (1 << P_SWITCH_TOP) //Bit mask for pin
|
||||
#define SWITCH_TOP_INIT() {DDRB |= SWITCH_TOP_BM; PORTB |= SWITCH_TOP_BM;} //Sets the button to an input and enables the internal pull up resistor
|
||||
#define SWITCH_TOP_GET() !(PINB & SWITCH_TOP_BM) //Returns whether the button has been pushed (Note inverted logic!!!)
|
||||
|
||||
|
||||
#define P_SWITCH_BOTTOM PORTB1 //Pin B2 senses whether the bottom button on the control switch has been pushed (ESTOP)
|
||||
#define SWITCH_BOTTOM_BM (1 << P_SWITCH_BOTTOM) //Bit mask for pin
|
||||
#define SWITCH_BOTTOM_INIT() {DDRB |= SWITCH_BOTTOM_BM; PORTB |= SWITCH_BOTTOM_BM;} //Sets the button to an input and enables the internal pull up resistor
|
||||
#define SWITCH_BOTTOM_GET() !(PINB & SWITCH_BOTTOM_BM) //Returns whether the button has been pushed (Note inverted logic!!!)
|
||||
//////////Control Switch Definitions//////////
|
||||
|
||||
|
||||
#endif /* DEFINEMACROSANDPINDEFS_H_ */
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* EncoderClass.cpp
|
||||
*
|
||||
* Created: 8/6/2014 9:20:23 AM
|
||||
* Author: corwin
|
||||
*/
|
||||
|
||||
|
||||
#include "EncoderClass.h"
|
||||
|
||||
// default constructor
|
||||
EncoderClass::EncoderClass()
|
||||
{
|
||||
} //EncoderClass
|
||||
|
||||
// default destructor
|
||||
EncoderClass::~EncoderClass()
|
||||
{
|
||||
} //~EncoderClass
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* EncoderClass.h
|
||||
*
|
||||
* Created: 8/6/2014 9:20:23 AM
|
||||
* Author: corwin
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __ENCODERCLASS_H__
|
||||
#define __ENCODERCLASS_H__
|
||||
|
||||
|
||||
class EncoderClass
|
||||
{
|
||||
//variables
|
||||
public:
|
||||
protected:
|
||||
private:
|
||||
|
||||
//functions
|
||||
public:
|
||||
EncoderClass();
|
||||
~EncoderClass();
|
||||
protected:
|
||||
private:
|
||||
EncoderClass( const EncoderClass &c );
|
||||
EncoderClass& operator=( const EncoderClass &c );
|
||||
|
||||
}; //EncoderClass
|
||||
|
||||
#endif //__ENCODERCLASS_H__
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* InterruptServiceRoutines.h
|
||||
*
|
||||
* Created: 8/4/2014 4:55:26 PM
|
||||
* Author: corwin
|
||||
*/
|
||||
|
||||
|
||||
#ifndef INTERRUPTSERVICEROUTINES_H_
|
||||
#define INTERRUPTSERVICEROUTINES_H_
|
||||
|
||||
extern SoftLCD LCD;
|
||||
extern StepperClass Stepper;
|
||||
extern int i;
|
||||
extern int TimeCount;
|
||||
|
||||
ISR(TIMER2_OVF_vect){
|
||||
static int CountDelay = 0;
|
||||
CountDelay++;
|
||||
if(CountDelay >= 61){
|
||||
TimeCount++;
|
||||
CountDelay = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ISR(TIMER1_COMPA_vect){
|
||||
Stepper.OneStep();
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
////////Pin change interrupt 2 is for pins pcint 23 to 16
|
||||
////////
|
||||
//Pin change interrupt 18 is on pin PORTD2
|
||||
//ISR(){
|
||||
|
||||
//}
|
||||
|
||||
//Pin change interrupt 19 is on pin PORTD3
|
||||
//ISR(){
|
||||
|
||||
//}
|
||||
|
||||
|
||||
|
||||
#endif /* INTERRUPTSERVICEROUTINES_H_ */
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* MegaUART.cpp
|
||||
*
|
||||
* Created: 7/31/2014 12:00:58 PM
|
||||
* Author: corwin
|
||||
*/
|
||||
|
||||
|
||||
#include "MegaUART.h"
|
||||
|
||||
// default constructor
|
||||
MegaUART::MegaUART()
|
||||
{
|
||||
} //MegaUART
|
||||
|
||||
// default destructor
|
||||
MegaUART::~MegaUART()
|
||||
{
|
||||
} //~MegaUART
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* MegaUART.h
|
||||
*
|
||||
* Created: 7/31/2014 12:00:58 PM
|
||||
* Author: corwin
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __MEGAUART_H__
|
||||
#define __MEGAUART_H__
|
||||
|
||||
|
||||
class MegaUART
|
||||
{
|
||||
//variables
|
||||
public:
|
||||
protected:
|
||||
private:
|
||||
|
||||
//functions
|
||||
public:
|
||||
MegaUART();
|
||||
~MegaUART();
|
||||
protected:
|
||||
private:
|
||||
MegaUART( const MegaUART &c );
|
||||
MegaUART& operator=( const MegaUART &c );
|
||||
|
||||
}; //MegaUART
|
||||
|
||||
#endif //__MEGAUART_H__
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* PumpClass.cpp
|
||||
*
|
||||
* Created: 8/6/2014 9:16:05 AM
|
||||
* Author: corwin
|
||||
*/
|
||||
|
||||
|
||||
#include "PumpClass.h"
|
||||
|
||||
// default constructor
|
||||
PumpClass::PumpClass()
|
||||
{
|
||||
} //PumpClass
|
||||
|
||||
// default destructor
|
||||
PumpClass::~PumpClass()
|
||||
{
|
||||
} //~PumpClass
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* PumpClass.h
|
||||
*
|
||||
* Created: 8/6/2014 9:16:05 AM
|
||||
* Author: corwin
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __PUMPCLASS_H__
|
||||
#define __PUMPCLASS_H__
|
||||
|
||||
|
||||
class PumpClass
|
||||
{
|
||||
//variables
|
||||
public:
|
||||
protected:
|
||||
private:
|
||||
|
||||
//functions
|
||||
public:
|
||||
PumpClass();
|
||||
~PumpClass();
|
||||
protected:
|
||||
private:
|
||||
PumpClass( const PumpClass &c );
|
||||
PumpClass& operator=( const PumpClass &c );
|
||||
|
||||
}; //PumpClass
|
||||
|
||||
#endif //__PUMPCLASS_H__
|
||||
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* SoftLCD.cpp
|
||||
*
|
||||
* Created: 7/31/2014 11:20:02 AM
|
||||
* Author: corwin
|
||||
*/
|
||||
|
||||
|
||||
#include "SoftLCD.h"
|
||||
|
||||
// default constructor
|
||||
SoftLCD::SoftLCD(volatile uint8_t *txport, volatile uint8_t *txddr, int txpin, volatile uint8_t *pwrport, volatile uint8_t *pwrddr, int pwrpin)
|
||||
{
|
||||
//Set up public variables
|
||||
//strncpy(TopLine, "Test", 16);
|
||||
snprintf(TopLine, 16, " ");
|
||||
snprintf(BottomLine, 16, " ");
|
||||
|
||||
strcpy(TopLinePrev, TopLine);
|
||||
strcpy(BottomLinePrev, BottomLine);
|
||||
|
||||
//Set up private variables
|
||||
serPort = txport;
|
||||
serDDR = txddr;
|
||||
serPin = txpin;
|
||||
|
||||
pwrPort = pwrport;
|
||||
pwrDDR = pwrddr;
|
||||
pwrPin = pwrpin;
|
||||
|
||||
//Set up tx pin for transmission
|
||||
*serDDR |= (1 << serPin);
|
||||
*serPort |= (1 << serPin);
|
||||
|
||||
//Set up power control pin for output
|
||||
*pwrDDR |= (1 << pwrPin);
|
||||
setLCDOn(true); //On by default
|
||||
putChar(124);
|
||||
putChar(157);
|
||||
|
||||
setRefreshRate(5); //Keep at 10fps or lower to keep screen looking nice. 5 fps seems like a good middle ground
|
||||
|
||||
|
||||
} //SoftLCD
|
||||
|
||||
// default destructor
|
||||
SoftLCD::~SoftLCD()
|
||||
{
|
||||
} //~SoftLCD
|
||||
|
||||
void SoftLCD::putChar(char c) {
|
||||
//TCCR1B &= ~((1 << CS10) | (1 << CS11) | (1 << CS12));
|
||||
//Start bit
|
||||
*serPort &= ~(1 << serPin); //Write a zero for the start bit
|
||||
_delay_us(MICROSECONDS_PER_BIT); //Wait one bit period
|
||||
|
||||
//Begin data bits
|
||||
for (uint8_t bit_mask = 0x01; bit_mask ; bit_mask <<= 1) { //Move through each bit in the char starting with the least significant bit
|
||||
if (c & bit_mask) { //If that position contains a 1
|
||||
*serPort |= (1 << serPin); //Write a 1 to the tx pin
|
||||
}else { //Otherwise...
|
||||
*serPort &= ~(1 << serPin); //Write a 0 to the tx pin
|
||||
}
|
||||
_delay_us(MICROSECONDS_PER_BIT); //Delay for the correct period of time for one bit
|
||||
}
|
||||
|
||||
//Stop bit(s)
|
||||
*serPort |= (1<<serPin); //Write a one for the stop bit
|
||||
_delay_us(MICROSECONDS_PER_BIT * STOP_BITS); //Wait the period of time required for the number of stop bits desired
|
||||
//TCCR1B |= ((1 << CS10) | (1 << CS11));
|
||||
}
|
||||
|
||||
|
||||
void SoftLCD::setLCDOn(bool on)
|
||||
{
|
||||
if(on == true){
|
||||
*pwrPort |= (1 << pwrPin);
|
||||
}else if(on == false){
|
||||
*pwrPort &= ~(1 << pwrPin);
|
||||
}
|
||||
}
|
||||
|
||||
void SoftLCD::setRefreshRate(int rate)
|
||||
{/*
|
||||
TCCR0A = 0;
|
||||
TCCR0B = ((1 << CS10) | (1 << CS12));
|
||||
TCNT0 = 0;
|
||||
TIMSK0 = (1 << TOIE0);
|
||||
*/
|
||||
}
|
||||
|
||||
void SoftLCD::show()
|
||||
{
|
||||
if(strcmp(TopLine, TopLinePrev) != 0){
|
||||
_moveToTop();
|
||||
_printLine((char *)" ");
|
||||
_moveToTop();
|
||||
_printLine(TopLine);
|
||||
strcpy(TopLinePrev, TopLine);
|
||||
}
|
||||
|
||||
if(strcmp(BottomLine, BottomLinePrev) != 0){
|
||||
_moveToBottom();
|
||||
_printLine((char *)" ");
|
||||
_moveToBottom();
|
||||
_printLine(BottomLine);
|
||||
strcpy(BottomLinePrev, BottomLine);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SoftLCD::_moveToTop()
|
||||
{
|
||||
putChar(254); //Puts lcd into command mode
|
||||
putChar(128); //Moves to first character on top
|
||||
}
|
||||
|
||||
void SoftLCD::_moveToBottom()
|
||||
{
|
||||
putChar(254); //Puts lcd into command mode
|
||||
putChar(192); //Moves to first character on bottom
|
||||
}
|
||||
|
||||
void SoftLCD::_printLine(char *text)
|
||||
{
|
||||
for(int i = 0 ; ((i < 16) && (text[i] != '\0')) ; i++){
|
||||
putChar(text[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void SoftLCD::setTopText(char *top)
|
||||
{
|
||||
snprintf(TopLine, 16, top);
|
||||
}
|
||||
|
||||
void SoftLCD::setTopText(const char *top)
|
||||
{
|
||||
snprintf(TopLine, 16, top);
|
||||
}
|
||||
|
||||
void SoftLCD::setBottomText(char *bottom)
|
||||
{
|
||||
snprintf(BottomLine, 16, bottom);
|
||||
}
|
||||
|
||||
void SoftLCD::setBottomText(const char *bottom)
|
||||
{
|
||||
snprintf(BottomLine, 16, bottom);
|
||||
}
|
||||
|
||||
void SoftLCD::showNameScreen()
|
||||
{
|
||||
_delay_ms(2000); //Delay for LCD
|
||||
setTopText(" Dechorionator"); //Startup Text Top
|
||||
setBottomText(" Revision 2.0"); //Startup Text Bottom
|
||||
show();
|
||||
_delay_ms(2750); //Pause for effect
|
||||
}
|
||||
|
||||
void SoftLCD::disableSparkfunLogo()
|
||||
{
|
||||
putChar(124);
|
||||
putChar(9);
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* SoftLCD.h
|
||||
*
|
||||
* Created: 7/31/2014 11:20:02 AM
|
||||
* Author: corwin
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __SOFTLCD_H__
|
||||
#define __SOFTLCD_H__
|
||||
#define F_CPU 16000000UL
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <inttypes.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <util/delay.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "DefineMacrosAndPinDefs.h"
|
||||
|
||||
#define REFRESH_RATE_CONSTANT (16000000ul/1024)
|
||||
|
||||
#define BAUD 9600
|
||||
#define STOP_BITS 1
|
||||
|
||||
#define MICROSECONDS_OVERHEAD_ADJUST 0
|
||||
#define MICROSECONDS_PER_BIT ((1000000ul / BAUD) - MICROSECONDS_OVERHEAD_ADJUST)
|
||||
|
||||
class SoftLCD
|
||||
{
|
||||
//variables
|
||||
public:
|
||||
protected:
|
||||
private:
|
||||
FILE static usartout;
|
||||
|
||||
volatile uint8_t *serPort;
|
||||
volatile uint8_t *serDDR;
|
||||
int serPin;
|
||||
|
||||
volatile uint8_t *pwrPort;
|
||||
volatile uint8_t *pwrDDR;
|
||||
int pwrPin;
|
||||
|
||||
char TopLine[17];
|
||||
char BottomLine[17];
|
||||
|
||||
char TopLinePrev[17];
|
||||
char BottomLinePrev[17];
|
||||
//functions
|
||||
public:
|
||||
SoftLCD(volatile uint8_t *txport, volatile uint8_t *txddr, int txpin, volatile uint8_t *pwrport, volatile uint8_t *pwrddr, int pwrpin);
|
||||
|
||||
void disableSparkfunLogo();
|
||||
void showNameScreen();
|
||||
|
||||
void putChar(char c);
|
||||
void setLCDOn(bool on);
|
||||
void setRefreshRate(int rate);
|
||||
void show();
|
||||
|
||||
void setTopText(char *top);
|
||||
void setBottomText(char *bottom);
|
||||
void setTopText(const char *top);
|
||||
void setBottomText(const char *bottom);
|
||||
|
||||
~SoftLCD();
|
||||
protected:
|
||||
private:
|
||||
SoftLCD(const SoftLCD & c);
|
||||
SoftLCD& operator=( const SoftLCD &c );
|
||||
void _printLine(char *text);
|
||||
void _moveToTop();
|
||||
void _moveToBottom();
|
||||
|
||||
}; //SoftLCD
|
||||
|
||||
#endif //__SOFTLCD_H__
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* StepperClass.cpp
|
||||
*
|
||||
* Created: 8/1/2014 5:13:57 PM
|
||||
* Author: corwin
|
||||
*/
|
||||
|
||||
|
||||
#include "StepperClass.h"
|
||||
|
||||
// default constructor
|
||||
StepperClass::StepperClass(volatile uint8_t *enport, volatile uint8_t *enddr, int enpin,
|
||||
volatile uint8_t *dirport, volatile uint8_t *dirddr, int dirpin,
|
||||
volatile uint8_t *stepport, volatile uint8_t *stepddr, int steppin,
|
||||
volatile uint8_t *faultport, volatile uint8_t *faultddr, int faultpin,
|
||||
volatile uint8_t *m0port, volatile uint8_t *m0ddr, int m0pin,
|
||||
volatile uint8_t *m1port, volatile uint8_t *m1ddr, int m1pin,
|
||||
volatile uint8_t *m2port, volatile uint8_t *m2ddr, int m2pin
|
||||
)
|
||||
{
|
||||
enPort = enport;
|
||||
enDDR = enddr;
|
||||
enPin = enpin;
|
||||
_setupPinAsOutput(enDDR, enPin);
|
||||
_disableStepper();
|
||||
|
||||
dirPort = dirport;
|
||||
dirDDR = dirddr;
|
||||
dirPin = dirpin;
|
||||
_setupPinAsOutput(enDDR, enPin);
|
||||
_setPinLow(dirPort, dirPin);
|
||||
|
||||
stepPort = stepport;
|
||||
stepDDR = stepddr;
|
||||
stepPin = steppin;
|
||||
_setupPinAsOutput(enDDR, enPin);
|
||||
_setPinLow(stepPort, stepPin);
|
||||
|
||||
faultPort = faultport;
|
||||
faultDDR = faultddr;
|
||||
faultPin = faultpin;
|
||||
_setupPinAsInput(faultPort, faultDDR, faultPin, false);
|
||||
|
||||
m0Port = m0port;
|
||||
m0DDR = m0ddr;
|
||||
m0Pin = m0pin;
|
||||
_setupPinAsOutput(enDDR, enPin);
|
||||
_setPinHigh(m0Port, m0Pin);
|
||||
|
||||
m1Port = m1port;
|
||||
m1DDR = m1ddr;
|
||||
m1Pin = m1pin;
|
||||
_setupPinAsOutput(enDDR, enPin);
|
||||
_setPinLow(m1Port, m1Pin);
|
||||
|
||||
m2Port = m2port;
|
||||
m2DDR = m2ddr;
|
||||
m2Pin = m2pin;
|
||||
_setupPinAsOutput(enDDR, enPin);
|
||||
_setPinLow(m2Port, m2Pin);
|
||||
|
||||
|
||||
TCCR1A = 0; //Set output compare mode for channel A and B to normal operation and waveform generation to normal
|
||||
TCCR1B = ((1 << WGM12) | (1 << CS10) | (1 << CS11)); //Set clk prescalar for timer to clk/1024 and enable clear on timer compare match
|
||||
TCNT1 = 0; //Zero the count register
|
||||
TIMSK1 = (1 << OCIE1A); //Set interrupt flag to trigger on counter 1 overflow
|
||||
OCR1A = 2000; //Set the count value based on what's needed to update at a specific number of fps
|
||||
|
||||
} //StepperClass
|
||||
|
||||
// default destructor
|
||||
StepperClass::~StepperClass()
|
||||
{
|
||||
} //~StepperClass
|
||||
|
||||
void StepperClass::_setupPinAsOutput(volatile uint8_t *ddr, int pin)
|
||||
{
|
||||
*ddr |= (1 << pin);
|
||||
}
|
||||
|
||||
void StepperClass::_setupPinAsInput(volatile uint8_t *port, volatile uint8_t *ddr, int pin, bool enablePullup = false)
|
||||
{
|
||||
*ddr &= ~(1 << pin);
|
||||
if(enablePullup){
|
||||
*port |= (1 << pin);
|
||||
}
|
||||
}
|
||||
|
||||
void StepperClass::_enableStepper()
|
||||
{
|
||||
*enPort &= ~(1 << enPin);
|
||||
}
|
||||
|
||||
void StepperClass::_disableStepper()
|
||||
{
|
||||
*enPort |= (1 << enPin);
|
||||
}
|
||||
|
||||
void StepperClass::_setPinLow(volatile uint8_t *port, int pin)
|
||||
{
|
||||
*port &= ~(1 << pin);
|
||||
}
|
||||
|
||||
void StepperClass::_setPinHigh(volatile uint8_t *port, int pin)
|
||||
{
|
||||
*port |= (1 << pin);
|
||||
}
|
||||
|
||||
void StepperClass::OneStep()
|
||||
{
|
||||
_setPinHigh(stepPort, stepPin);
|
||||
_delay_us(2);
|
||||
_setPinLow(stepPort, stepPin);
|
||||
}
|
||||
|
||||
void StepperClass::SetRPM(int rpm)
|
||||
{
|
||||
OCR1B = 35000;//(long(STEPPER_RPM_CONSTANT)/rpm); //Set the count value based on what's needed to update at a specific number of fps
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* StepperClass.h
|
||||
*
|
||||
* Created: 8/1/2014 5:13:57 PM
|
||||
* Author: corwin
|
||||
*
|
||||
* MSTEP M2 M1 M0 DEC
|
||||
* 1 0 0 0 0
|
||||
* 2 0 0 1 1
|
||||
* 4 0 1 0 2
|
||||
* 8 0 1 1 3
|
||||
* 16 1 0 0 4
|
||||
* 32 1 0 1 5
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __STEPPERCLASS_H__
|
||||
#define __STEPPERCLASS_H__
|
||||
#define F_CPU 16000000UL
|
||||
|
||||
#include <util/delay.h>
|
||||
#include <avr/io.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#define STEPPER_RPM_CONSTANT (16000000ul/1024)*60)
|
||||
|
||||
class StepperClass
|
||||
{
|
||||
//variables
|
||||
public:
|
||||
protected:
|
||||
private:
|
||||
volatile uint8_t *enPort;
|
||||
volatile uint8_t *enDDR;
|
||||
int enPin;
|
||||
|
||||
volatile uint8_t *dirPort;
|
||||
volatile uint8_t *dirDDR;
|
||||
int dirPin;
|
||||
|
||||
volatile uint8_t *stepPort;
|
||||
volatile uint8_t *stepDDR;
|
||||
int stepPin;
|
||||
|
||||
volatile uint8_t *faultPort;
|
||||
volatile uint8_t *faultDDR;
|
||||
int faultPin;
|
||||
|
||||
volatile uint8_t *m0Port;
|
||||
volatile uint8_t *m0DDR;
|
||||
int m0Pin;
|
||||
|
||||
volatile uint8_t *m1Port;
|
||||
volatile uint8_t *m1DDR;
|
||||
int m1Pin;
|
||||
|
||||
volatile uint8_t *m2Port;
|
||||
volatile uint8_t *m2DDR;
|
||||
int m2Pin;
|
||||
|
||||
//functions
|
||||
public:
|
||||
StepperClass(volatile uint8_t *enport, volatile uint8_t *enddr, int enpin,
|
||||
volatile uint8_t *dirport, volatile uint8_t *dirddr, int dirpin,
|
||||
volatile uint8_t *stepport, volatile uint8_t *stepddr, int steppin,
|
||||
volatile uint8_t *faultport, volatile uint8_t *faultddr, int faultpin,
|
||||
volatile uint8_t *m0port, volatile uint8_t *m0ddr, int m0pin,
|
||||
volatile uint8_t *m1port, volatile uint8_t *m1ddr, int m1pin,
|
||||
volatile uint8_t *m2port, volatile uint8_t *m2ddr, int m2pin
|
||||
);
|
||||
void SetRPM(int rpm);
|
||||
void OneStep();
|
||||
|
||||
~StepperClass();
|
||||
protected:
|
||||
private:
|
||||
StepperClass( const StepperClass &c );
|
||||
StepperClass& operator=( const StepperClass &c );
|
||||
void _setupPinAsOutput(volatile uint8_t *ddr, int pin);
|
||||
void _setupPinAsInput(volatile uint8_t *port, volatile uint8_t *ddr, int pin, bool enablePullup);
|
||||
|
||||
void _enableStepper();
|
||||
void _disableStepper();
|
||||
|
||||
void _setPinLow(volatile uint8_t *port, int pin);
|
||||
void _setPinHigh(volatile uint8_t *port, int pin);
|
||||
|
||||
}; //StepperClass
|
||||
|
||||
#endif //__STEPPERCLASS_H__
|
||||
Reference in New Issue
Block a user