PIC C Compiler help needed

Thread Starter

bilal sheikh

Joined Jan 21, 2015
22
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
 

shteii01

Joined Feb 19, 2010
4,644
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.
 

Thread Starter

bilal sheikh

Joined Jan 21, 2015
22
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.
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:
#include <adc.h>
#include <PIC16F877A_registers.h>      // hex file that defines each register with its adress.
float result;

void main()
{
set_adc_channel(0);
while (1)
{
   setup_adc_ports(AN0_VREF_VREF);
result=read_adc(0);                                           // reading adc value from channel 0
result=MCU_PORTC;                                       // writing adc results to port C
}

}
Moderators note : Please use code tags for pieces of code
 
Last edited by a moderator:

Papabravo

Joined Feb 24, 2006
21,227
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!!??!!
 

shteii01

Joined Feb 19, 2010
4,644
ok , kindly tell me how can i write the adc results directly to a port in controller.
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.
 
Top