예제 #1
0
파일: icc_measure.c 프로젝트: bzdegluk/ACQ
/**
  * @brief  To return the supply measurmeent
  * @caller several functions
  * @param None
  * @retval ADC value
  */ 
uint16_t ADC_Supply(void)
{
  uint8_t i;
  uint16_t res;

    /* Initializes ADC */
  ADC_Icc_Init();
 
  ADC_TempSensorVrefintCmd(ENABLE);

  /* ADC1 regular channel 17 for VREF configuration */
  ADC_RegularChannelConfig(ADC1, ADC_Channel_17, 1, ADC_SampleTime_192Cycles);
  
  /* initialize result */
  res = 0;
  for(i=4; i>0; i--)
  {
  /* start ADC convertion by software */
    ADC_SoftwareStartConv(ADC1);

    /* wait until end-of-covertion */
    while( ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == 0 );
  /* read ADC convertion result */
    res += ADC_GetConversionValue(ADC1);
  }
	
  /* de-initialize ADC */
  ADC_TempSensorVrefintCmd(DISABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, DISABLE);
  
  return (res>>2);
}
예제 #2
0
파일: icc_measure.c 프로젝트: bzdegluk/ACQ
/**
  * @brief Current measurement
  * @caller main and ADC_Icc_Test
  * @param None
  * @retval ADC conversion value
  */
uint16_t Current_Measurement (void)
{
  uint16_t res,i;

  /* re-start ADC chanel 24 for Current measurement */
  ADC_Icc_Init();	

  /* initialize result */
  res = 0;

  for(i=4; i>0; i--)
  {
    /* start ADC convertion by software */
    ADC_SoftwareStartConv(ADC1);
    
    /* wait until end-of-covertion */
    while( ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == 0 );
    
    /* read ADC convertion result */
    res += ADC_GetConversionValue(ADC1);
  }
   
  return (res>>2);
}
예제 #3
0
파일: main.c 프로젝트: awalter3/General
int main(void)
{ 
    bool StanbyWakeUp ;
    float Current_STBY;
  
 /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32l1xx_md.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32l1xx.c file
     */ 
  
    Int_CurrentSTBY = Current_Measurement();
  
    /* Check if the StandBy flag is set */
    if (PWR_GetFlagStatus(PWR_FLAG_SB) != RESET)
    {
        /* System resumed from STANDBY mode */
        /* Clear StandBy flag */
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE);
        PWR_ClearFlag(PWR_FLAG_SB); 
        
        StanbyWakeUp = TRUE;
    
    } else
    {
        StanbyWakeUp = FALSE;    
    } 

    PWR_PVDCmd(DISABLE);
    
    RCC_Configuration();
    
    PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1);
    
    /* Wait Until the Voltage Regulator is ready */
    while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) ;
     
    /* Init I/O ports */
    Init_GPIOs ();
    
    /* Initializes ADC */
    ADC_Icc_Init();
    
    enableInterrupts();	
    
    /* Warning ! in TSL Init the sysTick interrupt is setted to:
    SysTick_Config(RCC_Clocks.HCLK_Frequency / 2000 ---> 500 µs*/
    
    /* Init Touch Sensing configuration */  
    TSL_Init();
    
    sMCKeyInfo[0].Setting.b.IMPLEMENTED = 1;
    sMCKeyInfo[0].Setting.b.ENABLED = 1;
    sMCKeyInfo[0].DxSGroup = 0x00; 
 
    /* Initializes the LCD glass */
    LCD_GLASS_Init();
  
      
      while (1)
    {
        
        switch( State ) 
        {
            case 0:
                //LED3 off and LED4 off
                blink = 0;
                GPIOB_ODR_value = 0x00000000;
                ptr_PORTB->GPIOx_ODR = GPIOB_ODR_value;
                break;
            case 1:
                //LED3 on and LED4 off
                blink = 0;
                GPIOB_ODR_value = 0x00000080;
                ptr_PORTB->GPIOx_ODR = GPIOB_ODR_value;
                break;
            case 2:
                //LED3 off and LED4 on
                blink = 0;
                GPIOB_ODR_value = 0x00000040;
                ptr_PORTB->GPIOx_ODR = GPIOB_ODR_value;
                break;
            case 3:
                //LED3 and LED4 blink with 2 second period
                blink = 1;
                break;
        }    
        
        if(blink == 1)
        {
          GPIOB_ODR_value = 0x000000C0;
          ptr_PORTB->GPIOx_ODR = GPIOB_ODR_value;
          Delay(100);
          GPIOB_ODR_value = 0x00000000;
          ptr_PORTB->GPIOx_ODR = GPIOB_ODR_value;
          Delay(100);
          
        }
        
    }
    
    
    return(0);
}		
예제 #4
0
파일: main.c 프로젝트: awalter3/General
int main(void)
{ 
    bool StanbyWakeUp ;
    float Current_STBY;
  
 /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32l1xx_md.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32l1xx.c file
     */ 
  
    Int_CurrentSTBY = Current_Measurement();
  
    /* Check if the StandBy flag is set */
    if (PWR_GetFlagStatus(PWR_FLAG_SB) != RESET)
    {
        /* System resumed from STANDBY mode */
        /* Clear StandBy flag */
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE);
        PWR_ClearFlag(PWR_FLAG_SB); 
        
        StanbyWakeUp = TRUE;
    
    } else
    {
        StanbyWakeUp = FALSE;    
    } 

    PWR_PVDCmd(DISABLE);
    
    RCC_Configuration();
    
    PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1);
    
    /* Wait Until the Voltage Regulator is ready */
    while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) ;
     
    /* Init I/O ports */
    Init_GPIOs ();
    
    /* Initializes ADC */
    ADC_Icc_Init();
    
    enableInterrupts();	
    
    /* Warning ! in TSL Init the sysTick interrupt is setted to:
    SysTick_Config(RCC_Clocks.HCLK_Frequency / 2000 ---> 500 µs*/
    
    /* Init Touch Sensing configuration */  
    TSL_Init();
    
    sMCKeyInfo[0].Setting.b.IMPLEMENTED = 1;
    sMCKeyInfo[0].Setting.b.ENABLED = 1;
    sMCKeyInfo[0].DxSGroup = 0x00; 
 
    /* Initializes the LCD glass */
    LCD_GLASS_Init();
  
    // EECE 337 Code -- Start
    int N;
    int f;
    
    char str[8];   
    
    N = 10;
    
    // Call to original factorial algorithm in C - for debugging
    //f = factorial_orig( N );
    
    factorial(&f, N);
    
    // Copy result to f
    sprintf (str, "%X", f);
    
    //printf( "factorial of %i is %i\n", N, f);
    LCD_GLASS_DisplayString(str);
    
    // EECE 337 Code -- End
    
    return(0);
}		
예제 #5
0
파일: main.c 프로젝트: awalter3/General
int main(void)
{ 
    bool StanbyWakeUp ;
    float Current_STBY;
  
 /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32l1xx_md.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32l1xx.c file
     */ 
  
    Int_CurrentSTBY = Current_Measurement();
  
    /* Check if the StandBy flag is set */
    if (PWR_GetFlagStatus(PWR_FLAG_SB) != RESET)
    {
        /* System resumed from STANDBY mode */
        /* Clear StandBy flag */
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE);
        PWR_ClearFlag(PWR_FLAG_SB); 
        
        StanbyWakeUp = TRUE;
    
    } else
    {
        StanbyWakeUp = FALSE;    
    } 

    PWR_PVDCmd(DISABLE);
    
    RCC_Configuration();
    
    PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1);
    
    /* Wait Until the Voltage Regulator is ready */
    while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) ;
     
    /* Init I/O ports */
    Init_GPIOs ();
    
    /* Initializes ADC */
    ADC_Icc_Init();
    
    enableInterrupts();	
    
    /* Warning ! in TSL Init the sysTick interrupt is setted to:
    SysTick_Config(RCC_Clocks.HCLK_Frequency / 2000 ---> 500 µs*/
    
    /* Init Touch Sensing configuration */  
    TSL_Init();
    
    sMCKeyInfo[0].Setting.b.IMPLEMENTED = 1;
    sMCKeyInfo[0].Setting.b.ENABLED = 1;
    sMCKeyInfo[0].DxSGroup = 0x00; 
 
    /* Initializes the LCD glass */
    LCD_GLASS_Init();
  
    // EECE 337 Code -- Start
        
    char str[50];                       // Used to display results
    unsigned int delay_time = 5000;      // Will delay for 5 seconds
    const unsigned int numItems = 10;          // # items in array
	int MyArray[10] = { 365, 245, -499, 0, 23, 8, 200, -4, -50, 25 };

	int minimum = 0;                    // Will hold minimum value
	int maximum = 0;                    // Will hold maximum value
    
    // Call Function to obtain Min and Max values from array
	min_max(MyArray, numItems, &minimum, &maximum);	
    
    // Copy min result to str
    sprintf (str, "%d", minimum);
    
    // Display on LCD
    LCD_GLASS_DisplayString(str);
    
    // Pause for 5 seconds
    Delay(delay_time);
    
    // Clear LCD
    LCD_GLASS_Clear();
    
    // Copy max result to str
    sprintf (str, "%d", maximum);
    
    // Display on LCD
    LCD_GLASS_DisplayString(str);
    
    // Pause for 5 seconds
    Delay(delay_time);
    
    // EECE 337 Code -- End
    
    return(0);
}		
예제 #6
0
/**
  * @brief Current measurement in different MCU modes:
		RUN/HALT/LowPower withouto LCD/LowPower with LCD
	* @caller main and ADC_Icc_Test
  * @param MCU state
  * @retval ADC value.
  */
