This commit is contained in:
Elp03 2024-04-25 14:06:51 +02:00
parent 8649d59d8d
commit eb7d96dd82
3 changed files with 20 additions and 16 deletions

View File

@ -1,4 +1,4 @@
#include <avr/ioavr128db48.h> //#include <avr/ioavr128db48.h>
#include "fan_speeeed.h" #include "fan_speeeed.h"
#include "uart.h" #include "uart.h"
@ -50,22 +50,26 @@ void PORTB_init() {
#define DACREF_VALUE (VDACREF * 256 / VREF) #define DACREF_VALUE (VDACREF * 256 / VREF)
void init_ac(){ void init_ac0(){
// CONFIGURE PINS AS ANALOG INPUTS // CONFIGURE PINS AS ANALOG INPUTS
PORTD.PIN2CTRL = PORT_ISC_INPUT_DISABLE_gc; PORTD.PIN6CTRL &= ~ PORT_ISC_gm ;
PORTD.PIN6CTRL = PORT_ISC_INPUT_DISABLE_gc;
// SET BENCH MARK PORTD.PIN7CTRL &= ~ PORT_ISC_gm ;
PORTD.PIN7CTRL = PORT_ISC_INPUT_DISABLE_gc;
//Wincontroll disabled
AC0.CTRLB = 0x00;
//SELECT POSITIVER INPUTS muxs //SELECT POSITIVE AND NEGATIVE INPUTS FOR COMPARRISON
AC0.MUXCTRLA = AC_MUXPOS_AINP0_gc | AC_MUXNEG_DACREF_gc; // FAN USE PD6 & PD7, COMPARE WITH PD3
AC0.MUXCTRL = AC_MUXPOS_AINP3_gc | AC_MUXPOS_AINP1_gc | AC_MUXNEG_AINN0_gc ;
// OPTIONAL: ENABLE INNPUT PIN BY WRITING "1" TO OUTEN // OPTIONAL: ENABLE INNPUT PIN BY WRITING "1" TO OUTEN
AC0.CTRLA = 0x40; // 0b01000000 //AC0.CTRLA = 0x40; // 0b01000000
// ENABLE AC BY WRITING 1 TO ENABLE BIT IN ACN.CTRLA // ENABLE AC BY WRITING 1 TO ENABLE BIT IN ACN.CTRLA
AC0.CTRLA |= PIN0_bm; // 0b00000001 //AC0.CTRLA |= PIN0_bm; // 0b00000001
AC0.CTRLA = AC_ENABLE_bm | AC_INTMODE_NORMAL_POSEDGE_gc | AC_OUTEN_bm; //AC0.CTRLA = AC_ENABLE_bm | AC_INTMODE_NORMAL_POSEDGE_gc | AC_OUTEN_bm;
// SET CMP TO 1 // SET CMP TO 1
AC0.INTCTRL = 0x01; AC0.INTCTRL = 0x01;
@ -73,6 +77,7 @@ void init_ac(){
ISR(AC0_AC_vect){ // AC0 vec flag ISR(AC0_AC_vect){ // AC0 vec flag
AC0.STATUS |= 0x10; //CMP flag to 0. AC0.STATUS |= 0x10; //CMP flag to 0.
printf("yo");
} }
//----------------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------------

View File

@ -27,7 +27,7 @@ extern "C" {
void init_TCA0(); void init_TCA0();
void TCA0_update_period_ms (); void TCA0_update_period_ms ();
uint16_t RPM_calculation(uint16_t test, uint16_t time); uint16_t RPM_calculation(uint16_t test, uint16_t time);
void init_ac0();
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -35,12 +35,11 @@ int main(void) {
init_uart((uint16_t)9600); init_uart((uint16_t)9600);
stdout = &USART_stream; stdout = &USART_stream;
init_ac0();
sei(); sei();
PIN2_bm
/* Replace with your application code */ /* Replace with your application code */
while (1) { while (1) {
printf("loop");
} }
} }