made interrupts as timer

This commit is contained in:
Inamr 2024-03-19 14:29:57 +01:00
parent 9aa9c444c1
commit df3d0c6ce6
2 changed files with 18 additions and 3 deletions

View File

@ -20,6 +20,9 @@ extern "C" {
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#include <avr/interrupt.h>
int fan_speed(float value);

View File

@ -2,6 +2,8 @@
#include "fan speeeed.h"
int fan_speed(float voltage_value){
init_millis()
sei();
float fan_speed;
float t = 0;
float past_time = 0;
@ -9,12 +11,22 @@ int fan_speed(float voltage_value){
int old_value = 0;
int f;
if (voltage_value > 300 && old_value < 300){
start_time = millis();
start_time = init_millis()
t =(start_time - past_time);
paste_time = start_time;
past_time = start_time;
}
voltage_value = old_value;
f = ((1/t)*1000);
fan_speed = (f*60)/2;
return fan_speed;
}
ISR(PORTB_PORT_vect)
{
static int counter = 0;
if (counter >=5){
PORTB.OUT ^= 0x0F;
counter = 0;
}
PORTB.INFLAFS = PIN2_bm;
}