mikrokontrollersystemer-pro.../prosjekt.X/fan speeeeeeeed.c

32 lines
719 B
C
Raw Normal View History

2024-03-13 12:39:35 +00:00
2024-03-19 11:59:56 +00:00
#include "fan speeeed.h"
2024-03-19 12:11:52 +00:00
int fan_speed(float voltage_value){
2024-03-19 13:29:57 +00:00
init_millis()
sei();
2024-03-19 11:59:56 +00:00
float fan_speed;
2024-03-19 12:11:52 +00:00
float t = 0;
float past_time = 0;
float start_time = 0;
int old_value = 0;
2024-03-19 11:59:56 +00:00
int f;
2024-03-19 12:11:52 +00:00
if (voltage_value > 300 && old_value < 300){
2024-03-19 13:29:57 +00:00
start_time = init_millis()
2024-03-19 12:11:52 +00:00
t =(start_time - past_time);
2024-03-19 13:29:57 +00:00
past_time = start_time;
2024-03-19 11:59:56 +00:00
}
2024-03-19 12:11:52 +00:00
voltage_value = old_value;
f = ((1/t)*1000);
2024-03-19 11:59:56 +00:00
fan_speed = (f*60)/2;
return fan_speed;
2024-03-19 13:29:57 +00:00
}
ISR(PORTB_PORT_vect)
{
static int counter = 0;
if (counter >=5){
PORTB.OUT ^= 0x0F;
counter = 0;
}
PORTB.INFLAFS = PIN2_bm;
}