Exemple #1
0
uint32_t PWMSetPeriod(uint8_t channel, uint32_t period) {
	if (channel > CHANNEL_C_TIMER_INDEX) {
		return 1;
	}
	if (eDVSMode != EDVS_MODE_INTERNAL && channel == 0) {
		return 1; // channel 0 taken for master/slave mode
	}
	LPC_TIMER_T * timer = halTimers[channel].timer;
	halTimers[channel].period = period;
	/**
	 * If the period equal 0, the timer is disable and its outputs are set as GPIO and driven low.
	 */
	if (period == 0) {
		Chip_TIMER_DeInit(timer); //Stop the timer
		Chip_TIMER_SetMatch(timer, 2, 0);
		halTimers[channel].enabled[0] = DISABLE;
		halTimers[channel].enabled[1] = DISABLE;
		Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, halTimers[channel].portGpio[0], halTimers[channel].pinGpio[0]);
		Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, halTimers[channel].portGpio[1], halTimers[channel].pinGpio[1]);
		Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, halTimers[channel].portGpio[0], halTimers[channel].pinGpio[0]);
		Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, halTimers[channel].portGpio[1], halTimers[channel].pinGpio[1]);
		Chip_SCU_PinMuxSet(halTimers[channel].port[0], halTimers[channel].pin[0], halTimers[channel].gpioMode[0]);
		Chip_SCU_PinMuxSet(halTimers[channel].port[1], halTimers[channel].pin[1], halTimers[channel].gpioMode[1]);
	} else {
		/**
		 * The channel match 2 is used as the controller of the base frequency.
		 * When there is a match on this channel, the timer is reset and the external match bit
		 * is set to 1.
		 * The M0 core is looking for this change and it sets the output of the channels to high.
		 */
		Chip_TIMER_Init(timer);
		Chip_TIMER_Disable(timer);
		Chip_TIMER_Reset(timer);
		/**
		 * The Main clock is running at 192Mhz so set the Prescaler in order to have
		 * a 1 Mhz timer. Timer_CLK = Main_CLK/ (PR+1)
		 */
		Chip_TIMER_PrescaleSet(timer, 191);
		Chip_TIMER_ResetOnMatchEnable(timer, 2);
		Chip_TIMER_StopOnMatchDisable(timer, 2);
		Chip_TIMER_MatchDisableInt(timer, 2);
		Chip_TIMER_SetMatch(timer, 2, period);
		//Reconfigure match channels!
		if (halTimers[channel].enabled[0]) {
			PWMSetWidth(channel, 0, halTimers[channel].witdh[0]);
		}
		if (halTimers[channel].enabled[1]) {
			PWMSetWidth(channel, 1, halTimers[channel].witdh[1]);
		}
		Chip_TIMER_ExtMatchControlSet(timer, 0, TIMER_EXTMATCH_SET, 2);
		// Clear interrupt pending
		timer->IR = 0xFFFFFFFF;
		Chip_TIMER_Enable(timer);
	}
	return 0;
}
Exemple #2
0
/*
 * @Brief   Disables timer peripheral
 * @param   timerNumber:   Timer number, 0 to 3
 * @return   nothing
 */
void Timer_DeInit(uint8_t timerNumber){
   NVIC_DisableIRQ(timer_sd[timerNumber].IRQn);
   Chip_TIMER_Disable(timer_sd[timerNumber].name);
   Chip_TIMER_DeInit(timer_sd[timerNumber].name);
}