Exemplo n.º 1
0
/*! \brief  Detect Board Revision
  *
  * @retval Version Number of Board
*/
uint8_t BOARD_Detect_Revision(void)
{
  ADC_Result  result;
  uint16_t    revision_value;
  uint8_t     i;
  
  PGA_SetChannel(SPI_DEVICE_AMP_V_I_DCBUS, CHANNEL1);
  
  ADC_Enable(TSB_ADB);  
  ADC_SetClk(TSB_ADB, ADC_HOLD_FIX, ADC_FC_DIVIDE_LEVEL_2);
  ADC_SetSWTrg(TSB_ADB, ADC_REG2, TRG_ENABLE(ADC_REG2));
  ADC_Start(TSB_ADB, ADC_TRG_SW);
  while (ADC_GetConvertState(TSB_ADB, ADC_TRG_SW) == BUSY);
  result=ADC_GetConvertResult(TSB_ADB, ADC_REG2);
  ADC_Disable(TSB_ADB);  

  PGA_SetChannel(SPI_DEVICE_AMP_V_I_DCBUS, CHANNEL0);
  
  for (i=0;i<sizeof(revisions)/sizeof(revisions[0]);i++)
  {
    revision_value = result.Bit.ADResult*10/gaintable[ChannelValues[1].gain_current_measure];
    if (abs((revisions[i][0]-revision_value)<100))
      break;
  }
  return revisions[i][1];
}
Exemplo n.º 2
0
void Example_ADC_ReadData(void)
{
    /* 1. set ADC clock */
    ADC_SetClk(TSB_ADB, ADC_HOLD_FIX, ADC_FC_DIVIDE_LEVEL_2);

    /* 2. select trigger and AD channel, this time we use sofeware trigger, */
    /*    the VR1 is connected to  ADC unit B channel 2, remember to input with macro TRG_ENABLE() */
    ADC_SetSWTrg(TSB_ADB, ADC_REG0, TRG_ENABLE(ADC_AIN2));

    /* 3. enable ADC module */
    ADC_Enable(TSB_ADB);

    /* 4. now start ADC */
    ADC_Start(TSB_ADB, ADC_TRG_SW);

    /* initialize LEDs on M374-SK board before display something */
    LED_Init();

    while (1U) {
        /* check ADC module state */
        adcState = ADC_GetConvertState(TSB_ADB, ADC_TRG_SW);

        if (adcState == DONE) {
            /* read ADC result when it is finished */
            result = ADC_GetConvertResult(TSB_ADB, ADC_REG0);

            /* get the real ADC result without other information */
            /* "/16" is to limit the range of AD value */
            myResult = result.Bit.ADResult / 16U;

            /* software trigger, need to trigger it again */
            ADC_Start(TSB_ADB, ADC_TRG_SW);
        }
        myDelay(myResult);  
        if(idx) 
        {
          LED_Off(LEDs[idx-1]);
        }
        idx &= 0x03U;
        myDelay(myResult); 
        LED_On(LEDs[idx]);
        idx++;
    }
}