Really simple test program not working.


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305

    Default Really simple test program not working.

    18F2550 20mhz HSPLL set up for USB

    PIC functions and pcb is fine. I can get a simple blinky light to work. I can get a correct ADC value to write to EEPROM and read through the programmer, but I cant get it compare the ADC value with the value stored in fb and turn on or off the LED as I vary the voltage in the ACD pin.

    What the heck am I missing?

    Code:
    define OSC 48
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50
    raw var word
    raw1 var word
    fb var word
    fb = 205
    ADCON1 = 001011
    ADCON2 = 000011
    
    
    TRISA = 001111
    TRISB = 110000
    TRISC = 000000
    PORTC.2 = 0
    
    
    main:
    pause 100
    adcin 0, raw
    raw1 = raw/10
    if raw1 => fb then
    Portc.0 = 1
    else 
    portc.0 = 0
    endif
    
    
    goto main]
    Last edited by mackrackit; - 24th October 2011 at 18:19. Reason: fix code tag

  2. #2
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: Really simple test program not working.

    Max value for raw is 1024? assuming 10 bit a/d. 1024/10=102. this is ALWAYS less the 205. So you will never be able to turn on the LED. If its a 12 bit A/D, then IDK
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  3. #3
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: Really simple test program not working.

    You are correct and I did remove the /10.

    However, the fix was left vs right justification of the result. It works as expected.

Members who have read this thread : 1

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