Exemplo n.º 1
0
/// \method read()
/// Read the value on the analog pin and return it.  The returned value
/// will be between 0 and 4095.
STATIC mp_obj_t adc_read(mp_obj_t self_in) {
    pyb_adc_obj_t *self = self_in;
    uint32_t sample;

    // wait until a new value is available
    while (!MAP_ADCFIFOLvlGet(ADC_BASE, self->channel));
    // read the sample
    sample = MAP_ADCFIFORead(ADC_BASE, self->channel);
    // the 12 bit sampled value is stored in bits [13:2]
    return MP_OBJ_NEW_SMALL_INT((sample & 0x3FFF) >> 2);
}
Exemplo n.º 2
0
uint16_t readBISEN(void)
{
    unsigned long sample = 0;

    /* ADC measurement */
	if(MAP_ADCFIFOLvlGet(ADC_BASE, BISENx))
	{
		sample = MAP_ADCFIFORead(ADC_BASE, BISENx);
		sample = sample >> 2;
		sample &= 0x0FFF;
	}

	return (uint16_t)(sample);
}
Exemplo n.º 3
0
void adc (void){

	unsigned long ulSample;
	unsigned int  uiChannel;
	unsigned int  uiIndex=0;

	while(uiIndex < NO_OF_SAMPLES + 4)
	{
		if(MAP_ADCFIFOLvlGet(ADC_BASE, uiChannel))
	    {
			ulSample = MAP_ADCFIFORead(ADC_BASE, uiChannel);

	        pulAdcSamples[uiIndex++] = ulSample;			// Fill data sample buffer
	    }


	        }

}
Exemplo n.º 4
0
//*****************************************************************************
//
//! main - calls Crypt function after populating either from pre- defined vector 
//! or from User
//!
//! \param  none
//!
//! \return none
//!
//*****************************************************************************
void 
main()
{
    unsigned long  uiAdcInputPin;  
    unsigned int  uiChannel;
    unsigned int  uiIndex=0;
    unsigned long ulSample;      

    //
    // Initialize Board configurations
    //
    BoardInit();

    //
    // Configuring UART for Receiving input and displaying output
    // 1. PinMux setting
    // 2. Initialize UART
    // 3. Displaying Banner
    //
    PinMuxConfig();
    InitTerm();
    DisplayBanner(APP_NAME);

    while(FOREVER)
    {
        //
        // Initialize Array index for multiple execution
        //
        uiIndex=0;
      
        //
        // Read inputs from user
        //
        if(!ReadFromUser(&uiAdcInputPin))
        {
          UART_PRINT("\n\rInvalid Input. Please try again. HAHAHAHAHAHAHAHAHA\n\r");
          continue;
        }

#ifdef CC3200_ES_1_2_1
        //
        // Enable ADC clocks.###IMPORTANT###Need to be removed for PG 1.32
        //
        HWREG(GPRCM_BASE + GPRCM_O_ADC_CLK_CONFIG) = 0x00000043;
        HWREG(ADC_BASE + ADC_O_ADC_CTRL) = 0x00000004;
        HWREG(ADC_BASE + ADC_O_ADC_SPARE0) = 0x00000100;
        HWREG(ADC_BASE + ADC_O_ADC_SPARE1) = 0x0355AA00;
#endif
        //
        // Pinmux for the selected ADC input pin
        //
        MAP_PinTypeADC(uiAdcInputPin,PIN_MODE_255);

        //
        // Convert pin number to channel number
        //
        switch(uiAdcInputPin)
        {
            case PIN_58:
                uiChannel = ADC_CH_1;
                break;
            case PIN_59:
                uiChannel = ADC_CH_2;
                break;
            case PIN_60:
                uiChannel = ADC_CH_3;
                break;
            default:
                break;
        }

        //
        // Configure ADC timer which is used to timestamp the ADC data samples
        //
        MAP_ADCTimerConfig(ADC_BASE,2^17);

        //
        // Enable ADC timer which is used to timestamp the ADC data samples
        //
        MAP_ADCTimerEnable(ADC_BASE);

        //
        // Enable ADC module
        //
        MAP_ADCEnable(ADC_BASE);

        //
        // Enable ADC channel
        //

        MAP_ADCChannelEnable(ADC_BASE, uiChannel);

        while(uiIndex < NO_OF_SAMPLES + 4)
        {
            if(MAP_ADCFIFOLvlGet(ADC_BASE, uiChannel))
            {
                ulSample = MAP_ADCFIFORead(ADC_BASE, uiChannel);
                pulAdcSamples[uiIndex++] = ulSample;
            }


        }

        MAP_ADCChannelDisable(ADC_BASE, uiChannel);

        uiIndex = 0;

        //UART_PRINT("\n\rTotal no of 32 bit ADC data printed :4096 \n\r");
        //UART_PRINT("\n\rADC data format:\n\r");
        //UART_PRINT("\n\rbits[13:2] : ADC sample\n\r");
        //UART_PRINT("\n\rbits[31:14]: Time stamp of ADC sample \n\r");

        //
        // Print out ADC samples
        //

        while(uiIndex < NO_OF_SAMPLES)
        {
            UART_PRINT("\n\rVoltage is %f\n\r",(((float)((pulAdcSamples[4+uiIndex] >> 2 ) & 0x0FFF))*1.4)/4096);
            uiIndex++;
        }


        //UART_PRINT("\n\rVoltage is %f\n\r",((pulAdcSamples[4] >> 2 ) & 0x0FFF)*1.4/4096);
        UART_PRINT("\n\r");

    }

}