예제 #1
0
/******************************************************************************
 * Function:        void InitPowerTrain(void)
 *
 * Overview:        Initializes power train.
 *
 * PreCondition:    USB power is on
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Note:            None
 *****************************************************************************/
void InitPowerTrain(void)
{
    memset(&gPowerInfo, 0, sizeof(gPowerInfo));
    
    pin_LVP     = 0;
    pin_LVP_EN  = 0;
    tris_LVP    = OUTPUT;
    tris_LVP_EN = OUTPUT;
    
    // Set timer 3 for PWMs (Vdd and Vpp)
    // See comments on the definition of MAX_VALUE_PERIOD_FOR_PWM_TIMER
    T3CON = 0;
    PR3   = MAX_VALUE_PERIOD_FOR_PWM_TIMER;
    T3CONbits.TON = 1;
    
    // Calibrate analog to digital converter.
    CalibrateADC();
     
    // Setup Analog to Digital converter to read Vdd and Vpp
    SetupADCToReadVddAndVpp();
    gPowerInfo.Flag.TargetPowered = TRUE;
    gPowerInfo.CurPwrMode = NO_PWR_MODE;
    TurnVPP(OFF);
    SetVdd(DEFAULT_VDD);
    SetVpp(DEFAULT_VPP);
}
예제 #2
0
파일: main.c 프로젝트: pyjhhh/stm32_f1x
/**
  * @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_stm32f072xb.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f0xx.c file
  
     PLL is set to x12 with  a PREDIV /2 so the system clock SYSCLK = 48MHz
     */

  ConfigureGPIO();
  SetClockForADC();
  CalibrateADC(); 
  ConfigureGPIOforADC();
  EnableADC();
  ConfigureADC();
  ConfigureDMA();
  ADC1->CR |= ADC_CR_ADSTART; /* start the ADC conversions */
  GPIOC->BSRR = (1<<9); /* switch on the green led */    
  __WFI(); /* No interrupt should occur, as only error could trigger an interrupt */ 
  GPIOC->BRR = (1<<9); /* switch off the green led */
  DisableADC();
  SysTick_Config(48000); /* 1ms config */
  while (1) /* Infinite loop */
  {
  }
}
예제 #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_stm32f072xb.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f0xx.c file
  
     PLL is set to x12 with  a PREDIV /2 so the system clock SYSCLK = 48MHz
     */
  ConfigureGPIO();
  ConfigureExternalIT();
  RCC->APB2ENR = RCC_APB2ENR_ADC1EN; /* Enable the peripheral clock of the ADC */
  RCC->CFGR |= RCC_CFGR_PPRE_2; /* Set peripheral prescaler to /2 so PCLK = HCLK/2 = 24MHz */
  CalibrateADC(); 
  EnableADC();
  ConfigureADC();
  ConfigureDMA();
  ADC1->CR |= ADC_CR_ADSTART; /* Start the ADC conversions */
      
  while (error < ERROR_UNEXPECTED_DMA_IT) /* loop till no unrecoverable error */
  {
    __WFI();
  }
  
  DisableADC();
  SysTick_Config(48000); /* 1ms config */
  while (1) /* Infinite loop */
  {
  }
}
예제 #4
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_stm32f072xb.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f0xx.c file
  
     PLL is set to x12 with  a PREDIV /2 so the system clock SYSCLK = 48MHz
     */

  ConfigureGPIO();
  ConfigureExternalIT();
  SetClockForADC();
  CalibrateADC();
  ConfigureGPIOforADC();
  EnableADC();
  ConfigureADC();
  CurrentChannel = 0; /* Initializes the CurrentChannel */
  ADC1->CR |= ADC_CR_ADSTART; /* start the ADC conversions */

  while (error == 0) /* loop till no unrecoverable error, should never be exited */
  {   
    __WFI();
  }  
  DisableADC();
  SysTick_Config(48000); /* 1ms config */
  while (1) /* Infinite loop */
  {
  }
}
예제 #5
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_stm32f072xb.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f0xx.c file
  
      PLL is set to x12 with  a PREDIV /2 so the system clock SYSCLK = 48MHz
     */
/* defines the upper limit 15% above the factory value 
   the value is adapted according to the application power supply
   versus the factory calibration power supply */
uint16_t vrefint_high = (*VREFINT_CAL_ADDR)* VDD_CALIB / VDD_APPLI * 115 / 100; 
/* defines the lower limit 15% below the factory value 
   the value is adapted according to the application power supply
   versus the factory calibration power supply */
