/******************************************************************************* * Function Name: ADC_SAR_1_SetResolution ******************************************************************************** * * Summary: * Sets the Relution of the SAR. * * Parameters: * resolution: * 12 -> RES12 * 10 -> RES10 * 8 -> RES8 * * Return: * None. * * Side Effects: * The ADC resolution cannot be changed during a conversion cycle. The * recommended best practice is to stop conversions with * ADC_StopConvert(), change the resolution, then restart the * conversions with ADC_StartConvert(). * If you decide not to stop conversions before calling this API, you * should use ADC_IsEndConversion() to wait until conversion is complete * before changing the resolution. * If you call ADC_SetResolution() during a conversion, the resolution will * not be changed until the current conversion is complete. Data will not be * available in the new resolution for another 6 + "New Resolution(in bits)" * clock cycles. * You may need add a delay of this number of clock cycles after * ADC_SetResolution() is called before data is valid again. * Affects ADC_CountsTo_Volts(), ADC_CountsTo_mVolts(), and * ADC_CountsTo_uVolts() by calculating the correct conversion between ADC * counts and the applied input voltage. Calculation depends on resolution, * input range, and voltage reference. * *******************************************************************************/ void ADC_SAR_1_SetResolution(uint8 resolution) { uint8 tmpReg; /* Set SAR ADC resolution and sample width: 18 conversion cycles at 12bits + 1 gap */ switch (resolution) { case (uint8)ADC_SAR_1__BITS_12: tmpReg = ADC_SAR_1_SAR_RESOLUTION_12BIT | ADC_SAR_1_SAR_SAMPLE_WIDTH; break; case (uint8)ADC_SAR_1__BITS_10: tmpReg = ADC_SAR_1_SAR_RESOLUTION_10BIT | ADC_SAR_1_SAR_SAMPLE_WIDTH; break; case (uint8)ADC_SAR_1__BITS_8: tmpReg = ADC_SAR_1_SAR_RESOLUTION_8BIT | ADC_SAR_1_SAR_SAMPLE_WIDTH; break; default: tmpReg = ADC_SAR_1_SAR_RESOLUTION_12BIT | ADC_SAR_1_SAR_SAMPLE_WIDTH; /* Halt CPU in debug mode if resolution is out of valid range */ CYASSERT(0u != 0u); break; } ADC_SAR_1_SAR_CSR2_REG = tmpReg; /* Calculate gain for convert counts to volts */ ADC_SAR_1_CalcGain(resolution); }
/******************************************************************************* * Function Name: ADC_SAR_1_SetResolution ******************************************************************************** * * Summary: * Sets the Relution of the SAR. * This function does not affect the actual conversion with PSoC5 ES1 silicon. * * Parameters: * resolution: * 12 -> RES12 * 10 -> RES10 * 8 -> RES8 * * Return: * None. * * Side Effects: * The ADC resolution cannot be changed during a conversion cycle. The * recommended best practice is to stop conversions with * ADC_StopConvert(), change the resolution, then restart the * conversions with ADC_StartConvert(). * If you decide not to stop conversions before calling this API, you * should use ADC_IsEndConversion() to wait until conversion is complete * before changing the resolution. * If you call ADC_SetResolution() during a conversion, the resolution will * not be changed until the current conversion is complete. Data will not be * available in the new resolution for another 6 + "New Resolution(in bits)" * clock cycles. * You may need add a delay of this number of clock cycles after * ADC_SetResolution() is called before data is valid again. * Affects ADC_CountsTo_Volts(), ADC_CountsTo_mVolts(), and * ADC_CountsTo_uVolts() by calculating the correct conversion between ADC * counts and the applied input voltage. Calculation depends on resolution, * input range, and voltage reference. * *******************************************************************************/ void ADC_SAR_1_SetResolution(uint8 resolution) { uint8 tmpReg; /* remember resolution for the GetResult APIs */ #if(CY_PSOC5A) ADC_SAR_1_resolution = resolution; #endif /* End CY_PSOC5A */ /* Set SAR ADC resolution and sample width: 18 conversion cycles at 12bits + 1 gap */ switch (resolution) { case (uint8)ADC_SAR_1__BITS_12: tmpReg = ADC_SAR_1_SAR_RESOLUTION_12BIT | ADC_SAR_1_SAR_SAMPLE_WIDTH; break; case (uint8)ADC_SAR_1__BITS_10: /* Use 12bits for PSoC5 production silicon and shift the * results for lower resolution in GetResult16() API */ #if(CY_PSOC5A) tmpReg = ADC_SAR_1_SAR_RESOLUTION_12BIT | ADC_SAR_1_SAR_SAMPLE_WIDTH; #else tmpReg = ADC_SAR_1_SAR_RESOLUTION_10BIT | ADC_SAR_1_SAR_SAMPLE_WIDTH; #endif /* End CY_PSOC5A */ break; case (uint8)ADC_SAR_1__BITS_8: #if(CY_PSOC5A) tmpReg = ADC_SAR_1_SAR_RESOLUTION_12BIT | ADC_SAR_1_SAR_SAMPLE_WIDTH; #else tmpReg = ADC_SAR_1_SAR_RESOLUTION_8BIT | ADC_SAR_1_SAR_SAMPLE_WIDTH; #endif /* End CY_PSOC5A */ break; default: tmpReg = ADC_SAR_1_SAR_RESOLUTION_12BIT | ADC_SAR_1_SAR_SAMPLE_WIDTH; /* Halt CPU in debug mode if resolution is out of valid range */ CYASSERT(0u != 0u); break; } ADC_SAR_1_SAR_CSR2_REG = tmpReg; /* Calculate gain for convert counts to volts */ ADC_SAR_1_CalcGain(resolution); }