Fix comment, variables and function

add referance
This commit is contained in:
Elp03 2024-04-29 08:57:02 +02:00
parent ac5a054f8b
commit 772960d046
2 changed files with 8 additions and 5 deletions

View File

@ -2,7 +2,6 @@
#include "uart.h" #include "uart.h"
uint16_t timer_period_ms = 1; uint16_t timer_period_ms = 1;
uint16_t timer_period = 0.01;
uint16_t fan_speed = 0; uint16_t fan_speed = 0;
volatile uint16_t fan1_edge_counter = 0; volatile uint16_t fan1_edge_counter = 0;
volatile uint16_t fan2_edge_counter = 0; volatile uint16_t fan2_edge_counter = 0;
@ -11,11 +10,10 @@ volatile uint16_t fan2_edge_counter = 0;
void init_TCA0() { void init_TCA0() {
TCA0.SINGLE.INTCTRL = TCA_SINGLE_OVF_bm ; TCA0.SINGLE.INTCTRL = TCA_SINGLE_OVF_bm ;
TCA0.SINGLE.CTRLA = TCA_SINGLE_ENABLE_bm | TCA_SINGLE_CLKSEL_DIV1024_gc ; /* Sysclk /1024 */ TCA0.SINGLE.CTRLA = TCA_SINGLE_ENABLE_bm | TCA_SINGLE_CLKSEL_DIV1024_gc ; /* Sysclk /1024 */
//TCA0.SINGLE.PERBUF = 3906; TCA0_update_period(timer_period_ms);
TCA0_update_period();
} }
void TCA0_update_period() { void TCA0_update_period(uint16_t timer_period) {
TCA0.SINGLE.PERBUF = (F_CPU * (1 / timer_period) / 1024); /* F_CPU * F_IRQ / TCA_prescaler */ TCA0.SINGLE.PERBUF = (F_CPU * (1 / timer_period) / 1024); /* F_CPU * F_IRQ / TCA_prescaler */
} }

View File

@ -23,13 +23,18 @@ extern "C" {
#include <avr/interrupt.h> #include <avr/interrupt.h>
#include <avr/io.h> #include <avr/io.h>
/*
The code has inspiration from "Getting Started with Analog comparator(AC)" by Microchip for setting up analog comparrator.
* web link: https://ww1.microchip.com/downloads/aemDocuments/documents/MCU08/ApplicationNotes/ApplicationNotes/TB3211-Getting-Started-with-AC-DS90003211.pdf
* and inspiration form practice 6 for TCA0 setup
*/
// INITALICE TIMER COUNTER // INITALICE TIMER COUNTER
void init_TCA0(); void init_TCA0();
// UPDATE TIMER PERIOD // UPDATE TIMER PERIOD
void TCA0_update_period_ms (); void TCA0_update_period_ms (uint16_t timer_period);
// TAKES INN A TIME AND A THE COUNTED FAN DIPS // TAKES INN A TIME AND A THE COUNTED FAN DIPS
// RETURNS THE RPM OF THE FAN // RETURNS THE RPM OF THE FAN