mikrokontrollersystemer-pro.../prosjekt.X/main.c

147 lines
3.0 KiB
C
Raw Normal View History

/*
* 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 <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <string.h>
#include <stdbool.h>
2024-04-09 13:39:11 +00:00
//#define F_CPU 4E6
#include <stdio.h>
#include <stdlib.h>
#include "uart.h"
#include <util/delay.h>
#include <stdint.h>
#include "themistor-temp.h"
2024-03-20 14:27:59 +00:00
#include "fan_speeeed.h"
2024-04-21 10:43:51 +00:00
/*
void main_1() {
init_uart((uint16_t)9600);
stdout = &USART_stream;
2024-04-21 10:43:51 +00:00
TCA0_init ();*/
2024-04-16 11:25:51 +00:00
//PORT_init();
//test
2024-04-21 10:43:51 +00:00
//TCB0_Init();
2024-04-16 11:25:51 +00:00
2024-04-21 10:43:51 +00:00
//PORT_init();
//EVSYS_Init();
//PORTB_init();
// testsettup();
//TCB3.INTCTRL = 0b00000001; // Bit 0 ? CAPT Capture Interrupt Enable
2024-04-16 11:25:51 +00:00
2024-04-21 10:43:51 +00:00
//sei();
2024-04-10 12:53:17 +00:00
2024-04-21 10:43:51 +00:00
//while (1) {
2024-04-17 12:59:46 +00:00
/*
printf("loop");
2024-04-10 13:52:07 +00:00
uint16_t yo = TCB3.CNT;
printf("CNT %u", yo);
uint16_t stewui = TCB3.CCMP;
printf("CCMP %u", stewui);
2024-04-17 12:59:46 +00:00
*/
2024-04-21 10:43:51 +00:00
//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);
// ;
// }
//}
2024-04-17 12:59:46 +00:00
/*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;
2024-04-21 10:43:51 +00:00
}*/
#define F_CPU 4000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#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;
}