예제 #1
0
파일: main.c 프로젝트: z80/stm32f429
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
  HAL_Init();
  /* Configure the system clock to 144 MHz */
  SystemClock_Config();
  
  /* Configure LED3 */
  BSP_LED_Init(LED3);
  
  /*##-1- TIM8 Peripheral Configuration ######################################*/
  TIM_Config();
  
  /*##-2- Configure the ADC3 peripheral ######################################*/
  ADC_Config();
 
  /*##-4- Start the conversion process and enable interrupt ##################*/  
  if(HAL_ADC_Start_IT(&AdcHandle) != HAL_OK)
  {
    /* Start Conversation Error */
    Error_Handler();
  }
  
  /*##-3- TIM8 counter enable ################################################*/ 
  if(HAL_TIM_Base_Start(&htim) != HAL_OK)
  {
    /* Counter Enable Error */
    Error_Handler();
  }
  
  /* Infinite loop */
  while (1)
  {
  }
}
예제 #2
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
  HAL_Init();
  
  /* Configure the system clock to 144 MHz */
  SystemClock_Config();
  
  /* Configure LED1 and LED3 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED3);
  
  /*##-1- Configure ADC1 and ADC2 peripherals ################################*/
  ADC_Config();

  /*##-2- Enable ADC2 ########################################################*/
  if(HAL_ADC_Start(&AdcHandle2) != HAL_OK)
  {
    /* Start Error */
    Error_Handler(); 
  }
  
  /*##-3- Start ADC1 and ADC2 multimode conversion process and enable DMA ####*/  
  if(HAL_ADCEx_MultiModeStart_DMA(&AdcHandle1, (uint32_t*)&uhADCDualConvertedValue, 1) != HAL_OK)
  {
    /* Start Error */
    Error_Handler(); 
  }
  
  /* Infinite loop */
  while (1)
  {
  }
}
예제 #3
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f30x.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f30x.c file
       */
  
  /* DMA1 channel1 configuration */
  DMA_Config();
  
  /* TIM3 channel3 configuration */
  TIM3_Config();
  
  /* ADC channel7 configuration */
  ADC_Config();
  
  while (1)
  {
  }
}
/*=====================================================================================================*/
int main( void )
{
  u16 ADC_AVE[2] = {0};

  SystemInit();
  GPIO_Config();
  ADC_Config();
  RS232_Config();

  while(1) {
    LED_G = !LED_G;
    Delay_100ms(1);
    ADC_Average(ADC_AVE, 128);
    RS232_SendStr((u8*)"\f");
    RS232_SendStr((u8*)"ADC_I = ");
    RS232_SendNum(Type_D, 4, ADC_AVE[0]);
    RS232_SendStr((u8*)"\r\n");
    RS232_SendStr((u8*)"ADC_V = ");
    RS232_SendNum(Type_D, 4, ADC_AVE[1]);
    RS232_SendStr((u8*)"\r\n");
  }
}
예제 #5
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
   /* CLK configuration -------------------------------------------*/
  CLK_Config(); 

  /* Init TIM2 to generate 1 ms time base update interrupt */
  TimingDelay_Init();

  /* Enable Interrupts */
  enableInterrupts();

  /* 1s delay to ensure proper LCD Init*/
  Delay(1000);

  /* Init the Eval board LCD */
  STM8_EVAL_LCD_Init();

  /* Clear LCD */
  LCD_Clear();

  /* print "Pot ADC Voltage" on LCD line1*/
  LCD_SetCursorPos(LCD_LINE1, 0);
  LCD_Print("Pot ADC Voltage");

   /* ADC configuration -------------------------------------------*/
  ADC_Config();

  /* Infinite loop*/
  while (1)
  {
    /* Calculate voltage value*/
    PotVoltage = (uint16_t)((uint32_t)((uint32_t)ADCdata * (uint32_t)ADC_RATIO) / (uint32_t)1000);

    /* Display voltage value on LCD*/
    ShowVoltage((uint16_t)PotVoltage);
  }

}
/**************************************************************************//**
 * @brief Main function
 *****************************************************************************/
int main(void)
{
  
  /* Chip revision alignment and errata fixes */
  CHIP_Init();
    
  /* Set the clock frequency to 11MHz so the ADC can run on the undivided HFCLK */
  CMU_HFRCOBandSet(cmuHFRCOBand_11MHz);
  
  /* Configure RTC to use LFRCO as clock source */
  RTC_Setup(cmuSelect_LFRCO);
    
  /* Configure ADC */
  ADC_Config();
 
  /* Start ADC sampling, adcFinished is set when sampling is finished. */
  /* It is safe to do other stuff or go to EM2 while adc sampling is active. */
  /* ADC sampling uses the RTC to trigger new samples. */
  startAdcSampling();
    
  /* Wait in EM2 until adc sampling is finished. */
  /* Disable interrupts until flag is checked in case loop finishes after flag 
  * check but before sleep command. Device will still wake up on any set IRQ 
  * and any pending interrupts will be handled after interrupts are enabled 
  * again. */
  INT_Disable();
  while(!adcFinished)
  {
   EMU_EnterEM2(false); 
   INT_Enable();
   INT_Disable();
  }
  INT_Enable();    
  
  /* Finished */
  while(1);
  
}  
/*=====================================================================================================*/
int main( void )
{
  u8 TrData[8] = {0};

	SystemInit();
	GPIO_Config();
	ADC_Config();
	RS232_Config();

  while(1) {
    LED_G = ~LED_G;
    ADC_Average(ADC_AveTr);

    TrData[0] = (u8)(ADC_AveTr[0]);
    TrData[1] = (u8)(ADC_AveTr[0]>>8);
    TrData[2] = (u8)(ADC_AveTr[1]);
    TrData[3] = (u8)(ADC_AveTr[1]>>8);
    TrData[4] = (u8)(0);
    TrData[5] = (u8)(0);
    TrData[6] = (u8)(0);
    TrData[7] = (u8)(0);
    RS232_VisualScope(USART3, TrData, 8);
	}
}
/*=====================================================================================================*/
int main( void )
{
  GPIO_Config();
	PWM_Config();
	ADC_Config();
  TIM_Config();
	
  while(1) {
		
		if(KEY_WU==1){
			while(KEY_WU==1);
			Kp+=1;
			if(Kp>=20) Kp = 0;
			Delay_10ms(2);
    }
		if(KEY_BO==1){
			while(KEY_BO==1);
			Kd+=0.1;
			if(Kd>=5) Kd = 0;
			Delay_10ms(2);
    }
    
  }
}
예제 #9
0
/**
	 * @brief Main thread of computation running in superloop to update sensor data and transmit
	 * and also subsequently run logic for PWM LED display and double tap detection
	 * @param void
   */
int main(void){	
		
	/* INITIALIZE SYSTEM CLOCK AND PERIPHERALS */
  HAL_Init();
  SystemClock_Config();	
	SPI_Init1();
	MEMS_Config();
	MEMS_Config_IT();
	ADC_Config();
	LED_Config();
	PWM_Config();
	
	/* CONFIG FOR PWM */
	#ifdef LED_SPEED_SLOWER
		speed = 1500;
	#endif

	#ifdef LED_SPEED_SLOW
		speed = 1000;
	#endif

	#ifdef LED_SPEED_MEDIUM
		speed = 800;
	#endif

	#ifdef LED_SPEED_FAST
		speed = 400;
	#endif

	#ifdef LED_SPEED_FASTER
		speed = 200;
	#endif			
	
	#ifdef LED_ALL_ON
		speed = 100;
	#endif
	
	/* CONFIG FOR DOUBLE TAP */
	counter2 = 0;
	thresh1 = 1300;
	assert1 = 0;
	assert2 = 0;
	assertFall = 0;
	assertRise2 = 0;
	assertDoubleTap = 0;
	
	/* BEGIN SUPERLOOP */
	while(1){
		
		/* SET SAMPLING DELAY FOR SENSORS */
		if(interrupt != 0){
			interrupt = 0;
			get_readings();			
		}		
		
		/* TRANSMIT SENSOR DATA TO MASTER */
		HAL_SPI_Transmit(&SpiHandle_2, txBuffer, 4, 10000);				
		
		/* LOGIC FOR IMPLEMENTING PWM DISPLAY LED */
		pwm_display();		
		
		/* LOGIG FOR IMPLEMENTING DOUBLE TAP DETECTION */
		double_tap();
	}
}
예제 #10
0
파일: main.c 프로젝트: szymon2103/Stm32
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured,
       this is done through SystemInit() function which is called from startup
       files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s/startup_stm32f429_439xx.s)
       before to branch to application main.
     */

  /* SysTick end of count event each 10ms */
  RCC_GetClocksFreq(&RCC_Clocks);
  SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);

  /* Initialize LEDs mounted on EVAL board */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);

  STM_EVAL_LEDOn(LED1);

 /* Initialize the LCD */
  LCD_Init();
  LCD_Clear(Black);
  LCD_SetTextColor(White);

  LCD_LOG_SetHeader((uint8_t*)"STM32 Camera Demo");
  LCD_LOG_SetFooter ((uint8_t*)"   Copyright (c) STMicroelectronics" );

  /* ADC configuration */
  ADC_Config();

  /* Initializes the DCMI interface (I2C and GPIO) used to configure the camera */
  OV2640_HW_Init();

  /* Read the OV9655/OV2640 Manufacturer identifier */
  OV9655_ReadID(&OV9655_Camera_ID);
  OV2640_ReadID(&OV2640_Camera_ID);

  if(OV9655_Camera_ID.PID  == 0x96)
  {
    Camera = OV9655_CAMERA;
    sprintf((char*)abuffer, "OV9655 Camera ID 0x%x", OV9655_Camera_ID.PID);
    ValueMax = 2;
  }
  else if(OV2640_Camera_ID.PIDH  == 0x26)
  {
    Camera = OV2640_CAMERA;
    sprintf((char*)abuffer, "OV2640 Camera ID 0x%x", OV2640_Camera_ID.PIDH);
    ValueMax = 2;
  }
  else
  {
    LCD_SetTextColor(LCD_COLOR_RED);
    LCD_DisplayStringLine(LINE(4), (uint8_t*)"Check the Camera HW and try again");
    while(1);
  }

  LCD_SetTextColor(LCD_COLOR_YELLOW);
  LCD_DisplayStringLine(LINE(4), (uint8_t*)abuffer);
  LCD_SetTextColor(LCD_COLOR_WHITE);
  Delay(200);

  /* Initialize demo */
  ImageFormat = (ImageFormat_TypeDef)Demo_Init();

  /* Configure the Camera module mounted on STM324xG-EVAL/STM324x7I-EVAL boards */
  Demo_LCD_Clear();
  LCD_DisplayStringLine(LINE(4), (uint8_t*)"Camera Init..               ");
  Camera_Config();

  sprintf((char*)abuffer, " Image selected: %s", ImageForematArray[ImageFormat]);
  LCD_DisplayStringLine(LINE(4),(uint8_t*)abuffer);

  /* Enable DMA2 stream 1 and DCMI interface then start image capture */
  DMA_Cmd(DMA2_Stream1, ENABLE);
  DCMI_Cmd(ENABLE);

  /* Insert 100ms delay: wait 100ms */
  Delay(200);

  DCMI_CaptureCmd(ENABLE);

  LCD_ClearLine(LINE(4));
  Demo_LCD_Clear();

  if(ImageFormat == BMP_QQVGA)
  {
    /* LCD Display window */
    LCD_SetDisplayWindow(179, 239, 120, 160);
    LCD_WriteReg(LCD_REG_3, 0x1038);
    LCD_WriteRAM_Prepare();
  }
  else if(ImageFormat == BMP_QVGA)
  {
    /* LCD Display window */
    LCD_SetDisplayWindow(239, 319, 240, 320);
    LCD_WriteReg(LCD_REG_3, 0x1038);
    LCD_WriteRAM_Prepare();
  }

  while(1)
  {
    /* Blink LD1, LED2 and LED4 */
    STM_EVAL_LEDToggle(LED1);
    STM_EVAL_LEDToggle(LED2);
    STM_EVAL_LEDToggle(LED3);
    STM_EVAL_LEDToggle(LED4);

    /* Insert 100ms delay */
    Delay(10);

    /* Get the last ADC3 conversion result data */
    uhADCVal = ADC_GetConversionValue(ADC3);

    /* Change the Brightness of camera using "Brightness Adjustment" register:
       For OV9655 camera Brightness can be positively (0x01 ~ 0x7F) and negatively (0x80 ~ 0xFF) adjusted
       For OV2640 camera Brightness can be positively (0x20 ~ 0x40) and negatively (0 ~ 0x20) adjusted */
    if(Camera == OV9655_CAMERA)
    {
      OV9655_BrightnessConfig(uhADCVal);
    }
    if(Camera == OV2640_CAMERA)
    {
      OV2640_BrightnessConfig(uhADCVal/2);
    }
  }
}
예제 #11
0
int main(void)
{
	GPIO_Config();
	SYSTICK_Config();
	LCD_Init();
	ADC_Config();
	USART_Config();
	DAC_Mode_Init();


	LCD_Clear(0, 0, 240, 320, BACKGROUND);
	LCD_DispStr(40, 60, (uint8_t*)"Iin_Base:", BLACK);
	LCD_DispStr(40, 90, (uint8_t*)"Iin_Phase:", BLACK);
	LCD_DispStr(40, 110, (uint8_t*)"Vin_Phase:", BLACK);
	LCD_DispStr(40, 140, (uint8_t*)"PF:", BLACK);
//	
//	Init_Iin(Iin);
//	Init_Vin(Vin);
//	
//	cr4_fft_256_stm32(Iin_FFT,Iin,NPT);
//	cr4_fft_256_stm32(Vin_FFT,Vin,NPT);
//	
//	GetPowerMag(Iin_Mag,Iin_FFT);
//	
//	BasePercent = GetBasePercent(Iin_Mag);
//	
//	Iin_Phase = GetPhase(Iin_FFT);
//	
//	Vin_Phase = GetPhase(Vin_FFT);
//	
//	PowerFactor = GetPFValue(BasePercent, Iin_Phase, Vin_Phase);
//	
//	LCD_DispADC(120, 60, BasePercent, BLACK);
//	LCD_DisNum(120, 90, (uint16_t)Iin_Phase, BLACK);
//	LCD_DisNum(120, 110, (uint16_t)Vin_Phase, BLACK);
//	LCD_DispADC(120, 140, PowerFactor, BLACK);
	
	while(1)
	{
		Vin_total=0;
		Iin_total=0;
		Iout_total=0;
		for(i=0;i<NPT;i++)
		{
				Vin[i]=ADCConvertedValue[i*5];
				//Vin_total+=Vin[i];
				Iin[i]=ADCConvertedValue[i*5+1];
				//Iin_total+=Iin[i];
				Iout[i]=ADCConvertedValue[i*5+2];
				//Iout_total+=Iout[i];
		}
//		Vin_total=Vin_total/256;
//		Iin_total=Iin_total/256;
//		Iout_total=Iout_total/256;		

//		LCD_DisNum(120, 90, Vin_total, BLACK);
//		LCD_DisNum(120, 110, Iin_total, BLACK);
//		LCD_DisNum(120, 130, Iout_total, BLACK);
		
	cr4_fft_256_stm32(Iin_FFT,Iin,NPT);
	cr4_fft_256_stm32(Vin_FFT,Vin,NPT);
	
	GetPowerMag(Iin_Mag,Iin_FFT);
	
	BasePercent = GetBasePercent(Iin_Mag);
	
	Iin_Phase = GetPhase(Iin_FFT);
	
	Vin_Phase = GetPhase(Vin_FFT);
	
	PowerFactor = GetPFValue(BasePercent, Iin_Phase, Vin_Phase);
	
	LCD_DispADC(120, 60, BasePercent, BLACK);
	LCD_DisNum(120, 90, (uint16_t)Iin_Phase, BLACK);
	LCD_DisNum(120, 110, (uint16_t)Vin_Phase, BLACK);
	LCD_DispADC(120, 140, PowerFactor, BLACK);
	
	
	
	}


}	//main
int main( void )
{
	uart_config_t uart0;
	gpio_config_t key1;
	i2c_config_t i2c0;
	i2c_command_t command;
	spi_config_t spi0;
	spi_command_t spi_cmd;
	adc_config_t adc5;
	dac_config_t dac0;


	error_code_t error;
	uart0.baudrate = B115200;
	uart0.block_type = NON_BLOCKING;
	uart0.buffer = 0;
	uart0.irqhandler = 0;
	uart0.parity = UART_PARITY_NONE;
	uart0.uart_port = COM0;
	uart0.wordlen = UART_WORDLEN8;
	uart0.stopbit = STOP_BIT_1_BIT;


	key1.Direction = INPUT;
	key1.Initial_Value = LO;
	key1.Interrupt_Type = INTERRUPT_ENABLED_BOTH;
	key1.Pin = PIN11;
	key1.Port= PORT2;
	key1.Pin_Mode = PULLUP_PULLDOWN_DISABLED;
	key1.Pin_Mode_OD = PIN_MODE_OPEN_DRAIN_NORMAL;
	key1.Pin_Typedef = 0;
	key1.irqhandler = 0;

	i2c0.i2c_port = I2C0;
	i2c0.i2c_mode = MASTER;
	i2c0.datarate = STANDARD;
	i2c0.buffer = 0;
	i2c0.irqhandler = 0;

	spi0.bits = SPI_8_BITS;
	spi0.buffer = 0;
	spi0.clk_phase = SPI_PHASE_INPHASE;
	spi0.clk_polarity = SPI_CLK_RISING;
	spi0.freq = 5e6;
	spi0.irqhandler = 0;
	spi0.lsbf = MSB_FIRST;
	spi0.mode = SPI_MASTER;
	spi0.port = SPI0;
	spi0.dummyData = 0x00;

	adc5.channel = ADC_CHANNEL5;
	adc5.rate = 200e3;
	adc5.trigger_mode = BURST;
	adc5.irqhandler = 0;

	dac0.sampling_rate = 32e3;


	if ( (error = GPIO_Config(&key1)) != NO_ERROR ) {
		while (1);
	}

	signal_level_t trigger_mode;
	GPIO_GetLevel(&key1, &trigger_mode);
	if (trigger_mode == HI) {
		adc5.trigger_mode = BURST;
	} else {
		adc5.trigger_mode = MANUAL;
	}

	if ( (error = UART_Config(&uart0)) != NO_ERROR) {
		while (1);
	}
	SetDebug_Port(COM0);

	if ( (error = I2C_Config(&i2c0)) != NO_ERROR ) {
		while (1);
	}

	if ( (error = SPI_Config(&spi0)) != NO_ERROR ) {
		while (1);
	}

	if ( (error = ADC_Config(&adc5)) != NO_ERROR ) {
		while (1);
	}

	if ( (error = DAC_Config(&dac0)) != NO_ERROR ) {
		while (1);
	}
	uc_printf ("HardWare Initialized\n\r");

	/* READ ID USING READ-ID */
	//Write Register.
	spi_cmd.writeReg = 0x90;
	spi_cmd.writeRegValid = 1;
	uint16_t write_data[] = {0x00, 0x00, 0x00  };
	spi_cmd.writeBuffer = write_data;
	spi_cmd.writeDataSize = sizeof(write_data);

	//Read Register.
	uint16_t read_data[4];
	spi_cmd.readReg = 0x00;
	spi_cmd.readRegValid = 0;
	spi_cmd.readBuffer = read_data;
	spi_cmd.readDataSize = sizeof(read_data);

	spi_cmd.operation = SPI_WRITE | SPI_READ; //back to back.

	error = SPI_Write(SPI0, &spi_cmd);
	if (error != NO_ERROR) {
		while (1);
	}
	uc_printf ("SPI Flash Device ID(READ-ID) %d %d %d %d\n\r", read_data[0], read_data[1], read_data[2], read_data[3]);

	/* READ ID USING JEDEC READ */
	uint16_t read_data_jedec[4];
	spi_cmd.readReg = 0x9F;
	spi_cmd.readRegValid = 1;
	spi_cmd.readBuffer = read_data_jedec;
	spi_cmd.readDataSize = sizeof(read_data_jedec);
	error = SPI_Read(SPI0, &spi_cmd);
	if (error != NO_ERROR) {
		while (1);
	}
	uc_printf ("SPI Flash Device ID(Jedec) %d %d %d %d\n\r", read_data_jedec[0], read_data_jedec[1], read_data_jedec[2], read_data_jedec[3]);

	int size = 18;
	char fw_version[18] = "PowerAvrVersion5.5";
	char fw_version_read[18] = { 0 };
	command.address = 0x50;
	command.data = fw_version;
	command.operation = WRITE;
	command.reg = 0x00;
	command.size = 1; //11;

	int i, j, k;
	for (j=0; j<1; j++) {
		for (i=0; i<size;i++) {
			//UART_PutChars(COM0,"Writing", 9);
			command.reg = 0x00 + i;
			command.size = 1;
			command.data = &(fw_version[i]);
			error = I2C_Write(I2C0, &command);
			if (error != NO_ERROR) {
				break;
			}
			//This is to cause a delay after write. This should be replaced with the wait in the I2C_Write Operation.
			for (k=0; k<16; k++) {
				uc_printf(".");
				uc_printf("\b");
			}
		}
		if (error != NO_ERROR) {
			while (1);
		}
	}
	uc_printf("I2C Write Done\n\r");

	command.operation = READ;
	command.data = fw_version_read;
	command.size = 1 ;
	for (j=0; j<1; j++) {
		for (i=0; i<size;i++) {
				fw_version_read[i] = 'X';
		}
		for (i=0; i<size;i++) {
			command.reg = 0x00 + i;
			command.size = 1;
			command.data = &(fw_version_read[i]);
			error = I2C_Read(I2C0, &command);
			if (error != NO_ERROR) {
				break;
			}
		}
		if (error != NO_ERROR) {
			while (1);
		}
	}

	uc_printf("I2C Read Done\n\r");
	for (i=0; i<size; i++) {
		uc_printf("%c",fw_version_read[i]);
	}
	uc_printf("\n\r");
	pin_interrupt_type_t key1_status;
	float vol=0;
	int timeout = 0;
	while (1) {
		error = GPIO_GetIRQ(&key1, &key1_status);
		if (error != NO_ERROR) {
			while (1);
		}
		if (key1_status == INTERRUPT_ENABLED_FALLING) {
			uc_printf ("Falling Edge\n\r");
			error = GPIO_ClrIRQ(&key1);
			if (error != NO_ERROR) {
				while (1);
			}
			if ( (error = ADC_Read(&adc5)) != NO_ERROR ) {
				while (1);
			}
		} else if (key1_status == INTERRUPT_ENABLED_RISING) {
			uc_printf ("Rising Edge\n\r");
			error = GPIO_ClrIRQ(&key1);
			if (error != NO_ERROR) {
				while (1);
			}
		}
		//#if (DISPLAY_ADC == 1)
				//if (adc5.trigger_mode == BURST) {
				if (timeout == 20000) {
					ADC_Read(&adc5);
					timeout = 0;
				} else {
					timeout++;
				}
				//}
				if (adc5.done) {
					vol =0 ;
					int i=0;
					int result = adc5.result;
					for (i=0; i<4096; i+=256) {
						vol++;
						if (result >= i && result <= (i + 256) ) {

							break;
						}
					}

					/*
					for (i=0; i<adc5.result/33; i++) {
						uc_printf("*");
					}
					uc_printf("\r");
					*/
					//uc_printf ("%d\n\r", adc5.result);
					adc5.done = 0;
				}
		//#endif
		//#if (PLAY_PIANO == 1)
		if (vol == 0) {
			vol = 1;
		} else if (vol > 1) {
			//vol = vol ; //1 + (vol - 1)*0.2;
		}
		Play_Piano(&dac0, vol );
		//#endif
	}

	#if (UART_TEST == 1)
	char rx_data;
	char tx_data[] = "This is x nnnnn\n\r";
	while (1) {
		//if ( UART_GetChar(COM0, &rx_data) != FIFO_EMPTY ) {
			tx_data[8] = 'a';
			//UART_PutChar(COM0, rx_data);
			UART_PutChars(COM0, tx_data, 17 );
			int i;
			tx_data[8] = 'b';
			for (i=0; i<17; i++) {
				UART_PutChar(COM0, tx_data[i]);
			}
		//}
	}
	#endif
	return 0;
}
예제 #13
0
int main(void) 
{
	int i;
	Systick_Configuration();
	LED_Configuration();
	button_Configuration();
	usart1_Configuration(9600);
	SPI_Configuration();
  TIM4_PWM_Init();
	Encoder_Configration();
	buzzer_Configuration();
	ADC_Config();
	
	//curSpeedX = 0;
	//curSpeedW = 0;
	//shortBeep(2000, 8000);
	
	while(1) {
		readSensor();
		readGyro();
		readVolMeter();
		printf("LF %d RF %d DL %d DR %d aSpeed %d angle %d voltage %d lenc %d renc %d\r\n", LFSensor, RFSensor, DLSensor, DRSensor, aSpeed, angle, voltage, getLeftEncCount(), getRightEncCount());
		displayMatrix("UCLA");
		
		setLeftPwm(100);
		setRightPwm(100);
		delay_ms(1000);
	}
	//forwardDistance(4000,0,0,true);
	//displayMatrix("Sped");
	//targetSpeedX = 100;
	//delay_ms(2000);
	
	//
	//targetSpeedX = 100;
	//delay_ms(2000);
	//printf("==============================================\n\r=======================================================\r\n");
	
	//delay_ms(1000); 
	//displayMatrix("Wat");
	//delay_ms(1000);
	//displayMatrix("STOP");
	//displayMatrix("GO");
	
	turnRightAngle(LEFT);
	
	targetSpeedW = 0;
	delay_ms(1000);
	turnRightAngle(RIGHT);
	targetSpeedW = 0;
	delay_ms(1000);
	
	displayMatrix("STOP");
	delay_ms(3000); 
	targetSpeedX = 0;
	//
	targetSpeedW = 10;
	delay_ms(1000);
	targetSpeedX = 0;
	targetSpeedW = 0;
	return 0;
}
예제 #14
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F103xB HAL library initialization:
       - Configure the Flash prefetch
       - Systick timer is configured by default as source of time base, but user 
         can eventually implement his proper time base source (a general purpose 
         timer for example or other time source), keeping in mind that Time base 
         duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
         handled in milliseconds basis.
       - Set NVIC Group Priority to 4
       - Low Level Initialization
     */
  HAL_Init();
  
  /* Configure the system clock to 64 MHz */
  SystemClock_Config();
  
  /*## Configure peripherals #################################################*/
  
  /* Initialize LED on board */
  BSP_LED_Init(LED2);
  
  /* Configure User push-button in Interrupt mode */
  BSP_PB_Init(BUTTON_USER, BUTTON_MODE_EXTI);
  
  /* Configure the ADC peripheral */
  ADC_Config();
  
  /* Run the ADC calibration */  
  if (HAL_ADCEx_Calibration_Start(&AdcHandle) != HAL_OK)
  {
    /* Calibration Error */
    Error_Handler();
  }

