当前位置: 首页>>代码示例>>C++>>正文


C++ HardwareTimer类代码示例

本文整理汇总了C++中HardwareTimer的典型用法代码示例。如果您正苦于以下问题:C++ HardwareTimer类的具体用法?C++ HardwareTimer怎么用?C++ HardwareTimer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了HardwareTimer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: delay_us

void FLYMAPLEScheduler::init(void* machtnichts)
{
    delay_us(2000000); // Wait for startup so we have time to connect a new USB console
    // 1kHz interrupts from systick for normal timers
    systick_attach_callback(_timer_procs_timer_event);

    // Set up Maple hardware timer for 1khz failsafe timer
    // ref: http://leaflabs.com/docs/lang/api/hardwaretimer.html#lang-hardwaretimer
    _failsafe_timer.pause();
    _failsafe_timer.setPeriod(1000); // 1000us = 1kHz
    _failsafe_timer.setChannelMode(TIMER_CH1, TIMER_OUTPUT_COMPARE);// Set up an interrupt on channel 1
    _failsafe_timer.setCompare(TIMER_CH1, 1);  // Interrupt 1 count after each update
    _failsafe_timer.attachInterrupt(TIMER_CH1, _failsafe_timer_event);
    _failsafe_timer.refresh();// Refresh the timer's count, prescale, and overflow
    _failsafe_timer.resume(); // Start the timer counting
    // We run this timer at a higher priority, so that a broken timer handler (ie one that hangs)
    // will not prevent the failsafe timer interrupt.
    // Caution: the timer number must agree with the HardwareTimer number
    nvic_irq_set_priority(NVIC_TIMER2, 0x14);
}
开发者ID:Checkie,项目名称:ardupilot,代码行数:20,代码来源:Scheduler.cpp

示例2: baud_time_get

unsigned int baud_time_get() 
{
  #ifdef ___MAPLE  
    timer4.pause();
    unsigned int tmp = timer4.getCount();  //get current timer count
    timer4.setCount(0);                    // reset timer count
    timer4.refresh();
    timer4.resume();
  #endif

  #ifdef ___ARDUINO
    TCCR1B &= 0xF8;                        // Clear CS10/CS11/CS12 bits, stopping the timer
    unsigned int tmp = int(TCNT1/2);       // get current timer count, dividing by two
                                           // because Arduino timer is counting at 2Mhz instead of 1Mhz
                                           // due to limited prescaler selection
    tmp += 0x8000 * baudOverflow;          // if timer overflowed, we will add 0xFFFF/2
    TCNT1 = 0;                             // reset timer count    
    baudOverflow = false;                  // reset baudOverflow after resetting timer    
    TCCR1B |= (1 << CS11);                 // Configure for 8 prescaler, restarting timer
  #endif

  #ifdef ___TEENSY
    unsigned int tmp = int(FTM0_CNT*2.8);
    FTM0_CNT = 0x0;
  #endif
  
  return tmp;
}
开发者ID:bullud,项目名称:radioModem,代码行数:28,代码来源:baudtimer.cpp

示例3: StepperTimerInt

void IRAM_ATTR StepperTimerInt() {
	hardwareTimer.initializeUs(deltat, StepperTimerInt);
	hardwareTimer.startOnce();

	if (steppersOn) {
		uint32_t pin_mask_steppers = 0;
		//set direction pins
		for (int i = 0; i < 4; i++) {
			if (curPos[i] != nextPos[i]) {
				int8_t sign = -1;
				if (nextPos[i] > curPos[i])
					sign = 1;
				if (sign > 0)
					digitalWrite(dir[i], false);
				else
					digitalWrite(dir[i], true);
				curPos[i] = curPos[i] + sign;
				pin_mask_steppers = pin_mask_steppers | (1 << step[i]);
			}
		}
		delayMicroseconds(3);
		GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pin_mask_steppers);
		delayMicroseconds(5);
		GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pin_mask_steppers); // Set pin a and b low
		delayMicroseconds(5);
	}
}
开发者ID:zhivko,项目名称:SmingRTOS,代码行数:27,代码来源:application.cpp

示例4: dxl_serial_init

