示例#1
0
static void pwm_init(void) {
	uint32_t frequency = 50;

	uint32_t period1 = SysCtlClockGet() / frequency;
	uint32_t extender1 = period1 >> 16;
	period1 &= 0xFFFF;

	uint32_t period2 =  SysCtlClockGet() / frequency;
	uint32_t extender2 = period2 >> 16;
	period2 &= 0xFFFF;

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	GPIOPinConfigure(GPIO_PB2_T3CCP0);
	GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_2);
	// Configure timer
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER3);
	TimerConfigure(TIMER3_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM);
	HWREG(TIMER3_BASE + TIMER_O_CTL) |= (TIMER_CTL_TAPWML);
	//set period
	TimerPrescaleSet(TIMER3_BASE, TIMER_A, extender1);
	TimerLoadSet(TIMER3_BASE, TIMER_A, period1);
	//set default value A
	TimerPrescaleMatchSet(TIMER3_BASE, TIMER_A, extender2);
	TimerMatchSet(TIMER3_BASE, TIMER_A, period2);
	TimerEnable(TIMER3_BASE, TIMER_A);
}
示例#2
0
void control_init() {
  //// laser control
  // Setup Timer0 for a 488.28125Hz "phase correct PWM" wave (assuming a 16Mhz clock)
  // Timer0 can pwm either PD5 (OC0B) or PD6 (OC0A), we use PD6
  // TCCR0A and TCCR0B are the registers to setup Timer0
  // see chapter "8-bit Timer/Counter0 with PWM" in Atmga328 specs
  // OCR0A sets the duty cycle 0-255 corresponding to 0-100%
  // also see: http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM

	GPIOPinTypeGPIOOutput(LASER_EN_PORT, LASER_EN_MASK);
	GPIOPinWrite(LASER_EN_PORT, LASER_EN_MASK, LASER_EN_INVERT);

	// Configure timer
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
	TimerConfigure(LASER_TIMER, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM|TIMER_CFG_B_ONE_SHOT);
	TimerControlLevel(LASER_TIMER, TIMER_A, 1);

	// PPI = PWMfreq/(feedrate/MM_PER_INCH/60)

	// Set PPI Pulse timer
	ppi_cycles = SysCtlClockGet() / 1000 * CONFIG_LASER_PPI_PULSE_MS;
	ppi_divider = ppi_cycles >> 16;
	ppi_cycles /= (ppi_divider + 1);
	TimerPrescaleSet(LASER_TIMER, TIMER_B, ppi_divider);
	TimerLoadSet(LASER_TIMER, TIMER_B, ppi_cycles);

	// Setup ISR
	TimerIntRegister(LASER_TIMER, TIMER_B, laser_isr);
	TimerIntEnable(LASER_TIMER, TIMER_TIMB_TIMEOUT);
    IntPrioritySet(INT_TIMER0B, CONFIG_LASER_PRIORITY);

	// Set PWM refresh rate
	laser_cycles = SysCtlClockGet() / CONFIG_LASER_PWM_FREQ; /*Hz*/
	laser_divider = laser_cycles >> 16;
	laser_cycles /= (laser_divider + 1);

	// Setup Laser PWM Timer
	TimerPrescaleSet(LASER_TIMER, TIMER_A, laser_divider);
	TimerLoadSet(LASER_TIMER, TIMER_A, laser_cycles);
	TimerPrescaleMatchSet(LASER_TIMER, TIMER_A, laser_divider);
	laser_intensity = 0;

	// Set default value
	control_laser_intensity(0);
	control_laser(0, 0);

	TimerEnable(LASER_TIMER, TIMER_A);

	// ToDo: Map the timer ccp pin sensibly
	GPIOPinConfigure(GPIO_PB6_T0CCP0);
	GPIOPinTypeTimer(LASER_PORT, (1 << LASER_BIT));

	//// air and aux assist control
	GPIOPinTypeGPIOOutput(ASSIST_PORT, ASSIST_MASK);
	control_air_assist(false);
	control_aux1_assist(false);
}
void T0Init_sample(uint32 Periodic)
 {
    
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    TimerConfigure(TIMER0_BASE, TIMER_CFG_16_BIT_PAIR|TIMER_CFG_A_PERIODIC);
	TimerPrescaleMatchSet(TIMER0_BASE, TIMER_A,0x00 );//SysCtlClockGet()/(Periodic*sample_nub))/0x10000);
    TimerLoadSet(TIMER0_BASE, TIMER_A, Periodic); //
    TimerEnable(TIMER0_BASE, TIMER_A);

 }
示例#4
0
文件: motors.c 项目: dani6rg/IMU
/*
    Sets a given motor to a given percent value
    \param motor is the motor number (1-4)
    \param percent is the percentage to set (0-100)
    \return none
*/
void motorSet(int motor, float percent)
{   
    //sterilize input
    if (percent > 100) percent = 100;
    if (percent < 0) percent = 0;

    //prepare prescale and match values
    uint32_t cycles_per_ms = SysCtlClockGet() / 1000;
    //*debug: straight pwm leds- */uint32_t matchl = SysCtlClockGet() / MOTORUPDATE / 100 * percent;
    uint32_t matchl = cycles_per_ms + (uint32_t)(percent * (cycles_per_ms / 100));
    uint8_t matchh = matchl >> 16;
    matchl &= 0xFFFF;

    //write to correct pwm module
    switch (motor) {
        case 1: { TimerPrescaleMatchSet(TIMER1_BASE, TIMER_A, matchh); TimerMatchSet(TIMER1_BASE, TIMER_A, matchl); }
        case 2: { TimerPrescaleMatchSet(TIMER1_BASE, TIMER_B, matchh); TimerMatchSet(TIMER1_BASE, TIMER_B, matchl); }
        case 3: { TimerPrescaleMatchSet(TIMER2_BASE, TIMER_A, matchh); TimerMatchSet(TIMER2_BASE, TIMER_A, matchl); }
        case 4: { TimerPrescaleMatchSet(TIMER2_BASE, TIMER_B, matchh); TimerMatchSet(TIMER2_BASE, TIMER_B, matchl); }
    }
    
}
示例#5
0
static void pwm_set_width(uint32_t pulse_duration, uint8_t pulse_unit) {
	   uint32_t pwm_period;
	   switch(pulse_unit) {
		   case PULSE_100NS:
			   pwm_period = tics_100ns*pulse_duration;
			   break;
		   case PULSE_MS:
			   pwm_period = tics_ms*pulse_duration;
			   break;
		   case PULSE_US:
		   default:
			   pwm_period = tics_us*pulse_duration;
			   break;
	   }

	   uint16_t pwm_extender = pwm_period >> 16;
	   pwm_period &= 0xFFFF;
	   //uint8_t pwm_extender = 0;

	   TimerPrescaleMatchSet(TIMER3_BASE, TIMER_A, pwm_extender);
       TimerMatchSet(TIMER3_BASE, TIMER_A, pwm_period);
}