Additions from 25/03/2022: Sending back the comparison between led adc, fixing initialization of values, recasting to int
instead of uchar
.
This commit is contained in:
parent
25684335f1
commit
25068d6ae1
5 changed files with 60 additions and 55 deletions
|
@ -10,12 +10,12 @@
|
||||||
<CVariant></CVariant>
|
<CVariant></CVariant>
|
||||||
<CVendor>Atmel</CVendor>
|
<CVendor>Atmel</CVendor>
|
||||||
<CVersion>1.8.0</CVersion>
|
<CVersion>1.8.0</CVersion>
|
||||||
<DefaultRepoPath>D:/Programs\Atmelstudio\7.0\Packs</DefaultRepoPath>
|
<DefaultRepoPath>C:/Program Files (x86)\Atmel\Studio\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>D:/Programs\Atmelstudio\7.0\Packs\atmel\ATtiny_DFP\1.8.332\include\</AbsolutePath>
|
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\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>
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
<SourcePath></SourcePath>
|
<SourcePath></SourcePath>
|
||||||
</d4p1:anyType>
|
</d4p1:anyType>
|
||||||
<d4p1:anyType i:type="FileInfo">
|
<d4p1:anyType i:type="FileInfo">
|
||||||
<AbsolutePath>D:/Programs\Atmelstudio\7.0\Packs\atmel\ATtiny_DFP\1.8.332\include\avr\iotn85.h</AbsolutePath>
|
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\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>
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
<SourcePath></SourcePath>
|
<SourcePath></SourcePath>
|
||||||
</d4p1:anyType>
|
</d4p1:anyType>
|
||||||
<d4p1:anyType i:type="FileInfo">
|
<d4p1:anyType i:type="FileInfo">
|
||||||
<AbsolutePath>D:/Programs\Atmelstudio\7.0\Packs\atmel\ATtiny_DFP\1.8.332\templates\main.c</AbsolutePath>
|
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\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>
|
||||||
|
@ -48,7 +48,7 @@
|
||||||
<SourcePath></SourcePath>
|
<SourcePath></SourcePath>
|
||||||
</d4p1:anyType>
|
</d4p1:anyType>
|
||||||
<d4p1:anyType i:type="FileInfo">
|
<d4p1:anyType i:type="FileInfo">
|
||||||
<AbsolutePath>D:/Programs\Atmelstudio\7.0\Packs\atmel\ATtiny_DFP\1.8.332\templates\main.cpp</AbsolutePath>
|
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\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>
|
||||||
|
@ -59,7 +59,7 @@
|
||||||
<SourcePath></SourcePath>
|
<SourcePath></SourcePath>
|
||||||
</d4p1:anyType>
|
</d4p1:anyType>
|
||||||
<d4p1:anyType i:type="FileInfo">
|
<d4p1:anyType i:type="FileInfo">
|
||||||
<AbsolutePath>D:/Programs\Atmelstudio\7.0\Packs\atmel\ATtiny_DFP\1.8.332\gcc\dev\attiny85</AbsolutePath>
|
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\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,7 +71,7 @@
|
||||||
</d4p1:anyType>
|
</d4p1:anyType>
|
||||||
</Files>
|
</Files>
|
||||||
<PackName>ATtiny_DFP</PackName>
|
<PackName>ATtiny_DFP</PackName>
|
||||||
<PackPath>D:/Programs/Atmelstudio/7.0/Packs/atmel/ATtiny_DFP/1.8.332/Atmel.ATtiny_DFP.pdsc</PackPath>
|
<PackPath>C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATtiny_DFP/1.8.332/Atmel.ATtiny_DFP.pdsc</PackPath>
|
||||||
<PackVersion>1.8.332</PackVersion>
|
<PackVersion>1.8.332</PackVersion>
|
||||||
<PresentInProject>true</PresentInProject>
|
<PresentInProject>true</PresentInProject>
|
||||||
<ReferenceConditionId>ATtiny85</ReferenceConditionId>
|
<ReferenceConditionId>ATtiny85</ReferenceConditionId>
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
<documentation help="" />
|
<documentation help="" />
|
||||||
<offline-documentation help="" />
|
<offline-documentation help="" />
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.42.0" />
|
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.25.0" />
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</framework-data>
|
</framework-data>
|
||||||
</AsfFrameworkConfig>
|
</AsfFrameworkConfig>
|
||||||
|
@ -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.8.332\gcc\dev\attiny85"</avrgcc.common.Device>
|
<avrgcc.common.Device>-mmcu=attiny85 -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\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.8.332\include\</Value>
|
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\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,7 +101,7 @@
|
||||||
</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.8.332\include\</Value>
|
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\include</Value>
|
||||||
</ListValues>
|
</ListValues>
|
||||||
</avrgcc.assembler.general.IncludePaths>
|
</avrgcc.assembler.general.IncludePaths>
|
||||||
</AvrGcc>
|
</AvrGcc>
|
||||||
|
@ -110,7 +110,7 @@
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||||
<ToolchainSettings>
|
<ToolchainSettings>
|
||||||
<AvrGcc>
|
<AvrGcc>
|
||||||
<avrgcc.common.Device>-mmcu=attiny85 -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.8.332\gcc\dev\attiny85"</avrgcc.common.Device>
|
<avrgcc.common.Device>-mmcu=attiny85 -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\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.8.332\include\</Value>
|
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\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,7 +140,7 @@
|
||||||
</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.8.332\include\</Value>
|
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\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>
|
||||||
|
|
|
@ -11,6 +11,9 @@ volatile unsigned char intr_count;
|
||||||
volatile unsigned char timer_flag=0;
|
volatile unsigned char timer_flag=0;
|
||||||
volatile unsigned char seconde=0;
|
volatile unsigned char seconde=0;
|
||||||
|
|
||||||
|
volatile unsigned char ledresult1=0;
|
||||||
|
volatile unsigned char ledresult2=0;
|
||||||
|
|
||||||
void ADC_init(void)
|
void ADC_init(void)
|
||||||
{
|
{
|
||||||
DDRB &=~(1<<PB3); //Pin B3 en entree
|
DDRB &=~(1<<PB3); //Pin B3 en entree
|
||||||
|
@ -47,33 +50,29 @@ float ADC_averaging(unsigned char val_ana)
|
||||||
|
|
||||||
char measureLed1(void)
|
char measureLed1(void)
|
||||||
{
|
{
|
||||||
char adcLed=0;
|
|
||||||
|
|
||||||
if(timer_flag == 1)
|
if(timer_flag == 1)
|
||||||
{
|
{
|
||||||
if(led1_state==0)
|
if(led1_state==0)
|
||||||
{
|
{
|
||||||
led1_init();
|
led1_init();
|
||||||
adcLed=ADCH;
|
ledresult1=ADCH;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
led1_stop();
|
led1_stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return adcLed;
|
return ledresult1;
|
||||||
};
|
};
|
||||||
|
|
||||||
char measureLed2(void)
|
char measureLed2(void)
|
||||||
{
|
{
|
||||||
char adcLed=0;
|
|
||||||
|
|
||||||
if(timer_flag == 1)
|
if(timer_flag == 1)
|
||||||
{
|
{
|
||||||
if(led2_state==0)
|
if(led2_state==0)
|
||||||
{
|
{
|
||||||
led2_init();
|
led2_init();
|
||||||
adcLed=ADCH;
|
ledresult2=ADCH;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -81,31 +80,29 @@ char measureLed2(void)
|
||||||
}
|
}
|
||||||
timer_flag=0;
|
timer_flag=0;
|
||||||
}
|
}
|
||||||
return adcLed;
|
return ledresult2;
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char compareLed(float led1,float led2)
|
unsigned char compareLed(int led1,int led2)
|
||||||
{
|
{
|
||||||
float adcLed1 = led1;
|
int adcCompare = led1 - led2;
|
||||||
float adcLed2 = led2;
|
if(adcCompare < 1)
|
||||||
float adcCompare = led1 - led2;
|
|
||||||
if (adcCompare < VOLTMIN) // adcLed2 > adcLed1
|
|
||||||
{
|
{
|
||||||
return LEFT;
|
if(led1 > 204)
|
||||||
}
|
|
||||||
else if (adcCompare > VOLTMIN)
|
|
||||||
{
|
|
||||||
return RIGHT;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if((adcLed1 > VOLTMIN) && (adcLed2 > VOLTMIN))
|
|
||||||
{
|
{
|
||||||
return NOTHING;
|
return NOTHING;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return FRONT;
|
return FRONT;
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
if (led1 > led2) // adcLed2 > adcLed1
|
||||||
|
{
|
||||||
|
return LEFT;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return RIGHT;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -29,10 +29,13 @@ char ADC_read_value(void);
|
||||||
float ADC_averaging(unsigned char val_ana);
|
float ADC_averaging(unsigned char val_ana);
|
||||||
char measureLed1(void);
|
char measureLed1(void);
|
||||||
char measureLed2(void);
|
char measureLed2(void);
|
||||||
unsigned char compareLed(float led1,float led2);
|
unsigned char compareLed(int led1,int led2);
|
||||||
|
|
||||||
volatile unsigned char intr_count;
|
volatile unsigned char intr_count;
|
||||||
volatile unsigned char timer_flag;
|
volatile unsigned char timer_flag;
|
||||||
volatile unsigned char seconde;
|
volatile unsigned char seconde;
|
||||||
|
|
||||||
|
volatile unsigned char ledresult1;
|
||||||
|
volatile unsigned char ledresult2;
|
||||||
|
|
||||||
#endif /* LED_RECEPTOR_H_ */
|
#endif /* LED_RECEPTOR_H_ */
|
|
@ -24,23 +24,28 @@
|
||||||
|
|
||||||
unsigned char adcled1;
|
unsigned char adcled1;
|
||||||
unsigned char adcled2;
|
unsigned char adcled2;
|
||||||
double moyLed1;
|
double moyLed1=0;
|
||||||
double moyLed2;
|
double moyLed2=0;
|
||||||
int iMoy=0;
|
int iMoy=0;
|
||||||
|
volatile unsigned char recVal1=0;
|
||||||
|
volatile unsigned char recVal2=0;
|
||||||
volatile unsigned char recVal=0;
|
volatile unsigned char recVal=0;
|
||||||
|
|
||||||
ISR (ADC_vect){
|
ISR (ADC_vect){
|
||||||
adcled1=measureLed1();
|
adcled1=measureLed1();
|
||||||
adcled2=measureLed2();
|
adcled2=measureLed2();
|
||||||
moyLed1+=(double)adcled1;
|
moyLed1=moyLed1 + adcled1;
|
||||||
moyLed2+=(double)adcled2;
|
moyLed2=moyLed2 + adcled2;
|
||||||
iMoy++;
|
iMoy++;
|
||||||
if(iMoy >= 100)
|
if(iMoy >= 2000)
|
||||||
{
|
{
|
||||||
moyLed1=moyLed1/iMoy;
|
moyLed1=moyLed1/iMoy;
|
||||||
moyLed2=moyLed2/iMoy;
|
moyLed2=moyLed2/iMoy;
|
||||||
recVal=(unsigned char)moyLed1;
|
recVal1=(int)moyLed1;
|
||||||
//recVal=compareLed(moyLed1,moyLed2);
|
recVal2=(int)moyLed2;
|
||||||
|
recVal=compareLed(recVal1,recVal2);
|
||||||
|
moyLed1=0;
|
||||||
|
moyLed2=0;
|
||||||
iMoy=0;
|
iMoy=0;
|
||||||
}
|
}
|
||||||
ADCSRA |= (1<<ADSC);
|
ADCSRA |= (1<<ADSC);
|
||||||
|
@ -94,11 +99,11 @@ int main( void )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VALEUR_DEMAN :
|
case VALEUR_DEMAN :
|
||||||
usiTwiTransmitByte(moyLed1/*recVal*/);
|
usiTwiTransmitByte(recVal/*recVal*/);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BASIC_MODE :
|
case BASIC_MODE :
|
||||||
usiTwiTransmitByte(moyLed1);
|
usiTwiTransmitByte(recVal);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue