made interrupts as timer
This commit is contained in:
parent
9aa9c444c1
commit
df3d0c6ce6
@ -20,6 +20,9 @@ extern "C" {
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
|
||||||
|
|
||||||
int fan_speed(float value);
|
int fan_speed(float value);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
#include "fan speeeed.h"
|
#include "fan speeeed.h"
|
||||||
|
|
||||||
int fan_speed(float voltage_value){
|
int fan_speed(float voltage_value){
|
||||||
|
init_millis()
|
||||||
|
sei();
|
||||||
float fan_speed;
|
float fan_speed;
|
||||||
float t = 0;
|
float t = 0;
|
||||||
float past_time = 0;
|
float past_time = 0;
|
||||||
@ -9,12 +11,22 @@ int fan_speed(float voltage_value){
|
|||||||
int old_value = 0;
|
int old_value = 0;
|
||||||
int f;
|
int f;
|
||||||
if (voltage_value > 300 && old_value < 300){
|
if (voltage_value > 300 && old_value < 300){
|
||||||
start_time = millis();
|
start_time = init_millis()
|
||||||
t =(start_time - past_time);
|
t =(start_time - past_time);
|
||||||
paste_time = start_time;
|
past_time = start_time;
|
||||||
}
|
}
|
||||||
voltage_value = old_value;
|
voltage_value = old_value;
|
||||||
f = ((1/t)*1000);
|
f = ((1/t)*1000);
|
||||||
fan_speed = (f*60)/2;
|
fan_speed = (f*60)/2;
|
||||||
return fan_speed;
|
return fan_speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ISR(PORTB_PORT_vect)
|
||||||
|
{
|
||||||
|
static int counter = 0;
|
||||||
|
if (counter >=5){
|
||||||
|
PORTB.OUT ^= 0x0F;
|
||||||
|
counter = 0;
|
||||||
|
}
|
||||||
|
PORTB.INFLAFS = PIN2_bm;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user