Additions from 28/01/2022: Removed volatile variables, calculating average adc, fixed an issue with sent direction.
This commit is contained in:
parent
dff2d872cd
commit
25684335f1
5 changed files with 113 additions and 101 deletions
|
@ -9,57 +9,57 @@
|
||||||
<CSub></CSub>
|
<CSub></CSub>
|
||||||
<CVariant></CVariant>
|
<CVariant></CVariant>
|
||||||
<CVendor>Atmel</CVendor>
|
<CVendor>Atmel</CVendor>
|
||||||
<CVersion>1.2.0</CVersion>
|
<CVersion>1.8.0</CVersion>
|
||||||
<DefaultRepoPath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs</DefaultRepoPath>
|
<DefaultRepoPath>D:/Programs\Atmelstudio\7.0\Packs</DefaultRepoPath>
|
||||||
<DependentComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
|
<DependentComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
|
||||||
<Description></Description>
|
<Description></Description>
|
||||||
<Files xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
|
<Files xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
|
||||||
<d4p1:anyType i:type="FileInfo">
|
<d4p1:anyType i:type="FileInfo">
|
||||||
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.2.118\include</AbsolutePath>
|
<AbsolutePath>D:/Programs\Atmelstudio\7.0\Packs\atmel\ATtiny_DFP\1.8.332\include\</AbsolutePath>
|
||||||
<Attribute></Attribute>
|
<Attribute></Attribute>
|
||||||
<Category>include</Category>
|
<Category>include</Category>
|
||||||
<Condition>C</Condition>
|
<Condition>C</Condition>
|
||||||
<FileContentHash i:nil="true" />
|
<FileContentHash i:nil="true" />
|
||||||
<FileVersion></FileVersion>
|
<FileVersion></FileVersion>
|
||||||
<Name>include</Name>
|
<Name>include/</Name>
|
||||||
<SelectString></SelectString>
|
<SelectString></SelectString>
|
||||||
<SourcePath></SourcePath>
|
<SourcePath></SourcePath>
|
||||||
</d4p1:anyType>
|
</d4p1:anyType>
|
||||||
<d4p1:anyType i:type="FileInfo">
|
<d4p1:anyType i:type="FileInfo">
|
||||||
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.2.118\include\avr\iotn85.h</AbsolutePath>
|
<AbsolutePath>D:/Programs\Atmelstudio\7.0\Packs\atmel\ATtiny_DFP\1.8.332\include\avr\iotn85.h</AbsolutePath>
|
||||||
<Attribute></Attribute>
|
<Attribute></Attribute>
|
||||||
<Category>header</Category>
|
<Category>header</Category>
|
||||||
<Condition>C</Condition>
|
<Condition>C</Condition>
|
||||||
<FileContentHash>RcYmivGpgsCGGCzeWAIjcA==</FileContentHash>
|
<FileContentHash>T0lnJZ6iliUJCzU7ZHCMPQ==</FileContentHash>
|
||||||
<FileVersion></FileVersion>
|
<FileVersion></FileVersion>
|
||||||
<Name>include/avr/iotn85.h</Name>
|
<Name>include/avr/iotn85.h</Name>
|
||||||
<SelectString></SelectString>
|
<SelectString></SelectString>
|
||||||
<SourcePath></SourcePath>
|
<SourcePath></SourcePath>
|
||||||
</d4p1:anyType>
|
</d4p1:anyType>
|
||||||
<d4p1:anyType i:type="FileInfo">
|
<d4p1:anyType i:type="FileInfo">
|
||||||
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.2.118\templates\main.c</AbsolutePath>
|
<AbsolutePath>D:/Programs\Atmelstudio\7.0\Packs\atmel\ATtiny_DFP\1.8.332\templates\main.c</AbsolutePath>
|
||||||
<Attribute>template</Attribute>
|
<Attribute>template</Attribute>
|
||||||
<Category>source</Category>
|
<Category>source</Category>
|
||||||
<Condition>C Exe</Condition>
|
<Condition>C Exe</Condition>
|
||||||
<FileContentHash>GD1k8YYhulqRs6FD1B2Hog==</FileContentHash>
|
<FileContentHash>KjvOcFWd++tbnsEMfVPd/w==</FileContentHash>
|
||||||
<FileVersion></FileVersion>
|
<FileVersion></FileVersion>
|
||||||
<Name>templates/main.c</Name>
|
<Name>templates/main.c</Name>
|
||||||
<SelectString>Main file (.c)</SelectString>
|
<SelectString>Main file (.c)</SelectString>
|
||||||
<SourcePath></SourcePath>
|
<SourcePath></SourcePath>
|
||||||
</d4p1:anyType>
|
</d4p1:anyType>
|
||||||
<d4p1:anyType i:type="FileInfo">
|
<d4p1:anyType i:type="FileInfo">
|
||||||
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.2.118\templates\main.cpp</AbsolutePath>
|
<AbsolutePath>D:/Programs\Atmelstudio\7.0\Packs\atmel\ATtiny_DFP\1.8.332\templates\main.cpp</AbsolutePath>
|
||||||
<Attribute>template</Attribute>
|
<Attribute>template</Attribute>
|
||||||
<Category>source</Category>
|
<Category>source</Category>
|
||||||
<Condition>C Exe</Condition>
|
<Condition>C Exe</Condition>
|
||||||
<FileContentHash>YXFphlh0CtZJU+ebktABgQ==</FileContentHash>
|
<FileContentHash>mkKaE95TOoATsuBGv6jmxg==</FileContentHash>
|
||||||
<FileVersion></FileVersion>
|
<FileVersion></FileVersion>
|
||||||
<Name>templates/main.cpp</Name>
|
<Name>templates/main.cpp</Name>
|
||||||
<SelectString>Main file (.cpp)</SelectString>
|
<SelectString>Main file (.cpp)</SelectString>
|
||||||
<SourcePath></SourcePath>
|
<SourcePath></SourcePath>
|
||||||
</d4p1:anyType>
|
</d4p1:anyType>
|
||||||
<d4p1:anyType i:type="FileInfo">
|
<d4p1:anyType i:type="FileInfo">
|
||||||
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.2.118\gcc\dev\attiny85</AbsolutePath>
|
<AbsolutePath>D:/Programs\Atmelstudio\7.0\Packs\atmel\ATtiny_DFP\1.8.332\gcc\dev\attiny85</AbsolutePath>
|
||||||
<Attribute></Attribute>
|
<Attribute></Attribute>
|
||||||
<Category>libraryPrefix</Category>
|
<Category>libraryPrefix</Category>
|
||||||
<Condition>GCC</Condition>
|
<Condition>GCC</Condition>
|
||||||
|
@ -71,8 +71,8 @@
|
||||||
</d4p1:anyType>
|
</d4p1:anyType>
|
||||||
</Files>
|
</Files>
|
||||||
<PackName>ATtiny_DFP</PackName>
|
<PackName>ATtiny_DFP</PackName>
|
||||||
<PackPath>C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATtiny_DFP/1.2.118/Atmel.ATtiny_DFP.pdsc</PackPath>
|
<PackPath>D:/Programs/Atmelstudio/7.0/Packs/atmel/ATtiny_DFP/1.8.332/Atmel.ATtiny_DFP.pdsc</PackPath>
|
||||||
<PackVersion>1.2.118</PackVersion>
|
<PackVersion>1.8.332</PackVersion>
|
||||||
<PresentInProject>true</PresentInProject>
|
<PresentInProject>true</PresentInProject>
|
||||||
<ReferenceConditionId>ATtiny85</ReferenceConditionId>
|
<ReferenceConditionId>ATtiny85</ReferenceConditionId>
|
||||||
<RteComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
|
<RteComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
|
||||||
|
|
|
@ -34,9 +34,9 @@
|
||||||
<documentation help="" />
|
<documentation help="" />
|
||||||
<offline-documentation help="" />
|
<offline-documentation help="" />
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.25.0" />
|
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.42.0" />
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</framework-data>
|
</framework-data>
|
||||||
</AsfFrameworkConfig>
|
</AsfFrameworkConfig>
|
||||||
<avrtool>com.atmel.avrdbg.tool.stk500</avrtool>
|
<avrtool>com.atmel.avrdbg.tool.stk500</avrtool>
|
||||||
<avrtoolserialnumber />
|
<avrtoolserialnumber />
|
||||||
|
@ -72,7 +72,7 @@
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||||
<ToolchainSettings>
|
<ToolchainSettings>
|
||||||
<AvrGcc>
|
<AvrGcc>
|
||||||
<avrgcc.common.Device>-mmcu=attiny85 -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\gcc\dev\attiny85"</avrgcc.common.Device>
|
<avrgcc.common.Device>-mmcu=attiny85 -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.8.332\gcc\dev\attiny85"</avrgcc.common.Device>
|
||||||
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
|
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
|
||||||
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
|
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
|
||||||
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
||||||
|
@ -87,7 +87,7 @@
|
||||||
</avrgcc.compiler.symbols.DefSymbols>
|
</avrgcc.compiler.symbols.DefSymbols>
|
||||||
<avrgcc.compiler.directories.IncludePaths>
|
<avrgcc.compiler.directories.IncludePaths>
|
||||||
<ListValues>
|
<ListValues>
|
||||||
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\include</Value>
|
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.8.332\include\</Value>
|
||||||
</ListValues>
|
</ListValues>
|
||||||
</avrgcc.compiler.directories.IncludePaths>
|
</avrgcc.compiler.directories.IncludePaths>
|
||||||
<avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
|
<avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
|
||||||
|
@ -101,16 +101,16 @@
|
||||||
</avrgcc.linker.libraries.Libraries>
|
</avrgcc.linker.libraries.Libraries>
|
||||||
<avrgcc.assembler.general.IncludePaths>
|
<avrgcc.assembler.general.IncludePaths>
|
||||||
<ListValues>
|
<ListValues>
|
||||||
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\include</Value>
|
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.8.332\include\</Value>
|
||||||
</ListValues>
|
</ListValues>
|
||||||
</avrgcc.assembler.general.IncludePaths>
|
</avrgcc.assembler.general.IncludePaths>
|
||||||
</AvrGcc>
|
</AvrGcc>
|
||||||
</ToolchainSettings>
|
</ToolchainSettings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||||
<ToolchainSettings>
|
<ToolchainSettings>
|
||||||
<AvrGcc>
|
<AvrGcc>
|
||||||
<avrgcc.common.Device>-mmcu=attiny85 -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\gcc\dev\attiny85"</avrgcc.common.Device>
|
<avrgcc.common.Device>-mmcu=attiny85 -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.8.332\gcc\dev\attiny85"</avrgcc.common.Device>
|
||||||
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
|
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
|
||||||
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
|
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
|
||||||
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
||||||
|
@ -125,7 +125,7 @@
|
||||||
</avrgcc.compiler.symbols.DefSymbols>
|
</avrgcc.compiler.symbols.DefSymbols>
|
||||||
<avrgcc.compiler.directories.IncludePaths>
|
<avrgcc.compiler.directories.IncludePaths>
|
||||||
<ListValues>
|
<ListValues>
|
||||||
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\include</Value>
|
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.8.332\include\</Value>
|
||||||
</ListValues>
|
</ListValues>
|
||||||
</avrgcc.compiler.directories.IncludePaths>
|
</avrgcc.compiler.directories.IncludePaths>
|
||||||
<avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
|
<avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
|
||||||
|
@ -140,11 +140,11 @@
|
||||||
</avrgcc.linker.libraries.Libraries>
|
</avrgcc.linker.libraries.Libraries>
|
||||||
<avrgcc.assembler.general.IncludePaths>
|
<avrgcc.assembler.general.IncludePaths>
|
||||||
<ListValues>
|
<ListValues>
|
||||||
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\include</Value>
|
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.8.332\include\</Value>
|
||||||
</ListValues>
|
</ListValues>
|
||||||
</avrgcc.assembler.general.IncludePaths>
|
</avrgcc.assembler.general.IncludePaths>
|
||||||
<avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
|
<avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
|
||||||
</AvrGcc>
|
</AvrGcc>
|
||||||
</ToolchainSettings>
|
</ToolchainSettings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -89,7 +89,7 @@ unsigned char compareLed(float led1,float led2)
|
||||||
float adcLed1 = led1;
|
float adcLed1 = led1;
|
||||||
float adcLed2 = led2;
|
float adcLed2 = led2;
|
||||||
float adcCompare = led1 - led2;
|
float adcCompare = led1 - led2;
|
||||||
if (adcCompare < -VOLTMIN) // adcLed2 > adcLed1
|
if (adcCompare < VOLTMIN) // adcLed2 > adcLed1
|
||||||
{
|
{
|
||||||
return LEFT;
|
return LEFT;
|
||||||
}
|
}
|
||||||
|
@ -101,11 +101,11 @@ unsigned char compareLed(float led1,float led2)
|
||||||
{
|
{
|
||||||
if((adcLed1 > VOLTMIN) && (adcLed2 > VOLTMIN))
|
if((adcLed1 > VOLTMIN) && (adcLed2 > VOLTMIN))
|
||||||
{
|
{
|
||||||
return FRONT;
|
return NOTHING;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return NOTHING;
|
return FRONT;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#define LEFT 0x53
|
#define LEFT 0x53
|
||||||
#define NOTHING 0x54
|
#define NOTHING 0x54
|
||||||
#define ERROR 0xF0
|
#define ERROR 0xF0
|
||||||
#define VOLTMIN 1
|
#define VOLTMIN 4
|
||||||
#define TIMING 10
|
#define TIMING 10
|
||||||
|
|
||||||
void ADC_init(void);
|
void ADC_init(void);
|
||||||
|
|
|
@ -22,15 +22,27 @@
|
||||||
#define VALEUR_DEMAN 0x49
|
#define VALEUR_DEMAN 0x49
|
||||||
#define BASIC_MODE 0x42
|
#define BASIC_MODE 0x42
|
||||||
|
|
||||||
volatile unsigned char rawVal;
|
unsigned char adcled1;
|
||||||
volatile unsigned char adcled1;
|
unsigned char adcled2;
|
||||||
volatile unsigned char adcled2;
|
double moyLed1;
|
||||||
volatile unsigned char recVal;
|
double moyLed2;
|
||||||
|
int iMoy=0;
|
||||||
|
volatile unsigned char recVal=0;
|
||||||
|
|
||||||
ISR (ADC_vect){
|
ISR (ADC_vect){
|
||||||
adcled1=measureLed1();
|
adcled1=measureLed1();
|
||||||
adcled2=measureLed2();
|
adcled2=measureLed2();
|
||||||
//recVal=compareLed(adcled1,adcled2);
|
moyLed1+=(double)adcled1;
|
||||||
|
moyLed2+=(double)adcled2;
|
||||||
|
iMoy++;
|
||||||
|
if(iMoy >= 100)
|
||||||
|
{
|
||||||
|
moyLed1=moyLed1/iMoy;
|
||||||
|
moyLed2=moyLed2/iMoy;
|
||||||
|
recVal=(unsigned char)moyLed1;
|
||||||
|
//recVal=compareLed(moyLed1,moyLed2);
|
||||||
|
iMoy=0;
|
||||||
|
}
|
||||||
ADCSRA |= (1<<ADSC);
|
ADCSRA |= (1<<ADSC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,11 +94,11 @@ int main( void )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VALEUR_DEMAN :
|
case VALEUR_DEMAN :
|
||||||
usiTwiTransmitByte(adcled1/*recVal*/);
|
usiTwiTransmitByte(moyLed1/*recVal*/);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BASIC_MODE :
|
case BASIC_MODE :
|
||||||
usiTwiTransmitByte(adcled1);
|
usiTwiTransmitByte(moyLed1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue