ADC problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ADC problem

3,008 Views
RChapman
Contributor I
Code:
byte AD1_Measure(bool WaitForResult) { if (ModeFlg != STOP) /* Is the device in different mode than "stop"? */ return ERR_BUSY; /* If yes then error */ ModeFlg = MEASURE; /* Set state of device to the measure mode */ OutFlg = FALSE; /* Output values aren't available */ /* ATDCTL5: DJM=1,DSGN=0,SCAN=0,MULT=0,??=0,CC=1,CB=1,CA=1 */ ATDCTL5 = 128; /*I 'VE CORRECTED THIS VALUE CHANNEL 0 - /* Start conversions */ if (WaitForResult) /* Is WaitForResult TRUE? */ while (ModeFlg == MEASURE) { /* Calling MainMeasure while IDLE state occured */ AD1_MainMeasure(); /* A/D converter handler */ } return ERR_OK; /* OK */ } 

 
This message contains an entire topic ported from a separate forum. The original message and all replies are in this single message. We have seeded this new forum with selected information that we expect will be of value to you as you search for answers to your questions.
 
Posted: Thu Apr 21, 2005 9:25 am    
 
Hi everyone,

I'm using the ADC bean(Processor Expert) in a project and it does not work.(The sampled values are always zero).I have spend a lot of hours trying to make it work and iam desperate!!! I also tried sample code that comes with processor Expert software and still nothing works.I'm beginning to suspect that there is a problem concerning the interrupts priorities or the optimization settings that may be enabled in the tool.
PLEASE if anyone has a clue reply cause iam out of ideas and explanations and i really want to work out this.
 
Posted: Mon Apr 25, 2005 9:59 am    
 
Hi,

What version of Processor Expert do you use? What CPU? Could you describe your HW and SW settings more detail?
 
Posted: Mon Apr 25, 2005 10:31 am    
 
Iam using Codewarrior 5.5.1272 and PE 2.94.01 for HCS12 family.
The hardware i'm using is Motorola Demo board for MC9HCS12NE64 with the serial monitor program.I just apply the methods generated by the bean and while everything seems to work just fine (interrupt routines,debugging flags i use,code execution) the conversion always returns zero.I'm starting to suspect that there is a bug in PE's code generation. Is this possible?
 
Posted: Mon Apr 25, 2005 3:10 pm  
 
Wuts up bro. I'm doin pretty much the same thing for my design project. If u send me wut u got i can test it on my board and let u know if it works. I tried pretty much the same thing on my board and it didn't work either. Sounds like u have the same set up i have as well. Toss me one back u_rkelly@umassd.edu. If i get something going on my end ill let u know wut i did.

Question Wink
 
Posted: Tue Apr 26, 2005 7:36 am    
 
I think i have figured out the problem at least at some point.The PE automatic code generation is not correct and if you are using one channel to sample, a specific register that points the channel selected to sample, is written with a false value(always with channel AD7 ??).

Code:
byte AD1_Measure(bool WaitForResult) { if (ModeFlg != STOP) /* Is the device in different mode than "stop"? */ return ERR_BUSY; /* If yes then error */ ModeFlg = MEASURE; /* Set state of device to the measure mode */ OutFlg = FALSE; /* Output values aren't available */ /* ATDCTL5: DJM=1,DSGN=0,SCAN=0,MULT=0,??=0,CC=1,CB=1,CA=1 */ ATDCTL5 = 128; /*I 'VE CORRECTED THIS VALUE CHANNEL 0 - /* Start conversions */ if (WaitForResult) /* Is WaitForResult TRUE? */ while (ModeFlg == MEASURE) { /* Calling MainMeasure while IDLE state occured */ AD1_MainMeasure(); /* A/D converter handler */ } return ERR_OK; /* OK */ } 

 
ALSO:
 
Code:
byte AD1_GetValue(void *Values) { if (ModeFlg != STOP) { /* Is the device in any measure mode? */ AD1_MainMeasure(); } if (!OutFlg) /* Is measured value(s) available? */ return ERR_NOTAVAIL; /* If no then error */ *((byte*)Values) = ATDDR1L; /* Save measured values to the output buffer */ return ERR_OK; /* OK */ } 

 
*((byte*)Values) = ATDDR1L; is wrong because FIFO is disabled and results go to ATDDR0L for chan0 ,ATDDR1L for chan1 and so on.

OK up to here it seems that the PE needs an update/patch.
What is mysterious for me is that i also needed to use variable
RESULT= ATDDR0L directly to have it work and bypass the use of pointer to an array( byte AD1_GetValue(void *Values)+*((byte*)Values) = ATDDR1L; ).This i don't understand. Can anyone help??
I interpret the code as: fill the address of the variable Values with the value of ATDDR1L. Shouldn't this work?
 
Posted: Tue Apr 26, 2005 1:23 pm    
 
Processor Expert generates incorrect code for selecting input AD channels (CC:CB:CA bits in ATDCTL5). The patchs fixed this problem will prepared and announced on Processor Expert web site (www.processorexpert.com) till the end of week.

The direct URL to download the patch will be added here too.

Thanks for your feedback.
 
Posted: Mon May 02, 2005 8:59 pm    
 
Wuts up. I also tried the processor expert anb it failed on me. I also noticed that for A/D that ports 23 and 45 are grouped together as a 16 bit register. I've got them set up to make 4 conversions and to put readings in the first 4 result registers. I'm not sure i got it working correctly though u have any progress on your side?
Labels (1)
0 Kudos
Reply
0 Replies