#if defined(ADC_TRIGGER_FROM_TIMER)
  /* Configure the TIM peripheral */
  TIM_Config();
#endif /* ADC_TRIGGER_FROM_TIMER */

  /* Note: This example, on some other STM32 boards, is performing            */
  /*       DAC configuration here.                                            */
  /*       On STM32F103RB-Nucleo, the device has no DAC available,            */
  /*       therefore analog signal must be supplied externally.               */

  /*## Enable peripherals ####################################################*/
#if defined(ADC_TRIGGER_FROM_TIMER)
  /* Timer enable */
  if (HAL_TIM_Base_Start(&TimHandle) != HAL_OK)
  {
    /* Counter Enable Error */
    Error_Handler();
  }
#endif /* ADC_TRIGGER_FROM_TIMER */

  /* Note: This example, on some other STM32 boards, is performing            */
  /*       DAC signal generation here.                                        */
  /*       On STM32F103RB-Nucleo, the device has no DAC available,            */
  /*       therefore analog signal must be supplied externally.               */

  /*## Start ADC conversions #################################################*/
  
  /* Start ADC conversion on regular group with transfer by DMA */
  if (HAL_ADC_Start_DMA(&AdcHandle,
                        (uint32_t *)aADCxConvertedValues,
                        ADCCONVERTEDVALUES_BUFFER_SIZE
                       ) != HAL_OK)
  {
    /* Start Error */
    Error_Handler();
  }
  
  
  /* Infinite loop */
  while (1)
  {
    /* Turn-on/off LED2 in function of ADC conversion result */
    /*  - Turn-off if voltage is into AWD window */ 
    /*  - Turn-on if voltage is out of AWD window */

    /* Variable of analog watchdog status is set into analog watchdog         */
    /* interrupt callback                                                     */
    if (ubAnalogWatchdogStatus == RESET)
    {
      BSP_LED_Off(LED2);
    }
    else
    {
      BSP_LED_On(LED2);
      
      /* Reset analog watchdog status for next loop iteration */
      ubAnalogWatchdogStatus = RESET;
    }
  
    /* For information: ADC conversion results are stored into array          */
    /* "aADCxConvertedValues" (for debug: check into watch window)            */
  
  
    /* Wait for event on push button to perform following actions */
    while ((ubUserButtonClickEvent) == RESET)
    {
    }
    /* Reset variable for next loop iteration */
    ubUserButtonClickEvent = RESET;

    /* Note: This example, on some other STM32 boards, is performing          */
    /*       DAC signal generation here.                                      */
    /*       On STM32F103RB-Nucleo, the device has no DAC available,          */
    /*       therefore analog signal must be supplied externally.             */
  }
}
예제 #15
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F103xG HAL library initialization:
       - Configure the Flash prefetch
       - Systick timer is configured by default as source of time base, but user 
         can eventually implement his proper time base source (a general purpose 
         timer for example or other time source), keeping in mind that Time base 
         duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
         handled in milliseconds basis.
       - Set NVIC Group Priority to 4
       - Low Level Initialization
     */
  HAL_Init();
  
  /* Configure the system clock to 72 MHz */
  SystemClock_Config();
  
  /*## Configure peripherals #################################################*/
  
  /* Initialize LEDs on board */
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED1);
  
  /* Configure Key push-button in Interrupt mode */
  BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI);
  
  /* Configure the ADC peripheral */
  ADC_Config();
  
  /* Run the ADC calibration */  
  if (HAL_ADCEx_Calibration_Start(&AdcHandle) != HAL_OK)
  {
    /* Calibration Error */
    Error_Handler();
  }


#if defined(WAVEFORM_VOLTAGE_GENERATION_FOR_TEST)
  /* Configure the DAC peripheral */
  DAC_Config();
#endif /* WAVEFORM_VOLTAGE_GENERATION_FOR_TEST */
  

  /*## Enable peripherals ####################################################*/
  
#if defined(WAVEFORM_VOLTAGE_GENERATION_FOR_TEST)
  /* Set DAC Channel data register: channel corresponding to ADC channel CHANNELa */
  /* Set DAC output to 1/2 of full range (4095 <=> Vdda=3.3V): 2048 <=> 1.65V              */
  if (HAL_DAC_SetValue(&DacHandle, DACx_CHANNEL_TO_ADCx_CHANNELa, DAC_ALIGN_12B_R, RANGE_12BITS/2) != HAL_OK)
  {
    /* Setting value Error */
    Error_Handler();
  }
  
  /* Enable DAC Channel: channel corresponding to ADC channel CHANNELa */
  if (HAL_DAC_Start(&DacHandle, DACx_CHANNEL_TO_ADCx_CHANNELa) != HAL_OK)
  {
    /* Start Error */
    Error_Handler();
  }
#endif /* WAVEFORM_VOLTAGE_GENERATION_FOR_TEST */

  /*## Start ADC conversions #################################################*/
  
  /* Start ADC conversion on regular group with transfer by DMA */
  if (HAL_ADC_Start_DMA(&AdcHandle,
                        (uint32_t *)aADCxConvertedValues,
                        ADCCONVERTEDVALUES_BUFFER_SIZE
                       ) != HAL_OK)
  {
    /* Start Error */
    Error_Handler();
  }
  
  
  /* Infinite loop */
  while (1)
  {

    /* Wait for event on push button to perform following actions */
    while ((ubUserButtonClickEvent) == RESET)
    {
    }
    /* Reset variable for next loop iteration */
    ubUserButtonClickEvent = RESET;

#if defined(WAVEFORM_VOLTAGE_GENERATION_FOR_TEST)
    /* Set DAC voltage on channel corresponding to ADCx_CHANNELa              */
    /* in function of user button clicks count.                               */
    /* Set DAC output successively to:                                        */
    /*  - minimum of full range (0 <=> ground 0V)                             */
    /*  - 1/4 of full range (4095 <=> Vdda=3.3V): 1023 <=> 0.825V             */
    /*  - 1/2 of full range (4095 <=> Vdda=3.3V): 2048 <=> 1.65V              */
    /*  - 3/4 of full range (4095 <=> Vdda=3.3V): 3071 <=> 2.475V             */
    /*  - maximum of full range (4095 <=> Vdda=3.3V)                          */
    if (HAL_DAC_SetValue(&DacHandle,
                         DACx_CHANNEL_TO_ADCx_CHANNELa,
                         DAC_ALIGN_12B_R,
                         (RANGE_12BITS * ubUserButtonClickCount / USERBUTTON_CLICK_COUNT_MAX)
                        ) != HAL_OK)
    {
      /* Start Error */
      Error_Handler();
    }
#endif /* WAVEFORM_VOLTAGE_GENERATION_FOR_TEST */

    /* Wait for DAC settling time */
    HAL_Delay(1);
    
    /* Start ADC conversion */
    /* Since sequencer is enabled in discontinuous mode, this will perform    */
    /* the conversion of the next rank in sequencer.                          */
    /* Note: For this example, conversion is triggered by software start,     */
    /*       therefore "HAL_ADC_Start()" must be called for each conversion.  */
    /*       Since DMA transfer has been initiated previously by function     */
    /*       "HAL_ADC_Start_DMA()", this function will keep DMA transfer      */
    /*       active.                                                          */
    HAL_ADC_Start(&AdcHandle);
      
    /* Wait for conversion completion before conditional check hereafter */
    HAL_ADC_PollForConversion(&AdcHandle, 1);
    
    /* Turn-on/off LED1 in function of ADC sequencer status */
    /* - Turn-off if sequencer has not yet converted all ranks */    
    /* - Turn-on if sequencer has converted all ranks */
    if (ubSequenceCompleted == RESET)
    {
      BSP_LED_Off(LED1);
    }
    else
    {
      BSP_LED_On(LED1);
      
      /* Computation of ADC conversions raw data to physical values */
      /* Note: ADC results are transferred into array "aADCxConvertedValues"  */
      /*       in the order of their rank in ADC sequencer.                   */
      uhADCChannelToDAC_mVolt    = COMPUTATION_DIGITAL_12BITS_TO_VOLTAGE(aADCxConvertedValues[0]);
      uhVrefInt_mVolt            = COMPUTATION_DIGITAL_12BITS_TO_VOLTAGE(aADCxConvertedValues[2]);
      wTemperature_DegreeCelsius = COMPUTATION_TEMPERATURE_STD_PARAMS(aADCxConvertedValues[1]);

      /* Reset variable for next loop iteration */
      ubSequenceCompleted = RESET;
    }
  }
}
예제 #16
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F3xx HAL library initialization:
       - Configure the Flash prefetch
       - Systick timer is configured by default as source of time base, but user 
         can eventually implement his proper time base source (a general purpose 
         timer for example or other time source), keeping in mind that Time base 
         duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
         handled in milliseconds basis.
       - Set NVIC Group Priority to 4
       - Low Level Initialization
     */
  HAL_Init();

  /* Configure LED1 and LED3 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED3);
  
  /* Configure the system clock to 72 MHz */
  SystemClock_Config();


  /*## Configuration of peripherals ##########################################*/
  /* Configure the ADCx and ADCy peripherals */
  ADC_Config();

  /* Run the ADC calibration in single-ended mode */  
  if (HAL_ADCEx_Calibration_Start(&AdcHandle_master, ADC_SINGLE_ENDED) != HAL_OK)
  {
    /* Calibration Error */
    Error_Handler();
  }
  
  if (HAL_ADCEx_Calibration_Start(&AdcHandle_slave, ADC_SINGLE_ENDED) != HAL_OK)
  {
    /* Calibration Error */
    Error_Handler();
  }
  
  /*## Enable peripherals ####################################################*/

  /* Enable ADC slave */
  if (HAL_ADC_Start(&AdcHandle_slave) != HAL_OK)
  {
    /* Start Error */
    Error_Handler();
  }

  /*## Start ADC conversions #################################################*/
  
  /* Start ADCx and ADCy multimode conversion with interruption */
  if (HAL_ADCEx_MultiModeStart_DMA(&AdcHandle_master, (uint32_t *)aADCDualConvertedValue, 256) != HAL_OK)
  {
    /* Start Error */
    Error_Handler();
  }

  /* Array "aADCDualConvertedValue" contains both ADC results on 16 bits:     */
  /*  - ADC master results in the 8 LSB [7:0]                                 */
  /*  - ADC slave results in the 8 MSB [15:8]                                 */
  
  /* Infinite loop */
  while (1)
  {
    if(aADCDualConversionDone == 1)
    {
      /* Toggle LED1: Conversions results are available                           */
      /* The toggle frequency depends on Conversion Value link to RV2 position    */
      /* In the case of this example:                                             */
      /* HAL_ADC_ConvCpltCallback() is called when DMA Transfer process is        */
      /* completed.                                                               */
      /* Since ADC and DMA are configured in continuous and circular mode, this   */
      /* function will be called each time the DMA buffer length is reached.      */
      BSP_LED_Toggle(LED1);
      HAL_Delay(aADCDualConversionValue*10);
      aADCDualConversionDone = 0;
    }
  }
}
예제 #17
0
/**
  * @brief   Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32l1xx_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32l1xx.c file
     */

  uint32_t index = 0;
  
  /* Configure all GPIO pins in Analog mode for lowsest consumption */
  GPIO_Config();

  /* ADC configuration: Channel 18 or 31 (PB12 or PF10) is used, End Of Conversion (EOC) interrupt is enabled */
  ADC_Config();

#ifdef USE_STM32L152_EVAL
  /* LCD GLASS Configuration: LSI as LCD clock source */
  LCD_Glass_Config();
  /* Initialize the TFT-LCD */
  STM32L152_LCD_Init();
#elif defined USE_STM32L152D_EVAL 
  /* Initialize the TFT-LCD */
  STM32L152D_LCD_Init();
#endif 
  
  /* Clear the TFT-LCD */
  LCD_Clear(LCD_COLOR_WHITE);
  
  while(1)
  {
    if (State == STATE_OVER_THRESHOLD) /* Input voltage is over the threshold */
    {
      /* Indicator LED: MCU in RUN mode */
      STM_EVAL_LEDOff(LED1);

      /* Disable COMP IRQ */
      NVIC_InitStructure.NVIC_IRQChannel = COMP_IRQn;
      NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
      NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;
      NVIC_Init(&NVIC_InitStructure);
      /* Enable ADC1 IRQ */
      NVIC_InitStructure.NVIC_IRQChannel = ADC1_IRQn;
      NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
      NVIC_Init(&NVIC_InitStructure);

      /* COMP clock disable */
      RCC_APB1PeriphClockCmd(RCC_APB1Periph_COMP, DISABLE);

      /* Restore MCU configuration */
      RestoreConfiguration();

      /* Enable ADC1 */
      ADC_Cmd(ADC1, ENABLE);
      /* Start ADC1 Software Conversion */
      ADC_SoftwareStartConv(ADC1);
      /* Wait for ADC to be ready */
      while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADONS));  

      while(State == STATE_OVER_THRESHOLD)
      {
        
        /* Display measured value on Glass LCD */
        DisplayVoltage(ADCVal);
        
        /* Display measured value on LCD */
        for (index = 0; index < 20; index++)
        {
          LCD_DisplayChar(LCD_LINE_3, (319 - (16 * index)), VoltageDisplay[index]);
        }
        /* Check if the measured value is below the threshold VREFINT: 1.22 V */
        if (ADCVal <= 0x000005EA)
        {
          State = STATE_UNDER_THRESHOLD;
        }
      }
    }
    else /* Input voltage is under the threshold */
    {
      /* LED1 ON: MCU in STOP mode */
      STM_EVAL_LEDInit(LED1);
      STM_EVAL_LEDOn(LED1);

      /* Disable ADC1 IRQ */
      NVIC_InitStructure.NVIC_IRQChannel = ADC1_IRQn;
      NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
      NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;
      NVIC_Init(&NVIC_InitStructure);
      /* Disable ADC1 */
      ADC_Cmd(ADC1, DISABLE);

      /* Configure COMP2 with interrupt enabled */
      COMP_Config();

      /* Check COMP2 output level before entering STOP mode */
      if (COMP_GetOutputLevel(COMP_Selection_COMP2) == COMP_OutputLevel_Low)
      {
        /* Disable LSI oscillator before entering STOP mode */
        RCC_LSICmd(DISABLE);

        /* Enter STOP mode with regulator in low power */
        PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
      }
    }
  }
}
예제 #18
0
파일: main.c 프로젝트: taegwonkim/STM32Cube
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F3xx HAL library initialization:
       - Configure the Flash prefetch
       - Systick timer is configured by default as source of time base, but user 
         can eventually implement his proper time base source (a general purpose 
         timer for example or other time source), keeping in mind that Time base 
         duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
         handled in milliseconds basis.
       - Set NVIC Group Priority to 4
       - Low Level Initialization
     */
  HAL_Init();
   
  /* Configure the system clock to 72 MHz */
  SystemClock_Config();
  
  /*## Configuration of peripherals ##########################################*/
  /* Initialize LEDs on board */
  BSP_LED_Init(LED2);
  BSP_LED_Init(LED3);
  
  /* Initialize the User Button in Interrupt mode */
  BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI);
  
  /* Configure external lines 9 to 5 in interrupt mode */
  EXTILine9_5_Config();  

  /* Configuration of ADC peripheral */
  ADC_Config();
  
  /* Run the ADC calibration in differential mode */  
  if (HAL_ADCEx_Calibration_Start(&AdcHandle, ADC_DIFFERENTIAL_ENDED) != HAL_OK)
  {
    /* Start Conversation Error */
    Error_Handler();
  }
  
  /* Configuration of DAC peripheral */
  DAC_Config();
  

  /*## Enable peripherals ####################################################*/
  
  /* Set DAC Channel data register: channel corresponding to ADC channel ADCx_CHANNEL_DIFF_HIGH */
  /* Set DAC output to 1/2 of full range (4095 <=> Vdda=3.3V): 2048 <=> 1.65V */
  if (HAL_DAC_SetValue(&DacHandle, DACx_CHANNEL_TO_ADCx_CHANNEL_DIFF_HIGH, DAC_ALIGN_12B_R, RANGE_12BITS/2) != HAL_OK)
  {
    /* Setting value Error */
    Error_Handler();
  }

  /* Set DAC Channel data register: channel corresponding to ADC channel ADCx_CHANNEL_DIFF_LOW */
      /* Set DAC output to minimum of full range (0 <=> ground 0V) */
  if (HAL_DAC_SetValue(&DacHandle, DACx_CHANNEL_TO_ADCx_CHANNEL_DIFF_LOW, DAC_ALIGN_12B_R, 0) != HAL_OK)
  {
    /* Setting value Error */
    Error_Handler();
  }
  
  /* Enable DAC Channel: channel corresponding to ADC channel ADCx_CHANNEL_DIFF_HIGH */
  if (HAL_DAC_Start(&DacHandle, DACx_CHANNEL_TO_ADCx_CHANNEL_DIFF_HIGH) != HAL_OK)
  {
    /* Start Error */
    Error_Handler();
  }
  
  /* Enable DAC Channel: channel corresponding to ADC channel ADCx_CHANNEL_DIFF_LOW */
  if (HAL_DAC_Start(&DacHandle, DACx_CHANNEL_TO_ADCx_CHANNEL_DIFF_LOW) != HAL_OK)
  {
    /* Start Error */
    Error_Handler();
  }
  
  /*## Start ADC conversions #################################################*/
  
  /* Start ADC conversion on regular group with interruption */
  if (HAL_ADC_Start_IT(&AdcHandle) != HAL_OK)
  {
    /* Start Conversation Error */
    Error_Handler();
  }
    
  
  /* Infinite loop */
  while (1)
  {
    /* Set DAC voltage on channel corresponding to ADC channel ADCx_CHANNEL_DIFF_LOW */
    /* in function of user button clicks count.                               */
    /* Set DAC output succesively to:                                         */
    /*  - minimum of full range (0 <=> ground 0V)                             */
    /*  - 1/4 of full range (4095 <=> Vdda=3.3V): 1023 <=> 0.825V             */
    /*  - 1/2 of full range (4095 <=> Vdda=3.3V): 2048 <=> 1.65V              */
    /*  - 3/4 of full range (4095 <=> Vdda=3.3V): 3071 <=> 2.475V             */
    /*  - maximum of full range (4095 <=> Vdda=3.3V)                          */
    if (HAL_DAC_SetValue(&DacHandle,
	                 DACx_CHANNEL_TO_ADCx_CHANNEL_DIFF_LOW, DAC_ALIGN_12B_R,
	                 (RANGE_12BITS * uwUserButtonClickCount / USERBUTTON_CLICK_COUNT_MAX)
	                 ) != HAL_OK)
    {
      /* Start Error */
      Error_Handler();
    }
    
    /* ADC Differential conversion result calculation:                        */
    /*  - An offset of half of full range is added to keep the full dynamic   */
    /*    range of differential voltage.                                      */
    /*  - Channels voltage is divided by 2, resolution is lowered of 1 bit.   */
    /*  => Diff conversion result = mid-range + (channel_high-channel_low)/2  */

    /* Turn-on/off LED2 in function of ADC differential conversion result */
    /*  - Turn-on LED2 if differential voltage is positive */
    /*  - Turn-off LED2 if differential voltage is negative */
    if (uhADCxConvertedValue > RANGE_12BITS/2)
    {
      BSP_LED_On(LED2);
    }
    else
    {
      BSP_LED_Off(LED2);
    }
  }
}
예제 #19
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F0xx HAL library initialization:
       - Configure the Flash prefetch
       - Systick timer is configured by default as source of time base, but user 
         can eventually implement his proper time base source (a general purpose 
         timer for example or other time source), keeping in mind that Time base 
         duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
         handled in milliseconds basis.
       - Low Level Initialization
     */
  HAL_Init();
  
  /* Configure the system clock to 48 MHz */
  SystemClock_Config();
  
  
  /*## Configure peripherals #################################################*/
  
  /* Initialize LED on board */
  BSP_LED_Init(LED2);
  
  /* Configure User push-button in Interrupt mode */
  BSP_PB_Init(BUTTON_USER, BUTTON_MODE_EXTI);
  
  /* Configure the ADCx peripheral */
  ADC_Config();
  
  /* Run the ADC calibration */
  if (HAL_ADCEx_Calibration_Start(&AdcHandle) != HAL_OK)
  {
    /* Calibration Error */
    Error_Handler();
  }

#if defined(ADC_TRIGGER_FROM_TIMER)
  /* Configure the TIM peripheral */
  TIM_Config();
#endif /* ADC_TRIGGER_FROM_TIMER */

#if defined(WAVEFORM_VOLTAGE_GENERATION_FOR_TEST)
  /* Configure the DAC peripheral and generate a constant voltage of Vdda/2.  */
  WaveformVoltageGenerationForTest_Config();
#endif /* WAVEFORM_VOLTAGE_GENERATION_FOR_TEST */
  
  
  /*## Enable peripherals ####################################################*/
  
#if defined(ADC_TRIGGER_FROM_TIMER)
  /* Timer enable */
  if (HAL_TIM_Base_Start(&TimHandle) != HAL_OK)
  {
    /* Counter Enable Error */
    Error_Handler();
  }
#endif /* ADC_TRIGGER_FROM_TIMER */
  
  
  /*## Start ADC conversions #################################################*/
  
  /* Start ADC conversion on regular group with transfer by DMA */
  if (HAL_ADC_Start_DMA(&AdcHandle,
                        (uint32_t *)aADCxConvertedValues,
                        ADCCONVERTEDVALUES_BUFFER_SIZE
                       ) != HAL_OK)
  {
    /* Start Error */
    Error_Handler();
  }
  
  
  /* Infinite loop */
  while (1)
  {
  
    /* Turn-on/off LED2 in function of ADC conversion result */
    /* - Turn-off if voltage is into AWD window */
    /* - Turn-on if voltage is out of AWD window */

    /* Variable of analog watchdog status is set into analog watchdog         */
    /* interrupt callback                                                     */
    if (ubAnalogWatchdogStatus == RESET)
    {
      BSP_LED_Off(LED2);
    }
    else
    {
      BSP_LED_On(LED2);
      
      /* Reset analog watchdog status for next loop iteration */
      ubAnalogWatchdogStatus = RESET;
    }
  
    /* For information: ADC conversion results are stored into array          */
    /* "aADCxConvertedValues" (for debug: check into watch window)            */
  
  
    /* Wait for event on push button to perform following actions */
    while ((ubUserButtonClickEvent) == RESET)
    {
    }
    /* Reset variable for next loop iteration */
    ubUserButtonClickEvent = RESET;

#if defined(WAVEFORM_VOLTAGE_GENERATION_FOR_TEST)
    /* Modifies the voltage level incrementally from 0V to Vdda at each call. */
    /* Circular waveform of ramp: When the maximum level is reaches,          */
    /* restart from 0V.                                                       */
    WaveformVoltageGenerationForTest_Update();
#endif /* WAVEFORM_VOLTAGE_GENERATION_FOR_TEST */
  }
}
예제 #20
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{

    /* STM32F3xx HAL library initialization:
         - Configure the Flash prefetch
         - Configure the Systick to generate an interrupt each 1 msec
         - Set NVIC Group Priority to 4
         - Global MSP (MCU Support Package) initialization
       */
    HAL_Init();

    /* Configure the system clock to have a system clock = 72 MHz */
    SystemClock_Config();

    /* Initialize STM32F3348-DISCO LEDs */
    BSP_LED_Init(LED3);
    BSP_LED_Init(LED4);
    BSP_LED_Init(LED6);

    /* Initialize User_Button on STM32F3348-DISCO */
    BSP_PB_Init(BUTTON_USER, BUTTON_MODE_GPIO);

    /* Initialize ADC to be triggered by the HRTIMER */
    ADC_Config();

    /* Initialize HRTIM and related inputs */
#ifdef SNIPPET
    HRTIM_Config_NoHAL();
#else
    HRTIM_Config();
#endif

    /* Initialize BUCK outputs (it has to be done after HRTIM init) */
    GPIO_BUCK_outputs_Config();

    /* Turn ON T6 MOSFET on discovery board */
    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, GPIO_PIN_SET);

    /* Infinite loop */
    while (1)
    {

        /* ---------------- */
        /* Fault management */
        /* ---------------- */
#ifdef SNIPPET
        /* If Fault occured */
        while(HRTIM1->sCommonRegs.ISR & HRTIM_ICR_FLT1C)
        {
            /* LED3 is flashing in case of fault */
            BSP_LED_On(LED3);
            HAL_Delay(20);
            BSP_LED_Off(LED3);
            HAL_Delay(80);

            /* Re-arm HRTIM TD1 output if "User" push button is pressed*/
            if((BSP_PB_GetState(BUTTON_USER) == SET))
            {
                /* Clear interrupt flag */
                HRTIM1->sCommonRegs.ICR = HRTIM_ICR_FLT1C;
                /* Re-enable TA1 and TA2 */
                HRTIM1->sCommonRegs.OENR = HRTIM_OENR_TA1OEN + HRTIM_OENR_TA2OEN;
            }
        }
#else
        while(__HAL_HRTIM_GET_FLAG(&hhrtim, HRTIM_FLAG_FLT1) == SET)
        {
            /* LED3 is flashing in case of fault */
            BSP_LED_On(LED3);
            HAL_Delay(20);
            BSP_LED_Off(LED3);
            HAL_Delay(80);

            /* Re-arm HRTIM TD1 output if "User" push button is pressed*/
            if((BSP_PB_GetState(BUTTON_USER) == SET))
            {
                __HAL_HRTIM_CLEAR_IT(&hhrtim, HRTIM_IT_FLT1);
                HAL_HRTIM_WaveformOutputStart(&hhrtim, HRTIM_OUTPUT_TA1 | HRTIM_OUTPUT_TA2);
            }
        }
#endif

        /* ---------------- */
        /* Normal operation */
        /* ---------------- */
        /* LED6 toggling to show MCU activity */
        BSP_LED_On(LED6);
        HAL_Delay(100);
        BSP_LED_Off(LED6);
        HAL_Delay(400);

        /* -----------------------------------------------------------------------*/
        /* Input and output voltages can be displayed real-time in a watch window */
        /* -----------------------------------------------------------------------*/
        Vin = (HAL_ADCEx_InjectedGetValue(&AdcHandle, ADC_INJECTED_RANK_1) * ADC_VREF)/0x1000;
        /* VIN bridge conversion is 4.97 (6.8K / 6.8K + 27K) */
        Vin = (497 * Vin )/100;

        Vout = (HAL_ADCEx_InjectedGetValue(&AdcHandle, ADC_INJECTED_RANK_2) * ADC_VREF)/0x1000;
        /* VOUT bridge conversion is 5.03 (3.3K / 3.3K + 13.3K) */
        Vout = (503 * Vout)/100;

    }
}
예제 #21
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
    //RCC_Config();
    //GPIO_Config();
    //RCC_MCO1Config(RCC_MCO1Source_PLLCLK,RCC_MCO1Div_1);
	uint8_t tmpreg;
	LIS302DL_InitTypeDef  LIS302DL_InitStruct;
  /*!< At this stage the microcontroller clock setting is already configured, 
  this is done through SystemInit() function which is called from startup
  file (startup_stm32f4xx.s) before to branch to application main.
  To reconfigure the default setting of SystemInit() function, refer to
  system_stm32f4xx.c file
  */

  /* SysTick end of count event each 10ms */
  RCC_GetClocksFreq(&RCC_Clocks);
  SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);

  //NVIC_SetPriority(SysTick_IRQn, -1);

    /* MEMS configuration and set int1/int2 pins*/
    LIS302DL_InitStruct.Power_Mode = LIS302DL_LOWPOWERMODE_ACTIVE;
    LIS302DL_InitStruct.Output_DataRate = LIS302DL_DATARATE_100;
    LIS302DL_InitStruct.Axes_Enable = LIS302DL_XYZ_ENABLE;
    LIS302DL_InitStruct.Full_Scale = LIS302DL_FULLSCALE_2_3;
    LIS302DL_InitStruct.Self_Test = LIS302DL_SELFTEST_NORMAL;
    LIS302DL_Init(&LIS302DL_InitStruct);
	//Set INT1/INT2 pins
	tmpreg = 0x40;
	LIS302DL_Write(&tmpreg, LIS302DL_CTRL_REG3_ADDR, 1);

	//Initialize the touchscreen
	TSC_Init();

  	/* Initialize LEDs and push-buttons mounted on STM324xG-EVAL board */
	STM_EVAL_LEDInit(LED1);
	STM_EVAL_LEDInit(LED2);
	//STM_EVAL_LEDInit(LED3);
	//STM_EVAL_LEDInit(LED4);

	/* Initialize the LCD */
  	STM324xG_LCD_Init();
  	//STM_EVAL_LEDOn(LED1);
  	LCD_Clear(Black);
  	LCD_SetTextColor(White);

  	LCD_LOG_SetHeader("STM32 Camera Demo");
  	LCD_LOG_SetFooter ("   Copyright (c) STMicroelectronics" );

  	/* ADC configuration */
  	ADC_Config();

  	/* Initializes the DCMI interface (I2C and GPIO) used to configure the camera */
  	//OV9655_HW_Init();
        OV9712_HW_Init();
  	/* Read the OV9655/OV2640 Manufacturer identifier */
  	//OV9655_ReadID(&OV9655_Camera_ID);
        OV9712_ReadID(&OV9712_Camera_ID);
        //while(1);  
  	if(OV9655_Camera_ID.PID  == 0x96)
  	{
    	Camera = OV9712_CAMERA;
    	sprintf((char*)buffer, "OV9655 Camera ID 0x%x", OV9655_Camera_ID.PID);
    	ValueMax = 2;
  	}
  	else if(OV9712_Camera_ID.PIDH  == 0x97)
  	{
    	Camera = OV9712_CAMERA;
    	sprintf((char*)buffer, "OV9712 Camera ID 0x%x", OV9712_Camera_ID.PIDH);
    	ValueMax = 2;
  	}
  	else
  	{
    	LCD_SetTextColor(LCD_COLOR_RED);
    	sprintf((char*)buffer, "OV Camera ID 0x%02x%02x", OV9655_Camera_ID.Version, OV9712_Camera_ID.PIDH);
    	LCD_DisplayStringLine(LINE(4), buffer);
    	while(1);  
  	}

  	LCD_SetTextColor(LCD_COLOR_YELLOW);
  	LCD_DisplayStringLine(LINE(4), (uint8_t*)buffer);
  	LCD_SetTextColor(LCD_COLOR_WHITE);

  	Delay(200);

  	/* Initialize demo */
  	ImageFormat = (ImageFormat_TypeDef)BMP_QVGA;

  	/* Configure the Camera module mounted on STM324xG-EVAL board */
  	Demo_LCD_Clear();
  	LCD_DisplayStringLine(LINE(4), "Camera Init..               ");
  	Camera_Config();

  	sprintf((char*)buffer, " Image selected: %s", ImageForematArray[ImageFormat]);
  	LCD_DisplayStringLine(LINE(4),(uint8_t*)buffer);

  	LCD_ClearLine(LINE(4));
  	Demo_LCD_Clear();
  
        
        

  	if(ImageFormat == BMP_QQVGA)
  	{
    	/* LCD Display window */
    	LCD_SetDisplayWindow(60, 80, 160, 120);
    	ReverseLCD();
    	LCD_WriteRAM_Prepare(); 
  	}
  	else if(ImageFormat == BMP_QVGA)
  	{
    	/* LCD Display window */
    	LCD_SetDisplayWindow(0, 0, 320, 240);
    	ReverseLCD();
    	LCD_WriteRAM_Prepare(); 
  	}

	{
		int i, j;
		for (j = 0; j < 16; j++)
		{
			LCD_SetDisplayWindow(0, (240 / 16) * j, 320, (240 / 16));
			LCD_WriteRAM_Prepare();
			for (i = 0; i <	320 * 240 / 16; i++)
			{
				LCD_WriteRAM(0x0003 << j);
			}
		}
	}

  	/* Enable DMA2 stream 1 and DCMI interface then start image capture */
  	DMA_Cmd(DMA2_Stream1, ENABLE); 
  	DCMI_Cmd(ENABLE); 

  	/* Insert 100ms delay: wait 100ms */
  	//Delay(200); 

  	DCMI_CaptureCmd(ENABLE); 

  	while(1)
  	{
	      OV9655_BrightnessConfig(0x7F);//

		//static int step = 0;
		int i, block, begin;
		unsigned short *p;

		if (!bShot)
		{
			begin = (datablock - 11 + 48) % 48;
	
			for (block = begin; block < begin + 11; block++)
			{
				p = (unsigned short *)(0x20000000 + (320 * 240 * 2 / 16) * ((block) % 12));
				LCD_SetDisplayWindow(0, (block % 16) * (240 / 16), 320, (240 / 16));
				//LCD_SetCursor(0, (block % 16) * (240 / 16));
				LCD_WriteRAM_Prepare();
				for (i = 0; i <	320 * 240 / 16; i++)
				{
					LCD_WriteRAM(*p++);
				}
			}
		}
		if (TSC_TouchDet())
		{
			int x, y;
			TP_GetAdXY(&x, &y);
			if (x > 300 && x < 2800 && y > 300 && y < 2800)
			{
				if (x < 1550 && y < 1550)
				{
					uint32_t StartSector = 0, EndSector = 0, Address = 0, SectorCounter = 0;
					int m;
					//拍照bShot
					bShot = 1;
					while(datablock % 16);
					DMA_Cmd(DMA2_Stream1, DISABLE); 
					DCMI_Cmd(DISABLE);
					//STM_EVAL_LEDOn(LED2); 
					DMA_ClearFlag(DMA2_Stream1, 0x2F7D0F7D);
					DMA_ClearFlag(DMA2_Stream1, 0x0F7D0F7D);
					DMA_ClearITPendingBit(DMA2_Stream1, DMA_IT_TCIF1);
					datablock = 0;
					DMA2_Stream1->M0AR = 0x20000000 + 9600 * (datablock % 12);
					DMA_SetCurrDataCounter(DMA2_Stream1, (320 * 240 * 2 / 4) / 16);

					DCMI_Cmd(ENABLE);
					DMA_Cmd(DMA2_Stream1, ENABLE);
					
					{
						unsigned long *p, *q;
						while(datablock < 4);	//等待准备好前4块数据,就将这4块数据导入到0x10000000+0x50000之后。
						q = (unsigned long *)(0x20000000);
						p = (unsigned long *)(0x10000000 + 0x5000);
						while (q < (unsigned long *)(0x20000000 + 4 * (320 * 240 * 2 / 16)))
						{
							*p = *q;
							p++;
							q++;
						}
					}


					while(datablock < 16);		//等待全部采集完成。

					STM_EVAL_LEDOn(LED2);		//LED2亮表示采集完成。
					LCD_SetDisplayWindow(0, 0, 320, 240);
					LCD_WriteRAM_Prepare();
					LCD_Clear(Black);
					//RAM位置
					/*
						序号  地址                大小
						1:    0x10005000+9600*0     9600
						2:    0x10005000+9600*1     9600
						3:    0x10005000+9600*2     9600
						4:    0x10005000+9600*3     9600
						5:    0x20000000+9600*5     9600
						6:    0x20000000+9600*6     9600
						7:    0x20000000+9600*7     9600
						8:    0x20000000+9600*8     9600
						9:    0x20000000+9600*9     9600
						10:   0x20000000+9600*10    9600
						11:   0x20000000+9600*11    9600
						12:   0x20000000+9600*0     9600
						13:   0x20000000+9600*1     9600
						14:   0x20000000+9600*2     9600
						15:   0x20000000+9600*3     9600					
					*/
				 	for (m = 0; m < 16; m++)	//显示保存的图片
					{
						unsigned short *q;
						if (m < 4)
						{
							q = (unsigned short *)(0x10000000 + 0x5000 + m * (320 * 240 * 2 / 16));
						}
						else
						{
							q = (unsigned short *)(0x20000000 + (m % 12) * (320 * 240 * 2 / 16));
						}
						LCD_SetDisplayWindow(0, m * (240 / 16), 320, (240 / 16));
						LCD_WriteRAM_Prepare();
						for (i = 0; i <	320 * 240 / 16; i++)
						{
							LCD_WriteRAM(*q++);
						}
					}

					/* Erase the user Flash area ***********/
					FLASH_Unlock();
					
					/* Clear pending flags (if any) */  
					FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | 
						FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR); 
					
					/* Get the number of the start and end sectors */
					StartSector = GetSector(FLASH_USER_START_ADDR);
					EndSector = GetSector(FLASH_USER_END_ADDR);
					
					for (SectorCounter = StartSector; SectorCounter < EndSector; SectorCounter += 8)
					{
						/* Device voltage range supposed to be [2.7V to 3.6V], the operation will
						be done by word */ 
						if (FLASH_EraseSector(SectorCounter, VoltageRange_3) != FLASH_COMPLETE)
						{ 
							/* Error occurred while sector erase. 
							User can add here some code to deal with this error  */
							while (1)
							{
							}
						}
					}
										
				 	for (m = 0; m < 16; m++)	//保存图片到flash
					{
						unsigned long *q;
						Address = FLASH_USER_START_ADDR + m * (320 * 240 * 2 / 16);
						if (m < 4)
						{
							q = (unsigned long *)(0x10000000 + 0x5000 + m * (320 * 240 * 2 / 16));
						}
						else
						{
							q = (unsigned long *)(0x20000000 + (m % 12) * (320 * 240 * 2 / 16));
						}
						while (Address < FLASH_USER_START_ADDR + (m + 1) *(320 * 240 * 2 / 16))
						{
							if (FLASH_ProgramWord(Address, *q) == FLASH_COMPLETE)
							{
								Address = Address + 4;
								q++;
							}
							else
							{ 
								/* Error occurred while writing data in Flash memory. 
								User can add here some code to deal with this error */
								while (1)
								{
								}
							}
						}
					}

					STM_EVAL_LEDOff(LED2);
					LCD_SetDisplayWindow(0, 0, 320, 240);
					LCD_WriteRAM_Prepare();
					LCD_Clear(Black);
				 	for (m = 0; m < 16; m++)	//显示flash中的图片
					{
						unsigned short *q;
						q = (unsigned short *)(FLASH_USER_START_ADDR + m * (320 * 240 * 2 / 16));
						LCD_SetDisplayWindow(0, m * (240 / 16), 320, (240 / 16));
						LCD_WriteRAM_Prepare();
						for (i = 0; i <	320 * 240 / 16; i++)
						{
							LCD_WriteRAM(*q++);
						}
					}
					/* Lock the Flash to disable the flash control register access (recommended
					 to protect the FLASH memory against possible unwanted operation) *********/
					FLASH_Lock(); 
				}
				else if (x >= 1550 && y < 1550)
				{
					//righttop
					STM_EVAL_LEDOff(LED1);
					STM_EVAL_LEDOff(LED2);
					bShot = 0;
					datablock = 0;
					DMA_Cmd(DMA2_Stream1, ENABLE);
					DCMI_Cmd(ENABLE); 
				}
				else if (x < 1550 && y >= 1550)
				{
					//righttop
					//DMA_Cmd(DMA2_Stream1, ENABLE);
					//DCMI_Cmd(ENABLE); 
				}
				else if (x >= 1550 && y >= 1550)
				{
					//righttop
					//DMA_Cmd(DMA2_Stream1, ENABLE);
					//DCMI_Cmd(ENABLE); 
				}
			}
		}
		//Delay(10);
  	}	
}
예제 #22
0
/**************************************************************/
//程 序 名: Adc_Init()
//开 发 者: chenhonglin
//入口参数: 无
//功能说明: ADC所有外设初始化
//**************************************************************/
void  Adc_Init(void)
{
	ADC_Config();
	DMA_Config();
}
예제 #23
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{

  /* STM32F3xx HAL library initialization:
       - Configure the Flash prefetch
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
  HAL_Init();

  /* Configure the system clock to have a system clock = 72 MHz */
  SystemClock_Config();

  /* Initialize STM32F3348-DISCO LEDs */
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4);
  BSP_LED_Init(LED6);

  /* Initialize User_Button on STM32F3348-DISCO */
  BSP_PB_Init(BUTTON_USER, BUTTON_MODE_GPIO);   

  /* Initialize ADC to be triggered by the HRTIMER */
  ADC_Config();
  
  /* Initialize HRTIM and related inputs */
  HRTIM_Config();
  /* Initialize HRTIM outputs (it has to be done after HRTIM init) */
  GPIO_HRTIM_outputs_Config();
  
  /* Infinite loop */
  while (1)
  {
    
    /* ---------------- */
    /* Fault management */
    /* ---------------- */
    while(__HAL_HRTIM_GET_FLAG(&hhrtim, HRTIM_FLAG_FLT1) == SET)
    {
      /* LED3 is flashing in case of fault */
      BSP_LED_On(LED3);
      HAL_Delay(20);
      BSP_LED_Off(LED3);
      HAL_Delay(80);
      
      /* Re-arm HRTIM TD1 output if "User" push button is pressed*/
      if((BSP_PB_GetState(BUTTON_USER) == SET))
      {
          __HAL_HRTIM_CLEAR_IT(&hhrtim, HRTIM_IT_FLT1);
          HAL_HRTIM_WaveformOutputStart(&hhrtim, HRTIM_OUTPUT_TD1);
      }
    }

    /* ---------------- */
    /* Normal operation */
    /* ---------------- */
    /* LED6 toggling to show MCU activity */
    BSP_LED_On(LED6);
    HAL_Delay(100);
    BSP_LED_Off(LED6);
    HAL_Delay(400);
    
    /* -------------------------------------------------------------------- */
    /* ADC monitoring (to be viewed with watch)                             */
    /* PA4 can be connected to the RC filter or any voltage to be monitored */
    /* -------------------------------------------------------------------- */
    ADCReadout = HAL_ADCEx_InjectedGetValue(&AdcHandle, ADC_INJECTED_RANK_1);
    
  }
}
예제 #24
0
파일: main.c 프로젝트: zk1132/contiki
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
    uint16_t voltage = 0;

    /* Init the Eval board LCD */
    STM8_EVAL_LCD_Init();

    /* Clear LCD */
    LCD_Clear();

    /* Print "RV ADC Voltage" on LCD line1*/
    LCD_SetCursorPos(LCD_LINE1, 0);
    LCD_Print("RV ADC Voltage");

    /* ADC configuration -------------------------------------------*/
    ADC_Config();

    /* Init Leds */
    STM_EVAL_LEDInit(LED1);
    STM_EVAL_LEDInit(LED3);
    STM_EVAL_LEDInit(LED4);

    /* Infinite loop*/
    while (1)
    {
        ADCSavedData = ADCData;
        while (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);
        ADCData = ADC_GetConversionValue(ADC1);

        if (ADCSavedData != ADCData)
        {
            /* Calculate voltage value*/
            voltage = (uint16_t)(((uint32_t)ADCData * (uint32_t)ADC_RATIO) / (uint32_t)1000);

            /* Display voltage value on LCD*/
            ShowVoltage(voltage);
            STM_EVAL_LEDOff(LED1);

            /* LED4 is On only if ADC converted data is higher
               than High Analog watchdog Threshold */
            if (ADCData >= HighThresholdData)
            {
                STM_EVAL_LEDOn(LED4);
                LCDString[14] = '<';
            }
            else
            {
                STM_EVAL_LEDOff(LED4);
                LCDString[14] = ' ';
            }

            /* LED3 is On only if ADC converted data is lower
              than Low Analog watchdog Threshold */
            if (ADCData <= LowThresholdData)
            {
                STM_EVAL_LEDOn(LED3);
                LCDString[0] = '>';
            }
            else
            {
                STM_EVAL_LEDOff(LED3);
                LCDString[0] = ' ';
            }
        }
    }

}
예제 #25
0
파일: main.c 프로젝트: mehdikhan/EvvGC-FW
int main(void)
{
    Delay_ms(100);
    Periph_clock_enable();
    GPIO_Config();
    Usart4Init();
    I2C_Config();
    ADC_Config();
    MPU6050_Init();
    Timer1_Config();
    Timer8_Config();
    Timer2_Config();
    Timer5_Config();
    Timer4_Config();
    Timer3_Config();//RC control timer
    NVIC_Configuration();
    EXTI_Config();

    TIM_Cmd(TIM5, ENABLE);
    TIM_CtrlPWMOutputs(TIM5, ENABLE);

    for (i = 1 ; i < 1 ; i++) ; //small delay before starting Timer4

    TIM_Cmd(TIM4, ENABLE);
    TIM_CtrlPWMOutputs(TIM4, ENABLE);



    Delay_ms(100);

    for (i = 0; i < configDataSize; i++) //reads configuration from eeprom
    {
        ReadFromEEPROM(i);
        configData[i] = EepromData;
        Delay_ms(5);
    }

    I2C_AcknowledgeConfig(I2C2, ENABLE);

    Delay_ms(100);



    while (1)
    {
        LEDon;
        DEBUG_LEDon;

        while (ConfigMode == 1)
        {
            TimerOff();   //Configuration loop
        }

        MPU6050_ACC_get();//Getting Accelerometer data

        acc_roll_angle = -(atan2(accADC_x, accADC_z)) + (configData[11] - 50.00) * 0.0035; //Calculating pitch ACC angle+callibration
        acc_pitch_angle  = +(atan2(accADC_y, accADC_z));   //Calculating roll ACC angle

        MPU6050_Gyro_get();//Getting Gyroscope data

        acc_roll_angle_vid = ((acc_roll_angle_vid * 99.00) + acc_roll_angle) / 100.00; //Averaging pitch ACC values
        acc_pitch_angle_vid = ((acc_pitch_angle_vid * 99.00) + acc_pitch_angle) / 100.00; //Averaging roll  ACC values

        sinus   = sinusas[(int)(rc4)];      //Calculating sinus
        cosinus = sinusas[90 - (int)(rc4)]; //Calculating cosinus

        ROLL = -gyroADC_z * sinus + gyroADC_y * cosinus;
        roll_angle = (roll_angle + ROLL * dt)    + 0.0002 * (acc_roll_angle_vid - roll_angle); //Roll Horizon

        //ROLL=-gyroADC_z*sinus+gyroADC_y*cosinus;
        yaw_angle = (yaw_angle + gyroADC_z * dt); //Yaw

        pitch_angle_true = ((pitch_angle_true  + gyroADC_x * dt) + 0.0002 * (acc_pitch_angle_vid - pitch_angle_true)); //Pitch Horizon

        ADC1Ch1_vid = ((ADC1Ch1_vid * 99.00) + (readADC1(1) / 4000.00)) / 100.00; //Averaging ADC values
        ADC1Ch1_vid = 0.00;

        rc4_avg = ((rc4_avg * 499.00) + (rc4)) / 500.00; //Averaging RC4 values
        pitch_angle = pitch_angle_true - rc4_avg / 57.3; //Adding angle

        pitch_angle_correction = pitch_angle * 150.0;

        if (pitch_angle_correction > 2.0)
        {
            pitch_angle_correction = 2.0;
        }

        if (pitch_angle_correction < -2.0)
        {
            pitch_angle_correction = -2.0;
        }

        pitch_setpoint = pitch_setpoint + pitch_angle_correction; //Pitch return to zero after collision

        roll_angle_correction = roll_angle * 200.0;

        if (roll_angle_correction > 2.0)
        {
            roll_angle_correction = 2.0;
        }

        if (roll_angle_correction < -2.0)
        {
            roll_angle_correction = -2.0;
        }

        roll_setpoint = roll_setpoint + roll_angle_correction; //Roll return to zero after collision



        ADC1Ch13_vid = ((ADC1Ch13_vid * 99.00) + ((readADC1(13) - 2000) / 4000.00)) / 100.00; //Averaging ADC values

        if (configData[10] == '0')
        {
            yaw_angle = (yaw_angle + gyroADC_z * dt) + 0.01 * (ADC1Ch13_vid - yaw_angle);   //Yaw AutoPan
        }

        if (configData[10] == '1')
        {
            yaw_angle = (yaw_angle + gyroADC_z * dt);   //Yaw RCPan
        }

        yaw_angle_correction = yaw_angle * 50.0;

        if (yaw_angle_correction > 1.0)
        {
            yaw_angle_correction = 1.0;
        }

        if (yaw_angle_correction < -1.0)
        {
            yaw_angle_correction = -1.0;
        }

        yaw_setpoint = yaw_setpoint + yaw_angle_correction; //Yaw return to zero after collision

        pitch_PID();//Pitch axis pid
        roll_PID(); //Roll axis pid
        yaw_PID(); //Yaw axis pid


        printcounter++; //Print data to UART

        if (printcounter >= 100)
        {
            //sprintf (buff, " %d %d %c Labas\n\r", ACCread[0], ACCread[1], ACCread[2]);
            //sprintf (buff, " %x %x %x %x %x %x Labas\n\r", ACCread[0], ACCread[1], ACCread[2], ACCread[3], ACCread[4], ACCread[5]);
            //sprintf (buff, "Labas %d %d\n\r", ACCread[0], ACCread[1]);
            //sprintf (buff, "%3.1f %f\n\r", ADC1Ch1_vid*57.3, sinus);
            //sprintf (buff, "Labas %f %f %f \n\r", accADC_x, accADC_y, accADC_z);
            //sprintf (buff, "%3.1f %3.1f \n\r", acc_roll_angle_vid*57.3,  acc_pitch_angle_vid *57.3);
            //sprintf (buff, "%3.1f %3.1f \n\r", pitch_angle*57.3,  roll_angle*57.3);
            //sprintf (buff, "%d\n\r", rc4);
            //USART_PutString(buff);
            printcounter = 0;
        }

        stop = 0;
        LEDoff;
        watchcounter = 0;

        while (stop == 0) {} //Closed loop waits for interrupt


    }
}
예제 #26
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F1xx HAL library initialization:
       - Configure the Flash prefetch
       - Systick timer is configured by default as source of time base, but user 
         can eventually implement his proper time base source (a general purpose 
         timer for example or other time source), keeping in mind that Time base 
         duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
         handled in milliseconds basis.
       - Set NVIC Group Priority to 4
       - Low Level Initialization
     */
  HAL_Init();
  
  /* Configure the system clock to 24 MHz */
  SystemClock_Config();
  
  /*## Configure peripherals #################################################*/
  
  /* Initialize LEDs on board */
  BSP_LED_Init(LED4);
  BSP_LED_Init(LED3);
  
  /* Configure User push-button in Interrupt mode */
  BSP_PB_Init(BUTTON_USER, BUTTON_MODE_EXTI);
  
  /* Configure the ADC peripheral */
  ADC_Config();
  
  /* Run the ADC calibration */  
  if (HAL_ADCEx_Calibration_Start(&AdcHandle) != HAL_OK)
  {
    /* Calibration Error */
    Error_Handler();
  }

#if defined(ADC_TRIGGER_FROM_TIMER)
  /* Configure the TIM peripheral */
  TIM_Config();
#endif /* ADC_TRIGGER_FROM_TIMER */
#if defined(WAVEFORM_VOLTAGE_GENERATION_FOR_TEST)
  /* Configure the DAC peripheral */
  DAC_Config();
#endif /* WAVEFORM_VOLTAGE_GENERATION_FOR_TEST */

  /*## Enable peripherals ####################################################*/
#if defined(ADC_TRIGGER_FROM_TIMER)
  /* Timer enable */
  if (HAL_TIM_Base_Start(&TimHandle) != HAL_OK)
  {
    /* Counter Enable Error */
    Error_Handler();
  }
#endif /* ADC_TRIGGER_FROM_TIMER */

#if defined(WAVEFORM_VOLTAGE_GENERATION_FOR_TEST)
  /* Set DAC Channel data register: channel corresponding to ADC channel CHANNELa */
  /* Set DAC output to 1/2 of full range (4095 <=> Vdda=3.3V): 2048 <=> 1.65V              */
  if (HAL_DAC_SetValue(&DacHandle, DACx_CHANNEL_TO_ADCx_CHANNELa, DAC_ALIGN_12B_R, RANGE_12BITS/2) != HAL_OK)
  {
    /* Setting value Error */
    Error_Handler();
  }
  
  /* Enable DAC Channel: channel corresponding to ADC channel CHANNELa */
  if (HAL_DAC_Start(&DacHandle, DACx_CHANNEL_TO_ADCx_CHANNELa) != HAL_OK)
  {
    /* Start Error */
    Error_Handler();
  }
#endif /* WAVEFORM_VOLTAGE_GENERATION_FOR_TEST */

  /*## Start ADC conversions #################################################*/
  
  /* Start ADC conversion on regular group with transfer by DMA */
  if (HAL_ADC_Start_DMA(&AdcHandle,
                        (uint32_t *)aADCxConvertedValues,
                        ADCCONVERTEDVALUES_BUFFER_SIZE
                       ) != HAL_OK)
  {
    /* Start Error */
    Error_Handler();
  }
  
  
  /* Infinite loop */
  while (1)
  {

    /* Wait for event on push button to perform following actions */
    while ((ubUserButtonClickEvent) == RESET)
    {
    }
    /* Reset variable for next loop iteration */
    ubUserButtonClickEvent = RESET;
    
    /* Start ADC conversion on injected group */
    if (HAL_ADCEx_InjectedStart_IT(&AdcHandle) != HAL_OK)
    {
      /* Start Conversation Error */
      Error_Handler();
    }
    

#if defined(WAVEFORM_VOLTAGE_GENERATION_FOR_TEST)
    /* Set DAC voltage on channel corresponding to ADCx_CHANNELa              */
    /* in function of user button clicks count.                               */
    /* Set DAC output successively to:                                        */
    /*  - minimum of full range (0 <=> ground 0V)                             */
    /*  - 1/4 of full range (4095 <=> Vdda=3.3V): 1023 <=> 0.825V             */
    /*  - 1/2 of full range (4095 <=> Vdda=3.3V): 2048 <=> 1.65V              */
    /*  - 3/4 of full range (4095 <=> Vdda=3.3V): 3071 <=> 2.475V             */
    /*  - maximum of full range (4095 <=> Vdda=3.3V)                          */
    if (HAL_DAC_SetValue(&DacHandle,
                         DACx_CHANNEL_TO_ADCx_CHANNELa,
                         DAC_ALIGN_12B_R,
                         (RANGE_12BITS * ubUserButtonClickCount / USERBUTTON_CLICK_COUNT_MAX)
                        ) != HAL_OK)
    {
      /* Start Error */
      Error_Handler();
    }
#endif /* WAVEFORM_VOLTAGE_GENERATION_FOR_TEST */

    /* Wait for acquisition time of ADC samples on regular and injected       */
    /* groups:                                                                */
    /* wait time to let 1/2 buffer of regular group to be filled (in ms)      */
    HAL_Delay(16);
    
    /* Turn-on/off LED3 in function of ADC conversion result */
    /* - Turned-off if voltage measured by injected group is below voltage    */
    /*   measured by regular group (average of results table)                 */
    /* - Turned-off if voltage measured by injected group is above voltage    */
    /*   measured by regular group (average of results table)                 */
    
    /* Variables of conversions results are updated into ADC conversions      */
    /* interrupt callback.                                                    */
    if (uhADCxConvertedValue_Injected < *puhADCxConvertedValue_Regular_Avg)
    {
      BSP_LED_Off(LED3);
    }
    else
    {
      BSP_LED_On(LED3);
    }
  
    /* For information: ADC conversion results are stored into array          */
    /* "aADCxConvertedValues" (for debug: check into watch window)            */
    
  }
}
예제 #27
0
uint32_t Syringe_Size(void)
{
	uint32_t adc_value;
	uint32_t adc_valuetest=0;
 ADC_Config();
	
	
	  if (HAL_ADCEx_Calibration_Start(&AdcHandle) != HAL_OK)
  {
    /* Calibration Error */
    Error_Handler();
  }
	
	#if defined(ADC_TRIGGER_FROM_TIMER)
  /* Configure the TIM peripheral */
  TIM_Config();
#endif /* ADC_TRIGGER_FROM_TIMER */
	
	 /*## Enable peripherals ####################################################*/
#if defined(ADC_TRIGGER_FROM_TIMER)
  /* Timer enable */
  if (HAL_TIM_Base_Start(&TimHandle) != HAL_OK)
  {
    /* Counter Enable Error */
    Error_Handler();
  }
#endif /* ADC_TRIGGER_FROM_TIMER */
  /* Note: This example, on some other STM32 boards, is performing            */
  /*       DAC signal generation here.                                        */
  /*       On STM32F103RB-Nucleo, the device has no DAC available,            */
  /*       therefore analog signal must be supplied externally.               */

  /*## Start ADC conversions #################################################*/
  
  /* Start ADC conversion on regular group with transfer by DMA */
//   if (HAL_ADC_Start_DMA(&AdcHandle,
//                         (uint32_t *)aADCxConvertedValues,
//                         ADCCONVERTEDVALUES_BUFFER_SIZE
//                        ) != HAL_OK)
//   {
//     /* Start Error */
//     Error_Handler();
//   }
   if (HAL_ADC_Start(&AdcHandle) != HAL_OK)
  {
    /* Start Error */
    Error_Handler();
  }
	
	if (HAL_ADC_PollForConversion(&AdcHandle,10) != HAL_OK)
		  {
    /* Start Error */
    Error_Handler();
  }
	
	adc_value= HAL_ADC_GetValue(&AdcHandle);
	if(adc_value<=0x400) return(10);
	else if(adc_value>0x400 && adc_value<=0x800) return(20); 
	else if(adc_value>0x800 && adc_value<=0xc00) return(30); 
	else if(adc_value>0xc00)
	return(50);

}
예제 #28
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
  /*************** Initialize LEDs available on STM8L15X-EVAL board ***********/
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);

  /* CLK configuration -------------------------------------------*/
  CLK_Config(); 
  
  /* ADC configuration -------------------------------------------*/
  ADC_Config(); 

  /* COMP configuration -------------------------------------------*/
  COMP_Config(); 

  while (1)
  {
    if (State != STATE_UNDER_THRESHOLD) /* Input voltage is over the threshold VREFINT */
    {
      /* LD1 ON and LD2 OFF: MCU in run mode */
      STM_EVAL_LEDOn(LED1);
      STM_EVAL_LEDOff(LED2);

      /* Disable global Interrupts */
      disableInterrupts();
      /* Disable COMP clock */
      CLK_PeripheralClockConfig(CLK_Peripheral_COMP, DISABLE);

      /* Enable ADC1 clock */
      CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);
      /* Enable end of conversion ADC1 Interrupt */
      ADC_ITConfig(ADC1, ADC_IT_EOC, DISABLE);
      /* Enable ADC1 */
      ADC_Cmd(ADC1, ENABLE);

      /* Start ADC1 Software Conversion */
      ADC_SoftwareStartConv(ADC1);
      /* Wait for first end of conversion */
      while (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);
      ADCVal = ADC_GetConversionValue(ADC1);
      /* Enable global Interrupts */
      enableInterrupts();

      /* Enable end of conversion ADC1 Interrupt */
      ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);

      while (State == STATE_OVER_THRESHOLD)
      {}
    }
    else /* Input voltage is under the threshold */
    {
      /* LD1 OFF and LD2 ON: MCU in halt mode */
      STM_EVAL_LEDOff(LED1);
      STM_EVAL_LEDOn(LED2);

      /* Disable global Interrupts */
      disableInterrupts();
      /* Clear EOC and OVR flags */
      ADC_ClearFlag(ADC1, (ADC_FLAG_TypeDef) (ADC_FLAG_EOC | ADC_FLAG_OVER));
      /* Disable ADC1 */
      ADC_Cmd(ADC1, DISABLE);
      /* Disable ADC1 clock */
      CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, DISABLE);

      /* Enable COMP clock */
      CLK_PeripheralClockConfig(CLK_Peripheral_COMP, ENABLE);
      /* Enable COMP2 Interrupt */
      COMP_ITConfig(COMP_Selection_COMP2, ENABLE);

      /* Enable global Interrupts */
      enableInterrupts();
      /* Check COMP2 output level before entering halt mode */
      if (COMP_GetOutputLevel(COMP_Selection_COMP2) == COMP_OutputLevel_Low)
      {
        /* Enter halt mode */
        halt();
      }
    }
  }
}
예제 #29
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
 /* This sample code shows how to convert an analog input and read the converted
    data using polling mode. */
   
  /* STM32F0xx HAL library initialization:
       - Configure the Flash prefetch
       - Systick timer is configured by default as source of time base, but user 
         can eventually implement his proper time base source (a general purpose 
         timer for example or other time source), keeping in mind that Time base 
         duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
         handled in milliseconds basis.
       - Low Level Initialization
     */
  HAL_Init();

  /* Configure the system clock to 48 MHz */
  SystemClock_Config();

  /* Initialize LEDs on board */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED3);

  
  /* Configure Tamper push-button in non-interrupt mode */
  BSP_PB_Init(BUTTON_TAMPER, BUTTON_MODE_GPIO);

  /* LCD Display init  */
  Display_Init();
  
  /* Configure the ADC peripheral */
  ADC_Config();

  /* Run the ADC calibration */  
  if (HAL_ADCEx_Calibration_Start(&AdcHandle) != HAL_OK)
  {
    /* Calibration Error */
    Error_Handler();
  }

  /* Configure the TIM peripheral */
  TIM_Config();  

  /*## Enable peripherals ####################################################*/

  /* Timer counter enable */
  if (HAL_TIM_Base_Start(&TimHandle) != HAL_OK)
  {
    /* Counter Enable Error */
    Error_Handler();
  }
  
  /* For this example purpose, enable ADC overrun interruption. */
  /* In this ADC LowPower example, ADC overrun is not considered as an error, */
  /* but as a way to watch the ADC low power modes effectiveness.             */
  /* Note: Enabling overrun has no usefulness except for this example purpose:*/
  /*       ADC overrun cannot occur with ADC low power mode "auto-wait"       */
  /*       Usually, in normal application, overrun is enabled automatically   */
  /*       by HAL ADC driver with functions "HAL_ADC_Start_IT()" or           */
  /*       "HAL_ADC_Start_DMA()", but this is not compliant with low power    */
  /*       modes. Refer to comments of parameter "LowPowerAutoWait" in HAL    */
  /*       ADC driver definition file.                                        */
  __HAL_ADC_ENABLE_IT(&AdcHandle, (ADC_IT_OVR));

  /* Start ADC conversion */
  HAL_ADC_Start(&AdcHandle);
  
  /* Wait for the first ADC conversion to be completed (timeout unit: ms) */
  HAL_ADC_PollForConversion(&AdcHandle, (1000/TIMER_FREQUENCY_HZ));
  
  /* Infinite loop */
  while (1)
  {
    /* Wait for at least 2 ADC conversions elapsed time, to let time for      */
    /* potential overrun event to occur (unit: ms)                            */
    HAL_Delay(2* (1000/TIMER_FREQUENCY_HZ));
  
    /* Manage LED1 status in function of ADC overrun event */
    if (ubADC_overrun_status != RESET)
    {
      /* Turn on LED1 to indicate ADC overrun event */
      BSP_LED_On(LED1);
      
      /* Reset overrun status variable for next iteration loop */ 
      ubADC_overrun_status = RESET;
    }
    else
    {
      /* Turn off LED1 to indicate no ADC overrun event */
      BSP_LED_Off(LED1);
    }
  
    /* Press Tamper push-button on STM32091C-EVAL to get the converted data */
    while(BSP_PB_GetState(BUTTON_TAMPER) != GPIO_PIN_RESET);
    while(BSP_PB_GetState(BUTTON_TAMPER) != GPIO_PIN_SET);
    
    /* Get ADC1 converted data */
    /* If ADC low power mode auto-wait is enabled, this release the ADC */
    /* from idle mode: a new conversion will start at the next trigger  */
    /* event.                                                           */
    uhADCxConvertedValue = HAL_ADC_GetValue(&AdcHandle);
    
    /* Compute the voltage */
    uhADCxConvertedVoltage = COMPUTATION_DIGITAL_12BITS_TO_VOLTAGE(uhADCxConvertedValue);
    
    /* Display converted data on the LCD */
    Display();
  }
}
예제 #30
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F3xx HAL library initialization:
       - Configure the Flash prefetch
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Low Level Initialization
     */
  HAL_Init();
  
  /* Configure the system clock to 64 MHz */
  SystemClock_Config();
  
  /*## Configure peripherals #################################################*/
  /* Initialize LED on board */
  BSP_LED_Init(LED2);

  /* Configure User push-button in Interrupt mode */
  BSP_PB_Init(BUTTON_USER, BUTTON_MODE_EXTI);

  /* Configure the ADC peripheral */
  ADC_Config();
  
  /* Run the ADC calibration in single-ended mode */  
  if (HAL_ADCEx_Calibration_Start(&AdcHandle, ADC_SINGLE_ENDED) != HAL_OK)
  {
    /* Calibration Error */
    Error_Handler();
  }

  /* Configure the TIM peripheral */
  TIM_Config();
  
  /* Configure the DAC peripheral */
  DAC_Config();
  

  /*## Enable peripherals ####################################################*/

  /* Timer counter enable */
  if (HAL_TIM_Base_Start(&TimHandle) != HAL_OK)
  {
    /* Counter Enable Error */
    Error_Handler();
  }
  
  /* Set DAC Channel data register: channel corresponding to ADC channel CHANNELa */
  /* Set DAC output to 1/2 of full range (4095 <=> Vdda=3.3V): 2048 <=> 1.65V              */
  if (HAL_DAC_SetValue(&DacHandle, DACx_CHANNEL_TO_ADCx_CHANNELa, DAC_ALIGN_12B_R, RANGE_12BITS/2) != HAL_OK)
  {
    /* Setting value Error */
    Error_Handler();
  }
  
  /* Enable DAC Channel: channel corresponding to ADC channel CHANNELa */
  if (HAL_DAC_Start(&DacHandle, DACx_CHANNEL_TO_ADCx_CHANNELa) != HAL_OK)
  {
    /* Start Error */
    Error_Handler();
  }
    
  /*## Start ADC conversions #################################################*/
  
  /* Start ADC conversion on regular group with transfer by DMA */
  if (HAL_ADC_Start_DMA(&AdcHandle,
                        (uint32_t *)aADCxConvertedValues,
                        ADCCONVERTEDVALUES_BUFFER_SIZE
                       ) != HAL_OK)
  {
    /* Start Error */
    Error_Handler();
  }
  
  
  /* Infinite loop */
  while (1)
  {
    /* Turn-on/off LED2 in function of ADC conversion result */
    /*  - Turn-off if voltage is into AWD window */ 
    /*  - Turn-on if voltage is out of AWD window */

    /* Variable of analog watchdog status is set into analog watchdog         */
    /* interrupt callback                                                     */
    if (ubAnalogWatchdogStatus == RESET)
    {
      BSP_LED_Off(LED2);
    }
    else
    {
      BSP_LED_On(LED2);
      
      /* Reset analog watchdog status for next loop iteration */
      ubAnalogWatchdogStatus = RESET;
    }
  
    /* For information: ADC conversion results are stored into array          */
    /* "aADCxConvertedValues" (for debug: check into watch window)            */
  
  
    /* Wait for event on push button to perform following actions */
    while ((ubUserButtonClickEvent) == RESET)
    {
      __NOP();
    }
    /* Reset variable for next loop iteration */
    ubUserButtonClickEvent = RESET;

    /* Set DAC voltage on channel corresponding to ADCx_CHANNELa              */
    /* in function of user button clicks count.                               */
    /* Set DAC output successively to:                                        */
    /*  - minimum of full range (0 <=> ground 0V)                             */
    /*  - 1/4 of full range (4095 <=> Vdda=3.3V): 1023 <=> 0.825V             */
    /*  - 1/2 of full range (4095 <=> Vdda=3.3V): 2048 <=> 1.65V              */
    /*  - 3/4 of full range (4095 <=> Vdda=3.3V): 3071 <=> 2.475V             */
    /*  - maximum of full range (4095 <=> Vdda=3.3V)                          */
    if (HAL_DAC_SetValue(&DacHandle,
                         DACx_CHANNEL_TO_ADCx_CHANNELa,
                         DAC_ALIGN_12B_R,
                         (RANGE_12BITS * ubUserButtonClickCount / USERBUTTON_CLICK_COUNT_MAX)
                        ) != HAL_OK)
    {
      /* Start Error */
      Error_Handler();
    }
  }
}