Skip to content

Commit 6714b1c

Browse files
author
Mohamed Hassanin
committed
make the code more modular
1 parent ea835ef commit 6714b1c

File tree

9 files changed

+365
-343
lines changed

9 files changed

+365
-343
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# ATmega328p
2+
3+
/ATmega328p/Debug
4+
/ATmega328p/.vs
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Atmel Studio Solution File, Format Version 11.00
44
VisualStudioVersion = 14.0.23107.0
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "OpenLoopOn_m328P", "OpenLoopOn_m328P\OpenLoopOn_m328P.cproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}"
6+
Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "ATmega328p", "ATmega328p.cproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution

OpenLoopOn_m328P/OpenLoopOn_m328P/OpenLoopOn_m328P.componentinfo.xml renamed to ATmega328p/ATmega328p.componentinfo.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
<CVariant></CVariant>
1111
<CVendor>Atmel</CVendor>
1212
<CVersion>1.2.0</CVersion>
13-
<DefaultRepoPath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs</DefaultRepoPath>
13+
<DefaultRepoPath>Z:/programs_installed\Atmel\Studio\7.0\Packs</DefaultRepoPath>
1414
<DependentComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
1515
<Description></Description>
1616
<Files xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
1717
<d4p1:anyType i:type="FileInfo">
18-
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include</AbsolutePath>
18+
<AbsolutePath>Z:/programs_installed\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include</AbsolutePath>
1919
<Attribute></Attribute>
2020
<Category>include</Category>
2121
<Condition>C</Condition>
@@ -26,7 +26,7 @@
2626
<SourcePath></SourcePath>
2727
</d4p1:anyType>
2828
<d4p1:anyType i:type="FileInfo">
29-
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include\avr\iom328p.h</AbsolutePath>
29+
<AbsolutePath>Z:/programs_installed\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include\avr\iom328p.h</AbsolutePath>
3030
<Attribute></Attribute>
3131
<Category>header</Category>
3232
<Condition>C</Condition>
@@ -37,18 +37,18 @@
3737
<SourcePath></SourcePath>
3838
</d4p1:anyType>
3939
<d4p1:anyType i:type="FileInfo">
40-
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\templates\main.c</AbsolutePath>
40+
<AbsolutePath>Z:/programs_installed\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\templates\main.c</AbsolutePath>
4141
<Attribute>template</Attribute>
4242
<Category>source</Category>
4343
<Condition>C Exe</Condition>
44-
<FileContentHash>4+DNT5g+dIl7s8YFfUQOFw==</FileContentHash>
44+
<FileContentHash>AXygS/Ab8g8iQ/WECuN7vw==</FileContentHash>
4545
<FileVersion></FileVersion>
4646
<Name>templates/main.c</Name>
4747
<SelectString>Main file (.c)</SelectString>
4848
<SourcePath></SourcePath>
4949
</d4p1:anyType>
5050
<d4p1:anyType i:type="FileInfo">
51-
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\templates\main.cpp</AbsolutePath>
51+
<AbsolutePath>Z:/programs_installed\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\templates\main.cpp</AbsolutePath>
5252
<Attribute>template</Attribute>
5353
<Category>source</Category>
5454
<Condition>C Exe</Condition>
@@ -59,7 +59,7 @@
5959
<SourcePath></SourcePath>
6060
</d4p1:anyType>
6161
<d4p1:anyType i:type="FileInfo">
62-
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega328p</AbsolutePath>
62+
<AbsolutePath>Z:/programs_installed\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega328p</AbsolutePath>
6363
<Attribute></Attribute>
6464
<Category>libraryPrefix</Category>
6565
<Condition>GCC</Condition>
@@ -71,7 +71,7 @@
7171
</d4p1:anyType>
7272
</Files>
7373
<PackName>ATmega_DFP</PackName>
74-
<PackPath>C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.209/Atmel.ATmega_DFP.pdsc</PackPath>
74+
<PackPath>Z:/programs_installed/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.209/Atmel.ATmega_DFP.pdsc</PackPath>
7575
<PackVersion>1.2.209</PackVersion>
7676
<PresentInProject>true</PresentInProject>
7777
<ReferenceConditionId>ATmega328P</ReferenceConditionId>

