Ejemplo n.º 1
0
//Config PA1 as an PWM output pin
void initPWM()
{
    //Timer is 16Mhz
    /* Enable module clock for the GPTx in Active mode, GPT0 clock enable, CPU running */
    REG(SYS_CTRL_RCGCGPT) |= SYS_CTRL_RCGCGPT_GPT0;

    disable_gptimer();

    /* Use 16-bit timer */
    REG(GPT_CONF_BASE + GPTIMER_CFG) = 0x04;

    /* Configure PWM mode, 0x00000008 Timer A alternate mode. */
    REG(GPT_CONF_BASE + GPTIMER_TAMR) = 0;
    REG(GPT_CONF_BASE + GPTIMER_TAMR) |= GPTIMER_TAMR_TAAMS;

    /* To enable PWM mode, the TACM bit must be cleared and the lowest 2 bits
       (TAMR) field must be configured to 0x2.
       GPTIMER_TnMR bit values, GPTIMER_TAMR_TAMR_PERIODIC is 0x00000002 */
    REG(GPT_CONF_BASE + GPTIMER_TAMR) |= GPTIMER_TAMR_TAMR_PERIODIC;

    //how often the counter is incremented:  every  pre-scaler / clock 16000000 seconds
    REG(GPT_CONF_BASE + GPTIMER_TAPR) = 0; 	        //PRESCALER_VALUE

    /* Set the start value (period), count down */
    REG(GPT_CONF_BASE+ GPTIMER_TAILR) = 16000;	    //frequency: 1kHz. 16000: 3E80, 16000000:F42400

    /* Set the deassert period */
    REG(GPT_CONF_BASE + GPTIMER_TAMATCHR) = 12800;  //duty cycle: 20% so vibrator time is 20%. 800: 0x1F40, 8000000: 7A1200

    // Defined in contiki/cpu/cc2538/dev/ioc.h
    /* Function select for Port:Pin.
       The third param sel can be any of the IOC_PXX_SEL_xyz defines.
       For example, IOC_PXX_SEL_UART0_TXD will set the port to act as UART0 TX.
       Selects one of the 32 pins on the four 8-pin I/O-ports (port A, port B, port C, and port D) to be the GPT0OCP1.
       Configure pin : PA:1 selected as GPT0OCP1*/
    ioc_set_sel(PWM_GPIO_CONF_PORT, PWM_GPIO_CONF_PIN, IOC_CONF_SEL);

    /* Set Port:Pin override function, IOC_OVERRIDE_OE: Output */
    ioc_set_over(PWM_GPIO_CONF_PORT, PWM_GPIO_CONF_PIN, IOC_OVERRIDE_OE);

    /* Configure the pin to be under peripheral control with PIN_MASK of port with PORT_BASE.*/
    GPIO_PERIPHERAL_CONTROL(GPIO_PORT_TO_BASE(PWM_GPIO_CONF_PORT), GPIO_PIN_MASK(PWM_GPIO_CONF_PIN));

    enable_gptimer();
}
Ejemplo n.º 2
0
void pwm_disable(struct pwm_device *pwm)
{
	disable_gptimer(pwm->id);
}
Ejemplo n.º 3
0
static void bfin_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
{
	struct bfin_pwm *priv = pwm_get_chip_data(pwm);

	disable_gptimer(priv->pin);
}