72 lines
2.0 KiB
C
72 lines
2.0 KiB
C
|
|
#include "fan speeeed.h"
|
|
RTC.PITCTRLA = RTC_PERIOD_CYC32768_gc | RTC_PITEN_bm;
|
|
|
|
int RTC_init() {
|
|
uint8_t temp;
|
|
/* Initialize 32.768kHz Oscillator: */
|
|
/* Disable oscillator: */
|
|
temp = CLKCTRL.XOSC32KCTRLA;
|
|
temp &= ~CLKCTRL_ENABLE_bm;
|
|
/* Writing to protected register */
|
|
ccp_write_io((void*) &CLKCTRL.XOSC32KCTRLA, temp);
|
|
|
|
while (CLKCTRL.MCLKSTATUS & CLKCTRL_XOSC32KS_bm) {
|
|
; /* Wait until XOSC32KS becomes 0 */
|
|
}
|
|
/* SEL = 0 (Use External Crystal): */
|
|
temp = CLKCTRL.XOSC32KCTRLA;
|
|
temp &= ~CLKCTRL_SEL_bm;
|
|
/* Writing to protected register */
|
|
ccp_write_io((void*) &CLKCTRL.XOSC32KCTRLA, temp);
|
|
|
|
/* Enable oscillator: */
|
|
temp = CLKCTRL.XOSC32KCTRLA;
|
|
temp |= CLKCTRL_ENABLE_bm;
|
|
/* Writing to protected register */
|
|
ccp_write_io((void*) &CLKCTRL.XOSC32KCTRLA, temp);
|
|
|
|
/* Initialize RTC: */
|
|
while (RTC.STATUS > 0) {
|
|
; /* Wait for all register to be synchronized */
|
|
}
|
|
/* 32.768kHz External Crystal Oscillator (XOSC32K) */
|
|
RTC.CLKSEL = RTC_CLKSEL_TOSC32K_gc;
|
|
/* Run in debug: enabled */
|
|
RTC.DBGCTRL = RTC_DBGRUN_bm;
|
|
|
|
RTC.PITINTCTRL = RTC_PI_bm; /* Periodic Interrupt: enabled */
|
|
|
|
RTC.PITCTRLA = RTC_PERIOD_CYC32768_gc /* RTC Clock Cycles 32768 */
|
|
| RTC_PITEN_bm; /* Enable: enabled */
|
|
|
|
}
|
|
// 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) {
|
|
|
|
f = ((1 / t)*1000);
|
|
fan_speed = (f * 60) / 2;
|
|
return fan_speed;
|
|
}
|
|
|
|
inline void put_in_array() {
|
|
int voltage_value [30] = {};
|
|
for(int i = 0; i <30; i++)
|
|
scanf("%d", &voltage_value[i]);
|
|
|
|
}
|
|
|
|
ISR(RTC_PIT_vect) {
|
|
RTC.PITINTFLAGS = RTC_PI_bm;
|
|
|
|
put_in_array();
|
|
}
|
|
|
|
int main(void) {
|
|
sei();
|
|
read_array_get_RPM();
|
|
RTC_init();
|
|
while (1) {
|
|
|
|
}
|
|
} |