18f4550 a/d


Closed Thread
Results 1 to 7 of 7

Thread: 18f4550 a/d

  1. #1
    Join Date
    Feb 2010
    Posts
    17

    Post 18f4550 a/d

    Hi all.
    I have done A/d to with success with 16f877 and16f887 now I have a problem with 18f4550 the value is fluctuating so much even in the high rail I still get values between 1023 and 1018 and in the low rail some times go up to 8. I think it's a TAD problem but I let you guys help me out.
    Here is the code(nothing fancy just read and display):
    Code:
    ==========================MCU SETUP============================================  
    DEFINE OSC 48
    Include "modedefs.bas"
    '***************************LCD DEFINE******************************* 
    DEFINE LCD_DREG PORTD 'LCD data port 
    DEFINE LCD_DBIT 0 'LCD data starting bit 0 or 4 
    DEFINE LCD_RSREG PORTD 'LCD register select port                      
    DEFINE LCD_RSBIT 5 'LCD register select bit , RS=PORTE.2
    DEFINE LCD_EREG PORTD 'LCD enable port 
    DEFINE LCD_EBIT 7 'LCD enable bit E=portE.0 
    DEFINE LCD_RWREG PORTD 'LCD read/write port 
    DEFINE LCD_RWBIT 6 'LCD read/write bit R/W=POTRD.1
    DEFINE LCD_BITS 4 'LCD bus size 4 or 8 
    DEFINE LCD_LINES 4 'Number lines on LCD 
    DEFINE LCD_COMMANDUS 2000 'Command delay time in us 
    DEFINE LCD_DATAUS 50
    '******************************************************************
    DEFINE ADC_BITS 10     ' ADCIN resolution  (Bits)
    DEFINE ADC_CLOCK 3     ' Work around that sets Vref bits in ADCON1
    DEFINE ADC_SAMPLEUS 50 ' ADC sampling time (uSec)
    
    
    '==========================I/O SETUP============================================
    
    
     
    TRISD=0
    TRISE=0
    TRISC=%10000000
    TRISA=%11111111
    TRISB=0
    
    ADCON1=14
    ADCON2=%10000000
     
    
    '================================variables======================================
    adcval var word 
    TX VAR PORTC.6
    RX VAR PORTC.7
    
    '==============================BAUD SETUP=======================================
    N96 con 16416 ' Inverted 19200 baud for the lcd rs232  
    T192 con 32 '19200 TTL 
    T96 CON 84'9600 TTL
    T38 CON 6'38K
    '==========================I/O SETUP============================================
    '======================LCD LINES SETUP==========================================
    L1 CON 1 'LINE1
    L2 CON $C0'LINE2
    L3 CON $94'LINE3
    L4 CON $D4'LINE4
    
    CLEAR
    
    '=============================================================================
    
      
    PAUSE 500
    loop:
    LCDOUT $FE,l1
    PAUSE 50
    LCDOUT "a/d test" 
    
     
    MAIN:
    
    gosub adc0
    lcdout $fe,l2
    lcdout "pot:" ,dec adcval,"  "
    pause 600
     
    GOTO MAIN
    
    
    '=================================ADC0==========================================
    ADC0:
    ADCin 0, adcval
    pause 50
    
    RETURN            
    '==============================================================================
    
    END

    can you please help have a 0.1uf between the input and ground of AN0 the power supply is solid do not change.
    ground wire from PS to MCU and to analog input.
    anything I'm missing.
    tried to change
    DEFINE ADC_CLOCK 3 to 0 then 2 then 6 with no help.
    Last edited by Archangel; - 27th November 2013 at 19:13. Reason: code tags

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,599


    Did you find this post helpful? Yes | No

    Default Re: 18f4550 a/d

    I don't see many CONFIGs (the cause of many problems when migrating from 16F to 18F.

    Robert

  3. #3
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: 18f4550 a/d

    Clock speed, sample times, power rail noise, board layout - lots of potential issues. But do you even have an issue? The readings you describe have less than than 1% error, and likely only at the rails. If you really need to get better than that there are techniques for averaging and even for deriving further bits if you do a search on the forum. Microchip also has application notes on the subject.

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: 18f4550 a/d

    Question: I see you have set ALL of PortA to be inputs, are they ALL PROPERLY terminated to either VCC or VSS or are they left floating?
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  5. #5
    Join Date
    Feb 2010
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: 18f4550 a/d

    Hi all and thanks for the replies,

    Demon:
    The Config are saved in the .INC file and are as follow:
    CONFIG FOSC = HSPLL_HS, PLLDIV = 5 , CPUDIV = OSC1_PLL2
    CONFIG FCMEN = ON , PWRT = OFF, BOR = ON, VREGEN = ON , WDT = OFF,PBADEN = OFF ,MCLRE = ON
    CONFIG CCP2MX = OFF, LPT1OSC = OFF , LVP=OFF, ICPRT = OFF,STVREN = OFF , IESO = OFF

    Charlie:
    I'm using a 20mhz crystal with the about settings.
    sample time: DEFINE ADC_SAMPLEUS 50 I think that's 50us.
    The power supply: I'm using a high end with no noise and constant 5vdc.
    the board I'm using has a ground plane but I still soldered wires from the PS directly the MCU and the analog input.
    You are correct about the error % but those numbers are only at rails when I'm in middle it can jump 25 max(ie: from 350 to 325) but not always sometime it does stay consistant within 1 which i'll be happy with.I'll be reading a temp sensor so variation of 20 can results in a false temp reading or big variation.


    Archangel:
    Good catch I changed porta to output except AN0 to input. But did not help


    I added a 10uf 50v cap to the input seems to help a bit but still once in a while not all the time I get those unexpected drop or rise in value as much as 20.

    I've done similar with 16F887 that was dead on i had problems at first but added cap and ground wires and worked perfect.

    Now what i don't understand is the DEFINE OSC 48 in the 18F4450 is it too fast should i just run everything internal OSC(4mhz) and ADC clock internal(RC) would that help? I don't want to go through that until i ask you guys speed is not an issue here(probably I should've run it with internal clock to start with and save a crystal HAHAHAHAH).Or is it the TAd the sampling time the clock speed of the ADC(DEFINE ADC_CLOCK 3)

    Thank you all for your help.

    Happy Thanksgiving,

    Joe

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,599


    Did you find this post helpful? Yes | No

    Default Re: 18f4550 a/d

    I never used a serial LCD before. LCDOUT will use parallel on Port D the way you defined it.

    I always use the internal oscillators on 18F PICs, never had a problem.

    Don't have enough skill to comment on ADC stuff.

    Robert

  7. #7
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: 18f4550 a/d

    Quote Originally Posted by starwick View Post
    Now what i don't understand is the DEFINE OSC 48 . . .
    The thing to remember is this: The define explains to PBP what OSC speed you are using, it does not SET the OSC to that speed. It is supposed to match so your timing is correct for all the bit / bang operations to work properly, and pause timing to be accurate. It is possible to lie to PBP and compensate in code.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

Similar Threads

  1. 18f4550
    By ngeronikolos in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 21st June 2007, 19:03
  2. 18f4550 help, please
    By dalibor in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 10th June 2007, 21:55
  3. 18f4550
    By alaaodeh in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 22nd February 2007, 18:33
  4. 18f4550
    By vanxn in forum USB
    Replies: 2
    Last Post: - 27th June 2006, 20:40
  5. 18f4550
    By vanxn in forum USB
    Replies: 1
    Last Post: - 27th June 2006, 19:59

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