u16 ADC_Icc_Test(u8 Mcu_State)
{
  uint16_t res;
	uint8_t i;
	
/* Test MCU state for configuration */
  switch (Mcu_State)
  {
    /* test Run mode nothing to do */	
    case MCU_RUN:
      break;

    /* Low power mode */		
    case MCU_LPR:
      Halt_Init();
      sim();
      /* To prepare to start counter */
      GPIO_HIGH(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN);
  
      /* To configure Low Power */			
      LPR_init();
      break;

    /* Halt mode */
    case MCU_HALT:
      /* Init for Halt mode  */
      Halt_Init();
      sim();	
      
      /* To prepare to start counter */
      GPIO_HIGH(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN);
  
      /* Falling edge for start counter */		
      GPIO_LOW(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN);
      delay_10us(1);
      
      /* MCU in halt during measurement */	
      /* Wake up by Interrupt done counter Input Port E pin 6 */
      halt();
      break;
    
    case MCU_LPR_LCD:
      PWR->CSR2 = 0x2;
      sim();
      /* To configure GPIO for reduce current. */
      GPIO_LowPower_Config();

      /* To prepare to start counter */
      GPIO_HIGH(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN);

      /* To configure Low Power */
      LPR_init();
      break;		
  }
	
  sim();

/* re-start ADC chanel 24 for Current measurement */
  ADC_Icc_Init();	
	
/* Read ADC for current measurmeent */
/* initialize result */
  res = 0;

  for(i=8; i>0; i--)
  {
    /* start ADC convertion by software */
    ADC_SoftwareStartConv(ADC1);
    
    /* wait until end-of-covertion */
    while( ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == 0 );
    
    /* read ADC convertion result */
    res += ADC_GetConversionValue(ADC1);
  }
	
  /* ICC_CNT_EN invalid */
  GPIO_HIGH(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN);
 
  GPIO_Init(BUTTON_GPIO_PORT, USER_GPIO_PIN,GPIO_Mode_In_FL_IT);

  rim();
	
/* Disable ADC 1 for reduce current */
  ADC_Cmd(ADC1, DISABLE);

  CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, DISABLE);

  if (Mcu_State !=MCU_LPR_LCD)
  {
    CLK_PeripheralClockConfig(CLK_Peripheral_RTC, ENABLE);
    LCD_GLASS_Init();
  }

  return (res>>3);
}