From c31db35b5b2610b47dd3f38140d432d637a021b5 Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Wed, 3 Feb 2021 18:37:18 +0100 Subject: [PATCH] Added tp8 --- tp8/exo1.c | 32 ++++++++ tp8/exo2.c | 122 +++++++++++++++++++++++++++++ tp8/main.c | 86 +++++++++++++++++++++ tp8/tp8.componentinfo.xml | 86 +++++++++++++++++++++ tp8/tp8.cproj | 157 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 483 insertions(+) create mode 100755 tp8/exo1.c create mode 100755 tp8/exo2.c create mode 100755 tp8/main.c create mode 100755 tp8/tp8.componentinfo.xml create mode 100755 tp8/tp8.cproj diff --git a/tp8/exo1.c b/tp8/exo1.c new file mode 100755 index 0000000..340e5d1 --- /dev/null +++ b/tp8/exo1.c @@ -0,0 +1,32 @@ +/* + * tp8.c + * + * Created: 30/03/2021 14:10:10 + * Author : yboujon1 + */ + +#include +#define F_CPU 3686400 +#include +void pwm0_init(void); +void pwm0_setalpha(float percent); + +int main(void) +{ + pwm0_init(); + pwm0_setalpha(25); + int i; + while (1) + { + //rien + }; +} + +void pwm0_init(void){ + TCCR0|=(1< +#define F_CPU 3686400 +#include +void timer1_init(int top); +void timer1_setalpha(float percent); + +int main(void) +{ + timer1_init(369); + timer1_setalpha(33); //soit 33% pour qu'ils soient complémentaires + while (1) + { + //rien + }; +} + +void timer1_init(int top){ + ICR1=top; + TCCR1A|=(1< +#include +#define F_CPU 3686400 +#include +#include +void ADC_init(void); +void ADC_start_conversion(void); +void uart_init(unsigned int ubrr); +void read_temp(int* e, int* d); +void uart_putchar(char c, FILE *stream); +static FILE out_rs232 = FDEV_SETUP_STREAM(uart_putchar, NULL,_FDEV_SETUP_WRITE); //on defini le flux de sortie avec uart putchar +volatile unsigned char etat=0; +volatile unsigned int valeur; + +int main(void) +{ + ADC_init(); + sei(); + uart_init(23); + stdout =&out_rs232; + int entier, decimal; + while (1) + { + ADC_start_conversion(); + if (etat == 1){ + read_temp(&entier,&decimal); + printf("La temperature est : %d.%d.C\n\t",entier,decimal); //on affiche la température + etat = 0; + }; + _delay_ms(500); + + }; +} + +void ADC_init(void) +{ + DDRA &=~(1<200KHz + //on autorise la conversion + //on autorise l'interruption +}; + +void ADC_start_conversion(void) +{ + ADCSRA|=(1< +#include +#define F_CPU 3686400 +#include +#include +void ADC_init(void); +float read_temp(void); +int ADC_read_value(void); +int compute_pwm(float temp); +void pwm0_init(void); +void pwm0_setalpha(float percent); + +int main(void) +{ + float temperature; + unsigned int alpha; + DDRC = 0xFF; //port C en sortie + ADC_init(); //initialisation ADC + pwm0_init(); //initialisation pwm0 + while (1) + { + ADC_read_value(); //lit la valeur d'ADC (poten + temperature = read_temp(); //lit la temperature + alpha=compute_pwm(temperature); //calcule le rapport cyclique en fonction de la température + PORTC = ~(char)temperature; //affiche temp sur les leds + pwm0_setalpha(alpha); //defini le rapport cyclique, vitesse du ventilateur + _delay_ms(100); //on attend 100 ms + }; +} +void ADC_init(void) +{ + DDRA &=~(1<200KHz + //on autorise la conversion +}; + +float read_temp(void) +{ + float x = (0.48828125*ADC_read_value()); //on converti la tension en température + return x; +}; + +int compute_pwm(float temp) +{ + if(temp<20) //si temperature inferieur à 20 + { + return 0; //alors alpha=0 + } + if(temp>=20 && temp<30) //si entre 20 et 30 + { + int a=(temp-20)*5+49; //fonction affine calculée + return a; + } + else + { + return 99; //Car comme c'est un int, l'approximation + //le mettra au-dessus de 100 + }; +} + +int ADC_read_value(void) +{ + ADCSRA|=(1< + + + + + + Device + Startup + + + Atmel + 1.6.0 + D:/Programs\Atmelstudio\7.0\Packs + + + + + D:/Programs\Atmelstudio\7.0\Packs\atmel\ATmega_DFP\1.6.364\include\ + + include + C + + + include/ + + + + + D:/Programs\Atmelstudio\7.0\Packs\atmel\ATmega_DFP\1.6.364\include\avr\iom16.h + + header + C + BDa+/Y5e630de26bwSjZpg== + + include/avr/iom16.h + + + + + D:/Programs\Atmelstudio\7.0\Packs\atmel\ATmega_DFP\1.6.364\templates\main.c + template + source + C Exe + KjvOcFWd++tbnsEMfVPd/w== + + templates/main.c + Main file (.c) + + + + D:/Programs\Atmelstudio\7.0\Packs\atmel\ATmega_DFP\1.6.364\templates\main.cpp + template + source + C Exe + mkKaE95TOoATsuBGv6jmxg== + + templates/main.cpp + Main file (.cpp) + + + + D:/Programs\Atmelstudio\7.0\Packs\atmel\ATmega_DFP\1.6.364\gcc\dev\atmega16 + + libraryPrefix + GCC + + + gcc/dev/atmega16 + + + + + ATmega_DFP + D:/Programs/Atmelstudio/7.0/Packs/atmel/ATmega_DFP/1.6.364/Atmel.ATmega_DFP.pdsc + 1.6.364 + true + ATmega16 + + + + Resolved + Fixed + true + + + \ No newline at end of file diff --git a/tp8/tp8.cproj b/tp8/tp8.cproj new file mode 100755 index 0000000..5b6af20 --- /dev/null +++ b/tp8/tp8.cproj @@ -0,0 +1,157 @@ + + + + 2.0 + 7.0 + com.Atmel.AVRGCC8.C + dce6c7e3-ee26-4d79-826b-08594b9ad897 + ATmega16 + none + Executable + C + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + tp8 + tp8 + tp8 + Native + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 0 + + + + + + + + + + + + + com.atmel.avrdbg.tool.stk500 + + 0x1E9403 + + + + + + + + com.atmel.avrdbg.tool.simulator + + + Simulator + + ISP + + + + 460800 + + ISP + + com.atmel.avrdbg.tool.stk500 + + + STK500 + + 460800 + 0 + + + + + + -mmcu=atmega16 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\gcc\dev\atmega16" + True + True + True + True + False + True + True + + + NDEBUG + + + + + %24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\include\ + + + Optimize for size (-Os) + True + True + True + + + libm + + + + + %24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\include\ + + + + + + + + + -mmcu=atmega16 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\gcc\dev\atmega16" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\include\ + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + + + %24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\include\ + + + Default (-Wa,-g) + + + + + + compile + + + + \ No newline at end of file