PIC C Compiler help needed

Discussion in 'Embedded Systems and Microcontrollers' started by bilal sheikh, Mar 15, 2015.

  1. bilal sheikh

    Thread Starter New Member

    Jan 21, 2015
    22
    0
    hello everyone, i am using pic16f877a in my project. i have to use ADC module. for programming purpose, i am using PIC C Compiler. now i want to select adc clock as 32*TOSC but i cant select any value other than 2*TOSC. drop down menu occurs but i cant select any value other than 0.4us. any PIC C user here who can help me out ??
    Screenshot (44).png
     
  2. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,386
    496
    Does datasheet list 32xTOSC?
     
  3. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,386
    496
    The ADC is not some magic juju. It is actual physical piece of equipment/hardware. And as an actual physical equipment/hardware it has limitations. Have you looked what those limitations are?

    The way around the limitation is to use external ADC that has the sampling frequency that you need/require. Then use serial or parallel communication to send results of external ADC conversion to the PIC.

    Another option is to replace the PIC with newer one. From what I read here, the 16F877 is ANCIENT. This works for you because there is a TONE of tutorials on how to use it. This works against you because the design is old and hardware is old and newer PICs are likely to have better hardware.
     
    bilal sheikh likes this.
  4. bilal sheikh

    Thread Starter New Member

    Jan 21, 2015
    22
    0
    ok , kindly tell me how can i write the adc results directly to a port in controller.
    e.g i am using 8 bit ADC (PIC Built in ADC) and want to write the 8 bits to one of the ports e.g port B. i am using the following code but its not working.

    Code (Text):
    1.  
    2. #include <adc.h>
    3. #include <PIC16F877A_registers.h>      // hex file that defines each register with its adress.
    4. float result;
    5.  
    6. void main()
    7. {
    8. set_adc_channel(0);
    9. while (1)
    10. {
    11.    setup_adc_ports(AN0_VREF_VREF);
    12. result=read_adc(0);                                           // reading adc value from channel 0
    13. result=MCU_PORTC;                                       // writing adc results to port C
    14. }
    15.  
    16. }
    17.  
    Moderators note : Please use code tags for pieces of code
     
    Last edited by a moderator: Mar 15, 2015
  5. Papabravo

    Expert

    Feb 24, 2006
    10,137
    1,786
    Don't you want to write:

    MCU_PORTC = result ;

    In your code you are first witing the A/D output to the global variable result, then you are writing the PORCTC input latch on top of the value you just stored in result. In what universe can you claim you are writing the result to PORTC!!??!!
     
    bilal sheikh likes this.
  6. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,386
    496
    When you use external adc chip, this external adc chip comes with facility to connect to other hardware, to uC for example. Here is an example of external adc chip connected to 16F877a:
    https://www.ccsinfo.com/forum/viewtopic.php?t=41915
    The adc chip is AD7812.
    The uC is 16F877a.
    The communication is done using SPI hardware and protocols built into adc and pic.
     
    bilal sheikh likes this.
Loading...