void dxl_serial_init(volatile struct dxl_device *device, int index)
{
    ASSERT(index >= 1 && index <= 3);

    // Initializing device
    struct serial *serial = (struct serial*)malloc(sizeof(struct serial));
    dxl_device_init(device);
    device->data = (void *)serial;
    device->tick = dxl_serial_tick;
    device->process = process;

    serial->index = index;
    serial->txComplete = true;
    serial->dmaEvent = false;

    if (index == 1) {
        serial->port = &Serial1;
        serial->direction = DIRECTION1;
        serial->channel = DMA_CH4;
    } else if (index == 2) {
        serial->port = &Serial2;
        serial->direction = DIRECTION2;
        serial->channel = DMA_CH7;
    } else {
        serial->port = &Serial3;
        serial->direction = DIRECTION3;
        serial->channel = DMA_CH2;
    }
            
    serial->syncReadCurrent = 0xff;
    serial->syncReadCount = 0;

    initSerial(serial);

    if (!serialInitialized) {
        serialInitialized = true;
    
        // Initializing DMA
        dma_init(DMA1);

        usart1_tc_handler = usart1_tc;
        usart2_tc_handler = usart2_tc;
        usart3_tc_handler = usart3_tc;

        // Reset allocation
        for (unsigned int k=0; k<sizeof(devicePorts); k++) {
            devicePorts[k] = 0;
        }

        // Initialize sync read timer
        syncReadTimer.pause();
        syncReadTimer.setPrescaleFactor(CYCLES_PER_MICROSECOND*10);
        syncReadTimer.setOverflow(0xffff);
        syncReadTimer.refresh();
        syncReadTimer.resume();
    }
}
开发者ID:RhobanProject,项目名称:Maplebot,代码行数:57,代码来源:dxl_serial.cpp

示例5: motor_read_current

void motor_read_current() {
  if (HAS_CURRENT_SENSING) {
    mot.current = analogRead(CURRENT_ADC_PIN) - 2048;

    if (abs(mot.current) > 500) {
      // Values that big are not taken into account. This is a bad hack and can
      // be optimized.
    } else {
      mot.averageCurrent =
          ((AVERAGE_FACTOR_FOR_CURRENT - 1) * mot.averageCurrent * PRESCALE +
           mot.current * PRESCALE) /
          (AVERAGE_FACTOR_FOR_CURRENT * PRESCALE);
    }

    if (currentDetailedDebugOn == true) {
      currentRawMeasures[currentMeasureIndex] = mot.current;
      currentTimming[currentMeasureIndex] = timer3.getCount();
      currentMeasureIndex++;
      if (currentMeasureIndex > (C_NB_RAW_MEASURES - 1)) {
        currentDetailedDebugOn = false;
        currentMeasureIndex = 0;
      }
    }
  }
}
开发者ID:RhobanProject,项目名称:Dynaban,代码行数:25,代码来源:motor.cpp

示例6: baud_timer_restart

void baud_timer_restart() 
{
  #ifdef ___MAPLE
    timer4.setCount(0); 
    timer4.refresh();  
  #endif
  
  #ifdef ___ARDUINO
    TCNT1 = 0;
    baudOverflow = false;   
  #endif   
  
  #ifdef ___TEENSY
    FTM0_CNT = 0x0;
  #endif     
}
开发者ID:bullud,项目名称:radioModem,代码行数:16,代码来源:baudtimer.cpp

示例7: serial_received

static void serial_received(struct serial *serial)
{
    dma_disable(DMA1, serial->channel);
    usart_tcie(serial->port->c_dev()->regs, 0);
    serial->dmaEvent = false;
    serial->txComplete = true;
    receiveMode(serial);
    serial->syncReadStart = syncReadTimer.getCount();
}
开发者ID:RhobanProject,项目名称:Maplebot,代码行数:9,代码来源:dxl_serial.cpp

示例8: OtaUpdate

void OtaUpdate() {
	uint8 slot;
	rboot_config bootconf;

	Serial.println("Updating...");

	hardwareTimer.stop();
	reportTimer.stop();

	sendToClients("Firmware ota update started...");

	// need a clean object, otherwise if run before and failed will not run again
	if (otaUpdater)
		delete otaUpdater;
	otaUpdater = new rBootHttpUpdate();

	sendToClients("Firmware ota update started...1");

	// select rom slot to flash
	bootconf = rboot_get_config();
	slot = bootconf.current_rom;
	if (slot == 0)
		slot = 1;
	else
		slot = 0;

#ifndef RBOOT_TWO_ROMS
	// flash rom to position indicated in the rBoot config rom table
	otaUpdater->addItem(bootconf.roms[slot], ROM_0_URL);
#else
	// flash appropriate rom
	if (slot == 0) {
		otaUpdater->addItem(bootconf.roms[slot], ROM_0_URL);
	} else {
		otaUpdater->addItem(bootconf.roms[slot], ROM_1_URL);
	}
#endif

#ifndef DISABLE_SPIFFS
	// use user supplied values (defaults for 4mb flash in makefile)
	if (slot == 0) {
		otaUpdater->addItem(RBOOT_SPIFFS_0, SPIFFS_URL);
	} else {
		otaUpdater->addItem(RBOOT_SPIFFS_1, SPIFFS_URL);
	}
#endif

	sendToClients("Firmware ota update started...2");
	// request switch and reboot on success
	otaUpdater->switchToRom(slot);
	// and/or set a callback (called on failure or success without switching requested)
	otaUpdater->setCallback(OtaUpdate_CallBack);

	// start update
	sendToClients("Firmware ota update started...3");
	otaUpdater->start();
}
开发者ID:zhivko,项目名称:SmingRTOS,代码行数:57,代码来源:application.cpp

