analog to digital setup on 18F2550


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2010
    Posts
    10

    Default analog to digital setup on 18F2550

    below is the setup portion of some code down the the ADCIN, adval1 command. the digital value is used to turn on 10 leds as a binary representation of adval1. num is set equal to adval1 and displayed as a binary number using LEDs. that part is farther down the program on not included. We had it working before connecting the potentiometer.

    It appears that we don't have a proper analog reference. We want to use the Vss as the ref. We have bits 4 and 5 set to 0 which should make it use Vdd and Vss. The reason for thinking it is the setup is the LED's light but not correctly.

    Can one of you experts please review our setup and tell us if we have it set up the way we think we do?

    thanks

    ************************************************** ************************************************** ***********

    'Define ADCIN parameters
    DEFINE ADC_BITS 10 ' Set number of bits in result
    DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
    DEFINE ADC_SAMPLEUS 100 ' Set sampling time in uS

    'define hpwm parameters
    DEFINE CCP1_REG PORTC 'Hpwm 1 port bit
    DEFINE CCP1_BIT 2 'Hpwm 1 pin bit
    DEFINE HPWM1_TIMER 1 'Hpwm 1 timer select
    DEFINE CCP2_REG PORTC 'Hpwm 2 pin port
    DEFINE CCP2_BIT 1 'Hpwm 2 pin bit
    DEFINE HPWM2_TIMER 1 'Hpwm 2 timer select

    DEFINE OSC 8

    TRISA = %11111111 'in,in,in,in,in,in,in,in
    TRISB = %00000000 'out,out,out,out,out,out,out,out
    TRISC = %00000000 'out,out,out,out,out,out,out,out
    OSCCON = %01110010
    ADCON0 = %00000101
    ADCON1 = %00001101

    out1 VAR PortC.6
    out2 VAR PortC.7
    out4 VAR PortB.0
    out8 VAR PortB.1
    out16 VAR PortB.2
    out32 VAR PortB.3
    out64 VAR PortB.4
    out128 VAR PortB.5
    out256 VAR PortB.6
    out512 VAR PortB.7
    adval1 VAR WORD
    'adval2 VAR WORD
    num var word

    mainloop:

    ADCIN 0, adval1
    'ADCIN 1, adval2

    Pause 10

    num = adval1

    .
    .
    .
    .

  2. #2
    Join Date
    Jan 2010
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Re: analog to digital setup on 18F2550

    Just in case someone is having the same issue - - we resolved it by reversing the justification of the A to D conversion value. It can be left to right for 8 bit values but for a 10 bit conversion value it has to be right to left. I found one little sentence somewhere in my reading that said that and it worked. I don't even remember if it was the datasheet or not.

Similar Threads

  1. Analog Digital Conversion ??
    By gunayburak in forum General
    Replies: 3
    Last Post: - 28th December 2012, 16:52
  2. analog and digital
    By lerameur in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 10th June 2008, 02:40
  3. PortA analog and digital IO
    By krohtech in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 30th November 2007, 02:25
  4. Digital to Analog Converter
    By kutsi in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 27th June 2007, 19:17
  5. 18F2550 config fuses, is my setup OK?
    By peu in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 28th July 2006, 03:48

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts