Beispiel #1
0
void samrt_servo_init(void)
{
  pinMode(SMART_SERVO_LED_R,GPIO_PMD_OUTPUT);
  pinMode(SMART_SERVO_LED_G,GPIO_PMD_OUTPUT);
  pinMode(SMART_SERVO_LED_B,GPIO_PMD_OUTPUT);   
  pinMode(SMART_SERVO_SLEEP,GPIO_PMD_OUTPUT);

  digitalWrite(SMART_SERVO_LED_R,0);
  digitalWrite(SMART_SERVO_LED_G,1);
  digitalWrite(SMART_SERVO_LED_B,0);
  digitalWrite(SMART_SERVO_SLEEP,1);
	
//  pinMode(SMART_SERVO_PW1,GPIO_PMD_OUTPUT);
//  pinMode(SMART_SERVO_PW2,GPIO_PMD_OUTPUT);
//  digitalWrite(SMART_SERVO_PW1,0);
//  digitalWrite(SMART_SERVO_PW2,0);
  pwm_init(SMART_SERVO_PW1,500);
  pwm_init(SMART_SERVO_PW2,500);

//  pinMode(SMART_SERVO_PW1,GPIO_PMD_OUTPUT);
//  pinMode(SMART_SERVO_PW2,GPIO_PMD_OUTPUT);
//  digitalWrite(SMART_SERVO_PW1,1);
//  digitalWrite(SMART_SERVO_PW2,1);
	
  smart_servo_cur_pos = adc_get_position_value();
  smart_servo_pre_pos = smart_servo_cur_pos;
	smart_servo_target_pos = smart_servo_cur_pos;
  smart_servo_speed = SMART_SERVO_PER_SPPED_MAX;
}
Beispiel #2
0
int main (void)
{
    SystemInit();

    pwm_init(PWM_CH0);
    pwm_io_config();
    //P2.7 will output pwm wave with period for 1000us and pulse for 400us
    pwm_config(PWM_CH0, PWM_PSCAL_DIV, PWM_COUNT_US(1000, PWM_PSCAL_DIV), PWM_COUNT_US(400, PWM_PSCAL_DIV));
    pwm_enable(PWM_CH0, MASK_ENABLE);
    
    pwm_config(PWM_CH0, PWM_PSCAL_DIV, PWM_COUNT_US(1000, PWM_PSCAL_DIV), PWM_COUNT_US(800, PWM_PSCAL_DIV));
    pwm_config(PWM_CH0, PWM_PSCAL_DIV, PWM_COUNT_US(1000, PWM_PSCAL_DIV), PWM_COUNT_US(1000, PWM_PSCAL_DIV));
    pwm_config(PWM_CH0, PWM_PSCAL_DIV, PWM_COUNT_US(1000, PWM_PSCAL_DIV), PWM_COUNT_US(0, PWM_PSCAL_DIV));
    pwm_config(PWM_CH0, PWM_PSCAL_DIV, PWM_COUNT_US(1000, PWM_PSCAL_DIV), PWM_COUNT_US(400, PWM_PSCAL_DIV));
    pwm_config(PWM_CH0, PWM_PSCAL_DIV, PWM_COUNT_US(1000, PWM_PSCAL_DIV), PWM_COUNT_US(800, PWM_PSCAL_DIV));
    pwm_config(PWM_CH0, PWM_PSCAL_DIV, PWM_COUNT_US(1000, PWM_PSCAL_DIV), PWM_COUNT_US(1000, PWM_PSCAL_DIV));
    pwm_config(PWM_CH0, PWM_PSCAL_DIV, PWM_COUNT_US(1000, PWM_PSCAL_DIV), PWM_COUNT_US(0, PWM_PSCAL_DIV));
    pwm_config(PWM_CH0, PWM_PSCAL_DIV, PWM_COUNT_US(1000, PWM_PSCAL_DIV), PWM_COUNT_US(800, PWM_PSCAL_DIV));
    pwm_enable(PWM_CH0, MASK_DISABLE);
    pwm_io_dis_config();

    pwm_init(PWM_CH1);
    pwm_io_config();
    //P2.6 will output pwm wave with period for 1500us and pulse for 1000us
    pwm_config(PWM_CH1, 119, PWM_COUNT_US(1500, 119), PWM_COUNT_US(1000, 119));
    pwm_enable(PWM_CH1, MASK_ENABLE);
    pwm_io_dis_config();

    while (1)                                /* Loop forever */
    {

    }
}
Beispiel #3
0
void set_dvfs(unsigned int domain, unsigned int index)
{
	int cur, to;
	static int init_flag = 0;
	if (!init_flag) {
		pwm_init(pwm_f);
		pwm_init(pwm_ao_a);
		init_flag = 1;
	}
	cur = dvfs_get_voltage(domain);
	for (to = 0; to < ARRAY_SIZE(pwm_voltage_table); to++) {
		if (domain == 0) {
			if (pwm_voltage_table[to][1] >= cpu_dvfs_tbl[index].volt_mv) {
				break;
			}
		}
		if (domain == 1) {
			if (pwm_voltage_table[to][1] >= vlittle_dvfs_tbl[index].volt_mv) {
				break;
			}
		}
	}
	if (to >= ARRAY_SIZE(pwm_voltage_table)) {
		to = ARRAY_SIZE(pwm_voltage_table) - 1;
	}
	if (cur < 0 || cur >=ARRAY_SIZE(pwm_voltage_table)) {
		if (domain == 0)
			P_AO_PWM_PWM_A = pwm_voltage_table[to][0];
		if (domain == 1)
			P_PWM_PWM_F  = pwm_voltage_table[to][0];
		_udelay(200);
		return ;
	}
	while (cur != to) {
		/*
		 * if target step is far away from current step, don't change
		 * voltage by one-step-done. You should change voltage step by
		 * step to make sure voltage output is stable
		 */
		if (cur < to) {
			if (cur < to - 3) {
				cur += 3;
			} else {
				cur = to;
			}
		} else {
			if (cur > to + 3) {
				cur -= 3;
			} else {
				cur = to;
			}
		}
		if (domain == 0)
			P_AO_PWM_PWM_A = pwm_voltage_table[cur][0];
		if (domain == 1)
			P_PWM_PWM_F  = pwm_voltage_table[to][0];
		_udelay(100);
	}
	_udelay(200);
}
/**
 * \brief Example 1 main application routine
 */
int main( void )
{
    /* The 4 PWM config structs */
    struct pwm_config pwm_cfg[4];

    /* Initialize sysclock */;
    sysclk_init();

    /* Set up all 4 PWM channels with 500 Hz frequency. We want to use TCE0
       since this is where our LEDs are connected (PE0-PE3) */
    pwm_init(&pwm_cfg[0], PWM_TCE0, PWM_CH_A, 500); /* LED0 / PE0 */
    pwm_init(&pwm_cfg[1], PWM_TCE0, PWM_CH_B, 500); /* LED1 / PE1 */
    pwm_init(&pwm_cfg[2], PWM_TCE0, PWM_CH_C, 500); /* LED2 / PE2 */
    pwm_init(&pwm_cfg[3], PWM_TCE0, PWM_CH_D, 500); /* LED3 / PE3 */

    /* Start all 4 PWM channels with different duty cycles
      (which means different LED intensity).
      Since the LEDs are active low, 0% duty cycle means constantly lit */
    pwm_start(&pwm_cfg[0], 97);
    pwm_start(&pwm_cfg[1], 85);
    pwm_start(&pwm_cfg[2], 60);
    pwm_start(&pwm_cfg[3], 0);

    while(1) {
        /* Nothing to do */
    }
}
Beispiel #5
0
void init(void)
{
	sys_init();
	pwm_init(&pwm0);
	pwm_init(&pwm1);
	pwm_init(&pwm2);
	pwm_init(&pwm3);
}
Beispiel #6
0
void power_init(int mode)
{
	pwm_init(pwm_b);
	pwm_init(pwm_d);
	serial_puts("set vcck to ");
	serial_put_dec(CONFIG_VCCK_INIT_VOLTAGE);
	serial_puts(" mv\n");
	pwm_set_voltage(pwm_b, CONFIG_VCCK_INIT_VOLTAGE);
	serial_puts("set vddee to ");
	serial_put_dec(CONFIG_VDDEE_INIT_VOLTAGE);
	serial_puts(" mv\n");
	pwm_set_voltage(pwm_d, CONFIG_VDDEE_INIT_VOLTAGE);
}
Beispiel #7
0
int main (void)
{
	mode_pointer = &mode_time; //assigns the mode_pointer initially to time mode
		
	pwm_init();
	timer_init();
	analog_init();
	pinchange_init();
	power_register_init();
	sei(); // global set enable interrupts
		
	while(1)
    {
		PRR &= ~(1<<PRADC); //turns on the ADC comparator
		PORTA |= (1<<MODE_SELECT_POWER); //turn on to power pot
		ADCSRA |= (1<<ADSC); // starts AtoD conversion by flipping ADC Start Conversion bit in AD Control and Status Register A
		while(ADCSRA & (1<<ADSC));  // loops while waiting for ADC to finish
		PORTA &= ~(1<<MODE_SELECT_POWER); //turn pot back off to conserve power
		PRR |= (1<<PRADC); //shuts down the ADC and comparator
		
		
		
		(*mode_pointer)();  //uses a pointer to call the function for the specific mode
		
		sleep_cpu();
		//just hang out and wait for interrupts
		
    }
	
	return 1;
}
Beispiel #8
0
void init_modules()
{
	gpio_init();
	an_init();
	spi_init();
	pwm_init();
}
Beispiel #9
0
int main(void) {
  WDTCTL = WDTPW + WDTHOLD;   // Stop WDT
  // configure the CPU clock (MCLK)
  // to run from SMCLK: DCO @ 16MHz and SMCLK = DCO
  // If no DCO calibration => stop here by loop
  if(CALBC1_16MHZ==0xff)
    while(1)
      _NOP();
  _BIC_SR(GIE);
  DCOCTL = 0;
  BCSCTL1= CALBC1_16MHZ;
  DCOCTL = CALDCO_16MHZ;
  
  clock_init();
  uart_init();
  motor_init();
  protocols_init();
  pwm_init();

  // ----------
  // **action**
  // ----------
  _BIS_SR(GIE);
  
  FOREVER {
    // read input
    input_scanner();
    // handle any pending state changes in motor
    motor_step();
    // send status reports to pi
    reporter();
  }
}
Beispiel #10
0
void lib_low_level_init()
{
	#ifdef _GPIO_H_
	gpio_init();
	#endif

	#ifdef _UART_H_
	uart_init(); 
	#endif

	#ifdef _TIMER_H_
	timer_init();
	#endif

	#ifdef _PWM_H_
	pwm_init();
	#endif

	#ifdef _I2C_H_
	i2c_0_init();
	#endif

	#ifdef _SPI_H_
	spi_init();
	#endif


	#ifdef _ADC_H_
	adc_init();
	#endif
}
Beispiel #11
0
int main(void)
{
  int16_t signe = 1;
  
  DDRG=0x3;
  PORTG=0x0;

  pwm_init();
  

  while(1)
    {
      pwm_set(NUM, 1 * signe); // not 0 to test for sign problems
      wait_ms(2* DELAY);

      pwm_set(NUM, P_MAX /2 * signe);
      wait_ms(DELAY);
      
      pwm_set(NUM, P_MAX* signe);
      wait_ms(DELAY);
      
      pwm_set(NUM, P_MAX /2 * signe);
      wait_ms(DELAY);

      signe *= -1;
    }

  return 0;
}
Beispiel #12
0
int main()
{
	unsigned int i;
	pwm_init();
	
	while(1);
	while(1)
	{
		for(i=0;i<=100;i++)
		{
			PWMMR1 	-= 10;
			PWMLER	= (1<<1);		// Load values to PWMMR1 
			delay(100);
		}

		for(i=0;i<=100;i++)
		{
			PWMMR1 	+= 10;
			PWMLER	= (1<<1);		// Load values to PWMMR1 
			delay(100);
		}
		
	}
	  
	
	
}
Beispiel #13
0
Motors::Motors(void) {
  if(pwm_init(MOT_PWM, MODE, FREQU, MAX_PWM) == 0) {
    setState(ERROR);
    return;
  }

  if(gpio_init(MOT1_DIR1, GPIO_OUT) != 0) {
    setState(ERROR);
    return;
  }

  if(gpio_init(MOT1_DIR2, GPIO_OUT) != 0) {
    setState(ERROR);
    return;
  }

  if(gpio_init(MOT2_DIR1, GPIO_OUT) != 0) {
    setState(ERROR);
    return;
  }

  if(gpio_init(MOT2_DIR2, GPIO_OUT) != 0) {
    setState(ERROR);
    return;
  }

  left().put(0);
  right().put(0);
}
Beispiel #14
0
/**
 * @brief Function for application main entry.
 */
int main(void)
{
    uint8_t new_duty_cycle;
    uint32_t err_code;

    lfclk_init();

    // Start APP_TIMER to generate timeouts.
    APP_TIMER_INIT(APP_TIMER_PRESCALER, OP_QUEUES_SIZE, NULL);

    /*Initialize low power PWM for all 3  channels of RGB or 3 channels of leds on pca10028*/
    pwm_init();

    while (true)
    {
        /* Duty cycle can also be changed from main context. */
        new_duty_cycle = low_power_pwm_2.period - low_power_pwm_2.duty_cycle;
        err_code = low_power_pwm_duty_set(&low_power_pwm_2, new_duty_cycle);
        APP_ERROR_CHECK(err_code);
        nrf_delay_ms(500);

        new_duty_cycle = low_power_pwm_2.period - low_power_pwm_2.duty_cycle;
        err_code = low_power_pwm_duty_set(&low_power_pwm_2, new_duty_cycle);
        APP_ERROR_CHECK(err_code);
        nrf_delay_ms(500);
    }
}
Beispiel #15
0
/*********************************************************************
  
  Main Program Loop

**********************************************************************/
int main()
{

  /* Initializations */
  debug_init();     /* This should be first. */
  timer_init();

  /* This should be before any GPIO activities. */
  uint32 ret_val = bcm2835_init(); 
  if ( ret_val == 0 )
  {
    DEBUG_MSG_ERROR("bcm2835_init() failed.");
  }

  pwm_init();
  pump_init();
  therm_init();
  pid_init();

  pump_start();

  /* Take temperature as input from console. */
  float setpoint;
  printf("Set your desired temperature: ");
  scanf("%f", &setpoint);
  pid_update_temp_setpoint(setpoint);

  pid_gain_params pid_gain;
  pid_gain.k_p = 1;
  pid_gain.k_d = 1;
  pid_gain.k_i = 1;
  pid_gain.k_windup = 1;
  pid_set_gain(&pid_gain);

  /* Main Program Loop */
  while (1)
  {
    pwm_run();
    therm_capture();
    pid_loop();
  }

  pump_stop();

  /* De-initializations */
  pump_deinit();
  pid_deinit();
  pwm_deinit();

  /* This should be after all GPIO activities. */
  ret_val = bcm2835_close();
  if ( ret_val == 0 )
  {
    DEBUG_MSG_ERROR("bcm2835_close() failed.");
  }
  timer_deinit();
  debug_deinit();   /* This should be last. */

  return 0;
}
Beispiel #16
0
/*---------------------------------------------------------------------------*/
void board_init()
{
	uint8_t int_disabled = ti_lib_int_master_disable();

	/* Turn on relevant PDs */
	wakeup_handler();

	/* Enable GPIO peripheral */
	ti_lib_prcm_peripheral_run_enable(PRCM_PERIPH_GPIO);

	/* Apply settings and wait for them to take effect */
	ti_lib_prcm_load_set();
	while (!ti_lib_prcm_load_get()) ;

	lpm_register_module(&srf_module);

	/* Re-enable interrupt if initially enabled. */
	if (!int_disabled) {
		ti_lib_int_master_enable();
	}

	/* Init of PWM */
	pwm_init();

}
int main (void) {		
	
	adc_init();
	pwm_init();
	uart_init(0);
	
	SysTick_Config(48000000/1000); // systick every 1 ms
	//             Hz      /ticks per sec
	
	while (1) {
		adc_measure(&adcval);
		counter++;
		if(counter == 1)
			adcval_prev = adcval;
		else
			adcval_prev = (adcval_prev + adcval)/2;

		if(counter > filter_limit-1)
		{
			adcval_filtered = adcval_prev;
			if(adcval_filtered < min_distance)
				pwm_systick_control(10);
			else if (adcval_filtered < 10000)
				pwm_systick_control(adcval_filtered%100);
			else
				pwm_systick_control(100);
			counter = 0;
		}
		
	}
	
	return(0);
}
Beispiel #18
0
/** Main initialisation. */
static void
main_init (void)
{
#ifndef HOST
    /* Disable watchdog (enabled in bootloader). */
    MCUSR &= ~(1 << WDRF);
    wdt_disable ();
#endif
    /* Serial port */
    uart0_init ();
    /* Enable interrupts */
    sei ();
    /* Main timer */
    timer_init ();
    timer_wait ();
    /* TWI communications */
    asserv_init ();
    mimot_init ();
    twi_master_init ();
    /* IO modules. */
    pwm_init ();
    contact_init ();
    codebar_init ();
    usdist_init ();
    /* AI modules. */
    clamp_init ();
    logistic_init ();
    path_init ();
    /* Initialization done. */
    proto_send0 ('z');
}
Beispiel #19
0
void servo_init(Leg *legs){
	//Set up the servos using the leg details + status LEDs
	volatile uint8_t *ports[PWM_COUNT];
	uint8_t pins[PWM_COUNT];

	for (uint8_t l = 0; l < LEG_COUNT; l++){
		for (uint8_t j = 0; j < JOINT_COUNT; j++){
			ports[(l * JOINT_COUNT) + j] = legs[l].getPort(j);
			pins[(l * JOINT_COUNT) + j] = legs[l].getPin(j);
		}
		
		for (uint8_t j = 0; j < CALIBRATION_COUNT; j++){
			legs[l].setCalibration(j, eeprom_read_byte((uint8_t*) (l * CALIBRATION_COUNT) + j));
		}
	}
	
	status_init(ports, pins);
	
	pwm_init(ports, pins, PWM_COUNT, 20000);
	status_set_color(0x00, 0x00, 0x00);
	
	for (uint8_t l = 0; l < LEG_COUNT; l++){
		legs[l].resetPosition();
	}
	pwm_apply_batch();

	delay_ms(500);
	
	pwm_stop();	
}
Beispiel #20
0
void lib_low_level_init()
{
	sytem_clock_init();

	#ifdef _GPIO_H_
	gpio_init();
	#endif

	#ifdef _UART_H_
	uart_init();
	#endif

	#ifdef _TIMER_H_
	timer_init();
	#endif

	#ifdef _PWM_H_
	pwm_init();
	#endif

	#ifdef _DRV8834_H_
	drv8834_init();
	#endif

	#ifdef _I2C_H_
	i2c_0_init();
	#endif

	#ifdef _ADC_H_
	// adc_init();
	#endif
}
Beispiel #21
0
void motor_cs_init()
{
  // initialize pwms
  pwm_init();

  // setup pwms dirs
  sbi(MOTOR_CS_PWM1_DDR,MOTOR_CS_PWM1_PIN);
  cbi(MOTOR_CS_PWM1_PORT,MOTOR_CS_PWM1_PIN);

  sbi(MOTOR_CS_PWM2_DDR,MOTOR_CS_PWM2_PIN);
  cbi(MOTOR_CS_PWM2_PORT,MOTOR_CS_PWM2_PIN);

  sbi(MOTOR_CS_PWM3_DDR,MOTOR_CS_PWM3_PIN);
  cbi(MOTOR_CS_PWM3_PORT,MOTOR_CS_PWM3_PIN);

  motor1_sign = 0;
  motor2_sign = 0;
  motor3_sign = 0;

  pwm_set_1A(0);
  pwm_set_1B(0);
  pwm_set_1C(0);
  
  // setup brake
  sbi(MOTOR_CS_BREAK_DDR, MOTOR_CS_BREAK_PIN);
  cbi(MOTOR_CS_BREAK_PORT, MOTOR_CS_BREAK_PIN);

  // activate interrupts
  sbi(TIMSK,TOIE1);

	return;
}
void _init_func(void)
{
	DEBUGPCR("\r\n===> main_pwm <===\r\n");
	help();

	rc632_init();
	DEBUGPCRF("turning on RF");
	rc632_turn_on_rf(RAH);

	/* switch PA17 (connected to MFIN on board) to input */
	AT91F_PIO_CfgInput(AT91C_BASE_PIOA, AT91C_PIO_PA17);

	DEBUGPCRF("Initializing carrier divider");
	tc_cdiv_init();

	DEBUGPCRF("Initializing PWM");
	pwm_init();
	pwm_freq_set(0, 105937);
	pwm_start(0);
	pwm_duty_set_percent(0, 22);	/* 22% of 9.43uS = 2.07uS */
	rc632_modulate_mfin();

#ifdef SSC
	DEBUGPCRF("Initializing SSC RX");
	ssc_rx_init();
#endif
}
void demo_centrifuge_stage() {
  uint8_t i;
  uint8_t j;

  pwm_init();

  OCR1AH = 0x50;
  OCR1AL = 0xff;

  PORTB |= _BV(ENA); // ON the enable bit

  int time_delay = 50;
  uint8_t j_high = 255;
  uint8_t j_low  = 40;

  uint8_t i_high = 255;
  uint8_t i_low  = 0;

  for (j = j_high ; j > j_low ; j--) {
    OCR1AH = j;
    for (i = i_high; i > i_low ; i--) {
      OCR1AL = i;
      _delay_us(time_delay);
    }
  }
  _delay_ms(4000);
  PORTD &= ~_BV(ENA);// OFF the enable bit
  TCCR1A &= ~_BV(COM1B0); // COM1B0 indicates COM-pare action toggling OCR1B (which is arduino pin 10) on Compare Match aka PWM.

}
Beispiel #24
0
int main()
{
    pic_init();
    logging_init();
    button_init();
    bumper_init();
    pwm_init();
    motor_timer_init();
    button_timer_init();
    sound_config_timer_init();

    //put_str_ln("Initialising DMA...");
    //init_DMA();

    //put_str_ln("Initialising ADC...");
    init_ADC();

    // setup des interrupts
    INTCONSET = _INTCON_MVEC_MASK;
    __builtin_enable_interrupts();

    if (VERBOSE_PIC_STATUS)
        put_str_ln("Ready.");

    while (1)
    {
        WDTCONbits.WDTCLR = 1;  // ecrire un 1 dans ce bit force la reinitialisation du watchdog
    }
}
Beispiel #25
0
void ioInit() {
	PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0);
	PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO4_U, FUNC_GPIO4);
	PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO5_U, FUNC_GPIO5);
	//PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12);