示例9: ppm_decode_go

void ppm_decode_go()
{


	SerialUSB.print("Starting timer.. rising edge of D");
    SerialUSB.print(PPM_PIN);

	//start the timer counting.
	timer4.resume();
	//the timer is now counting up, and any rising edges on D16
	//will trigger a DMA request to clone the timercapture to the array

}
开发者ID:dotjairo,项目名称:tricopter,代码行数:13,代码来源:ppm-decode.cpp

示例10: begin

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, 10000);//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);*/

	/*
	 * Timer Configuation for Dynamixel bus
	 * 2013-04-03 ROBOTIS Changed it as the below codes
	 * Dynamixel bus used timer 2(channel 1) to check timeout for receiving data from the bus.
	 * So, don't use time 2(channel 1) in other parts.
	 * */
	// Pause the timer while we're configuring it
	timer.pause();

	// Set up period
	timer.setPeriod(1); // in microseconds

	// Set up an interrupt on channel 1
	timer.setMode(TIMER_CH1,TIMER_OUTPUT_COMPARE);
	timer.setCompare(TIMER_CH1, 1);  // Interrupt 1 count after each update
	timer.attachInterrupt(TIMER_CH1,TIM2_IRQHandler);

	// Refresh the timer's count, prescale, and overflow
	timer.refresh();

	// Start the timer counting
	//timer.resume();
	 dxl_initialize(0, baud);
}
开发者ID:planius,项目名称:ROBOTIS_CM9_Series,代码行数:56,代码来源:Dynamixel.cpp

示例11: process

/**
 * Processing master packets (sending it to the local bus)
 */
static void process(volatile struct dxl_device *self, volatile struct dxl_packet *packet)
{
    struct serial *serial = (struct serial*)self->data;
    dxl_serial_tick(self);

    if (serial->txComplete && !syncReadMode) {
        if (packet->instruction == DXL_SYNC_READ && packet->parameter_nb > 2) {
            ui8 i;
            syncReadMode = true;
            syncReadAddr = packet->parameters[0];
            syncReadLength = packet->parameters[1];
            syncReadDevices = 0;
            ui8 total = 0;

            for (i=0; (i+2)<packet->parameter_nb; i++) {
                ui8 id = packet->parameters[i+2];

                if (devicePorts[id]) {
                    struct serial *port = serials[devicePorts[id]];
                    if (port->syncReadCount == 0) {
                        port->syncReadCurrent = 0xff;
                        syncReadDevices++;
                    }
                    port->syncReadIds[port->syncReadCount] = packet->parameters[i+2];
                    port->syncReadOffsets[port->syncReadCount] = i;
                    port->syncReadCount++;
                    total++;
                }
            }

            syncReadTimer.refresh();
            syncReadResponse = (struct dxl_packet*)&self->packet;
            syncReadResponse->error = 0;
            syncReadResponse->parameter_nb = (syncReadLength+1)*total;
            syncReadResponse->process = false;
            syncReadResponse->id = packet->id;
        } else {
            // Forwarding the packet to the serial bus
            if (packet->id == DXL_BROADCAST || packet->id < 200) {
                self->packet.dxl_state = 0;
                self->packet.process = false;
                sendSerialPacket(serial, packet);
            }
        }
    }
}
开发者ID:RhobanProject,项目名称:Maplebot,代码行数:49,代码来源:dxl_serial.cpp

示例12: baud_timer_init

