From 25684335f193df6f69b02353f7748425dee41bdf Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Tue, 5 Apr 2022 20:40:15 +0200 Subject: [PATCH] Additions from 28/01/2022: Removed volatile variables, calculating average adc, fixed an issue with sent direction. --- .../i2c_test_attiny85.componentinfo.xml | 26 +-- i2c_test_attiny85/i2c_test_attiny85.cproj | 154 +++++++++--------- i2c_test_attiny85/led_receptor.c | 6 +- i2c_test_attiny85/led_receptor.h | 2 +- i2c_test_attiny85/main.c | 26 ++- 5 files changed, 113 insertions(+), 101 deletions(-) diff --git a/i2c_test_attiny85/i2c_test_attiny85.componentinfo.xml b/i2c_test_attiny85/i2c_test_attiny85.componentinfo.xml index 80c79cc..f38ac81 100755 --- a/i2c_test_attiny85/i2c_test_attiny85.componentinfo.xml +++ b/i2c_test_attiny85/i2c_test_attiny85.componentinfo.xml @@ -9,57 +9,57 @@ Atmel - 1.2.0 - C:/Program Files (x86)\Atmel\Studio\7.0\Packs + 1.8.0 + D:/Programs\Atmelstudio\7.0\Packs - C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.2.118\include + D:/Programs\Atmelstudio\7.0\Packs\atmel\ATtiny_DFP\1.8.332\include\ include C - include + include/ - C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.2.118\include\avr\iotn85.h + D:/Programs\Atmelstudio\7.0\Packs\atmel\ATtiny_DFP\1.8.332\include\avr\iotn85.h header C - RcYmivGpgsCGGCzeWAIjcA== + T0lnJZ6iliUJCzU7ZHCMPQ== include/avr/iotn85.h - C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.2.118\templates\main.c + D:/Programs\Atmelstudio\7.0\Packs\atmel\ATtiny_DFP\1.8.332\templates\main.c template source C Exe - GD1k8YYhulqRs6FD1B2Hog== + KjvOcFWd++tbnsEMfVPd/w== templates/main.c Main file (.c) - C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.2.118\templates\main.cpp + D:/Programs\Atmelstudio\7.0\Packs\atmel\ATtiny_DFP\1.8.332\templates\main.cpp template source C Exe - YXFphlh0CtZJU+ebktABgQ== + mkKaE95TOoATsuBGv6jmxg== templates/main.cpp Main file (.cpp) - C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.2.118\gcc\dev\attiny85 + D:/Programs\Atmelstudio\7.0\Packs\atmel\ATtiny_DFP\1.8.332\gcc\dev\attiny85 libraryPrefix GCC @@ -71,8 +71,8 @@ ATtiny_DFP - C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATtiny_DFP/1.2.118/Atmel.ATtiny_DFP.pdsc - 1.2.118 + D:/Programs/Atmelstudio/7.0/Packs/atmel/ATtiny_DFP/1.8.332/Atmel.ATtiny_DFP.pdsc + 1.8.332 true ATtiny85 diff --git a/i2c_test_attiny85/i2c_test_attiny85.cproj b/i2c_test_attiny85/i2c_test_attiny85.cproj index 758d011..759dbf0 100755 --- a/i2c_test_attiny85/i2c_test_attiny85.cproj +++ b/i2c_test_attiny85/i2c_test_attiny85.cproj @@ -28,15 +28,15 @@ 0 - - - - - - - - - + + + + + + + + + com.atmel.avrdbg.tool.stk500 @@ -72,79 +72,79 @@ - -mmcu=attiny85 -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\gcc\dev\attiny85" - True - True - True - True - False - True - True - - - NDEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\include - - - Optimize for size (-Os) - True - True - True - - - libm - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\include - - - + -mmcu=attiny85 -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.8.332\gcc\dev\attiny85" + True + True + True + True + False + True + True + + + NDEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.8.332\include\ + + + Optimize for size (-Os) + True + True + True + + + libm + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.8.332\include\ + + + - -mmcu=attiny85 -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\gcc\dev\attiny85" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.2.118\include - - - Default (-Wa,-g) - + -mmcu=attiny85 -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.8.332\gcc\dev\attiny85" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.8.332\include\ + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.8.332\include\ + + + Default (-Wa,-g) + diff --git a/i2c_test_attiny85/led_receptor.c b/i2c_test_attiny85/led_receptor.c index f93fa9a..097f10b 100755 --- a/i2c_test_attiny85/led_receptor.c +++ b/i2c_test_attiny85/led_receptor.c @@ -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; }; }; }; diff --git a/i2c_test_attiny85/led_receptor.h b/i2c_test_attiny85/led_receptor.h index d80cb5d..66dcb6d 100755 --- a/i2c_test_attiny85/led_receptor.h +++ b/i2c_test_attiny85/led_receptor.h @@ -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); diff --git a/i2c_test_attiny85/main.c b/i2c_test_attiny85/main.c index 2eb610c..1e3cd07 100755 --- a/i2c_test_attiny85/main.c +++ b/i2c_test_attiny85/main.c @@ -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<