• AVR Freaks

Hot!Trying to use LCD with UART in DMX Mode

Author
PRWiley
New Member
  • Total Posts : 22
  • Reward points : 0
  • Joined: 2019/07/04 06:16:51
  • Location: Lewisburg PA USA
  • Status: offline
2019/07/22 10:51:53 (permalink)
0

Trying to use LCD with UART in DMX Mode

I am experimenting with an 18F45K42 using the UART DMX mode on a Curiosity HPC board.  I have a standard 2x16 LCD connected.
 
Currently I have UART1 set at 250000 baud as required for DMX. The internal oscillator HFINTOSC is set at 64MHz. The clock divider is set at 1. With these settings the LCD does not display anything in response to commands or input.
 
If I lower the internal oscillator frequency, the LCD does receive commands and display properly. It works with the oscillator set as high as 16MHz.
 
The problem is that any oscillator setting less than 64MHz breaks the DMX functionality. I can see on my scope that a DMX signal is still being transmitted, but the DMX lighting fixture I am using to test does not respond to it. It looks like this is because the timing of the signal is altered.
 
I'd like to have the LCD and the DMX work at the same time. I presume I have three possible fixes:
 
1) Change the value of U1BRG in the UART setup to produce the 250000 baud rate at 16MHz,
2) Alter the LCD code to work at the higher frequency,
3) Some combination of 1 & 2.
 
I am new to PIC micro controllers and at my present level of understanding, I'm not sure I can even ask the questions needed to attack this issue. Can someone kindly point me in the right direction? 
 
This is how the UART is initialized:

//UART module settings

U1CON0bits.MODE = 0b1010; //Select DMX mode

U1CON0bits.TXEN = 1; //Enable transmitter

U1CON0bits.RXEN = 0; //Disable receiver

U1CON2bits.TXPOL = 0; //Standard polarity, TX pin will idle high

U1CON2bits.STP = 0b10; //2 stop bits

 

//DMX data packet settings

U1P1 = 512-1; //Total number of data bytes - 1

U1P2 = 0x00; //Not used in DMX controller

U1P3 = 0x00; //Not used in DMX controller

 

// Baud rate generator settings

U1CON0bits.U1BRGS = 1; //High speed baud generation

U1BRG = 0x3F; //Value for U1BRG for Fosc = 64MHz

 

U1ERRIEbits.TXMTIE = 1;

 

//PPS settings for TX functionality on pin RC6

ANSELCbits.ANSELC6 = 0; //Make RC6 a digital I/O

TRISCbits.TRISC6 = 0; //Make RC6 an output

RC6PPS = 0b010011; //Assign TX functionality to RC6

U1ON = 0x01; //Turn on UART module



Peter R. Wiley
I feel a lot more like I do now than I did when I came in.
#1

8 Replies Related Threads

    ric
    Super Member
    • Total Posts : 24582
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Trying to use LCD with UART in DMX Mode 2019/07/22 13:14:49 (permalink)
    0
    Better to show your USART read and write code too.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11423
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: Trying to use LCD with UART in DMX Mode 2019/07/22 13:34:15 (permalink)
    0
    Are you including the required delays between LCD commands?  Are you using the compiler's delay functions?  Have you set _XTAL_FREQ correctly?
    #3
    Jerry Messina
    Super Member
    • Total Posts : 445
    • Reward points : 0
    • Joined: 2003/11/07 12:35:12
    • Status: offline
    Re: Trying to use LCD with UART in DMX Mode 2019/07/22 16:30:33 (permalink)
    0
    The problem is that any oscillator setting less than 64MHz breaks the DMX functionality

    While you figure out how to get the LCD working with Fosc = 64MHz, if you change U1BRG = 15 that should get you 250K baud with Fosc=16MHz and your other settings.
    #4
    PRWiley
    New Member
    • Total Posts : 22
    • Reward points : 0
    • Joined: 2019/07/04 06:16:51
    • Location: Lewisburg PA USA
    • Status: offline
    Re: Trying to use LCD with UART in DMX Mode 2019/07/23 07:10:44 (permalink)
    0
    @Jerry
     
    Winner, winner, chicken dinner. Changing U1BRG to 15 allows the LCD to display and the DMX to work. You can see from the scope traces that the timing is spot on at 16MHz compared with 64MHz (one has more noise because my probe was not properly grounded).
     
    Did you calculate U1BRG or look it up? If you calculated, what formula did you use? I tried the one in data sheet and somehow did not end up with an answer of 15.
     
    Many thanks.
    post edited by PRWiley - 2019/07/23 07:12:29

    Attached Image(s)


    Peter R. Wiley
    I feel a lot more like I do now than I did when I came in.
    #5
    mbrowning
    USNA79
    • Total Posts : 1564
    • Reward points : 0
    • Joined: 2005/03/16 14:32:56
    • Location: Melbourne, FL
    • Status: offline
    Re: Trying to use LCD with UART in DMX Mode 2019/07/23 08:09:05 (permalink)
    0
    Did you calculate U1BRG or look it up?
    Sorry, but really?
     
    Pretty simple calculation. Divide Fosc by 4 (64->16MHz), divide (BRG+1) by 4. So (63+1)/4 = (15+1).

    Go Navy! Beat Army!
    #6
    Jerry Messina
    Super Member
    • Total Posts : 445
    • Reward points : 0
    • Joined: 2003/11/07 12:35:12
    • Status: offline
    Re: Trying to use LCD with UART in DMX Mode 2019/07/23 08:18:54 (permalink)
    0
    As above. See table 31-1.
     
    Did you remember to account for your BRGS=1 setting?
     
    #7
    PRWiley
    New Member
    • Total Posts : 22
    • Reward points : 0
    • Joined: 2019/07/04 06:16:51
    • Location: Lewisburg PA USA
    • Status: offline
    Re: Trying to use LCD with UART in DMX Mode 2019/07/23 08:51:15 (permalink)
    0
    Yeah, really. I am completely new at this so . . .
     
    I look at the Internal Oscillator settings in the MCC and I see "Current System Clock 16MHz" which I assume is the Fosc to use, so I get the wrong answer.  What I find no mention anywhere, certainly not in the data sheet, is that one has to use 64MHz, not 16MHz to calculate the proper value. Once one knows that, then indeed the calculation is trivial.
     
    Everything is easy when one already knows how things work and what assumptions to make. 

    Peter R. Wiley
    I feel a lot more like I do now than I did when I came in.
    #8
    mbrowning
    USNA79
    • Total Posts : 1564
    • Reward points : 0
    • Joined: 2005/03/16 14:32:56
    • Location: Melbourne, FL
    • Status: offline
    Re: Trying to use LCD with UART in DMX Mode 2019/07/23 10:22:28 (permalink)
    0
    Current System clock is the same as Fosc. You must have used the wrong formula - the one for "Normal Rate" - to get the right answer using the wrong Fosc. With BRGS = 1, you use the High Rate formula.
     
     

    Go Navy! Beat Army!
    #9
    Jump to:
    © 2019 APG vNext Commercial Version 4.5