# Reading ADC value from Q2686

**URL:** <https://forum.sierrawireless.com/t/reading-adc-value-from-q2686/3005>\
**Category:** Legacy AirPrime modules\
**Created:** [March 4, 2009, 9:26am UTC](https://forum.sierrawireless.com/t/reading-adc-value-from-q2686/3005 "2009-03-04T09:26:39Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vanee](https://avatars.discourse-cdn.com/v4/letter/v/f19dbf/32.png) [@Vanee](https://forum.sierrawireless.com/u/Vanee)\
**Post date:** [March 4, 2009, 9:26am UTC](https://forum.sierrawireless.com/t/reading-adc-value-from-q2686/3005/1 "2009-03-04T09:26:39Z")

</div>

Hi,  
can someone tell how to get the adc value using the “adl\_adcRead”? The syntax is “s32 adl\_adcRead (u32 ChannelID, u32\* AdcRawValue );” But, what is the channelID that has to be sent? Is it the ADC pin number which is 21 or is it the parameter value equivalent to the at+adc?  
Expecting a reply at the earliest.

---

<div class="post-metadata">

**Author:** ![Madouc](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@Madouc](https://forum.sierrawireless.com/u/Madouc)\
**Post date:** [March 4, 2009, 9:54am UTC](https://forum.sierrawireless.com/t/reading-adc-value-from-q2686/3005/2 "2009-03-04T09:54:48Z")

</div>

the parameter value equivalent to at+adc seems the most likely to me,  
Have you tried it? (most of the times way faster than to wait for a forumreply)

actually it’s even in the documentation.  
Notes:  
• ADCs will be identified with a number as 0, 1, 2, . . . . adc\_NbBlocks-1.  
• For each block, the sampling time capability is defined in the PTS.

---

<div class="post-metadata">

**Author:** ![tomridl](https://sea1.discourse-cdn.com/flex025/user_avatar/forum.sierrawireless.com/tomridl/32/2704_2.png) [@tomridl](https://forum.sierrawireless.com/u/tomridl)\
**Post date:** [March 4, 2009, 10:22am UTC](https://forum.sierrawireless.com/t/reading-adc-value-from-q2686/3005/3 "2009-03-04T10:22:03Z")

</div>

Here is all you need to read either the actual millivolt or the raw ADC value from the 2nd ADC (ADC2 or AUX ADC) on a Q2686, using v7.1 firmware.

```auto
#include "adl_global.h"

const u16 wm_apmCustomStackSize = 1024*3;
s32 MilliVolts;
u32 ADC_Raw;

void ADC_Read (u8 ID)
{
	adl_adcAnalogRead( 2, &MilliVolts);
    TRACE((1,"ADC mV: %d", MilliVolts));
	adl_adcRead( 2, &ADC_Raw);
    TRACE((1,"ADC Raw Value: %d", ADC_Raw));
}

void adl_main ( adl_InitType_e InitType )
{
    TRACE (( 1, "Embedded Application : Main" ));
    adl_tmrSubscribe(TRUE, 20, ADL_TMR_TYPE_100MS, ADC_Read );
}
```

ADC value is read every second, and result is shown in trace.

---

<div class="post-metadata">

**Author:** ![Vanee](https://avatars.discourse-cdn.com/v4/letter/v/f19dbf/32.png) [@Vanee](https://forum.sierrawireless.com/u/Vanee)\
**Post date:** [March 4, 2009, 10:35am UTC](https://forum.sierrawireless.com/t/reading-adc-value-from-q2686/3005/4 "2009-03-04T10:35:35Z")

</div>

Thanks all for the immediate reply. It’s really helpful. Let me try it out and get back on this. I have few more queries wrt GPIO handling.  
Do we need to subscribe to adl\_ioeventsubscribe if we are going to poll for GPIO values periodically?  
Also, can we use \>1 adl\_iowritesingle commands continuously in the code will it affect the way the GPIO pins are enabled in anyway?  
How accurate are the adc values? I have this Qn as there was some high error percent in the adc values obtained from Q2501.  
Few general Qns as well:  
Can we configure the timer handler to 5 secs? Or should the interval be some higher value?  
Has anyone faced issues while using DOTA in Q2686?  
Need help on the hardware and software watchdog timer handling. Sample code on this will be really helpful.  
And, im using Q2686 with OS R70 version and 2.12 IDE.

Regards,  
S. Vanee

---

<div class="post-metadata">

**Author:** ![tomridl](https://sea1.discourse-cdn.com/flex025/user_avatar/forum.sierrawireless.com/tomridl/32/2704_2.png) [@tomridl](https://forum.sierrawireless.com/u/tomridl)\
**Post date:** [March 4, 2009, 2:24pm UTC](https://forum.sierrawireless.com/t/reading-adc-value-from-q2686/3005/5 "2009-03-04T14:24:20Z")

</div>

> [@](#):
>
> Do we need to subscribe to adl\_ioeventsubscribe if we are going to poll for GPIO values periodically?

No, if you want to manually poll GPIO values, you don’t need to subscribe. In order to set-up an automatic GPIO polling process, the adl\_ioEventSubscribe() function has to be called before the adl\_ioSubscribe().

> [@](#):
>
> Can we configure the timer handler to 5 secs? Or should the interval be some higher value?

The smallest timer value is 18.5ms. Don’t know what the longest timer value can be.

> [@](#):
>
> Also, can we use \>1 adl\_iowritesingle commands continuously in the code will it affect the way the GPIO pins are enabled in anyway?

guess you can use its as many times as you like, as long as you have subscribed the GPIO pins you are writing to using adl\_ioSubscribe().

---

<div class="post-metadata">

**Author:** ![Madouc](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@Madouc](https://forum.sierrawireless.com/u/Madouc)\
**Post date:** [March 4, 2009, 3:15pm UTC](https://forum.sierrawireless.com/t/reading-adc-value-from-q2686/3005/6 "2009-03-04T15:15:52Z")

</div>

> [@tomridl](#):
>
> > [@](#):
> >
> > Do we need to subscribe to adl\_ioeventsubscribe if we are going to poll for GPIO values periodically?
> 
> No, if you want to manually poll GPIO values, you don’t need to subscribe. In order to set-up an automatic GPIO polling process, the adl\_ioEventSubscribe() function has to be called before the adl\_ioSubscribe().
> 
> > [@](#):
> >
> > Can we configure the timer handler to 5 secs? Or should the interval be some higher value?
> 
> The smallest timer value is 18.5ms. Don’t know what the longest timer value can be.

longest timer is in the direction of day’s.

> [@tomridl](#):
>
> > [@](#):
> >
> > Also, can we use \>1 adl\_iowritesingle commands continuously in the code will it affect the way the GPIO pins are enabled in anyway?
> 
> guess you can use its as many times as you like, as long as you have subscribed the GPIO pins you are writing to using adl\_ioSubscribe().

although it’s NOT apparant from the documentation.  
adl\_ioWriteSingle is depricated and will be removed in the future.

> [@adl\_gpio.h](#):
>
> @deprecated This function is kept in the GPIO service interface for ascendant compatibility only, but should not be used anymore by any application. It shall be removed from future GPIO service interface.

---

<div class="post-metadata">

**Author:** ![Vanee](https://avatars.discourse-cdn.com/v4/letter/v/f19dbf/32.png) [@Vanee](https://forum.sierrawireless.com/u/Vanee)\
**Post date:** [March 5, 2009, 4:53am UTC](https://forum.sierrawireless.com/t/reading-adc-value-from-q2686/3005/7 "2009-03-05T04:53:43Z")

</div>

Thanks for the useful tips. can you send some sample on how to use adl\_iowrite() say for using GPIO 1 and 2 as output and 21 and 32 as input?  
Also, did anyone face issues with DOTA in Q2686?

---

<div class="post-metadata">

**Author:** ![Vanee](https://avatars.discourse-cdn.com/v4/letter/v/f19dbf/32.png) [@Vanee](https://forum.sierrawireless.com/u/Vanee)\
**Post date:** [March 11, 2009, 8:17am UTC](https://forum.sierrawireless.com/t/reading-adc-value-from-q2686/3005/8 "2009-03-11T08:17:53Z")

</div>

Hi,  
will there be any difference in the adc value read using adl\_adcRead() and at+adc? or do they both give the same values?

Pls do reply at the earliest.

---

<div class="post-metadata">

**Author:** ![Madouc](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@Madouc](https://forum.sierrawireless.com/u/Madouc)\
**Post date:** [March 11, 2009, 9:17am UTC](https://forum.sierrawireless.com/t/reading-adc-value-from-q2686/3005/9 "2009-03-11T09:17:20Z")

</div>

here should be no difference, the analog value (or ‘raw’ digital value) is comming from the same internal registers.

---

<div class="post-metadata">

**Author:** ![Vanee](https://avatars.discourse-cdn.com/v4/letter/v/f19dbf/32.png) [@Vanee](https://forum.sierrawireless.com/u/Vanee)\
**Post date:** [March 11, 2009, 9:19am UTC](https://forum.sierrawireless.com/t/reading-adc-value-from-q2686/3005/10 "2009-03-11T09:19:46Z")

</div>

That means if there is a correction factor required when we use at+adc, the same will apply to adl\_adcread() as well? Then, what is the need for having a separate api? Is there any performance advantage?

---

<div class="post-metadata">

**Author:** ![Madouc](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@Madouc](https://forum.sierrawireless.com/u/Madouc)\
**Post date:** [March 11, 2009, 9:32am UTC](https://forum.sierrawireless.com/t/reading-adc-value-from-q2686/3005/11 "2009-03-11T09:32:45Z")

</div>

I don’t know about you, but i really don’t like to mess around with having to send at-commands from my program to the Open-AT OS and then having to interpret the results.  
a simple api-call is much more desireable (would really like to have them for all available at-commands)

it’s like you have two way’s to accomplish the same thing, (as with all the AT-commands which interface with the GSM/GPRS parts of the module)

---

<div class="post-metadata">

**Author:** ![awneil](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@awneil](https://forum.sierrawireless.com/u/awneil)\
**Post date:** [March 11, 2009, 9:33am UTC](https://forum.sierrawireless.com/t/reading-adc-value-from-q2686/3005/12 "2009-03-11T09:33:53Z")

</div>

> [@Vanee](#):
>
> Then, what is the need for having a separate api?

Do you not find that it is easier to simply make an API call like adl\_adcRead() rather than having to issue the AT command, and then handle the response?

There is, of course, nothing to stop you from just issuing the AT command and handling the response - if you find that preferable.

---

<div class="post-metadata">

**Author:** ![awneil](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@awneil](https://forum.sierrawireless.com/u/awneil)\
**Post date:** [March 11, 2009, 9:36am UTC](https://forum.sierrawireless.com/t/reading-adc-value-from-q2686/3005/13 "2009-03-11T09:36:13Z")

</div>

> [@Madouc](#):
>
> I don’t know about you, but i really don’t like to mess around with having to send at-commands from my program to the Open-AT OS and then having to interpret the results.  
> a simple api-call is much more desireable (would really like to have them for all available at-commands)

I thoroughly agree!

See: [viewtopic.php?t=1171&hilit=mess+about+with+AT+commands](http://www.wavecom.com/modules/movie/scenes/forums/viewtopic.php?t=1171&hilit=mess+about+with+AT+commands)

---

<div class="post-metadata">

**Author:** ![Vanee](https://avatars.discourse-cdn.com/v4/letter/v/f19dbf/32.png) [@Vanee](https://forum.sierrawireless.com/u/Vanee)\
**Post date:** [March 11, 2009, 10:52am UTC](https://forum.sierrawireless.com/t/reading-adc-value-from-q2686/3005/14 "2009-03-11T10:52:08Z")

</div>

Thanks for the suggestion. But, why i asked the question is because, the adc value read using at command is not accurate hence, had a hope if the adl command would solve this issue. The adc value read using at command has an added value of approximately 20 to 60 values for a value of 4mA - 20mA resulting in 420 - 460 as opposed to the expected to the 400 value. Does any know why this problem occurs and how to rectify it? Do we need to use external chips via I2C to read the adc?  
Pls do reply at the earliest.

---

<div class="post-metadata">

**Author:** ![Madouc](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@Madouc](https://forum.sierrawireless.com/u/Madouc)\
**Post date:** [March 11, 2009, 11:07am UTC](https://forum.sierrawireless.com/t/reading-adc-value-from-q2686/3005/15 "2009-03-11T11:07:16Z")

</div>

I seems that there is no way to change the calibration for the internal adc’s. So if you need to change the offset of the adc’s then you need to compensate in your code or indeed use an external adc (can be connected trough I2C or SPI)  
added advantage of an external adc is that you have much greater control over it’s parameters. (offset, calibration, range, etc)

---

<div class="post-metadata">

**Author:** ![awneil](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@awneil](https://forum.sierrawireless.com/u/awneil)\
**Post date:** [March 11, 2009, 11:55am UTC](https://forum.sierrawireless.com/t/reading-adc-value-from-q2686/3005/16 "2009-03-11T11:55:44Z")

</div>

> [@Vanee](#):
>
> The adc value read using at command has an added value of approximately 20 to 60 values for a value of 4mA - 20mA

But the ADC measures voltage, not current - doesn’t it?

So, have you confirmed that the error is really in the ADC reading - or is it actually in your current-to-voltage conversion?

Is it within the quoted specifications for the ADC?

---

<div class="post-metadata">

**Author:** ![Vanee](https://avatars.discourse-cdn.com/v4/letter/v/f19dbf/32.png) [@Vanee](https://forum.sierrawireless.com/u/Vanee)\
**Post date:** [March 12, 2009, 3:50am UTC](https://forum.sierrawireless.com/t/reading-adc-value-from-q2686/3005/17 "2009-03-12T03:50:13Z")

</div>

Where do i find the specifications for ADC? im confident that the ADC reading is causing the problem. To cross check, is there a way to find out where the problem is if it is in the adc or in the current-voltage conversion? If it is measuring the voltage supplied, then we have done this. And the conversion is quite accurate.  
Also, i would like to know if Q2686 has different way of handling ADC than Q2501 or is it the same? As we faced this issue a lot with Q2501.

---

<div class="post-metadata">

**Author:** ![awneil](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@awneil](https://forum.sierrawireless.com/u/awneil)\
**Post date:** [March 12, 2009, 10:55pm UTC](https://forum.sierrawireless.com/t/reading-adc-value-from-q2686/3005/18 "2009-03-12T22:55:15Z")

</div>

> [@Vanee](#):
>
> Where do i find the specifications for ADC?

In the Product Technical Specification - or PTS.

> [@](#):
>
> If it is measuring the voltage supplied, then we have done this. And the conversion is quite accurate.

So the ADC is accurately converting the voltage supplied to it? What more can you expect?

The ADC cannot see anything other than the voltage applied to its input!

---

<div class="post-metadata">

**Author:** ![Madouc](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@Madouc](https://forum.sierrawireless.com/u/Madouc)\
**Post date:** [March 13, 2009, 8:48am UTC](https://forum.sierrawireless.com/t/reading-adc-value-from-q2686/3005/19 "2009-03-13T08:48:32Z")

</div>

> [@Vanee](#):
>
> If it is measuring the voltage supplied, then we have done this. And the conversion is quite accurate.

So the ADC is accurately converting the voltage supplied to it? What more can you expect?

The ADC cannot see anything other than the voltage applied to its input!  
[/quote]  
i suspect that the conversion he’s referencing to is the current to voltage conversion.

---

<div class="post-metadata">

**Author:** ![Vanee](https://avatars.discourse-cdn.com/v4/letter/v/f19dbf/32.png) [@Vanee](https://forum.sierrawireless.com/u/Vanee)\
**Post date:** [March 13, 2009, 9:24am UTC](https://forum.sierrawireless.com/t/reading-adc-value-from-q2686/3005/20 "2009-03-13T09:24:55Z")

</div>

Sorry there’s mis interpretation of what i said. It’s actually through external means we measured the voltage going into the chip and that is accurate. But, what comes from the Wavecom chip via ADC’s having the issue that i have been mentioning.

“The adc value read using at command has an added value of approximately 20 to 60 values for a value of 4mA - 20mA resulting in 420 - 460 as opposed to the expected to the 400 value. Does any know why this problem occurs and how to rectify it?”

And interestingly one of my friends working on Wavecom has also been facing this issue. Pls do reply at the earliest.