//	gpio_output_set(0, 0, (1<<LEDGPIO), (1<<BTNGPIO));
//	os_timer_disarm(&resetBtntimer);
//	os_timer_setfn(&resetBtntimer, resetBtnTimerCb, NULL);
//	os_timer_arm(&resetBtntimer, 500, 1);

	light_param.pwm_period = 1000;

	uint32 io_info[][3] = {   {PWM_0_OUT_IO_MUX,PWM_0_OUT_IO_FUNC,PWM_0_OUT_IO_NUM},
		                      {PWM_1_OUT_IO_MUX,PWM_1_OUT_IO_FUNC,PWM_1_OUT_IO_NUM},
		                      {PWM_2_OUT_IO_MUX,PWM_2_OUT_IO_FUNC,PWM_2_OUT_IO_NUM},
//		                      {PWM_3_OUT_IO_MUX,PWM_3_OUT_IO_FUNC,PWM_3_OUT_IO_NUM},
//		                      {PWM_4_OUT_IO_MUX,PWM_4_OUT_IO_FUNC,PWM_4_OUT_IO_NUM},
		                      };

    uint32 pwm_duty_init[PWM_CHANNEL] = {0,0,0};

    /*PIN FUNCTION INIT FOR PWM OUTPUT*/
    pwm_init(light_param.pwm_period,  pwm_duty_init ,PWM_CHANNEL,io_info);
    set_pwm_debug_en(0);
    pwm_start();
}
Beispiel #26
0
int main(void)
{
    bool erase_bonds;

    // Initialize.
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, NULL);
    buttons_leds_init(&erase_bonds);
    uart_init();
    printf("Battery collector example\r\n");
    ble_stack_init();
    device_manager_init(erase_bonds);
    db_discovery_init();
    //hrs_c_init();
    bas_c_init();
    pwm_init();

    // Start scanning for peripherals and initiate connection
    // with devices that advertise Heart Rate UUID.
    scan_start();

    for (;; )
    {
        power_manage();
    }
}
Beispiel #27
0
int main(void)
{
	
	//Initial Serial, ADC & LCD Display:
	USARTInit(52);
	lcd_init();
	ADCinit();
	pwm_init();
	
	char adc_output[6][4];	
	int adc_value[6]; // Variable to hold ADC result
	
    while(1)
   {	
	   for(int i=0;i<6;i++){
		   adc_value[i] = ADCread(i);
		   itoa(adc_value[i],adc_output[i],10);
		   USARTWriteString(adc_output[i]);
		   if(i!=5){USARTWriteChar(';');}
	   }
	   
		//Sending a new line:
	   	USARTWriteChar('\r');
	   	USARTWriteChar('\n');
		
		//Set PWM:
		pwm(adc_value[5]);
		
		//Show data on the lcd display   
		show(adc_output);
		
		//Delay:
		_delay_ms(500);
   }
}
Beispiel #28
0
void bd_display_run(char *cmd, int bl_duty, int bl_on)
{
	static int display_init = 0;

	if (!display_init) {
		bd_display();

#if defined(CFG_LCD_PRI_PWM_CH)
		pwm_init(CFG_LCD_PRI_PWM_CH, 0, 0);
		pwm_config(CFG_LCD_PRI_PWM_CH,
			TO_DUTY_NS(bl_duty, CFG_LCD_PRI_PWM_FREQ),
			TO_PERIOD_NS(CFG_LCD_PRI_PWM_FREQ));
#endif

		display_init = 1;
	}

	if (cmd) {
		struct nxp_lcd *lcd = nanopi2_get_lcd();

		run_command(cmd, 0);
		lcd_draw_boot_logo(CONFIG_FB_ADDR, lcd->width, lcd->height,
			CFG_DISP_PRI_SCREEN_PIXEL_BYTE);
	}

	if (bl_on) {
#if defined(CFG_LCD_PRI_PWM_CH)
		pwm_enable(CFG_LCD_PRI_PWM_CH);
#endif
		onewire_set_backlight(127);
	}
}
Beispiel #29
0
void lcd_set_backlight_level(int num)
{
	int _val = num;
	int _half;
	int _period;
	int prescaler = 1;
	if (_val>=CONFIG_SYS_PWM_FULL)
		_val = CONFIG_SYS_PWM_FULL-1;
	if (_val<1)
		_val =1;
	if (CONFIG_SYS_PWM_PERIOD < 200)
		_period = 200;
	else if (CONFIG_SYS_PWM_PERIOD > 1000000000)
		_period = 1000000000;
	else
		_period = CONFIG_SYS_PWM_PERIOD;
	_period = (unsigned long long)CONFIG_SYS_EXTAL * _period / 1000000000;
	while (_period > 0xffff && prescaler < 6) {
		_period >>= 2;
		++prescaler;
	}
	_half =_period * _val / (CONFIG_SYS_PWM_FULL);
#ifdef SOC_X1000
	gpio_set_func(GPIO_PORT_C, GPIO_FUNC_0,1 << (CONFIG_GPIO_LCD_PWM % 32));
#else
	gpio_set_func(GPIO_PORT_E, GPIO_FUNC_0,1 << (CONFIG_GPIO_LCD_PWM % 32));
#endif
	struct pwm pwm_backlight = {CONFIG_SYS_PWM_CHN,prescaler,EXTAL,_period,_half};
	pwm_init(&pwm_backlight);
}
Beispiel #30
0
int board_late_init(void)
{
#ifdef CONFIG_CMD_BMODE
	add_board_boot_modes(board_boot_modes);
#endif

#ifdef CONFIG_VIDEO_IPUV3
	/* We need at least 200ms between power on and backlight on
	 * as per specifications from CHI MEI */
	mdelay(250);

	/* enable backlight PWM 1 */
	pwm_init(0, 0, 0);

	/* duty cycle 5000000ns, period: 5000000ns */
	pwm_config(0, 5000000, 5000000);

	/* Backlight Power */
	gpio_direction_output(LVDS_BACKLIGHT_GP, 1);

	pwm_enable(0);
#endif

	/* board specific pmic init */
	pmic_init();

	return 0;
}