Forum Index
getADC() returns 0.0 with TMR5 active

 
Author Message
pjc30943



Joined: 02 Dec 2005

Posted: 06 August 2008, 21:14 PM    Post subject: getADC() returns 0.0 with TMR5 active

I looked in the resource usage section, but I'm still uncertain why I'm seeing this specific effect:

When TMR5 is untouched, the getADC() function works all the time.
After setting up TMR5, getADC() often returns 0.0.

What shared resources do they have?

At first though it seemed to be an interrupt-related issue since some are enabled, but interrupts are disabled around the getADC() command with no change.
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Location: Portland, OR

Posted: 06 August 2008, 21:48 PM    Post subject: Re: getADC() returns 0.0 with TMR5 active

pjc30943 wrote:
After setting up TMR5, getADC() often returns 0.0.
In what way is Timer5 being set up? Do you have a small test case that demonstrates the problem.

It could be an undetected problem with task suspension/resumption relating to the ADC. You can test this hypothesis by locking the task before the GetADC() call and unlocking it afterward.
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Location: Portland, OR

Posted: 06 August 2008, 21:57 PM    Post subject:

It could also be caused by a resource conflict if multiple tasks attempt to use the ADC. There is only one ADC in the system and if a conversion is underway when another call to GetADC() is made the latter call will silently return 0.

The locking method described in my previous response will guard against this problem unless an ISR uses the ADC. The alternate method to protect against this problem is to create a semaphore variable representing the ADC. Then, in each place that you call GetADC() you'll want to first acquire the semaphore, call GetADC() and then clear the semaphore. This technique can be used on any resource that must be used serially. Note, however, that you probably do not want to use this technique in an ISR because of the delay that it will introduce.

Code:
Public adcSem as Boolean
...
  Do While Not Semaphore(adcSem)
  Loop
  Call GetADC(chan, adcVal)
  acdSem = False
Back to top
Display posts from previous:   
Page 1 of 1

 



ZBasic Microcontrollers Home
All content Copyright © 2005, 2006, 2007, 2008 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group