Jump to content
Sign in to follow this  
robotchen

Question For Adc_Measure() Function For Pic16F1827 Mcu

Recommended Posts

According to the PIC16F1827 data sheet (http://ww1.microchip.com/downloads/en/DeviceDoc/41391D.pdf), the channel selection bits in the 'adcon0' register are from bit 6 to bit 2 ( CHS4:CHS0), therefore I suppose to shift left 'two' bits to get the input for CHS4:CHS0.

 

But from the source code for adc_measure function in adc.c, it shows

// Clear the channel selection in adcon0
adcon0 &= 11000111b;
// Shift the channel value to the appropriate position
channel = (channel & 0x07) << 3; <================================= shift left 3 bits
// And move it to the appropriate position in adcon0
adcon0 |= channel;

Any can point out the mistake ?

 

Thanks

 

 

Share this post


Link to post
Share on other sites

The adc.c source supplied was written before the PIC161827 was invented and covered the chips that were around at the time.

 

You will have to make the necessary changes to suit the device you are using.

 

It is diffucult to keep up with all the new parts from Micrcochip and where they put all the pins.

 

Use the supplied libraries as a guide and write the code to suit your application.

Do you want to use interrupts with adc or trigger it using the ccp feature.

 

Cheers

 

Reynard

 

Share this post


Link to post
Share on other sites

Thanks, Reynard.

Just to make sure I do not misunderstanding the data sheet, but I am also hoping that libraries bundled with Sourceboost Compiler is correct.

Best regards

Chen

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
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...
Sign in to follow this  

×