OpenLoopOn_m328P/OpenLoopOn_m328P/OpenLoopOn_m328P.cproj renamed to ATmega328p/ATmega328p.cproj

Lines changed: 51 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,22 @@
1212
<OutputFileName>$(MSBuildProjectName)</OutputFileName>
1313
<OutputFileExtension>.elf</OutputFileExtension>
1414
<OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
15-
<AssemblyName>OpenLoopOn_m328P</AssemblyName>
16-
<Name>OpenLoopOn_m328P</Name>
17-
<RootNamespace>OpenLoopOn_m328P</RootNamespace>
15+
<AssemblyName>ATmega328p</AssemblyName>
16+
<Name>ATmega328p</Name>
17+
<RootNamespace>ATmega328p</RootNamespace>
1818
<ToolchainFlavour>Native</ToolchainFlavour>
1919
<KeepTimersRunning>true</KeepTimersRunning>
2020
<OverrideVtor>false</OverrideVtor>
2121
<CacheFlash>true</CacheFlash>
2222
<ProgFlashFromRam>true</ProgFlashFromRam>
23-
<RamSnippetAddress>0x20000000</RamSnippetAddress>
23+
<RamSnippetAddress />
2424
<UncachedRange />
2525
<preserveEEPROM>true</preserveEEPROM>
26-
<OverrideVtorValue>exception_table</OverrideVtorValue>
26+
<OverrideVtorValue />
2727
<BootSegment>2</BootSegment>
2828
<ResetRule>0</ResetRule>
2929
<eraseonlaunchrule>0</eraseonlaunchrule>
3030
<EraseKey />
31-
<AsfFrameworkConfig>
32-
<framework-data xmlns="">
33-
<options />
34-
<configurations />
35-
<files />
36-
<documentation help="" />
37-
<offline-documentation help="" />
38-
<dependencies>
39-
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.40.0" />
40-
</dependencies>
41-
</framework-data>
42-
</AsfFrameworkConfig>
4331
</PropertyGroup>
4432
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
4533
<ToolchainSettings>
@@ -82,51 +70,59 @@
8270
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
8371
<ToolchainSettings>
8472
<AvrGcc>
85-
<avrgcc.common.Device>-mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega328p"</avrgcc.common.Device>
86-
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
87-
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
88-
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
89-
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
90-
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
91-
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
92-
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
93-
<avrgcc.compiler.symbols.DefSymbols>
94-
<ListValues>
95-
<Value>DEBUG</Value>
96-
</ListValues>
97-
</avrgcc.compiler.symbols.DefSymbols>
98-
<avrgcc.compiler.directories.IncludePaths>
99-
<ListValues>
100-
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value>
101-
</ListValues>
102-
</avrgcc.compiler.directories.IncludePaths>
103-
<avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
104-
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
105-
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
106-
<avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
107-
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
108-
<avrgcc.linker.libraries.Libraries>
109-
<ListValues>
110-
<Value>libm</Value>
111-
</ListValues>
112-
</avrgcc.linker.libraries.Libraries>
113-
<avrgcc.assembler.general.IncludePaths>
114-
<ListValues>
115-
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value>
116-
</ListValues>
117-
</avrgcc.assembler.general.IncludePaths>
118-
<avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
119-
</AvrGcc>
73+
<avrgcc.common.Device>-mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega328p"</avrgcc.common.Device>
74+
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
75+
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
76+
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
77+
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
78+
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
79+
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
80+
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
81+
<avrgcc.compiler.symbols.DefSymbols>
82+
<ListValues>
83+
<Value>DEBUG</Value>
84+
</ListValues>
85+
</avrgcc.compiler.symbols.DefSymbols>
86+
<avrgcc.compiler.directories.IncludePaths>
87+
<ListValues>
88+
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value>
89+
<Value>../inc</Value>
90+
</ListValues>
91+
</avrgcc.compiler.directories.IncludePaths>
92+
<avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
93+
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
94+
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
95+
<avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
96+
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
97+
<avrgcc.linker.libraries.Libraries>
98+
<ListValues>
99+
<Value>libm</Value>
100+
</ListValues>
101+
</avrgcc.linker.libraries.Libraries>
102+
<avrgcc.assembler.general.IncludePaths>
103+
<ListValues>
104+
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value>
105+
</ListValues>
106+
</avrgcc.assembler.general.IncludePaths>
107+
<avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
108+
</AvrGcc>
120109
</ToolchainSettings>
121110
</PropertyGroup>
122111
<ItemGroup>
123-
<Compile Include="hall_sensor.h">
112+
<Folder Include="inc" />
113+
<Folder Include="src" />
114+
</ItemGroup>
115+
<ItemGroup>
116+
<Compile Include="inc\hall_sensor.h">
117+
<SubType>compile</SubType>
118+
</Compile>
119+
<Compile Include="inc\main.h">
124120
<SubType>compile</SubType>
125121
</Compile>
126-
<Compile Include="main.c">
122+
<Compile Include="inc\main_open_loop.h">
127123
<SubType>compile</SubType>
128124
</Compile>
129-
<Compile Include="main_open_loop.h">
125+
<Compile Include="src\main.c">
130126
<SubType>compile</SubType>
131127
</Compile>
132128
</ItemGroup>
File renamed without changes.

