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>
|
||||
<CVariant></CVariant>
|
||||
<CVendor>Atmel</CVendor>
|
||||
<CVersion>1.2.0</CVersion>
|
||||
<DefaultRepoPath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs</DefaultRepoPath>
|
||||
<CVersion>1.8.0</CVersion>
|
||||
<DefaultRepoPath>D:/Programs\Atmelstudio\7.0\Packs</DefaultRepoPath>
|
||||
<DependentComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
|
||||
<Description></Description>
|
||||
<Files xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
|
||||
<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>
|
||||
<Category>include</Category>
|
||||
<Condition>C</Condition>
|
||||
<FileContentHash i:nil="true" />
|
||||
<FileVersion></FileVersion>
|
||||
<Name>include</Name>
|
||||
<Name>include/</Name>
|
||||
<SelectString></SelectString>
|
||||
<SourcePath></SourcePath>
|
||||
</d4p1:anyType>
|
||||
<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>
|
||||
<Category>header</Category>
|
||||
<Condition>C</Condition>
|
||||
<FileContentHash>RcYmivGpgsCGGCzeWAIjcA==</FileContentHash>
|
||||
<FileContentHash>T0lnJZ6iliUJCzU7ZHCMPQ==</FileContentHash>
|
||||
<FileVersion></FileVersion>
|
||||
<Name>include/avr/iotn85.h</Name>
|
||||
<SelectString></SelectString>
|
||||
<SourcePath></SourcePath>
|
||||
</d4p1:anyType>
|
||||
<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>
|
||||
<Category>source</Category>
|
||||
<Condition>C Exe</Condition>
|
||||
<FileContentHash>GD1k8YYhulqRs6FD1B2Hog==</FileContentHash>
|
||||
<FileContentHash>KjvOcFWd++tbnsEMfVPd/w==</FileContentHash>
|
||||
<FileVersion></FileVersion>
|
||||
<Name>templates/main.c</Name>
|
||||
<SelectString>Main file (.c)</SelectString>
|
||||
<SourcePath></SourcePath>
|
||||
</d4p1:anyType>
|
||||
<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>
|
||||
<Category>source</Category>
|
||||
<Condition>C Exe</Condition>
|
||||
<FileContentHash>YXFphlh0CtZJU+ebktABgQ==</FileContentHash>
|
||||
<FileContentHash>mkKaE95TOoATsuBGv6jmxg==</FileContentHash>
|
||||
<FileVersion></FileVersion>
|
||||
<Name>templates/main.cpp</Name>
|
||||
<SelectString>Main file (.cpp)</SelectString>
|
||||
<SourcePath></SourcePath>
|
||||
</d4p1:anyType>
|
||||
<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>
|
||||
<Category>libraryPrefix</Category>
|
||||
<Condition>GCC</Condition>
|
||||
|
@ -71,8 +71,8 @@
|
|||
</d4p1:anyType>
|
||||
</Files>
|
||||
<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>
|
||||
<PackVersion>1.2.118</PackVersion>
|
||||
<PackPath>D:/Programs/Atmelstudio/7.0/Packs/atmel/ATtiny_DFP/1.8.332/Atmel.ATtiny_DFP.pdsc</PackPath>
|
||||
<PackVersion>1.8.332</PackVersion>
|
||||
<PresentInProject>true</PresentInProject>
|
||||
<ReferenceConditionId>ATtiny85</ReferenceConditionId>
|
||||
<RteComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
|
||||
|
|
|
@ -34,9 +34,9 @@
|
|||
<documentation help="" />
|
||||
<offline-documentation help="" />
|
||||
<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>
|
||||
</framework-data>
|
||||
</framework-data>
|
||||
</AsfFrameworkConfig>
|
||||
<avrtool>com.atmel.avrdbg.tool.stk500</avrtool>
|
||||
<avrtoolserialnumber />
|
||||
|
@ -72,7 +72,7 @@
|
|||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<ToolchainSettings>
|
||||
<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.lss>True</avrgcc.common.outputfiles.lss>
|
||||
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
||||
|
@ -87,7 +87,7 @@
|
|||
</avrgcc.compiler.symbols.DefSymbols>
|
||||
<avrgcc.compiler.directories.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\include</Value>
|
||||
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.8.332\include\</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.directories.IncludePaths>
|
||||
<avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
|
||||
|
@ -101,16 +101,16 @@
|
|||
</avrgcc.linker.libraries.Libraries>
|
||||
<avrgcc.assembler.general.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\include</Value>
|
||||
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.8.332\include\</Value>
|
||||
</ListValues>
|
||||
</avrgcc.assembler.general.IncludePaths>
|
||||
</AvrGcc>
|
||||
</AvrGcc>
|
||||
</ToolchainSettings>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<ToolchainSettings>
|
||||
<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.lss>True</avrgcc.common.outputfiles.lss>
|
||||
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
||||
|
@ -125,7 +125,7 @@
|
|||
</avrgcc.compiler.symbols.DefSymbols>
|
||||
<avrgcc.compiler.directories.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\include</Value>
|
||||
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.8.332\include\</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.directories.IncludePaths>
|
||||
<avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
|
||||
|
@ -140,11 +140,11 @@
|
|||
</avrgcc.linker.libraries.Libraries>
|
||||
<avrgcc.assembler.general.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\include</Value>
|
||||
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.8.332\include\</Value>
|
||||
</ListValues>
|
||||
</avrgcc.assembler.general.IncludePaths>
|
||||
<avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
|
||||
</AvrGcc>
|
||||
</AvrGcc>
|
||||
</ToolchainSettings>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -89,7 +89,7 @@ unsigned char compareLed(float led1,float led2)
|
|||
float adcLed1 = led1;
|
||||
float adcLed2 = led2;
|
||||
float adcCompare = led1 - led2;
|
||||
if (adcCompare < -VOLTMIN) // adcLed2 > adcLed1
|
||||
if (adcCompare < VOLTMIN) // adcLed2 > adcLed1
|
||||
{
|
||||
return LEFT;
|
||||
}
|
||||
|
@ -101,11 +101,11 @@ unsigned char compareLed(float led1,float led2)
|
|||
{
|
||||
if((adcLed1 > VOLTMIN) && (adcLed2 > VOLTMIN))
|
||||
{
|
||||
return FRONT;
|
||||
return NOTHING;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NOTHING;
|
||||
return FRONT;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#define LEFT 0x53
|
||||
#define NOTHING 0x54
|
||||
#define ERROR 0xF0
|
||||
#define VOLTMIN 1
|
||||
#define VOLTMIN 4
|
||||
#define TIMING 10
|
||||
|
||||
void ADC_init(void);
|
||||
|
|
|
@ -22,15 +22,27 @@
|
|||
#define VALEUR_DEMAN 0x49
|
||||
#define BASIC_MODE 0x42
|
||||
|
||||
volatile unsigned char rawVal;
|
||||
volatile unsigned char adcled1;
|
||||
volatile unsigned char adcled2;
|
||||
volatile unsigned char recVal;
|
||||
unsigned char adcled1;
|
||||
unsigned char adcled2;
|
||||
double moyLed1;
|
||||
double moyLed2;
|
||||
int iMoy=0;
|
||||
volatile unsigned char recVal=0;
|
||||
|
||||
ISR (ADC_vect){
|
||||
adcled1=measureLed1();
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -82,11 +94,11 @@ int main( void )
|
|||
break;
|
||||
|
||||
case VALEUR_DEMAN :
|
||||
usiTwiTransmitByte(adcled1/*recVal*/);
|
||||
usiTwiTransmitByte(moyLed1/*recVal*/);
|
||||
break;
|
||||
|
||||
case BASIC_MODE :
|
||||
usiTwiTransmitByte(adcled1);
|
||||
usiTwiTransmitByte(moyLed1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue