1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Pic18f4550 adc

Discussion in 'Microcontrollers' started by adrianvon, Jan 11, 2012.

  1. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,185
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi,
    Downloaded OK, will post when ready.

    EDIT:
    Still looking thru it.
    Noticed that you are using the REF Reg in the ADC delay.
    ACQ_DELAY
    movlw REF
    movwf REG1


    This the REF Reg that you are also using for the Inc/Dec push button counter.??
     
    Last edited: Jan 15, 2012
  2. adrianvon

    adrianvon Member

    Joined:
    Jan 22, 2011
    Messages:
    322
    Likes:
    2
    Thanks for the correction.

    I changed the delay coding as below:

    Code (text):
    ACQ_DELAY
    MOVLW .30
    MOVWF REG1
    ACQ1
    DECFSZ REG1
    BRA ACQ1
    RETURN 
    ...but unfortunately the problem is still there.
     
  3. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,185
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi,
    This now works, its very difficult to relate whats on the ADC Vinp and the PORTD display.

    The main problems were, sharing Reg REF with inc/dec and the ADC delay.

    Kept the REF for the adc delay and created REGF that holds the inc/dec compare value.

    You were also loading 'movlw REGF' instead of 'movf REGF, W.

    Lets know how it runs..
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. adrianvon

    adrianvon Member

    Joined:
    Jan 22, 2011
    Messages:
    322
    Likes:
    2

    OHH finally it worked :D the problem was with the movlw instruction. When i changed it to movf, as you said, it worked.

    Thank you so much for your help ericgibbs, really appreciate it :)
     
  6. adrianvon

    adrianvon Member

    Joined:
    Jan 22, 2011
    Messages:
    322
    Likes:
    2
    Hi,
    The ADC is missing codes (from 50 its jumping to 64). What can be causing this please? by the way, the ref voltages of the ADC are set from 0.5V to 4.5V.

    And another question. I want to display the respective temperature to an LCD display. Is it difficult to do that in assembly? do i have to refer to every binary value as a character? OR is it better to chance to C language for this part of the program?

    Thanks in advance
     
  7. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,185
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi,
    Are you saying as you increase the adc input voltage that the PORTD value is jumping from 50d to 64d,, as you decrease the input does it jump from 64d to 50d.??

    Ref the LCD what type is it, how many lines etc.

    You do have to convert the hex value of the ADC to ASCII in order to display in decimal.

    EDIT:
    Using Oshonsoft I have stepped thru all the combinations from 0 to 127 and I see no jumping of the codes up or down, the problem is elsewhere, have you changed the code, if so please post it.
     
    Last edited: Jan 18, 2012
  8. adrianvon

    adrianvon Member

    Joined:
    Jan 22, 2011
    Messages:
    322
    Likes:
    2
    Hi,

    Thanks for your reply.

    Yes

    Im not sure about this, but i will check that.

    But were the ADC (of the pic) set to 0.5V to 4.5V ? because i notice that when the -Vref was set to 0v it worked fine, but for my project i want to set -Vref to 0.5V. By the way, the coding was not changed.
    I think this is a common problem as i found it on google. The problem is that i cannot clearly understand what can cause this:
    http://www.google.com.mt/search?hl=...urce=og&sa=N&tab=wi&ei=vs8WT_SIHtGN4gSb_pSZBA

    The LCD to be used is the one below:
    http://www.ebay.co.uk/itm/16x4-1604...947?pt=LH_DefaultDomain_0&hash=item27c1d227ab

    I think to display temperature using asm would be a long and difficult task, am i right?

    Thanks
     
    Last edited: Jan 18, 2012
  9. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,185
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi,
    The LCD is a standard type, not too difficult to program in asm or C.

    Are you going to use a 4 or 8 wire Data connection to the LCD and/or use the R/W line on the LCD.?

    I will try the -0.5Vref and +4.5Vref
     
  10. adrianvon

    adrianvon Member

    Joined:
    Jan 22, 2011
    Messages:
    322
    Likes:
    2
    Hi,

    The LCD will be used in 4bit mode.

    Thanks for that
     
    Last edited: Jan 18, 2012
  11. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,185
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi,
    Checked the ADC with those Vrefs, no problems see in Oshonsoft simulation, could be a PIC hardware problem.??
     
  12. adrianvon

    adrianvon Member

    Joined:
    Jan 22, 2011
    Messages:
    322
    Likes:
    2
    Could be. I will replace the PIC with another one and see if it works.
     
  13. adrianvon

    adrianvon Member

    Joined:
    Jan 22, 2011
    Messages:
    322
    Likes:
    2
    Hi, i replaced the pic and its still the same, but when i set the ref voltage was set from 0V to 5V it works fine. Can the left justified (to set it to 7 bit) affect it?
     
  14. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,185
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi,
    I you could try to right justify the ADC and then right shift ADRSH and ADRESL say 3 times, then AND ADRESL with 01111111, that may avoid the jump problem
     
  15. adrianvon

    adrianvon Member

    Joined:
    Jan 22, 2011
    Messages:
    322
    Likes:
    2
    OK the circuit is working fine if i set the ref voltage from 0 to 5v. Another problem solved :) now the next task: displaying the temperature on the LCD.

    Thanks
     
  16. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,185
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi,
    Let us know which PORT and which pins are connected to the LCD, we could post code fragments to get you started.

    You could look at links near my signature on this post, I know they are 16F, but they cover the LCD programming.

    BTW: did reading the ADRESH and ADRESL and shifting, fix the missing ADC codes.???
     
    Last edited: Jan 19, 2012
  17. adrianvon

    adrianvon Member

    Joined:
    Jan 22, 2011
    Messages:
    322
    Likes:
    2
    Hi ericgibbs,

    The LCD will be connected as below:

    Pin 1: GND
    Pin 2: Vdd
    Pin 3: Pot
    Pin 4: RE0
    Pin 5: RE1
    Pin 6: RE2
    Pin 7: NC
    Pin 8: NC
    Pin 9: NC
    Pin 10: NC
    Pin 11: RD4
    Pin 12: RD5
    Pin 13: RD6
    Pin 14: RD7
    Pin 15: BACK-LIGHT (5V)


    I haven't tried that, but with Vref set from 0V to 5V it worked fine.

    Thanks for your help.
     
  18. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,185
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ok,
    Did you look at this link.?
    You could look at links near my signature on this post, I know they are 16F, but they cover the LCD programming.

    There are examples for 4bit LCD
     
  19. adrianvon

    adrianvon Member

    Joined:
    Jan 22, 2011
    Messages:
    322
    Likes:
    2
    Yes i did, but they are in C. If its not that difficult, i would like to do it in asm.

    Thanks
     
  20. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,185
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi,
    They are not in C.
    http://www.winpicprog.co.uk/pic_tutorial3.htm originals in ASM

    The rewrites are in C.
    E.
     
  21. adrianvon

    adrianvon Member

    Joined:
    Jan 22, 2011
    Messages:
    322
    Likes:
    2
    Sorry, i missed that URL. Thanks for that.
     

Share This Page