/* * File: main.c * Author: Sebastian H. Gabrielli * * Created on March 6, 2024, 12:34 PM */ #include "voltage.h" #include "uart.h" #define RTC_PERIOD (511) #define DELAY_TIME 1000 #include #include #include #include #include //#define F_CPU 4E6 #include #include #include "uart.h" #include #include #include "themistor-temp.h" #include "fan_speeeed.h" /* void main_1() { init_uart((uint16_t)9600); stdout = &USART_stream; TCA0_init ();*/ //PORT_init(); //test //TCB0_Init(); //PORT_init(); //EVSYS_Init(); //PORTB_init(); // testsettup(); //TCB3.INTCTRL = 0b00000001; // Bit 0 ? CAPT Capture Interrupt Enable //sei(); //while (1) { /* printf("loop"); uint16_t yo = TCB3.CNT; printf("CNT %u", yo); uint16_t stewui = TCB3.CCMP; printf("CCMP %u", stewui); */ //EVSYS.USERTCB0CAPT = EVSYS_USER_CHANNEL0_gc; // EVSYS.CHANNEL0 = EVSYS_CHANNEL0_PORTA_PIN5_gc; /* TCB uses event channel 0 */ /// EVSYS.USERTCB0CAPT = EVSYS_USER_CHANNEL0_gc; //uint8_t test = TCB3.CCMP; //printf("ccmp %u", test); // _delay_ms(500); // ; // } //} /*ISR (TCB3_INT_vect){ uint16_t yo = TCB3.CNT; printf("CNT %u", yo); uint16_t stewui = TCB3.CCMP; printf("CCMP %u", stewui); TCB3.INTFLAGS = 0x03; //TCB3.INTFLAGS = PIN0_bm; }*/ #define F_CPU 4000000UL #include #include #include #define MAX_PER 0x50 volatile uint16_t data = 0; volatile uint16_t cnt = 0; int main(void) { init_uart((uint16_t)9600); stdout = &USART_stream; //TCA Init /* PORTMUX.TCAROUTEA = PORTMUX_TCA0_PORTD_gc; PORTD.DIR = PIN0_bm; TCA0.SINGLE.PERBUF = MAX_PER; TCA0.SINGLE.CMP0BUF = MAX_PER / 2; TCA0.SINGLE.CTRLB = TCA_SINGLE_CMP0EN_bm | 0x3; TCA0.SINGLE.CTRLA = TCA_SINGLE_CLKSEL_DIV1_gc | TCA_SINGLE_ENABLE_bm; */ TCA0_init(); //TCB Init /* PORTA.IN = PIN3_bm; PORTA.PIN3CTRL = PORT_PULLUPEN_bm; EVSYS.CHANNEL0 = 0x43; TCB0.EVCTRL = TCB_CAPTEI_bm; TCB0.INTCTRL = TCB_CAPT_bm; TCB0.CTRLB = TCB_CNTMODE_FRQ_gc; EVSYS.USERTCB0CAPT = EVSYS_USER_CHANNEL0_gc; TCB0.CTRLA = TCB_CLKSEL_TCA0_gc | TCB_ENABLE_bm; */ //testsettup(); PORT_init(); sei(); /* Replace with your application code */ while (1) { if (data) { printf("TEST1_____ %u ", data); data = RPM_calculation(data, cnt); printf("TEST1 %u ", data); //printf("ccnt %d", cnt); data = 0; } } } ISR(TCB0_INT_vect) { data = TCB0.CCMP; cnt = TCB0.CNT; TCB0.INTFLAGS = TCB_CAPT_bm; }