MikroE clicker, 18f47J53, serout 2 to serial LCD issues


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2005
    Location
    brookfield, ct, usa
    Posts
    24

    Default MikroE clicker, 18f47J53, serout 2 to serial LCD issues

    Hello all
    What I suspect is a simple problem is driving me nuts.
    I got a MikroE clicker1 board, it has a 18F47J53 PIC on it. Doesn't have enough output pins in one port for an LCD so I'm using a serial LCD. The serial LCD is 5 volts, the board is 3.3 so I'm using a level shifter. I'm using the PBP3 default/automatic PIC configuration although I've tried putting the configuration file in the program. My first step with any new pic is usually to send a message to a display, flash a few leds, read an ADC channel and send the value to a display. However, the display is reading garbage. The text string is being ignored although the display clears, and then I'm getting repeated characters that bear no relation to the ADC output. I tried the identical serout2 commands on my easypic 7 with a 18F45K22 at 3.3 volts hooked to the level shifter and it works like a charm so it isn't code I don't think. Any suggestions/thoughts would be appreciated.
    Alec
    '************************************************* ***************
    '* Name : MikroE clicker1.pbp *
    '* Author : Alec Noble *
    '* Notice : Copyright (c) 2016 Alec Noble *
    '* : All Rights Reserved *
    '* Date : 7/11/2016 *
    '* Version : 1.0 *
    '* Notes : pic 18F47J53 *
    '* : *
    '************************************************* ***************

    DEFINE OSC 16


    '------------------setup ADC channels----------------------

    ADCON1 = %10001011 'Tad = 2, Frc osc
    ANCON0 = %11111111 'AN0 - 7 digital
    ANCON1 = %00010111 'VBGEN disable, AN11 analog, all others digital

    '----------------setup serial LCD-----------------------
    txpin var portc.0
    mode con 84 '9600 baud 8N1 true
    clr con 12
    lcdon con 17
    first_line con 128

    LED1 var portA.0
    LED2 var portA.1

    'make it high to start
    '----------------set port directions---------------------
    TRISA = %11111100 'RA0, RA1 outputs, all others inputs
    TRISC = %11111100 'RC0, 1 output, others all inputs

    '--------------------------------------------------------------
    adc_result var word

    high txpin 'make txpin high to start

    pause 1000 'let LCD wake up

    serout2 txpin, mode, [lcdon]
    pause 50
    serout2 txpin, mode, [clr]
    pause 50
    serout2 txpin, mode, [first_line, "hello world"]

    pause 5000

    serout2 txpin, mode, [clr]
    pause 50

    LED1 = 1
    LED2 = 0

    main:
    'high txpin
    toggle LED1
    toggle LED2
    adcin 11, adc_result

    serout2 txpin, mode, [first_line, dec4 adc_result]
    pause 500
    goto main

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


    Did you find this post helpful? Yes | No

    Default Re: MikroE clicker, 18f47J53, serout 2 to serial LCD issues

    Hi,
    How are you programming the PIC? Are you using the MikroE USB bootloader that comes pre-installed or are you using an actual device programmer?
    If you're using the bootloader then the CONFIG bits won't be written (I Think) and the chip will use whatever CONFIG was written to it when the bootloader was programmed into it.

    What I'm trying to say is that the chip may not actually run at the speed you're telling the compiler (16MHz) but something else (and therefore the baudrate is wrong) depending on how the CONFIG bits are set and even though you include them in your code there's a chanse they're not written to the chip by the bootloader - but I don't know that for sure in the case of the MikroE USB bootloader. If you ARE using the bootloader then try to DEFINE OSC 48 instead.

    If you're using an actual device programmer to program the chip then the default PBP CONFIG has the PLL enabled with a divide ratio of 5 which is suitable for a 20MHz x-tal. The board has a 16MHz x-tal so you need a divide ratio of 4 instead and then also DEFINE OSC 48 instead of 16 - OR change the oscillator type to normal HS instead of HSPLL.

    /Henrik.

  3. #3
    Join Date
    Feb 2005
    Location
    brookfield, ct, usa
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Re: MikroE clicker, 18f47J53, serout 2 to serial LCD issues

    Thanks Henrik
    The default config file has the PLL disabled. I did get it running on the internal oscillator, so yes, its a configuration issue. More time with the datasheet I guess...

  4. #4
    Join Date
    Feb 2005
    Location
    brookfield, ct, usa
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Re: MikroE clicker, 18f47J53, serout 2 to serial LCD issues

    And yes, I'm using the bootloader.

    Thanks much - I'll keep reading the datasheet, see what I'm missing.

    Take care

    Alec

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: MikroE clicker, 18f47J53, serout 2 to serial LCD issues

    Hi,
    If you're using the MikroE USB bootloader then the device is running at 48MHz, not 16MHz so you need to change your DEFINE OSC 16 to DEFINE OSC 48 - try it!

    And here's the default PBP configuration from my PBP3 installation:
    Code:
    ;  The PBP default configuration for the PIC18F47J53 is:
    ;
    ;  #CONFIG
    ;    CONFIG  WDTEN = ON            ; Enabled
    ;    CONFIG  PLLDIV = 5            ; Divide by 5 (20 MHz oscillator input)
    ;    CONFIG  CFGPLLEN = OFF        ; PLL Disabled
    ;    CONFIG  STVREN = ON           ; Enabled
    ;    CONFIG  XINST = OFF           ; Disabled
    ;    CONFIG  CPUDIV = OSC1         ; No CPU system clock divide
    ;    CONFIG  CP0 = OFF             ; Program memory is not code-protected
    ;    CONFIG  OSC = HSPLL           ; HS+PLL, USB-HS+PLL
    ;    CONFIG  SOSCSEL = HIGH        ; High Power T1OSC/SOSC circuit selected
    ;    CONFIG  CLKOEC = ON           ; CLKO output enabled on the RA6 pin
    ;    CONFIG  FCMEN = OFF           ; Disabled
    ;    CONFIG  IESO = OFF            ; Disabled
    ;    CONFIG  WDTPS = 512           ; 1:512
    ;    CONFIG  DSWDTOSC = INTOSCREF  ; DSWDT uses INTRC
    ;    CONFIG  RTCOSC = T1OSCREF     ; RTCC uses T1OSC/T1CKI
    ;    CONFIG  DSBOREN = ON          ; Enabled
    ;    CONFIG  DSWDTEN = ON          ; Enabled
    ;    CONFIG  DSWDTPS = G2          ; 1:2,147,483,648 (25.7 days)
    ;    CONFIG  IOL1WAY = ON          ; The IOLOCK bit (PPSCON<0>) can be set once
    ;    CONFIG  ADCSEL = BIT12        ; 12 - Bit ADC Enabled
    ;    CONFIG  MSSP7B_EN = MSK7      ; 7 Bit address masking mode
    ;    CONFIG  WPFP = PAGE_0         ; Write Protect Program Flash Page 0
    ;    CONFIG  WPCFG = OFF           ; Configuration Words page not erase/write-protected
    ;    CONFIG  WPDIS = OFF           ; WPFP<6:0>/WPEND region ignored
    ;    CONFIG  WPEND = PAGE_WPFP     ; Pages WPFP<6:0> through Configuration Words erase/write protected
    ;    CONFIG  LS48MHZ = SYS24X4     ; System clock at 24 MHz USB CLKEN divide-by is set to 4
    ;  #ENDCONFIG
    Look at the lines in bold. The PLL is enabled with a division ratio of 5. The MicroE Clicker board has a 16MHz x-tal which will result in an input frequency to the PLL of 16/5=3.2MHz where it expects to get 4MHz, the output will be 38.4MHz instead of the expected 48MHz. So even if the bootloader DOES write the CONFIG bits using the PBP default ones for that board doesn't work.

    /Henrik.

  6. #6
    Join Date
    Feb 2005
    Location
    brookfield, ct, usa
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Re: MikroE clicker, 18f47J53, serout 2 to serial LCD issues

    OK Henrik - you were right. I changed PLLDIV to 4, and set OSC = 48, and it works.

    But now I have to ask why it didn't work when I tried OSC = HS

    ; CONFIG CFGPLLEN = OFF ; PLL Disabled - doesn't this mean PLL is turned off?

    Thanks for your help - as usual more to learn.

    Thanks again

    Alec

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: MikroE clicker, 18f47J53, serout 2 to serial LCD issues

    Hi,
    OK, I'll try this again:
    When you're using the MikroE USB HID bootloader the CONFIG bits aren't written to device since doing so can make the bootloader it self stop working, basically bricking the board. The bootloader code (and the actual USB hardware in the PIC) relies on the fact that the PIC is running at 48MHz. IF the bootloader allowed itself to change the CONFIG it would sort of allow itself to commit suicide and you'd need to reload the bootloader into the chip using a normal device programmer. I'm 99.9% sure this is the case with the MikroE USB Bootloader as well.

    This means that you changing to OSC = HS or trying to change the PLLDIV doesn't actually do anything to the operation of the device. It is and always has been running at 48MHz. I only said that IF the config bits where updated the default PBP config, with PLLDIV=5 isn't correct when using a 16MHz x-tal. But for that change to actually end up in the chip you'd need to use an actual device programmer.

    I'm pretty sure that the sole thing that made it work in your case was specifying the correct oscillator frequency to the compiler, ie DEFINE OSC 48.

    CONFIG CFGPLLEN = OFF ; PLL Disabled - doesn't this mean PLL is turned off?
    Yes, you're quite right. It means that the PLL is off by default but that it CAN - (because OSC = HSPLL) - be turned ON at runtime by setting OSCTUNE.6
    If CFGPLLEN = ON then the PLL is permanently on and can not be turned off by software.

    Does that make any sort of sense?

    /Henrik.

  8. #8
    Join Date
    Feb 2005
    Location
    brookfield, ct, usa
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Re: MikroE clicker, 18f47J53, serout 2 to serial LCD issues

    Thanks Henrik, now it makes sense. When I got it to operate correctly under the internal oscillator, by setting the correct values for the OSCCON register, telling it to use the 8 mhz internal clock, it works because software changed the clock source, and not from setting the configuration files which the bootloader ignores to make sure that the configuration needed for the bootloader never changes.

    Thanks again

    Alec

Similar Threads

  1. 18F47J53 ADCON Setting
    By gavo in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 28th August 2014, 14:06
  2. StartUSB board from MikroE
    By Fredrick in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 2nd June 2014, 06:37
  3. Random Serin/Serout issues
    By Szczepaniec in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th May 2011, 03:11
  4. Parallax Serial LCD and issues
    By nbrucew in forum mel PIC BASIC
    Replies: 5
    Last Post: - 18th September 2009, 04:42
  5. Serout/serin issues, advice required
    By Agent36 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 29th May 2008, 22:51

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