//void _init(_codeur * codeur) //{ //// Codeur est un pointeur valide //if(codeur != NULL) //{ //codeur_raz(codeur); //codeur->sens = 0; // Avance par defaut (pas d'importance , juste pour initialisation) // //// permet de faire les calculs necessaires a l'initialisation, et pas pendant l'execution du code //codeur->coeffDep = ( M_PI * codeur->diaRoue) / (codeur->nbPasCodeur); //codeur->coeffVit = 1 / PERIODE; //} //} //void codeur_init(_codeur * codeur1) //{ // //_init(codeur1); //} void codeurs_init() { uint16_t lineCount = 1024; QDEC_Total_Setup(&PORTD, /*PORT_t * qPort*/ 0, /*uint8_t qPin*/ false, /*bool invIO*/ 0, /*uint8_t qEvMux*/ EVSYS_CHMUX_PORTD_PIN0_gc, /*EVSYS_CHMUX_t qPinInput*/ false, /*bool useIndex*/ EVSYS_QDIRM_00_gc, /*EVSYS_QDIRM_t qIndexState*/ &TCC0, /*TC0_t * qTimer*/ TC_EVSEL_CH0_gc, /*TC_EVSEL_t qEventChannel*/ lineCount); /*uint8_t lineCount*/ TC_Restart( &TCC0 ); TC_SetCount(&TCC0,10000); QDEC_Total_Setup(&PORTD, /*PORT_t * qPort*/ 2, /*uint8_t qPin*/ false, /*bool invIO*/ 2, /*uint8_t qEvMux*/ EVSYS_CHMUX_PORTD_PIN2_gc, /*EVSYS_CHMUX_t qPinInput*/ false, /*bool useIndex*/ EVSYS_QDIRM_00_gc, /*EVSYS_QDIRM_t qIndexState*/ &TCD0, /*TC0_t * qTimer*/ TC_EVSEL_CH2_gc, /*TC_EVSEL_t qEventChannel*/ lineCount); /*uint8_t lineCount*/ TC_Restart( &TCD0 ); TC_SetCount(&TCD0,10000); }
/** \brief Sets the period of the given timer, and restarts it from 0. * * Restarts the timer from 0, incrementing by 1 every timer clock cycle, and * changes the period of the timer to the given value. This also clears any CC * channels on the timer. * * \param[in] timer the timer to set (TIMER0 or TIMER1) * \param[in] period the new timer period (TOP) */ static void SM_timer_set_period(SM_timer_t timer, uint16_t period) { if (timer == SM_TIMER_NEEDLE) { TC_SetCount(&TIMER_RING, 0x0000); TC_SetPeriod(&TIMER_NEEDLE, period); } else { TC_SetCount(&TIMER_RING, 0x0000); TC_SetPeriod(&TIMER_RING, period); } }
/* This example shows how to configure TCC0 for basic timer operation. The timer will run at the main clock frequency (32MHz) so we need to do a bit of math to derive the number of clock cycles to arrive at the desired microsecond time out. */ void startTimer(uint16_t microseconds) { uint32_t cycles; // There are 31.25 nano seconds per clock cycle. // So we multiply the micro seconds by the clock period to determine // the number of clock cycles to achieve the microsecond timeout. // That number of cycles becomes our TOP value. // We will use 32 nano seconds to preclude floating point arithmetic. cycles = 32*microseconds; // Set period/TOP value. TCC0.CCA = cycles; // Set the CNT to 0. TC_SetCount(&TCC0, 0); /* Enable Input "Capture or Compare" channel A. */ TC0_EnableCCChannels( &TCC0, TC0_CCAEN_bm ); // Select clock source and start the timer. TC0_ConfigClockSource( &TCC0, TC_CLKSEL_DIV1_gc ); // Enable CCA interrupt. TC0_SetCCAIntLevel( &TCC0, TC_CCAINTLVL_LO_gc ); PMIC.CTRL |= PMIC_LOLVLEN_bm; }