Question on include files and problem with serial LCD/USB program


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: Question on include files and problem with serial LCD/USB program

    Not sure if this means anything but if I don't define the oscillator "DEFINE OSC 20" and then I adjust the osc setting from HS to HSPLL the serout commands can stay in the program and the USB portion works. The only problem is now my LCD screen has garbage on it because the PIC isn't sending data at the right speed.

    Correct me if I'm wrong but doesn't that mean that the PIC is working faster than it should because the OSC isn't defined. If so, is there a way to find the speed and adjust my LCD screen to match? Perhaps in the final design I should use a faster oscillator too.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Question on include files and problem with serial LCD/USB program

    Hi,
    Well, the manual says at least every 10ms... I wouldn't have expected 2ms either but if that what it takes then that is what it takes. I'm pretty sure THAT part has nothing to do with PBP really, it's just what's needed to have USB working.

    As previosuly discussed the amount of time that your SEROUT2 statement takes at a certain baudrate depends on the amount of data. If RPM is 0-9 then you're sendning 3 bytes, if it's 10-99 you're sending 4 bytes, if it's 100-999 you're sedning 5 bytes and so on.

    When you DEFINE OSC 20 (and asuming RPM needs 3 bytes) your SEROUT2 PORTD.3, $4054,[16,85,DEC RPM] statement will take 60/9600=6.25ms (+some for processing). If you RUN the PIC at 20MHz but doesn't tell the compiler that you are the compiler thinks it's running at 4MHz and calculates all the internal timing based on that. At 4MHz each cycles is 1us but at 20MHz each cycle is 200ns, the PIC is executing code 5 times faster then the compiler expected, your SEROUT2 statement is not sending at 9600baud, it's sending at 48000baud (or trying to, I don't think it'll actually work). So what previosuly took 6.25ms now only takes 1.25ms - which puts you inside the window for USBERVICE timeout.

    Since you are running at 20MHz it's likely that SEROUT2 will work at 19200 or even 38400. At 38400 you're down to ~1.6ms for the above. You will need to check the documentation for your serial LCD if there's a way to change the buadrate. I'd expect some jumpers or dipswitches or perhaps it's software controlled. Do you have a link?

    /Henrik.

  3. #3
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: Question on include files and problem with serial LCD/USB program

    Quote Originally Posted by HenrikOlsson View Post

    Since you are running at 20MHz it's likely that SEROUT2 will work at 19200 or even 38400. At 38400 you're down to ~1.6ms for the above. You will need to check the documentation for your serial LCD if there's a way to change the buadrate. I'd expect some jumpers or dipswitches or perhaps it's software controlled. Do you have a link?

    /Henrik.
    According to the datasheet, I can only use 9600 or 2400 baud. I bought a graphic LCD that will be here today but haven't looked at the documentation yet. The current screen I have is:

    http://www.seetron.com/bpp420.html

    The one I just bought is:

    http://www.seetron.com/sgx120.html

    Thanks again for the advice.

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Question on include files and problem with serial LCD/USB program

    Hi,
    If you can't set the LCD to accept data at a faster rate then there's not much else to do than try to split the messages up. Perhaps you could do somethine like
    Code:
    Message VAR BYTE[20]
    i VAR BYTE
    
    ArrayWrite Message, [16, 85, DEC RPM, 0]
    USBSERVICE
    GOSUB SendIt
    
    SendIt:
      i = 0
      While Message[i] <> 0
        USBSERVICE
        SEROUT2 Portd.3, $4054, Message[i]
        i = i + 1
      WEND
    RETURN
    That graphic LCD is also 9600baud max and my guess it needs even more data to be sent than the basic alphanumeric one so I wouldn't expect that to solve anything.

    EDIT: Ooops, still 2.50...time for an upgrade perhaps? Since you learned to love using INLCUDE to structure your code you're going to like the conditional compilation features available in PBP3.
    Last edited by HenrikOlsson; - 10th August 2012 at 12:05.

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