//Timer control routines
void baud_timer_init() 
{
  #ifdef ___MAPLE
    timer4.pause();                                    // Pause the timer while configuring it
    timer4.setMode(TIMER_CH1, TIMER_OUTPUT_COMPARE);   // Set up interrupt on channel 1
    timer4.setCount(0);                                // Reset count to zero
        
    timer4.setPrescaleFactor(72);                      // Timer counts at 72MHz/72 = 1MHz  1 count = 1uS
    timer4.setOverflow(0xFFFF);                        // reset occurs at 15.259Hz
    timer4.refresh();                                  // Refresh the timer's count, prescale, and overflow
    timer4.resume();                                   // Start the timer counting
  #endif

  #ifdef ___ARDUINO
    cli();                               // stop interrupts during configuration
    TCCR1A = 0;                          // Clear TCCR1A register
    TCCR1B = 0;                          // Clear TCCR1B register
    TCNT1  = 0;                          // Initialize counter value
    OCR1A  = 0xFFFF;                     // Set compare match register to maximum value
    TCCR1B |= (1 << WGM12);              // CTC mode
                                         // We want 1uS ticks, for 16MHz CPU, we use prescaler of 16
                                         // as 1MHz = 1uS period, but Arduino is lame and only has
                                         // 3 bit multiplier, we can have 8 (overflows too quickly)
                                         // or 64, which operates at 1/4 the desired resolution
    TCCR1B |= (1 << CS11);               // Configure for 8 prescaler
    TIMSK1 |= (1 << OCIE1A);             // enable compare interrupt
    sei();                               // re-enable interrupts 
  #endif    
  
  #ifdef ___TEENSY
    FTM0_MODE |= FTM_MODE_WPDIS;
    
    FTM0_CNT = 0;
    FTM0_CNTIN = 0;
    FTM0_SC |= FTM_SC_PS(7);
    FTM0_SC |= FTM_SC_CLKS(1);
    FTM0_MOD = 0xFFFF;
    FTM0_MODE |= FTM_MODE_FTMEN;
    /*
    PIT_LDVAL1 = 0x500000;
    PIT_TCTRL1 = TIE;
    PIT_TCTRL1 |= TEN;
    PIT_TFLG1 |= 1;
    */
  #endif  
}
开发者ID:bullud,项目名称:radioModem,代码行数:47,代码来源:baudtimer.cpp

示例13: setup_timer_int

void setup_timer_int() {
    // Pause the timer while we're configuring it
    timer.pause();

    // Set up period
    timer.setPeriod(TIMER_PERIODE); // in microseconds

    // Set up an interrupt on channel 1
    timer.setChannel1Mode(TIMER_OUTPUT_COMPARE);
    timer.setCompare(TIMER_CH1, 1);  // Interrupt 1 count after each update
    timer.attachCompare1Interrupt(timer_int_handler);

    // Refresh the timer's count, prescale, and overflow
    timer.refresh();

    // Start the timer counting
    timer.resume();
}
开发者ID:lomempow,项目名称:crim-flapping-bot,代码行数:18,代码来源:test-gps-xbee-2.cpp

示例14: dma_isr

//invoked as configured by the DMA mode flags.
void dma_isr()
{

	dma_irq_cause cause = dma_get_irq_cause(DMA1, DMA_CH1);
        //using serialusb to print messages here is nice, but
        //it takes so long, we may never exit this isr invocation
        //before the next one comes in.. (dma is fast.. m'kay)

	timer4.setCount(0);  // clear counter
	if(ppm_timeout) ppm_timeout=0;
	switch(cause)
	{
		case DMA_TRANSFER_COMPLETE:
			// Transfer completed
			//SerialUSB.println("DMA Complete");


			dma_data_captured=1;

			break;

		case DMA_TRANSFER_HALF_COMPLETE:
			// Transfer is half complete
			SerialUSB.println("DMA Half Complete");
			break;

		case DMA_TRANSFER_ERROR:
			// An error occurred during transfer
			SerialUSB.println("DMA Error");
			dma_data_captured=1;
			break;

		default:
			// Something went horribly wrong.
			// Should never happen.
			SerialUSB.println("DMA WTF");
			dma_data_captured=1;
			break;
	}

}
开发者ID:dotjairo,项目名称:tricopter,代码行数:42,代码来源:ppm-decode.cpp

示例15: setup

void setup() {
    // Set up the LED to blink
    pinMode(D13, OUTPUT);

    // Pause the timer while we're configuring it
    timer.pause();

    // Set up period
    timer.setPeriod(LED_RATE); // in microseconds

    // Set up an interrupt on channel 1
    timer.setChannel1Mode(TIMER_OUTPUT_COMPARE);
    timer.setCompare(TIMER_CH1, 1);  // Interrupt 1 count after each update
    timer.attachCompare1Interrupt(handler_led);

    // Refresh the timer's count, prescale, and overflow
    timer.refresh();

    // Start the timer counting
    timer.resume();
}
开发者ID:hendruw,项目名称:crim-flapping-bot,代码行数:21,代码来源:test_timer_int.cpp


注:本文中的HardwareTimer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。