From dc8a85820418e03cc503f1397b8f8ca531097267 Mon Sep 17 00:00:00 2001 From: Inamr Date: Wed, 20 Mar 2024 15:25:59 +0100 Subject: [PATCH] resets array and puts diode readings in array --- prosjekt.X/fan speeeed.h | 2 + prosjekt.X/fan speeeeeeeed.c | 44 +-- prosjekt.X/main.c | 73 ++--- prosjekt.X/nbproject/configurations.xml | 366 ++++++++++++------------ prosjekt.X/nbproject/project.xml | 4 +- 5 files changed, 258 insertions(+), 231 deletions(-) diff --git a/prosjekt.X/fan speeeed.h b/prosjekt.X/fan speeeed.h index f13d447..7746664 100644 --- a/prosjekt.X/fan speeeed.h +++ b/prosjekt.X/fan speeeed.h @@ -23,6 +23,8 @@ extern "C" { #include #include #include +#include "voltage.h" + int RTC_init(); int read_array_get_RPM(int voltage_value); inline void put_in_array(); diff --git a/prosjekt.X/fan speeeeeeeed.c b/prosjekt.X/fan speeeeeeeed.c index 504093f..ae17d2c 100644 --- a/prosjekt.X/fan speeeeeeeed.c +++ b/prosjekt.X/fan speeeeeeeed.c @@ -1,5 +1,13 @@ + + #include "fan speeeed.h" + +int voltage_value_counter = 0; +int voltage_value [30]; + + + RTC.PITCTRLA = RTC_PERIOD_CYC32768_gc | RTC_PITEN_bm; int RTC_init() { @@ -42,31 +50,35 @@ int RTC_init() { } // skal lage en som finner data hvert ... sekund. Datane skal samles inn i en array. Når arrayen er full skal jeg regne ut rpm. Vet t det er ... mange sek mellom så blir enklere. så noe signalbehandling shit. -int read_array_get_RPM(int voltage_value) { +int read_array_get_RPM() { f = ((1 / t)*1000); fan_speed = (f * 60) / 2; + return fan_speed; } inline void put_in_array() { - int voltage_value [30] = {}; - for(int i = 0; i <30; i++) - scanf("%d", &voltage_value[i]); - + voltage_values[voltage_value_counter] = read_photodiode_voltage(); + voltage_value_counter++; } +void reset_voltage_array(){ + for(int i = 0; i < voltage_values_counter; i++){ + voltage_values[i]= 0; + } + voltage_value_counter = 0; +} + + ISR(RTC_PIT_vect) { RTC.PITINTFLAGS = RTC_PI_bm; - - put_in_array(); -} - -int main(void) { - sei(); - read_array_get_RPM(); - RTC_init(); - while (1) { - + if(voltage_value_counter < sizeof(voltage_values)/sizeof(voltage_value[0])){ + put_in_array(); } -} \ No newline at end of file + else{ + read_array_get_RPM(); + reset_voltage_array(); + } + +} diff --git a/prosjekt.X/main.c b/prosjekt.X/main.c index d9ed9e8..ab2f11a 100644 --- a/prosjekt.X/main.c +++ b/prosjekt.X/main.c @@ -1,36 +1,39 @@ -/* - * File: main.c - * Author: Sebastian H. Gabrielli - * - * Created on March 6, 2024, 12:34 PM - */ -#include "voltage.h" -#include "uart.h" -#define RTC_PERIOD (511) -#define DELAY_TIME 1000 -#include -#include -#include -#include -#include - -#define F_CPU 4E6 - -#include -#include -#include "uart.h" -#include -#include -#include "themistor-temp.h" - -int main() { - sensor_init(); - ADC0_init(); - init_uart((uint16_t)9600); - stdout = &USART_stream; - - while (1) { - uint16_t adcVal = voltage_values(); - printf("The values: \n%u , %u\n",VREF_REFSEL_VDD_gc , adcVal); - } +/* + * File: main.c + * Author: Sebastian H. Gabrielli + * + * Created on March 6, 2024, 12:34 PM + */ +#include "voltage.h" +#include "uart.h" +#define RTC_PERIOD (511) +#define DELAY_TIME 1000 +#include +#include +#include +#include +#include + +#define F_CPU 4E6 + +#include +#include +#include "uart.h" +#include +#include +#include "themistor-temp.h" +#include "fan speeeed.h" + + +int main() { + sensor_init(); + ADC0_init(); + RTC_init(); + sei(); + init_uart((uint16_t)9600); + stdout = &USART_stream; + + while (1) { + ; + } } \ No newline at end of file diff --git a/prosjekt.X/nbproject/configurations.xml b/prosjekt.X/nbproject/configurations.xml index 765c75e..87ae9eb 100644 --- a/prosjekt.X/nbproject/configurations.xml +++ b/prosjekt.X/nbproject/configurations.xml @@ -1,179 +1,187 @@ - - - - - themistor-temp.h - fan speeeed.h - - - Makefile - - - - - main.c - thermistor-temp.c - - - Makefile - - - - localhost - AVR128DB48 - - - nEdbgTool - XC8 - 2.46 - 3 - - - - - - - - - - - - - - - false - false - - - - - - - false - false - - false - - false - false - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + themistor-temp.h + fan speeeed.h + uart.h + voltage.h + + + Makefile + + + + + main.c + thermistor-temp.c + uart.c + voltage.c + fan speeeeeeeed.c + + + + . + + Makefile + + + + localhost + AVR128DB48 + + + nEdbgTool + XC8 + 2.46 + 3 + + + + + + + + + + + + + + + false + false + + + + + + + false + false + + false + + false + false + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/prosjekt.X/nbproject/project.xml b/prosjekt.X/nbproject/project.xml index 9d6ede3..718a0c6 100644 --- a/prosjekt.X/nbproject/project.xml +++ b/prosjekt.X/nbproject/project.xml @@ -8,7 +8,9 @@ 0 ISO-8859-1 - + + . + default