Example #1
0
void Dynamixel::begin(int baud) {
	//TxDString("[DXL]start begin\r\n");

	afio_remap(AFIO_REMAP_USART1);//USART1 -> DXL
	afio_cfg_debug_ports(AFIO_DEBUG_FULL_SWJ_NO_NJRST);
#ifdef BOARD_CM900  //Engineering version case

	 gpio_set_mode(PORT_ENABLE_TXD, PIN_ENABLE_TXD, GPIO_OUTPUT_PP);
	 gpio_set_mode(PORT_ENABLE_RXD, PIN_ENABLE_RXD, GPIO_OUTPUT_PP);
	 gpio_write_bit(PORT_ENABLE_TXD, PIN_ENABLE_TXD, 0 );// TX Disable
	 gpio_write_bit(PORT_ENABLE_RXD, PIN_ENABLE_RXD, 1 );// RX Enable
#else
	 gpio_set_mode(PORT_TXRX_DIRECTION, PIN_TXRX_DIRECTION, GPIO_OUTPUT_PP);
	 gpio_write_bit(PORT_TXRX_DIRECTION, PIN_TXRX_DIRECTION, 0 );// RX Enable
#endif
	 timer_set_mode(TIMER2, TIMER_CH1, TIMER_OUTPUT_COMPARE);

	 timer_pause(TIMER2);

	 uint16 ovf = timer_get_reload(TIMER2);
	 timer_set_count(TIMER2, min(0, ovf));

	 timer_set_reload(TIMER2, 30000);//set overflow

	 ovf = timer_get_reload(TIMER2);
	 timer_set_compare(TIMER2, TIMER_CH1, min(1000, ovf));

	 timer_attach_interrupt(TIMER2, TIMER_CH1, TIM2_IRQHandler);

	 timer_generate_update(TIMER2);
	 timer_resume(TIMER2);

	 dxl_initialize(0, baud);
}
Example #2
0
// TimerChannel
void TimerChannel::init(const pin_timer_channel_t *tpin)
{
    _timer = tpin->timer;
    _channel = tpin->channel;
    _pin = tpin->pin;

    pinMode(_pin, PWM);
    timer_port *timer = timer_dev_table[_timer].base;
    switch(_channel)
    {
        case 1:
            timer->CCMR1 &= ~(0x00FF);
            timer->CCMR1 |= 0x0040;
            timer->CCER |= 0x0001;
            break;
        case 2:
            timer->CCMR1 &= ~(0xFF00);
            timer->CCMR1 |= 0x4000;
            timer->CCER |= 0x0010;
            break;
        case 3:
            timer->CCMR2 &= ~(0x00FF);
            timer->CCMR2 |= 0x0040;
            timer->CCER |= 0x0100;
            break;
        case 4:
            timer->CCMR2 &= ~(0xFF00);
            timer->CCMR2 |= 0x4000;
            timer->CCER |= 0x1000;
            break;
    }
    timer_attach_interrupt(_timer, _channel, tpin->isr);
    timer_set_compare_value(_timer, _channel, 0);
}
Example #3
0
void TIM2_init() {
  uint32_t SystemCoreClock = 72000000;
  uint16_t prescalerValue = (uint16_t) (SystemCoreClock / 24000000) - 1;
  rcc_clk_enable(RCC_TIMER2);
  /* Time base configuration */
  timer_pause(TIMER2);
  timer_set_prescaler(TIMER2, prescalerValue);
  timer_set_reload(TIMER2, 29); // 800kHz
  
  /* Timing Mode configuration: Channel 1 */
  timer_set_mode(TIMER2, 1, TIMER_OUTPUT_COMPARE);
  timer_set_compare(TIMER2, 1, 8);
  timer_oc_set_mode(TIMER2, 1, TIMER_OC_MODE_FROZEN, ~TIMER_OC_PE);

  /* Timing Mode configuration: Channel 2 */
  timer_set_mode(TIMER2, 2, TIMER_OUTPUT_COMPARE);
  timer_set_compare(TIMER2, 2, 17);
  timer_oc_set_mode(TIMER2, 2, TIMER_OC_MODE_PWM_1, ~TIMER_OC_PE);
  //timer_resume(TIMER2);


  timer_attach_interrupt(TIMER2, TIMER_UPDATE_INTERRUPT, TIM2_IRQHandler);
  /* configure TIM2 interrupt */
  nvic_irq_set_priority(NVIC_TIMER2, 2);
  nvic_irq_enable(NVIC_TIMER2);
}
Example #4
0
/**
 * Non-blocking piezo/headphone beep
 */
void buzzer_nonblocking_buzz(float time, bool piezo, bool headphones) {

	// No need to go further if both outputs are
	// false
  if (!(piezo || headphones))
	  return;
  piezo_out = piezo;
  headphones_out = headphones;
  buzz_time = 4100*time*2;

  // Configure timer2 to fire every N microseconds
  timer_pause(TIMER2);
  timer_set_prescaler(TIMER2,1);
  timer_set_reload(TIMER2,(125*CYCLES_PER_MICROSECOND)/2);

  // setup interrupt on channel 2
  timer_set_mode(TIMER2,TIMER_CH2,TIMER_OUTPUT_COMPARE);
  timer_set_compare(TIMER2,TIMER_CH2,MAX_RELOAD-1);
  timer_attach_interrupt(TIMER2,TIMER_CH2,buzzer_handler);

  // start timer2
  buzz_count=0;
  timer_generate_update(TIMER2); // refresh timer count, prescale, overflow
  timer_resume(TIMER2);
}
Example #5
0
void DmxClass::begin(uint16 n) {
  SerialUSB.println("DMX begin");
  this->number_of_channels = n; // red, green, and blue are independent channels
  //SerialUSB.end();
  
  // initializes timer configurations
  timer_pause(this->dmx_timer);
  timer_set_prescaler(this->dmx_timer, 1); 
  timer_set_reload(this->dmx_timer, 288); // 4 us = 288 clock pulses @ 72MHz
  timer_generate_update(this->dmx_timer); // update new reload value
  timer_set_mode(this->dmx_timer, dmx_timer_ch, TIMER_OUTPUT_COMPARE);
  timer_set_compare(this->dmx_timer, dmx_timer_ch, 1); // test
  timer_attach_interrupt(this->dmx_timer, TIMER_CC1_INTERRUPT, dmx_handler_hack);
  timer_resume(this->dmx_timer);
}
Example #6
0
void buzzer_nonblocking_buzz(float time) {

  buzz_time = 4100*time*2;

  // Configure timer2 to fire every N microseconds
  timer_pause(TIMER2);
  timer_set_prescaler(TIMER2,1);
  timer_set_reload(TIMER2,(125*CYCLES_PER_MICROSECOND)/2);

  // setup interrupt on channel 2
  timer_set_mode(TIMER2,TIMER_CH2,TIMER_OUTPUT_COMPARE);
  timer_set_compare(TIMER2,TIMER_CH2,MAX_RELOAD-1);
  timer_attach_interrupt(TIMER2,TIMER_CH2,buzzer_handler);

  // start timer2
  buzz_count=0;
  timer_generate_update(TIMER2); // refresh timer count, prescale, overflow
  timer_resume(TIMER2);
}
void HardwareTimer::attachInterrupt(int channel, voidFuncPtr handler) {
    timer_attach_interrupt(this->dev, (uint8)channel, handler);
}
Example #8
0
void speaker_attachInterrupt(int channel, voidFuncPtr handler) {
    timer_attach_interrupt(SPEAKER_TIMER, (uint8)channel, handler);
}