示例#1
0
/**
 * Change the dutycycle of the selected channel.
 *
 * Note: we do channel conversion (+1) for correct logical channel mapping
 *
 * @param p_pwm 		p_pwm device
 * @param channel		channel (0 - 5)
 * @param dutycycle		wanted dutycycle (in percent)
 * @return	status_ok if succeeded (otherwise check status.h for details).
 */
status_t PWM_setdutycycle(pwm_t* p_pwm, pwm_channel_t channel, uint8_t dutycycle)
{
	status_t status = status_ok;
	uint32_t ticks = 0;


	if(dutycycle <= 100)
	{
		ticks = Chip_SCTPWM_GetTicksPerCycle(PWM_SCT);
		ticks = ticks / 100;
		ticks = ticks * dutycycle;
		Chip_SCTPWM_SetDutyCycle(PWM_SCT, channel + 1, ticks); /* we add + 1 because the logic channel is 1 more (we cannot use logic channel 0) */
	}
	else
	{
		status = pwm_dutycycle;
	}
	return status;
}
示例#2
0
void AnchoPulsoPWM(int dutyccycle,int index){

	/*Funcio */
	  if((dutyccycle < 50)&&(index==3)){
		  //Ver esto funcion mayor 50%
		 LPC_SCT->OUT[3].CLR     = (1 << 3);     // event 0 and 3 clear OUT1 (red LED)
	  }
	  if((dutyccycle >= 50)&&(index==3)) {
		  LPC_SCT->OUT[3].CLR    = (1 << 3) | (1 << 0);     // event 0 and 3 clear OUT1 (red LED)
	  }




	/*Dutycycle en porcentaje*/
	 Chip_SCTPWM_SetDutyCycle(LPC_SCT,index,Chip_SCTPWM_PercentageToTicks(LPC_SCT, dutyccycle));
	 /***********04/11/2015************/

	 /*Para que nadie modifique el desfasaje 180*/
	 /*LPC_SCT->MATCH[0].L     = 180;                 // match on (half) PWM period
	 LPC_SCT->MATCHREL[0].L = 180;*/
}
示例#3
0
文件: sct_pwm.c 项目: ttzeng/lpcopen
/* Example entry point */
int main(void)
{
    uint32_t cnt1 = 0, cnt2 = 0;
    int led_dp = 0, led_step = 1, out_dp = 0;

    /* Generic Initialization */
    SystemCoreClockUpdate();
    Board_Init();

    /* Initialize the SCT as PWM and set frequency */
    Chip_SCTPWM_Init(SCT_PWM);
    Chip_SCTPWM_SetRate(SCT_PWM, SCT_PWM_RATE);

    /* Setup Board specific output pin */
    app_setup_pin();

    /* Use SCT0_OUT1 pin */
    Chip_SCTPWM_SetOutPin(SCT_PWM, SCT_PWM_OUT, SCT_PWM_PIN_OUT);
    Chip_SCTPWM_SetOutPin(SCT_PWM, SCT_PWM_LED, SCT_PWM_PIN_LED);

    /* Start with 0% duty cycle */
    Chip_SCTPWM_SetDutyCycle(SCT_PWM, SCT_PWM_OUT, Chip_SCTPWM_GetTicksPerCycle(SCT_PWM) / 2);
    Chip_SCTPWM_SetDutyCycle(SCT_PWM, SCT_PWM_LED, 0);
    Chip_SCTPWM_Start(SCT_PWM);

    /* Enable SysTick Timer */
    SysTick_Config(SystemCoreClock / TICKRATE_HZ);

    while (1) {
        cnt1++;
        cnt2++;
        if (cnt1 >= OUT_STEP_CNT) {
            out_dp += 10;
            if (out_dp > 100) {
                out_dp = 0;
            }

            /* Increase dutycycle by 10% every second */
            Chip_SCTPWM_SetDutyCycle(SCT_PWM, SCT_PWM_OUT,
                                     Chip_SCTPWM_PercentageToTicks(SCT_PWM, out_dp));
            cnt1 = 0;
        }

        if (cnt2 >= LED_STEP_CNT) {
            led_dp += led_step;
            if (led_dp < 0) {
                led_dp = 0;
                led_step = 1;
            }
            if (led_dp > 200) {
                led_dp = 200;
                led_step = -1;
            }

            /* Increment or Decrement Dutycycle by 0.5% every 10ms */
            Chip_SCTPWM_SetDutyCycle(SCT_PWM, SCT_PWM_LED,
                                     Chip_SCTPWM_PercentageToTicks(SCT_PWM, led_dp) / 2);
            cnt2 = 0;
        }
        __WFI();
    }
}
示例#4
0
void Board_PWM_SetDutyCycle(uint8_t outNumber, uint8_t duty)
{
	uint32_t indexCounter = calculatePwmIndexCounterByOutNumber(outNumber);
	Chip_SCTPWM_SetDutyCycle(LPC_SCT, indexCounter,Chip_SCTPWM_PercentageToTicks(LPC_SCT, duty));
}
示例#5
0
/**
* @param[in] pin		Pointer to pin configuration
* @param[in] duty_cycle	Duty cycle
*/
void SctSetDutyCycle(sctPin_t * pin, uint8_t duty_cycle){
	Chip_SCTPWM_SetDutyCycle(LPC_SCT,sct[pin->id].ch , Chip_SCTPWM_PercentageToTicks(LPC_SCT, duty_cycle));
	pin->duty_cycle = duty_cycle;
}
示例#6
0
void pwm_set(pwm_id_t id, uint32_t duty_cycle)
{
    Chip_SCTPWM_SetDutyCycle(pwm_config[id].sct, pwm_config[id].index, duty_cycle);

    return;
}