• AVR Freaks

Hot!PIC16F18855 Analog input problem

Author
DavidMS
New Member
  • Total Posts : 4
  • Reward points : 0
  • Joined: 2011/12/30 01:38:30
  • Location: 0
  • Status: offline
2020/03/08 07:07:51 (permalink)
0

PIC16F18855 Analog input problem

I am trying to get a basic analogue input port working in assembler on 16F18855 Xpress board. This has board a potentiometer connected RA4. Looking in the databook for the device there is some example assembler  (see attached picture) to read an analogue port.  I think there are some errors in the listing, for instance the initial setup of ADCON1 does not match information in the manual, and the ANSEL setup is wrong - I assume it should be referring to 'ANSELA'. 
 
So I guess I am looking to be clear the example code is wrong and then what the correct setup assembler code to read RA4 in basic mode into W should be - I only need 9:2 bits, happy to lose the lower 2 bits.
 
I have used PICs a lot in the past but this setup for this chip is a whole lot more complex that devices I have used before.

Attached Image(s)

#1

1 Reply Related Threads

    Mysil
    Super Member
    • Total Posts : 3678
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: PIC16F18855 Analog input problem 2020/03/08 10:44:27 (permalink)
    5 (2)
    Hi,
    You seem to be right, there is a copy/paste mistake in the assembly code example attached in message #1.
    In the Datasheet, just beside example code, there is comment 1. referring you to study ANSELx register.
    (fill in A, B, C ... instead of the x)
     
    I cannot see that there is a lot of complexity.
    ADC hardware for this device have a couple of optional counters for automatic precharge and aquisition time. These are not used in the basic mode example.
    Instead, the example assume a function:  SampleTime       to be called to provide a suitable delay.
     
    But there are more mistakes in the example code.
    In this device type, the bit controlling result format:  ADFRM0  is in ADCON0 register,
    not in ADCON1 register, as in some previous PIC device types,
    so comment about ';Right justified' result in connection with setting ADCON1 register is wrong.
    If you need only 8 bits precision in result, you may leave ADFRM0 bit in ADCON0 register = 0,
    and use result value from ADRESH directly.
     
    Also, comment about ';Select channel AN0' 
    in connection with setting value for ADCON0 register is also wrong.
    In this family of PIC devices, selection of Analog input channel is done by ADPCH register, 
    so selection of AN0 channel in example, is because reset default, not by concious code.
     
    If you do not specifically want to, or are required to program in assembly language, 
    then setting up ADC registers may just as easily be done in C language.
    Device support file: 
    #include <xc.h>
    have symbolic names and bitfield definitions for all the registers in the microcontroller.
    By using symbolic names for control bits and registers,
    compiler may help by warning you if trying to use a named control bit or field in the wrong register.
     
        Mysil
    #2
    Jump to:
    © 2020 APG vNext Commercial Version 4.5