Ejemplo n.º 1
0
void delta_sigma_start(uint32_t period, uint32_t range, uint8_t pins[],
                       uint8_t n_pins)
{
  // Stop the timer during configuration
  timer_set_run(FRC1, false);

  g_n_pins = n_pins;
  for (uint8_t i = 0; i < n_pins; ++i)
  {
    g_pins[i].gpio_mask = BIT(pins[i]);
    g_pins[i].duty = 0;
    g_pins[i].acc = 0;
    gpio_enable(pins[i], GPIO_OUTPUT);
  }
  g_range = range;

  timer_set_interrupts(FRC1, false);
  timer_set_divider(FRC1, TIMER_CLKDIV_256);
  if (period > TIMER_FRC1_MAX_LOAD)
  {
    printf("delta_sigma: period %u too large\n", period);
    period = TIMER_FRC1_MAX_LOAD;
  }
  timer_set_load(FRC1, period);
  timer_set_reload(FRC1, true);
  _xt_isr_attach(INUM_TIMER_FRC1, timer_isr, NULL);
  timer_set_interrupts(FRC1, true);
  timer_set_run(FRC1, true);
}
Ejemplo n.º 2
0
void user_init(void)
{
    uart_set_baud(0, 115200);

    /* configure GPIOs */
    gpio_enable(gpio_frc1, GPIO_OUTPUT);
    gpio_enable(gpio_frc2, GPIO_OUTPUT);
    gpio_write(gpio_frc1, 1);

    /* stop both timers and mask their interrupts as a precaution */
    timer_set_interrupts(FRC1, false);
    timer_set_run(FRC1, false);
    timer_set_interrupts(FRC2, false);
    timer_set_run(FRC2, false);

    /* set up ISRs */
    _xt_isr_attach(INUM_TIMER_FRC1, frc1_interrupt_handler);
    _xt_isr_attach(INUM_TIMER_FRC2, frc2_interrupt_handler);

    /* configure timer frequencies */
    timer_set_frequency(FRC1, freq_frc1);
    timer_set_frequency(FRC2, freq_frc2);

    /* unmask interrupts and start timers */
    timer_set_interrupts(FRC1, true);
    timer_set_run(FRC1, true);
    timer_set_interrupts(FRC2, true);
    timer_set_run(FRC2, true);

    gpio_write(gpio_frc1, 0);
}
Ejemplo n.º 3
0
void pwm_start()
{
    pwmInfo._onLoad = pwmInfo.dutyCicle * pwmInfo._maxLoad / UINT16_MAX;
    pwmInfo._offLoad = pwmInfo._maxLoad - pwmInfo._onLoad;
    pwmInfo._step = PERIOD_ON;

    // Trigger ON
    uint8_t i = 0;
    for (; i < pwmInfo.usedPins; ++i)
    {
        gpio_write(pwmInfo.pins[i].pin, true);
    }

    timer_set_load(FRC1, pwmInfo._onLoad);
    timer_set_reload(FRC1, false);
    timer_set_interrupts(FRC1, true);
    timer_set_run(FRC1, true);

    pwmInfo.running = 1;
}
Ejemplo n.º 4
0
void pwm_stop()
{
    timer_set_interrupts(FRC1, false);
    timer_set_run(FRC1, false);
    pwmInfo.running = 0;
}