It is currently 21 May 2018 05:59

All times are UTC + 1 hour

Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: 07 Feb 2018 19:52 

Joined: 07 Feb 2018 19:38
Posts: 1
Dear colleagues,

I am carrying out the reading of a voltage divider using mikroC PRO for PIC and a PIC16LF1509. The board I am using is the EasyPIC v7.

I have connected the output of the voltage divider to RA2 and I have configured that PIC pin to be an analog input by TRISA.F2 = 1 and ANSELA.F2 = 1.

The PIC16LF1509 has an HS clock of 8 Mhz.

For the use of ADC I use the function ADC_Read (2) of mikroC, although I have also tried to make my own function ADCInit and ADCRead with the typical PIC commands. In both cases the problem is the same.

I explain the problem: When I try to read the value of the ADC in RA2 it always gives me the same result, 662. This happens having the voltage divider value in the output or without any value at the output, that is, the output is zero. However, the curious thing is that by trying and trying to figure out if the problem was the design of the voltage divider or some other external component, I connected the output of the voltage divider to RA0 and configured this pin as an analog input, in the same way as before with RA2. I used ADC_Read (0) of mikroC and I insist, it worked perfectly.

I have also tested with the EasyPICv7 potentiometer and something similar happens, RA0 reads perfectly but RA2 does not. RA2 varies between 772 and 996 (position 0 and maximum of the potentiometer respectively).

My question is: What am I doing wrong so that it does not work in RA2?. The problem is that the design of my electronic board involves using RA2 as input and that's why I need your help.

Receive a warm greeting,


PostPosted: 13 Feb 2018 15:52 
mikroElektronika team
User avatar

Joined: 25 Jan 2008 09:56
Posts: 9769

I have tried this on PIC16F1509 and it works OK, here is my code :
#include <built_in.h>

unsigned int adc_rd;

void main() {
  ANSELA = 0x04;             // Configure RA2 pin as analog
  ANSELC = 0;                // Configure PORTC pins as digital
  TRISA = 0x04;              // Set RA2 pin as input
  TRISC = 0x00;              // Set PORTC as output

  while (1) {
    adc_rd = ADC_Read(2);    // get ADC value from 2nd channel
    LATC = adc_rd;           // display adc_rd[7..0]
Can you attach the detailed photo of your EasyPIC7 configuration when using on-board potentiometer ?


Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour

Who is online

Users browsing this forum: No registered users and 7 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: