Exemple #1
0
/**
* @brief Maps the timer to the outputs
*
* @param[in] pin	Pointer to pin configuration
*/
void SctConfig(sctPin_t * pin){

	Chip_SCU_PinMux(sct[pin->id].port,sct[pin->id].pin, SCU_MODE_INACT, sct[pin->id].func);
	Chip_SCTPWM_SetOutPin(LPC_SCT, sct[pin->id].ch , sct[pin->id].out);
	pin->duty_cycle = 0;
	Chip_SCTPWM_SetDutyCycle(LPC_SCT,sct[pin->id].ch, Chip_SCTPWM_PercentageToTicks(LPC_SCT, 0));
}
Exemple #2
0
static void pwm_2_init(void)
{
    uint8_t i = 0;

    /* Setup Board specific output pin */
    /* Enable SWM clock before altering SWM */
    Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);
    /* Connect SCT outputs. */
    for(i = 2; i < 4; i++)
    {
        Chip_SWM_MovablePortPinAssign(pwm_config[i].pin_mov, pwm_config[i].port, pwm_config[i].pin);
    }
    /* Disable SWM clock after altering SWM */
    Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM);

    Chip_SCTPWM_Init(LPC_SCT2);
    Chip_SCTPWM_SetRate(LPC_SCT2, PWM_2_RATE);

    for(i = 2; i < 4; i++)
    {
        /* Use SCT2_OUTx pin. */
        Chip_SCTPWM_SetOutPin(pwm_config[i].sct, pwm_config[i].index, i - 2);
        /* Start with 0% duty cycle */
        Chip_SCTPWM_SetDutyCycle(pwm_config[i].sct, pwm_config[i].index, 0);
    }

    Chip_SCTPWM_Start(LPC_SCT2);

    return;
}
Exemple #3
0
/**
 * Initialize the PWM.
 *
 * This function will initialize the PWM.
 * It will set the global frequency.
 * And it will enable any enabled pwm channel
 *
 * Note: In higher level functions we will use pwm channel 0 - 5, but in fact these are routed to logic channels 1 - 6.
 * This number conversion has been taken care of in all pwm functions.
 * We need to do this, because pwm logic channel 0 cannot be used. (See datasheet)
 * We fix this mapping in this init function, because we do not need to remap afterwards.
 * @param p_pwm 	p_pwm device
 * @param p_pwmConfig	configuration data
 * @return	status_ok if succeeded (otherwise check status.h for details).
 */
status_t PWM_Init(pwm_t* p_pwm, pwm_config_t *p_pwmConfig)
{
	status_t status = status_ok;
	uint8_t i;
	/* populate the pwm struct */
	p_pwm->frequency 	   = p_pwmConfig->frequency;
	for(i = 0; i < PWM_AMOUNTOFCHANNELS; i++)
	{
		p_pwm->dutycycle[i]		= p_pwmConfig->dutycycle[i];
		p_pwm->usechannel[i]	= p_pwmConfig->usechannel[i];
	}

	/* Initialize the SCT as PWM and set frequency */
	Chip_SCTPWM_Init(PWM_SCT);
	Chip_SCTPWM_SetRate(PWM_SCT, p_pwm->frequency);

	/* then enable the outputchannel, we here fix pins to logic channel + 1 (because channel 0 should not be used) */
	for(i = 0; i < PWM_AMOUNTOFCHANNELS; i++)
	{
		if(p_pwm->usechannel[i])
		{
			Chip_SCTPWM_SetOutPin(PWM_SCT, ctout1 + i, ctout0 + i);
		}
	}

	/* then set the dutycycles */
	for(i = 0; i < PWM_AMOUNTOFCHANNELS; i++)
	{
		if(status == status_ok)
		{
			if(p_pwm->usechannel[i])
			{
				status = PWM_setdutycycle(p_pwm, i, p_pwm->dutycycle[i]);
			}
		}
	}

	if(status == status_ok)
	{
		/* start the pwm */
		Chip_SCTPWM_Start(PWM_SCT);
	}

	return status;
}
Exemple #4
0
/* 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();
    }
}
Exemple #5
0
void Board_PWM_ConfigureOut(uint8_t outNumber)
{
	uint32_t indexCounter = calculatePwmIndexCounterByOutNumber(outNumber);
	Chip_SCU_PinMux(pwmsData[outNumber].port, pwmsData[outNumber].pin, MD_PUP|MD_EZI, pwmsData[outNumber].fnc);
        Chip_SCTPWM_SetOutPin(LPC_SCT, indexCounter, pwmsData[outNumber].ctout);
}
Exemple #6
0
 /*Configurar PinMUX, PinOUT, Frecuencia*/
