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>
|
||||
<CVendor>Atmel</CVendor>
|
||||
<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" />
|
||||
<Description></Description>
|
||||
<Files xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
|
||||
<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>
|
||||
<Category>include</Category>
|
||||
<Condition>C</Condition>
|
||||
|
@ -26,7 +26,7 @@
|
|||
<SourcePath></SourcePath>
|
||||
</d4p1:anyType>
|
||||
<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>
|
||||
<Category>header</Category>
|
||||
<Condition>C</Condition>
|
||||
|
@ -37,7 +37,7 @@
|
|||
<SourcePath></SourcePath>
|
||||
</d4p1:anyType>
|
||||
<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>
|
||||
<Category>source</Category>
|
||||
<Condition>C Exe</Condition>
|
||||
|
@ -48,7 +48,7 @@
|
|||
<SourcePath></SourcePath>
|
||||
</d4p1:anyType>
|
||||
<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>
|
||||
<Category>source</Category>
|
||||
<Condition>C Exe</Condition>
|
||||
|
@ -59,7 +59,7 @@
|
|||
<SourcePath></SourcePath>
|
||||
</d4p1:anyType>
|
||||
<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>
|
||||
<Category>libraryPrefix</Category>
|
||||
<Condition>GCC</Condition>
|
||||
|
@ -71,7 +71,7 @@
|
|||
</d4p1:anyType>
|
||||
</Files>
|
||||
<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>
|
||||
<PresentInProject>true</PresentInProject>
|
||||
<ReferenceConditionId>ATtiny85</ReferenceConditionId>
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
<documentation help="" />
|
||||
<offline-documentation help="" />
|
||||
<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>
|
||||
</framework-data>
|
||||
</AsfFrameworkConfig>
|
||||
|
@ -72,7 +72,7 @@
|
|||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<ToolchainSettings>
|
||||
<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.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.8.332\include\</Value>
|
||||
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\include</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.directories.IncludePaths>
|
||||
<avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
|
||||
|
@ -101,7 +101,7 @@
|
|||
</avrgcc.linker.libraries.Libraries>
|
||||
<avrgcc.assembler.general.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.8.332\include\</Value>
|
||||
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\include</Value>
|
||||
</ListValues>
|
||||
</avrgcc.assembler.general.IncludePaths>
|
||||
</AvrGcc>
|
||||
|
@ -110,7 +110,7 @@
|
|||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<ToolchainSettings>
|
||||
<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.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.8.332\include\</Value>
|
||||
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\include</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.directories.IncludePaths>
|
||||
<avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
|
||||
|
@ -140,7 +140,7 @@
|
|||
</avrgcc.linker.libraries.Libraries>
|
||||
<avrgcc.assembler.general.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.8.332\include\</Value>
|
||||
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\include</Value>
|
||||
</ListValues>
|
||||
</avrgcc.assembler.general.IncludePaths>
|
||||
<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 seconde=0;
|
||||
|
||||
volatile unsigned char ledresult1=0;
|
||||
volatile unsigned char ledresult2=0;
|
||||
|
||||
void ADC_init(void)
|
||||
{
|
||||
DDRB &=~(1<<PB3); //Pin B3 en entree
|
||||
|
@ -47,33 +50,29 @@ float ADC_averaging(unsigned char val_ana)
|
|||
|
||||
char measureLed1(void)
|
||||
{
|
||||
char adcLed=0;
|
||||
|
||||
if(timer_flag == 1)
|
||||
{
|
||||
if(led1_state==0)
|
||||
{
|
||||
led1_init();
|
||||
adcLed=ADCH;
|
||||
ledresult1=ADCH;
|
||||
}
|
||||
else
|
||||
{
|
||||
led1_stop();
|
||||
}
|
||||
}
|
||||
return adcLed;
|
||||
return ledresult1;
|
||||
};
|
||||
|
||||
char measureLed2(void)
|
||||
{
|
||||
char adcLed=0;
|
||||
|
||||
if(timer_flag == 1)
|
||||
{
|
||||
if(led2_state==0)
|
||||
{
|
||||
led2_init();
|
||||
adcLed=ADCH;
|
||||
ledresult2=ADCH;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -81,31 +80,29 @@ char measureLed2(void)
|
|||
}
|
||||
timer_flag=0;
|
||||
}
|
||||
return adcLed;
|
||||
return ledresult2;
|
||||
};
|
||||
|
||||
unsigned char compareLed(float led1,float led2)
|
||||
unsigned char compareLed(int led1,int led2)
|
||||
{
|
||||
float adcLed1 = led1;
|
||||
float adcLed2 = led2;
|
||||
float adcCompare = led1 - led2;
|
||||
if (adcCompare < VOLTMIN) // adcLed2 > adcLed1
|
||||
int adcCompare = led1 - led2;
|
||||
if(adcCompare < 1)
|
||||
{
|
||||
return LEFT;
|
||||
}
|
||||
else if (adcCompare > VOLTMIN)
|
||||
{
|
||||
return RIGHT;
|
||||
}
|
||||
else
|
||||
{
|
||||
if((adcLed1 > VOLTMIN) && (adcLed2 > VOLTMIN))
|
||||
if(led1 > 204)
|
||||
{
|
||||
return NOTHING;
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
char measureLed1(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 timer_flag;
|
||||
volatile unsigned char seconde;
|
||||
|
||||
volatile unsigned char ledresult1;
|
||||
volatile unsigned char ledresult2;
|
||||
|
||||
#endif /* LED_RECEPTOR_H_ */
|
|
@ -24,23 +24,28 @@
|
|||
|
||||
unsigned char adcled1;
|
||||
unsigned char adcled2;
|
||||
double moyLed1;
|
||||
double moyLed2;
|
||||
double moyLed1=0;
|
||||
double moyLed2=0;
|
||||
int iMoy=0;
|
||||
volatile unsigned char recVal1=0;
|
||||
volatile unsigned char recVal2=0;
|
||||
volatile unsigned char recVal=0;
|
||||
|
||||
ISR (ADC_vect){
|
||||
adcled1=measureLed1();
|
||||
adcled2=measureLed2();
|
||||
moyLed1+=(double)adcled1;
|
||||
moyLed2+=(double)adcled2;
|
||||
moyLed1=moyLed1 + adcled1;
|
||||
moyLed2=moyLed2 + adcled2;
|
||||
iMoy++;
|
||||
if(iMoy >= 100)
|
||||
if(iMoy >= 2000)
|
||||
{
|
||||
moyLed1=moyLed1/iMoy;
|
||||
moyLed2=moyLed2/iMoy;
|
||||
recVal=(unsigned char)moyLed1;
|
||||
//recVal=compareLed(moyLed1,moyLed2);
|
||||
recVal1=(int)moyLed1;
|
||||
recVal2=(int)moyLed2;
|
||||
recVal=compareLed(recVal1,recVal2);
|
||||
moyLed1=0;
|
||||
moyLed2=0;
|
||||
iMoy=0;
|
||||
}
|
||||
ADCSRA |= (1<<ADSC);
|
||||
|
@ -94,11 +99,11 @@ int main( void )
|
|||
break;
|
||||
|
||||
case VALEUR_DEMAN :
|
||||
usiTwiTransmitByte(moyLed1/*recVal*/);
|
||||
usiTwiTransmitByte(recVal/*recVal*/);
|
||||
break;
|
||||
|
||||
case BASIC_MODE :
|
||||
usiTwiTransmitByte(moyLed1);
|
||||
usiTwiTransmitByte(recVal);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue