Example #1
0
void ScanColumn(uint8 col)
{
    InputControl_Write(0u);
//    CyDelayUs(10);
    SetColumns(col);
    //CyDelayUs(10);
    ADC_StartConvert();
    ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);
    InputControl_Write(1u);
    ResetColumns();
}
Example #2
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));
}
Example #3
0
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);
    }
}