Help with 18F2520


Closed Thread
Results 1 to 15 of 15
  1. #1
    BertMan's Avatar
    BertMan Guest

    Default Help with 18F2520

    Okay, I havent been pic programming that long, but I have been able to write simple programs with my 16f628A that would output data to the serial port of a computer from a pressure sensor and a maxim ADC. I have been working on firmware to for a Vector compass module using a pic and the code comes out to be around 15k, so I had to upgrade to a larger pic. I chose the 18f2520 with 16k.

    Anyways, the problem I am having is I can get this pic to communicate to a uart host (serial port on a computer). I scraped the 15k of code and just came up with some test code that would output a simple text string over and over, and check the results in hyperterminal. Same thing. Just a bunch of characters on the screen that look like $. I know that the pic is making an effert to communicate, but something is slightly off like timing.

    Here is my setup:
    18f2520 with connections only to power, ground and the asyncronous output. My config bits are setup to use the internal oscillator at 8mhz, and MCLR disabled. I have defined debug to use 9600, and setup hyperterminal to use the same. My code looks something like this:

    define DEBUG_REG PORTA
    define DEBUG_BIT 1
    define DEBUG_BAUD 9600
    define DEBUG_MODE 1
    define DEBUG_PACING 1000
    define OSC = 8

    :Main
    Debug "The program is working"
    Goto Main

    Any suggestions?

  2. #2


    Did you find this post helpful? Yes | No

    Default

    You probably need to configure the A/D on PORTA.1 to a digital instead of analog.

  3. #3
    BertMan's Avatar
    BertMan Guest


    Did you find this post helpful? Yes | No

    Default

    From the datasheet:

    Pin Name: Pin Type: BufferType: Description:
    RA1 I/O TTL Digital I/O
    AN1 I Analog Analog

    Praytell kind sir, how'st thou'st do'st that?

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    datasheet, a/d converter section ADCON, ANSEL, CMCON etc etc
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Code:
        ADCON0 = %00000000          ' Turn off A/D converter
        ADCON1 = %00001110          ' Make PORTA.0 & PORTA.1 analog, others digital
    I believe this will do it. If I'm incorrect someone please let me know.

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    No or partially... you forget the internal comparator, but Ra1 will be digital in deed if the comparator is turn off... not AN0

    CMCON and ADCON1 only to disable all analog stuff, use ADCON0 only if you want to play really safe.

    Not much... you'll discover everything in the... datasheet. it's free to download and really usefull
    http://ww1.microchip.com/downloads/e...Doc/39631a.pdf
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    BertMan's Avatar
    BertMan Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks for the replies. I didnt have to do this with the 628A, so I just expected it to work on the 18f2520 (which is 32k code not 16k..oops). I have been reading the datasheet for a week now and it has info on ADCON, ANSEL, CMCON, etc, but not how and where to use it. Nothing in the Picbasic help about it either.

    So to change these registers, I need to identify them and add them to the top of my pic basic code like TRIS? Can I do this with any register I want to alter? Or is there only a few that Picbasic recognizes?

  8. #8


    Did you find this post helpful? Yes | No

    Default

    I believe PBP will allow you to change virtually any register that is applicable for the MCU you've chosen.

  9. #9
    BertMan's Avatar
    BertMan Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks for all your help Cokehead and Mr E! I will give this a try this evening and let you know what happens.

  10. #10
    BertMan's Avatar
    BertMan Guest


    Did you find this post helpful? Yes | No

    Default

    Hmm... Same thing. I put this at the top: ADCON1 = %00001111
    CMCON = %00000111 and same character over and over. Could it be possible that I need to use a line driver?

  11. #11
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    <bgsound src="http://www.darreltaylor.com/files/woohoo2.wav" loop="false">BertMan,

    It may have just been a typo, but in your first post you had this line ...

    define OSC = 8

    It shouldn't have an equal sign in there, and PBP won't complain if it's wrong. But it may be thinking it's running at a different frequency.
    <br>
    Last edited by Darrel Taylor; - 7th October 2005 at 03:40.
    DT

  12. #12
    BertMan's Avatar
    BertMan Guest


    Did you find this post helpful? Yes | No

    Default

    Just for grins I adjusted the baud rate in hyperterminal to see if I could get any different results, and found something very interesting. At 300 baud it works! I set the baud rate to 2400 as it is defined in pbp, and nothing.

  13. #13
    BertMan's Avatar
    BertMan Guest


    Did you find this post helpful? Yes | No

    Smile

    Thanks Darrel, it was a typo.

  14. #14


    Did you find this post helpful? Yes | No

    Default

    One more thing, use uppercase for your DEFINE statements.

  15. #15
    BertMan's Avatar
    BertMan Guest


    Did you find this post helpful? Yes | No

    Default

    Figured it out! The 4x clock multiplier is enabled by default. This means I was running at 32mhz instead of 8mhz. Had to set both of these to get the oscillator to perform the way I needed it to:

    OSCTUNE = %00000000
    OSCCON = %11110000

    This would explain running at 300baud when I selected 2400.

Similar Threads

  1. 18F2520 clock speed ?
    By Gixxer in forum mel PIC BASIC Pro
    Replies: 24
    Last Post: - 21st August 2008, 19:01
  2. who knows how to let LCD03 work with 18F2520?
    By Janine in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 23rd May 2008, 14:24
  3. 18f2520 - Option_reg
    By mpardinho in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 14th April 2008, 17:06
  4. A/D conversion problem in 18F2520, 2523, 2550 etc.
    By selimkara in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 10th March 2008, 16:26
  5. Writecode With 18f2520
    By TomM in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 30th March 2006, 18: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