void ConfigurarPWM(int Frec){

	/*Seteamos Frecuencia*/
	Chip_SCTPWM_SetRate(LPC_SCT,Frec);

	/*Seteamos pinMux*/
	/*****************/
	/******Leds*******/
	/*****************/
/* remapea P2_10 en CTOUT_2, LED1 y habilita el pull up
	Chip_SCU_PinMux(2,10,MD_PUP,FUNC1);
 remapea P2_11 en CTOUT_5, LED2 y habilita el pull up
	Chip_SCU_PinMux(2,11,MD_PUP,FUNC1);
 remapea P2_12 en CTOUT_4, LED3 y habilita el pull up
	Chip_SCU_PinMux(2,12,MD_PUP,FUNC1);*/
	/*****************/
	/******Pines*******/
	/*****************/
/* remapea P4_1 en CTOUT_1, GPIO2(1) y habilita el pull up*/
	Chip_SCU_PinMux(4,1,MD_PLN,FUNC1);
/* remapea P4_2 en CTOUT_0, GPIO2(2) y habilita el pull up*/
	Chip_SCU_PinMux(4,2,MD_PLN,FUNC1);
/* remapea P4_3 en CTOUT_3, GPIO2(3) y habilita el pull up*/
	Chip_SCU_PinMux(4,3,MD_PLN,FUNC1);
	/*****************/
	/******Leds*******/
	/*****************/

	/*Seteamos pinOUT de LED1
	Chip_SCTPWM_SetOutPin(LPC_SCT,10,2);
	Seteamos pinOUT de LED2
	Chip_SCTPWM_SetOutPin(LPC_SCT,11,5);
	Seteamos pinOUT de LED3
	Chip_SCTPWM_SetOutPin(LPC_SCT,12,4);*/
	/*****************/
	/******Pines*******/
	/*****************/
	/*Seteamos pinOUT de CTOUT_1. T_FIL1*/
	Chip_SCTPWM_SetOutPin(LPC_SCT,1,1);
	/*Seteamos pinOUT de CTOUT_0, T_FIL2*/
	Chip_SCTPWM_SetOutPin(LPC_SCT,2,0);
	/*Seteamos pinOUT de CTOUT_3, T_FIL3*/
	Chip_SCTPWM_SetOutPin(LPC_SCT,3,3);

		//LPC_SCT->CONFIG        |= (1 << 17)|(1 << 18);               // split timers, auto limit
	/******************************/
	/*****************************/
	/*****04/11/2015**************/
	  //  LPC_SCT->CTRL_L        |= (1 << 4);                // configure SCT1 as BIDIR
	  //  LPC_SCT->MATCH[5].U    = 180;                 // match on (half) PWM period

/*******************************/
	/*****************************/
	    /***********************/
	   /* LPC_SCT->MATCH[1].L     = 0;                     // match on duty cycle 1
	    LPC_SCT->MATCHREL[1].L  = 0;
	    LPC_SCT->MATCH[2].L     = 180;                     // match on duty cycle 2
	    LPC_SCT->MATCHREL[2].L  = 180;*/

	   /* LPC_SCT->EVENT[0].STATE = 0xFFFFFFFF;              // event 0 happens in all states
	    LPC_SCT->EVENT[0].CTRL  = (2 << 10) | (2 << 12);   // IN_0 falling edge only condition*/

	   /* LPC_SCT->EVENT[1].STATE = 0xFFFFFFFF;              // event 1 happens in all states
	    LPC_SCT->EVENT[1].CTRL  = (1 << 10) | (2 << 12);   // IN_0 rising edge only condition*/

	    /************************************/

	   /* LPC_SCT->EVENT[1].STATE = 0xFFFFFFFF;              // event 2 happens in all states
	    LPC_SCT->EVENT[1].CTRL  = (1 << 0) | (1 << 12);    // match 1 (DC1) only condition

	    LPC_SCT->EVENT[2].STATE = 0xFFFFFFFF;              // event 3 happens in all states
	    LPC_SCT->EVENT[2].CTRL  = (2 << 0) | (1 << 12);    // match 2 (DC2) only condition*/

	   /* LPC_SCT->OUT[0].SET     = (1 << 0) | (1 << 2);     // event 0 and 2 set OUT0 (blue LED)
	    LPC_SCT->OUT[0].CLR     = (1 << 2);                // event 2 clears OUT0 (blue LED)

	    LPC_SCT->OUT[1].SET     = (1 << 1);                // event 3 sets OUT1 (red LED)
	    LPC_SCT->OUT[1].CLR     = (1 << 0) | (1 << 1);     // event 0 and 3 clear OUT1 (red LED)*/
/**********************************/
	/*******04/11/2015**********/

	   /* LPC_SCT->RES           |= 0x0000000F; */             // toggle OUT0 and OUT1 on conflict
/***********************************/
	    //LPC_SCT->OUTPUT        |= 1;                       // default set OUT0 and and clear OUT1*/

	   /*****************/
	    /*int ix = (int) index;
	    	pSCT->EVENT[ix].CTRL = index | (1 << 12);
	    	pSCT->EVENT[ix].STATE = 1;

	    	pSCT->OUT[pin].SET = 1;
	    	pSCT->OUT[pin].CLR = 1 << ix;

	    	pSCT->OUT[pin].SET = 1 | (1 << ix);
	    	pSCT->OUT[pin].CLR = 1 << ix;
	    */
	    /*********************/


    LPC_SCT->OUT[2].SET     = (1 << 0) ;     // event 0 and 2 set OUT0 (blue LED)
	LPC_SCT->OUT[2].CLR     = (1 << 2);                // event 2 clears OUT0 (blue LED)

    LPC_SCT->OUT[3].SET     = (1 << 1);                // event 3 sets OUT1 (red LED)

    LPC_SCT->OUT[3].CLR     = (1 << 3) | (1 << 0);     // event 0 and 3 clear OUT1 (red LED)

	//LPC_SCT->OUT[3].CLR     = (1 << 3);     // event 0 and 3 clear OUT1 (red LED)



 }