resets array and puts diode readings in array

This commit is contained in:
Inamr 2024-03-20 15:25:59 +01:00
parent 8b5b4e186a
commit dc8a858204
5 changed files with 258 additions and 231 deletions

View File

@ -23,6 +23,8 @@ extern "C" {
#include <avr/interrupt.h> #include <avr/interrupt.h>
#include <avr/io.h> #include <avr/io.h>
#include <avr/cpufunc.h> #include <avr/cpufunc.h>
#include "voltage.h"
int RTC_init(); int RTC_init();
int read_array_get_RPM(int voltage_value); int read_array_get_RPM(int voltage_value);
inline void put_in_array(); inline void put_in_array();

View File

@ -1,5 +1,13 @@
#include "fan speeeed.h" #include "fan speeeed.h"
int voltage_value_counter = 0;
int voltage_value [30];
RTC.PITCTRLA = RTC_PERIOD_CYC32768_gc | RTC_PITEN_bm; RTC.PITCTRLA = RTC_PERIOD_CYC32768_gc | RTC_PITEN_bm;
int RTC_init() { 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. // 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); f = ((1 / t)*1000);
fan_speed = (f * 60) / 2; fan_speed = (f * 60) / 2;
return fan_speed; return fan_speed;
} }
inline void put_in_array() { inline void put_in_array() {
int voltage_value [30] = {}; voltage_values[voltage_value_counter] = read_photodiode_voltage();
for(int i = 0; i <30; i++) voltage_value_counter++;
scanf("%d", &voltage_value[i]);
} }
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) { ISR(RTC_PIT_vect) {
RTC.PITINTFLAGS = RTC_PI_bm; RTC.PITINTFLAGS = RTC_PI_bm;
if(voltage_value_counter < sizeof(voltage_values)/sizeof(voltage_value[0])){
put_in_array(); put_in_array();
}
int main(void) {
sei();
read_array_get_RPM();
RTC_init();
while (1) {
} }
else{
read_array_get_RPM();
reset_voltage_array();
}
} }

View File

@ -22,15 +22,18 @@
#include <util/delay.h> #include <util/delay.h>
#include <stdint.h> #include <stdint.h>
#include "themistor-temp.h" #include "themistor-temp.h"
#include "fan speeeed.h"
int main() { int main() {
sensor_init(); sensor_init();
ADC0_init(); ADC0_init();
RTC_init();
sei();
init_uart((uint16_t)9600); init_uart((uint16_t)9600);
stdout = &USART_stream; stdout = &USART_stream;
while (1) { while (1) {
uint16_t adcVal = voltage_values(); ;
printf("The values: \n%u , %u\n",VREF_REFSEL_VDD_gc , adcVal);
} }
} }

View File

@ -6,6 +6,8 @@
projectFiles="true"> projectFiles="true">
<itemPath>themistor-temp.h</itemPath> <itemPath>themistor-temp.h</itemPath>
<itemPath>fan speeeed.h</itemPath> <itemPath>fan speeeed.h</itemPath>
<itemPath>uart.h</itemPath>
<itemPath>voltage.h</itemPath>
</logicalFolder> </logicalFolder>
<logicalFolder name="ExternalFiles" <logicalFolder name="ExternalFiles"
displayName="Important Files" displayName="Important Files"
@ -21,8 +23,14 @@
projectFiles="true"> projectFiles="true">
<itemPath>main.c</itemPath> <itemPath>main.c</itemPath>
<itemPath>thermistor-temp.c</itemPath> <itemPath>thermistor-temp.c</itemPath>
<itemPath>uart.c</itemPath>
<itemPath>voltage.c</itemPath>
<itemPath>fan speeeeeeeed.c</itemPath>
</logicalFolder> </logicalFolder>
</logicalFolder> </logicalFolder>
<sourceRootList>
<Elem>.</Elem>
</sourceRootList>
<projectmakefile>Makefile</projectmakefile> <projectmakefile>Makefile</projectmakefile>
<confs> <confs>
<conf name="default" type="2"> <conf name="default" type="2">

View File

@ -8,7 +8,9 @@
<make-project-type>0</make-project-type> <make-project-type>0</make-project-type>
<sourceEncoding>ISO-8859-1</sourceEncoding> <sourceEncoding>ISO-8859-1</sourceEncoding>
<make-dep-projects/> <make-dep-projects/>
<sourceRootList/> <sourceRootList>
<sourceRootElem>.</sourceRootElem>
</sourceRootList>
<confList> <confList>
<confElem> <confElem>
<name>default</name> <name>default</name>