Jump to content
steve34

A/d Conversion On Pic16f690

Recommended Posts

Hey guys this is my first PIC project and I was wondering if you could help me by looking at my A/D conversion code for the PIC16F690. I have gone through the datasheets and sample code but I cant find what is wrong. It always hangs up on my while(adcon0.GO_DONE) polling instruction. Thanks alot.

 

 

 

short adc_measure()

{

 

trisa=0x01;

porta=0x00;

ansel=0x01;

 

clear_bit(adcon1,ADCS0);

set_bit(adcon1,ADCS1);

clear_bit(adcon1,ADCS2); // Select Tad = 32 * Tosc

 

clear_bit(adcon0,CHS0); //

clear_bit(adcon0,CHS1); //

clear_bit(adcon0,CHS2); //

clear_bit(adcon0,CHS3); // Channel 0

 

set_bit(adcon0,ADFM); // AD result needs to be right justified

clear_bit(adcon0,VCFG); // Vref = Vdd

set_bit(adcon0,ADON); // Activate AD module

 

 

// Start the conversion

set_bit(adcon0,GO_DONE);

delay_10us(2);

 

// Wait until it is done

while (adcon0.GO_DONE);

 

short retval;

retval = (short)adresh;

retval = retval << 8;

retval |= adresl;

 

return retval;

}

Share this post


Link to post
Share on other sites

Are you running this on a real PIC or using the debug tool ?

 

The debug tool will not give you a conversion complete signal.

 

i.e. GO_DONE will always be set.

 

Regards

 

Reynard

Share this post


Link to post
Share on other sites

Well maybe then that is the problem. Thanks alot, Reynard. Ill try to program the board then. So what is the signal generator in the extra plugins good for. I was hoping I could use this in the debug. Oh well. Ill program the board and see what happens.

 

Thanks again.

Steve

Share this post


Link to post
Share on other sites

Hi Steve,

 

Not really sure what this plud-in does. Looks like it applies (simulates) a waveform onto a digital input and provides a 0 or 1 onto the pin when the switching thresholds of the input pin are passed through (i.e. 2.5V).

 

It may have a use to someone though.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites

steve34,

So what is the signal generator in the extra plugins good for.
Some devices have full ADC support and so the signal generator can be used on those with the ADC. Also the signal generator can be connected to digital pins to provide other stimulation.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...