This commit is contained in:
Elp03 2024-04-16 13:25:51 +02:00
parent 9cf37461d2
commit 58014e17d1
2 changed files with 41 additions and 6 deletions

View File

@ -62,6 +62,30 @@ void PORT_init(){
}
void TCB0_Init(void){
TCB3.CTRLB = TCB_CNTMODE_FRQPW_gc; /* Input Capture Frequency */
TCB3.EVCTRL = TCB_CAPTEI_bm; /* Event Input Enable: enabled */
TCB3.EVCTRL |= (1 << TCB_CAPTEI_bp | 1 << TCB_EDGE_bp | 1 << TCB_FILTER_bp); /* Event Input Enable: enabled */
TCB3.INTCTRL = TCB_CAPT_bm; /* Capture or Timeout: enabled */
TCB3.CTRLA = TCB_CLKSEL_DIV1_gc /* CLK_PER/1 (From Prescaler) - This is needed to be able to count to 40 Hz with a 4 Mhz system clock */
| TCB_ENABLE_bm /* Enable: enabled */
| TCB_RUNSTDBY_bm; /* Run Standby: enabled */
}
void EVSYS_Init(void)
{
/* Zero-cross detector 0 out linked to event channel 0 */
EVSYS.CHANNEL0 = EVSYS_CHANNEL0_PORTA_PIN5_gc;
/* TCB uses event channel 0 */
EVSYS.USERTCB0CAPT = EVSYS_USER_CHANNEL0_gc;
}
void PORT_Init(void)
{
PORTB.OUTSET |= PIN5_bm;
PORTB.DIRSET |= PIN5_bm;
}
//-----------------------------------------------------------------------------------------------------
//-------------------------------------- S E T U P-----------------------------------------------------
/*
ISR ( TCA0_OVF_vect ) {
@ -77,6 +101,8 @@ ISR (TCB3_INT_vect){
uint16_t yo = TCB3.CNT;
printf("CNT %u", yo);
printf("too");
uint16_t stewui = TCB3.CCMP;
printf("CCMP %u", stewui);

View File

@ -30,15 +30,24 @@ int main() {
init_uart((uint16_t)9600);
stdout = &USART_stream;
TCA0_init ();
PORT_init();
//PORT_init();
//test
TCB0_Init();
EVSYS_Init();
PORT_Init();
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);
//printf("loop");
//uint16_t yo = TCB3.CNT;
//printf("CNT %u", yo);
//uint16_t stewui = TCB3.CCMP;
//printf("CCMP %u", stewui)
;
}
}