Author Topic: PIC16F877a ADC help  (Read 4528 times)

0 Members and 1 Guest are viewing this topic.

Offline galannthegreatTopic starter

  • Supreme Robot
  • *****
  • Posts: 615
  • Helpful? 4
  • Blue-Lensed Blue LEDs?! What?! Impossible!!
PIC16F877a ADC help
« on: January 29, 2009, 07:22:37 PM »
On this MCU the ADC port is 10bit, i want to work with 8bit values so do i have to set this in software, or is it 8bit from the start and then it has to be set to 10bit?
Kurt

Offline cosminprund

  • Robot Overlord
  • ****
  • Posts: 284
  • Helpful? 8
Re: PIC16F877a ADC help
« Reply #1 on: January 30, 2009, 04:35:30 AM »
To work with 8 bits you simply make the ADC result "left align" and only read from the ADRESH register. I don't think there's a way to make the MCU actually convert only 8 bits, it allways converts 10 bits. The details are in the datasheet, there's an whole chapter on ADC operation.

Offline galannthegreatTopic starter

  • Supreme Robot
  • *****
  • Posts: 615
  • Helpful? 4
  • Blue-Lensed Blue LEDs?! What?! Impossible!!
Re: PIC16F877a ADC help
« Reply #2 on: January 30, 2009, 12:05:51 PM »
thanks,
so simply said it would be easier to work with 10bit ADC vs the 8bit way
Kurt

Offline HDL_CinC_Dragon

  • Supreme Robot
  • *****
  • Posts: 1,261
  • Helpful? 5
Re: PIC16F877a ADC help
« Reply #3 on: January 30, 2009, 03:44:31 PM »
10bit ADC allows for finer detection anyway which is always good :) Why do you prefer the 8bit to the 10bit? Just curious

As cosmin suggested, try reading the datasheet. They contain some good info for ADC
United States Marine Corps
Infantry
Returns to society: 2014JAN11

Offline galannthegreatTopic starter

  • Supreme Robot
  • *****
  • Posts: 615
  • Helpful? 4
  • Blue-Lensed Blue LEDs?! What?! Impossible!!
Re: PIC16F877a ADC help
« Reply #4 on: January 30, 2009, 04:42:28 PM »
I do prefer to work with 8bit numbers but like you said the best option, i guess, would be 10bit, like you said for the better precision.

I am also wondering how would i set up the clock configuration for a 20MHz HS crystal, should i use  #use delay(20000000)  ? or is there a  #fuse   setting that needs to be used?
« Last Edit: January 30, 2009, 07:26:35 PM by galannthegreat »
Kurt

Offline cosminprund

  • Robot Overlord
  • ****
  • Posts: 284
  • Helpful? 8
Re: PIC16F877a ADC help
« Reply #5 on: January 30, 2009, 11:35:52 PM »
Using only 8 bits out of the total 10 bits available makes sense for many application, it still gives you about 255 different "levels" and it directly maps to the MCU's data size (8 bit). Since the MCU itself can't operate on more then 8 bits / 1 byte at a time, every time you use in your C compiler something that's bigger then 8 bits (say an 16 bits "int" that can record the full 10 bit ADC result) the compiler will generate code to use two distinct bytes and will use discrete operations on the two distinct bytes: the result is that anything you do with that artificial 16 bits value will be 4 times slower (or more). In other words: stick with 8 bits unless absolutely required to switch.

 

SMF spam blocked by CleanTalk