This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

with ADC other output is not working right.

hi ..

i am new to mbed and nrf51.

softdevice is s130

if i enable the ADC in my project then other output(out3,4,5,6) is not working ok. if ADC is not enabled then all other output is working fine.

here is my code...

 void my_analogin_init(void)
{   
    NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled; 
    NRF_ADC->CONFIG = (ADC_CONFIG_RES_10bit << ADC_CONFIG_RES_Pos) |
                      (ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos) |
                      (ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos) |
                      (ADC_CONFIG_PSEL_Disabled << ADC_CONFIG_PSEL_Pos) |
                      (ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos);                   
}


uint16_t my_analogin_read_u16(void)
{
    NRF_ADC->CONFIG     &= ~ADC_CONFIG_PSEL_Msk;
    NRF_ADC->CONFIG     |= ADC_CONFIG_PSEL_Disabled << ADC_CONFIG_PSEL_Pos;
    NRF_ADC->TASKS_START = 1;
    while (((NRF_ADC->BUSY & ADC_BUSY_BUSY_Msk) >> ADC_BUSY_BUSY_Pos) == ADC_BUSY_BUSY_Busy) {};
    return (uint16_t)NRF_ADC->RESULT; // 10 bit
}


int main(void)
{   
    float value;
    
    // my_analogin_init();   // THIS LINE WHEN UNCOMMENTED the analog inputs, ain1, ain2,.. don't work ??
    
    // Infinite loop waiting for BLE interrupt events   
    while (true) { 
        if (triggerSensorPolling && ble.gap().getState().connected) {
 
         triggerSensorPolling = false;
                           
         out1 = ain1 * 100; // Change the value to be in the 0 to 100 range
         ble.updateCharacteristicValue(readChar.getValueHandle(), &out1, sizeof(out1));          
              
         out2 = ain2 * 100;  
         
         // When ADC is Initialised I retriewe the mV Value ===========    
         // value = (float)my_analogin_read_u16();    
         // value = 10* (value * 3.6) / 1024.0;              
         // out2 = value;
         // end When ADC is used ====================================== 
         
         ble.updateCharacteristicValue(readChar2.getValueHandle(), &out2, sizeof(out2));
         
         out3 = ain3 * 100; 
         ble.updateCharacteristicValue(readChar3.getValueHandle(), &out3, sizeof(out3));
         
         out4 = ain4 * 100; 
         ble.updateCharacteristicValue(readChar4.getValueHandle(), &out4, sizeof(out4));
         
         out5 = ain5 * 100;         
         ble.updateCharacteristicValue(readChar5.getValueHandle(), &out5, sizeof(out5));   
            
         out6 = ain6 * 100; 
         ble.updateCharacteristicValue(readChar6.getValueHandle(), &out6, sizeof(out6)); 
         
         sensor1ServicePtr->updateSensor1State(out6);
        
        } else {
            ble.waitForEvent();
        }
}
}
Parents Reply Children
Related