add comment
This commit is contained in:
parent
e01c4d41ad
commit
f0a435d578
@ -22,41 +22,40 @@ void TCA0_update_period_ms() {
|
||||
}
|
||||
|
||||
uint16_t RPM_calculation(uint16_t fancounter, uint16_t time) {
|
||||
printf("time: %u", time);
|
||||
fan_speed = (fancounter / time);
|
||||
fan_speed = fan_speed/2;
|
||||
fan_speed = fan_speed * 60/5;
|
||||
printf("falling edge: %u", fancounter);
|
||||
fancounter = 0;
|
||||
printf("falling edge: ", fancounter);
|
||||
printf("fanspeed %u \n", fan_speed);
|
||||
return fan_speed;
|
||||
}
|
||||
|
||||
|
||||
void init_fanports() {
|
||||
// CONFIGURE PINS AS ANALOG INPUTS
|
||||
|
||||
// PIN FOR FAN 1
|
||||
PORTD.DIRSET &= ~PIN6_bm;
|
||||
PORTD.PIN6CTRL &= ~ PORT_ISC_gm;
|
||||
PORTD.PIN6CTRL = PORT_ISC_INPUT_DISABLE_gc;
|
||||
|
||||
// PIN FOR FAN 2
|
||||
PORTD.DIRSET &= ~PIN4_bm;
|
||||
PORTD.PIN4CTRL &= ~ PORT_ISC_gm ;
|
||||
PORTD.PIN4CTRL = PORT_ISC_INPUT_DISABLE_gc;
|
||||
|
||||
// PIN FOR REFRENCE
|
||||
PORTD.DIRSET &= PIN7_bm;
|
||||
PORTD.PIN7CTRL &= ~ PORT_ISC_gm ;
|
||||
PORTD.PIN7CTRL = PORT_ISC_INPUT_DISABLE_gc;
|
||||
}
|
||||
|
||||
void init_ac0_fan1(){
|
||||
void init_ac0(){
|
||||
//Wincontroll disabled
|
||||
AC0.CTRLB = 0x00;
|
||||
|
||||
//SELECT POSITIVE AND NEGATIVE INPUTS FOR COMPARRISON
|
||||
// FAN USE PD6 & PD7, COMPARE WITH PD3
|
||||
// FAN USE PD6 COMPARE WITH PD3
|
||||
AC0.MUXCTRL = AC_MUXPOS_AINP3_gc | AC_MUXNEG_AINN2_gc;
|
||||
//AC_MUXPOS_AINP1_gc
|
||||
|
||||
// ENABLE AC BY WRITING 1 TO ENABLE BIT IN ACN.CTRLA
|
||||
AC0.CTRLA = AC_ENABLE_bm | AC_INTMODE_NORMAL_POSEDGE_gc | AC_OUTEN_bm;
|
||||
@ -66,12 +65,12 @@ void init_ac0_fan1(){
|
||||
}
|
||||
|
||||
|
||||
void init_ac1_fan2(){
|
||||
void init_ac1(){
|
||||
//Wincontroll disabled
|
||||
AC1.CTRLB = 0x00;
|
||||
|
||||
//SELECT POSITIVE AND NEGATIVE INPUTS FOR COMPARRISON
|
||||
// FAN USE PD6 & PD7, COMPARE WITH PD3
|
||||
// FAN USE PD4, COMPARE WITH PD3
|
||||
AC1.MUXCTRL = AC_MUXPOS_AINP2_gc | AC_MUXNEG_AINN2_gc;
|
||||
|
||||
// ENABLE AC BY WRITING 1 TO ENABLE BIT IN ACN.CTRLA
|
||||
@ -85,27 +84,22 @@ void init_ac1_fan2(){
|
||||
ISR(AC0_AC_vect){ // AC0 vec flag
|
||||
cli();
|
||||
falling_edge_counter_1++;
|
||||
printf("ac0");
|
||||
AC0.STATUS |= 0x10; //CMP flag to 0
|
||||
sei();
|
||||
}
|
||||
|
||||
|
||||
ISR(AC1_AC_vect){ // AC0 vec flag
|
||||
ISR(AC1_AC_vect){ // AC1 vec flag
|
||||
cli();
|
||||
falling_edge_counter_2++;
|
||||
printf("ac1");
|
||||
AC1.STATUS |= 0x10; //CMP flag to 0
|
||||
sei();
|
||||
}
|
||||
|
||||
|
||||
// TIMER INTERUPT
|
||||
ISR (TCA0_OVF_vect) {
|
||||
cli();
|
||||
|
||||
printf("fan1");
|
||||
RPM_calculation(falling_edge_counter_1,1);
|
||||
printf("fan2");
|
||||
RPM_calculation(falling_edge_counter_2,1);
|
||||
falling_edge_counter_1 = 0;
|
||||
falling_edge_counter_2 = 0;
|
||||
|
||||
@ -24,12 +24,24 @@ extern "C" {
|
||||
#include <avr/io.h>
|
||||
#include <avr/cpufunc.h>
|
||||
|
||||
// INITALICE TIMER COUNTER
|
||||
void init_TCA0();
|
||||
|
||||
// UPDATE TIMER PERIODE
|
||||
void TCA0_update_period_ms ();
|
||||
|
||||
// TAKES INN A TIME AND A THE COUNTED FAN DIPS
|
||||
// RETURNS THE RPM OF THE FAN
|
||||
uint16_t RPM_calculation(uint16_t fancounter, uint16_t time);
|
||||
|
||||
// INITIALISING FAN PORTS
|
||||
void init_fanports();
|
||||
void init_ac0_fan1();
|
||||
void init_ac1_fan2();
|
||||
|
||||
// INIT AC0 TO COMPARE PD6 AND PD7
|
||||
void init_ac0();
|
||||
|
||||
// INIT AC1 TO COMPARE PD4 AND PD7
|
||||
void init_ac1();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@ -37,8 +37,8 @@ int main(void) {
|
||||
stdout = &USART_stream;
|
||||
init_TCA0();
|
||||
init_fanports();
|
||||
init_ac0_fan1();
|
||||
init_ac1_fan2();
|
||||
init_ac0();
|
||||
init_ac1();
|
||||
|
||||
sei();
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user