PIC18F4620 , what's wrong with my A/D converter code


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2009
    Posts
    2

    Default PIC18F4620 , what's wrong with my A/D converter code

    Hello everyone, I'm new to this forum.
    My project is due in 1 week and I can't figure out why my code doesn't work. I'm doing an analog to digital conversion from the port AN0 and I must send it via the USART. The rate of transfer must be 19200. When I program it in the microcontroller it doesn't send anything through the serial port. PLS HELP !!! Thank you 

    list p=18f4620 ; type
    include <P18f4620.INC>
    org 20h

    Initialisation
    movlw B'11101111'; RC6 and 7 must be set to 1(it's in the datasheet)
    movwf TRISC

    movlw 0x02; 0x02 =19200 bps (calculated for 4mhz clock, it’s in the datasheet)
    movwf SPBRG ; register for setting the transfer rate

    movlw B'00100100' ;
    movwf TXSTA; activate asynch transmition
    movlw B'10000000'
    movwf RCSTA ; activate serial port for receiving (i dont know if this is necessary


    movlw B'00000001'
    movwf ADCON0 ; AN0 selected, idle state, A/D enabled

    movlw B'00000000' ; VDD and VSS set as references
    movwf ADCON1 ;

    movlw B'00001000' ; small endian(only interested in ADRESH), aquisition time 2AD, aquisition clock FOSC/2 (This might be the problem)
    movwf ADCON2

    Main
    call conversion
    goto Main

    conversion
    bsf ADCON0,GO; starts the conversoin
    Wait
    btfsc ADCON0,GO; waits for the conversion to end
    goto Wait

    movf ADRESH,W ; moves the 8 most significant bits in W
    movwf TXREG ; W to TXREG, serial transmition register

    Transmisiune
    btfss TXSTA,TRMT; it TRMT is 1 the transmision is done
    goto Transmisiune
    return

    end

  2. #2
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Talking

    Hello Porcusoru,

    It looks like your code is suffering from a general lack of PicBasic commands. I personally, would throw a lot of the picbasic commands in, and take most of the assembly out. For instance, debug, serout or serout2 should solve the serial problem, and ADCIN pretty much would solve the rest. But your professor may have other ideas.
    Last edited by ScaleRobotics; - 2nd July 2009 at 17:57.
    http://www.scalerobotics.com

  3. #3
    Join Date
    Jul 2009
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Thanks

    U were kind of right. I addes this lines and now the b*tch works just fine

    CONFIG WDT=OFF; disable watchdog timer
    CONFIG MCLRE=ON;
    CONFIG DEBUG=ON;
    CONFIG LVP = OFF; Low-Voltage programming disabled (necessary for debugging)
    CONFIG OSC = INTIO67; (INTO67 was NOT in the 400 page datasheet, i found it somewhere else)

Similar Threads

  1. DC volts and A/D converter
    By michel in forum Schematics
    Replies: 3
    Last Post: - 17th September 2008, 11:44
  2. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  3. A/D converter with pic16f84, i need a help
    By micro in forum General
    Replies: 0
    Last Post: - 13th December 2005, 21:17
  4. HDD IDE ATA 2 interface problems. code wrong?
    By rastan in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 27th March 2005, 16:01
  5. Need help, high speed D/A converter, see code
    By rpatel in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 20th December 2004, 01:33

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