ATmega328p/inc/main.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* main.h
3+
*
4+
* Created: 2/24/2020 10:59:33 PM
5+
* Author: Mohamed_Hassanin
6+
*/
7+
8+
9+
#ifndef MAIN_H_
10+
#define MAIN_H_
11+
12+
#ifdef DIRECTION_CCW
13+
// Direction = 0x01
14+
unsigned char Hall_DIR_sequence[] = { 0x00,
15+
HS_W|LS_V, // Hall position 001
16+
HS_V|LS_U, // Hall position 010
17+
HS_W|LS_U, // Hall position 011
18+
HS_U|LS_W, // Hall position 100
19+
HS_U|LS_V, // Hall position 101
20+
HS_V|LS_W, // Hall position 110
21+
0x00 };
22+
#endif
23+
24+
#ifdef DIRECTION_CW
25+
// Direction = 0x00
26+
unsigned char Hall_DIR_sequence[] = { 0x00,
27+
HS_V|LS_W, // Hall position 001
28+
HS_U|LS_V, // Hall position 010
29+
HS_U|LS_W, // Hall position 011
30+
HS_W|LS_U, // Hall position 100
31+
HS_V|LS_U, // Hall position 101
32+
HS_W|LS_V, // Hall position 110
33+
0x00 };
34+
#endif
35+
36+
// Motor and Commutation Variables
37+
unsigned int Desired_PWM_DutyCycle, Current_PWM_DutyCycle, PWM_BucketStep, PWM_Update_Counter,ADC_Sample_Counter , Temp_DutyCycle;
38+
unsigned char PreDriver_Sequence, Hall_IN, Motor_Status;
39+
unsigned char Motor_status;
40+
41+
// ADC Variables
42+
volatile int curADC, prevADC = 0;
43+
volatile unsigned char SampleADC = false;
44+
45+
// Function definition
46+
void PWM_update (unsigned char Next_Hall_Sequence);
47+
void Start_Motor(void);
48+
void Stop_Motor(void);
49+
void Start_ADC_Conversation(void);
50+
51+
//peripherals
52+
void PCINT0_init(void);
53+
void ADC_init(void);
54+
void Timer1_config(void);
55+
56+
#endif /* MAIN_H_ */
File renamed without changes.

0 commit comments

Comments
 (0)