Beispiel #1
0
/*******************************************************************************
* Function Name: ADC_Sleep
********************************************************************************
*
* Summary:
*  Stops the ADC operation and saves the configuration registers and component
*  enable state. Should be called just prior to entering sleep.
*
* Parameters:
*  None.
*
* Return:
*  None.
*
* Global Variables:
*  ADC_backup - modified.
*
*******************************************************************************/
void ADC_Sleep(void)
{
    /* During deepsleep/ hibernate mode keep SARMUX active, i.e. do not open
    *   all switches (disconnect), to be used for ADFT
    */
    ADC_SAR_DFT_CTRL_REG |= ADC_ADFT_OVERRIDE;
    if((ADC_SAR_CTRL_REG  & ADC_ENABLE) != 0u)
    {
        if((ADC_SAR_SAMPLE_CTRL_REG & ADC_CONTINUOUS_EN) != 0u)
        {
            ADC_backup.enableState = ADC_ENABLED | ADC_STARTED;
        }
        else
        {
            ADC_backup.enableState = ADC_ENABLED;
        }
        ADC_StopConvert();
        ADC_Stop();
        
        /* Disable the SAR internal pump before entering the chip low power mode */
        if((ADC_SAR_CTRL_REG & ADC_BOOSTPUMP_EN) != 0u)
        {
            ADC_SAR_CTRL_REG &= (uint32)~ADC_BOOSTPUMP_EN;
            ADC_backup.enableState |= ADC_BOOSTPUMP_ENABLED;
        }
    }
    else
    {
        ADC_backup.enableState = ADC_DISABLED;
    }
}
void main()
{
    /* Place your initialization/startup code here (e.g. MyInst_Start()) */
    uint16 adc, compare;
    
    LCD_Start();
    ADC_Start();
    PWM_Start();
    
    

    /* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */
    for(;;)
    {
        /* Place your application code here. */
//        LCD_ClearDisplay();
        LCD_Start();
        
        adc = 0;
        ADC_StartConvert();
        ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);
        ADC_StopConvert();
        adc = ADC_GetResult16();
        
        if(adc > 255)
        {
            if(adc == 0xFFFF) /* underflow correction */
            {
                adc = 0x00;
            }
            else
            adc = 0xFF; /* Overflow correction */
        }    
        
        LCD_Position(0,0);
        LCD_PrintHexUint8(adc);
                
        compare = (uint16)(1000 + ((float)((float)((float)adc / (float)255) * (float)1000)));
        LCD_Position(1,0);
        LCD_PrintDecUint16(compare);
        
        PWM_WriteCompare(compare);
        PWM_WritePeriod(compare + 39999);
    }
}
Beispiel #3
0
/*****************************************************************************
* Function Name: MeasureSensorVoltage()
******************************************************************************
* Summary:
* Measures the voltage connected at ADC input. 
*
* Parameters:
* None
*
* Return:
* uint16 - Measured voltage
*
* Theory:
* This functions sequences the AMux to next channel and connects reference 
* signal or thermistor or offset signal at ADC input. It then triggers the ADC
* and measures the signal.
*
* Side Effects:
* None
*
* Note:
*
*****************************************************************************/
static uint16 MeasureSensorVoltage ()
{
    /* Connect next channel available at AMux input to Amux output */
    /* Note: If no channels are connected, channel 0 gets connected by this 
    *  fucntion */
    AMuxSeq_Next();
    
    /* Start sample conversion */
    ADC_StartConvert();
    
    /* Wait till end of two conversions and drop one sample for signal to settle 
    *  down, it's not required if reference is continuously available.  
    *  To reduce current consumption, CPU can be put to sleep while ADC conversion
    *  is in process. */
    ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);
    ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);
    
    /* Stop ADC coversion */ 
    ADC_StopConvert();
    
    /* Return 16 bit measured value */
    return (ADC_GetResult16(0));
}