uint16_t vrefint_low = (*VREFINT_CAL_ADDR) * VDD_CALIB / VDD_APPLI * 85 / 100;

  ConfigureGPIO();
  SetClockForADC();
  CalibrateADC(); 
  EnableADC();
  ConfigureADC();
  ConfigureTIM15();
  ADC1->CR |= ADC_CR_ADSTART; /* start the ADC conversion */
  
  while (error == 0) /* Loop till the measure is in the range */
  {   
    while ((ADC1->ISR & ADC_ISR_EOC) == 0); /* wait end of conversion */

    if ((ADC1->DR > vrefint_high) && (ADC1->DR > vrefint_low))
    {
      error |= WARNING_MEASURE; /* report a warning, the measure being out of range due to VDD shift */
    }
    GPIOC->ODR ^= (1<<9); /* Toggle green led on PC9 */
  }
  DisableADC();
  SysTick_Config(48000); /* 1ms config */
  while(1)
  {
  }
}
예제 #6
0
void main()
{
  WDTCTL = WDTPW + WDTHOLD;             //Stop Watchdog Timer
  CSCTL0_H = 0xA5;
    
  
  CSCTL1 |= DCOFSEL0 + DCOFSEL1;                //set max. DCO setting.. 8Mhz
  CSCTL2 = SELA_3 + SELS_3 + SELM_3;            //set ACLK = MCLK = DCO
  CSCTL3 = DIVA_0 + DIVS_0 + DIVM_0;            //set all dividers
  
  P1DIR |= BIT0;
  P1SEL0 |= BIT0;
  
  TA0CCR0 = 207;                                //timer count value 207 for 38 kHz carrier.
  TA0CCR1 = 69;                                 //25% duty cycle for the 38 kHz carrier.
  //TA0CCTL1 = OUTMOD_7;
  TA0CCTL0 = 0x10;
  TA0CTL = TASSEL_1 + MC_1;
  
  
  LEDonboardInit(0);
  
  AccelInit();                          //Setup the accelerometer pins.
  SetupAccel();                         //Setup the ADC and Accel. ADC can only convert one axis at a time.
  CalibrateADC();                       //Find zero points of all 3 axis.

  ADC10CTL0 |= ADC10ENC | ADC10SC; //Start the first sample. If this is not done the ADC10 interupt will not trigger.
  
  __enable_interrupt();
  
  
   while(1)
	{
          TA0CTL |= MC_1;
          ADC10IE &= ~ADC10IE0;
          LED_off_all();
          if (ADCResult_X < CalValue_X - 60 && ADCResult_Y > CalValue_Y - 60 && ADCResult_Y < CalValue_Y + 60)        
          {
          LED_off_all();
          LED_on(8);
          transmit_command(0x04, 0x01);
          }
          else if(ADCResult_X > CalValue_X + 60 && ADCResult_Y > CalValue_Y - 60 && ADCResult_Y < CalValue_Y + 60)
          {LED_off_all();
          LED_on(7);
          transmit_command(0x04, 0x00); 
          }
           else if(ADCResult_Y < CalValue_Y - 60 && ADCResult_X > CalValue_X - 60 && ADCResult_X < CalValue_X + 60)
          {
          LED_off_all();
          LED_on(2);
          transmit_command(0x04, 0x03); 
          }
          else if (ADCResult_Y > CalValue_Y + 60 && ADCResult_X > CalValue_X - 60 && ADCResult_X < CalValue_X + 60)
          {
          LED_off_all();
          LED_on(1);
          transmit_command(0x04, 0x02); 
          }
          TA0CTL = TASSEL_1 + MC_0;           //timer off
          TA0CCTL1 = OUTMOD_0;                //avoid constant high
          //__delay_cycles(500000); 
          ADC10IE |= ADC10IE0;
          //ADC10IE &= ~ADC10IE0;
        }
  
  /*
  while(1)
  {
    transmit_command(0x04, 0x00);
  }
   */
}
예제 #7
0
void Mode4(void)
{
  // One time initialization of header and footer transmit package
  TX_Buffer[0] = 0xFA;    
  TX_Buffer[6] = 0xFE;  
        
  // variable initialization
  ADCTemp = 0;
  temp = 0;
  WriteCounter = 0;
  active = 1;
  ULPBreakSync = 0;
  counter = 0;
  
  // One time setup and calibration          
  SetupThermistor();
  CalValue = CalibrateADC(); 
  while((mode == TEMP_MEAS) && (UserInput == 0))
    {
      // Take 1 ADC Sample
      TakeADCMeas();
      if (ADCResult >= CalValue)        
        {
          temp = DOWN;
          ADCTemp = ADCResult - CalValue;
        }
      else
        {
          temp = UP;
          ADCTemp = CalValue - ADCResult; 
        }                         
          
      if((ULP==1) && (UserInput == 0))
        {
          // P3.4- P3.7 are set as output, low
          P3OUT &= ~(BIT4 + BIT5 + BIT6 + BIT7);   
	  P3DIR |= BIT4 + BIT5 + BIT6 + BIT7; 	    
          // PJ.0,1,2,3 are set as output, low
          PJOUT &= ~(BIT0 + BIT1 + BIT2 + BIT3);  
	  PJDIR |= BIT0 + BIT1 + BIT2 + BIT3;  
          // Transmit break packet for GUI freeze
          if(!(ULPBreakSync))
            {
              TXBreak(mode);              
              ULPBreakSync++;
            }              
          
        }            
      if((ULP==0) && (UserInput == 0))
        {
          ULPBreakSync = 0;
          WriteCounter++;            
          if(WriteCounter > 300)
            {
              LEDSequence(ADCTemp,temp);
              // Every 300 samples   	
              // Transmit 7 Bytes
              // Prepare mode-specific data
              // Standard header and footer
              WriteCounter = 0;
              TX_Buffer[1] = 0x04; 
              TX_Buffer[2] = counter;
              TX_Buffer[3] = 0x00;
              TX_Buffer[4] = 0x00;
              TX_Buffer[5] = 0x00;
              TXData();                                     
          } 
        }
      }
    // turn off Thermistor bridge for low power      
    ShutDownTherm();


}