Scaling ADC Result to a Set Range


Closed Thread
Results 1 to 40 of 45

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,682


    Did you find this post helpful? Yes | No

    Default Re: Scaling ADC Result to a Set Range

    try
    HSEROUT ["ADCInVal=", DEC ADCInVal, " ", LCD_INST,LCD_L2, "MotorDuty=", DEC MotorDuty, " ",13,10]




  2. #2


    Did you find this post helpful? Yes | No

    Default Re: Scaling ADC Result to a Set Range

    I used the HSEROUT line exactly as above and when I turn on the power:

    Name:  IMG_3667.JPG
Views: 1297
Size:  109.9 KB

    Then, as I turn the trim pot wiper:

    Name:  IMG_3669.JPG
Views: 1299
Size:  113.4 KB

    The serial LCD is 2400 baud by default and that's what I have set in code, but maybe there's some timing issues?

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Scaling ADC Result to a Set Range

    If I'm using a PIC16F1825 how do I know whether to use the USART or EUSART settings from Mister E's PIC Multi-Calc application? This is what I have set currently:

    Code:
    DEFINE OSC 16               ; Set oscillator 16Mhz
    
    DEFINE HSER_TXSTA   20h     ; Set transmit status and control register
    DEFINE HSER_BAUD    2400    ; Set baud rate
    DEFINE HSER_CLROERR 1
    
    OSCCON    = %01111000       ; 16MHz internal osc
    
    PAUSE 100
    
    APFCON0.2 = 0               ; Tx on RC4 for LCD display
    APFCON0.7 = 0               ; Rx on RC5
    
    BAUDCON.4 = 1               ; Transmit inverted data to the Tx pin
    I see that Mister E's app doesn't use DEFINE HSER_BAUD. For USART I get:

    Code:
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
    DEFINE HSER_SPBRG 103 ' 2400 Baud @ 16MHz, 0.17%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    For EUSART:

    Code:
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    DEFINE HSER_SPBRG 130 ' 2400 Baud @ 16MHz, 0.0%
    SPBRGH = 6
    BAUDCON.3 = 1         ' Enable 16 bit baudrate generator
    Which should I use? And should I continue to use DEFINE HSER_BAUD which I think I got from this board a ling time ago?

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,682


    Did you find this post helpful? Yes | No

    Default Re: Scaling ADC Result to a Set Range

    either setting will work the 0% error eusart option is probably best ,
    if you set the baudrate regs manually ie
    DEFINE HSER_SPBRG 130 ' 2400 Baud @ 16MHz, 0.0%/SPBRGH = 6
    or
    DEFINE HSER_SPBRG 103 ' 2400 Baud @ 16MHz, 0.17%

    then DEFINE HSER_BAUD should not be used ,it may cause your setting to be overwritten

    ps
    baudrate error is not your display problem, you need to find out
    1. how to initialise your display and how long it takes to happen
    2. how to send control codes to the display ( seems $fe is not correct)

    do you have any docs for the display / or a model no ?

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: Scaling ADC Result to a Set Range

    I switched to using the EUSART DEFINEs & register settings (commenting out the original ones) and it seems better (no initial wonky characters) but the 2nd line still isn't going to the 2nd line. Maybe if I split out the instruction for the 2nd line with a 5 ms pause?

    Here's the data sheet for my serial LCD.

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: Scaling ADC Result to a Set Range

    From Data sheet
    Smart Linefeed (control-J, ASCII 10)
    Move cursor down one line. If immediately preceded by carriage return, linefeed is ignored

    Try it without the 13, see what happens. Or try it with only 13 (more likely)
    Failing that, if your message never changes, add spaces between " and MOTOR
    Last edited by Archangel; - 1st November 2015 at 01:50.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,682


    Did you find this post helpful? Yes | No

    Default Re: Scaling ADC Result to a Set Range

    none of these are correct
    #IFDEF USE_LCD_FOR_DEBUG
    LCD_INST CON 254 ' instruction
    LCD_CLR CON 1 ' Clear screen
    LCD_L1 CON 128 ' LCD line 1
    LCD_L2 CON 192 ' LCD line 2
    #ENDIF

    LCD_CLR CON 12 ' Clear screen
    LCD_HOME CON 1 ' HOME
    LCD_NEXT_LINE CON 13 ' CR does this go back to line 1 when current line is line2 ? seems it will go to first pos of line

    LINE 2
    WOULD BE HSEROUT [16,80] to be sure


    TRY
    HSEROUT [1,"ADCInVal=", DEC ADCInVal, " ", 13, "MotorDuty=", DEC MotorDuty, " "]
    or
    HSEROUT [1,"ADCInVal=", DEC ADCInVal, " ", 16,80, "MotorDuty=", DEC MotorDuty, " "]


    ps the display needs 1000ms delay to power on/boot before you try to write to it
    Last edited by richard; - 1st November 2015 at 02:34. Reason: ps and home display

  8. #8


    Did you find this post helpful? Yes | No

    Default Re: Scaling ADC Result to a Set Range

    Quote Originally Posted by richard View Post
    none of these are correct



    LCD_CLR CON 12 ' Clear screen
    LCD_HOME CON 1 ' HOME
    LCD_NEXT_LINE CON 13 ' CR does this go back to line 1 when current line is line2 ? seems it will go to first pos of line

    LINE 2
    WOULD BE HSEROUT [16,80] to be sure


    TRY
    HSEROUT [1,"ADCInVal=", DEC ADCInVal, " ", 13, "MotorDuty=", DEC MotorDuty, " "]
    or
    HSEROUT [1,"ADCInVal=", DEC ADCInVal, " ", 16,80, "MotorDuty=", DEC MotorDuty, " "]


    ps the display needs 1000ms delay to power on/boot before you try to write to it
    What makes you think they're not correct? The clear screen command has worked just fine all along. Nonetheless, I will try what you suggest.

Similar Threads

  1. Replies: 4
    Last Post: - 27th January 2015, 16:34
  2. Replies: 4
    Last Post: - 30th May 2012, 09:28
  3. Converting 10bit ADC result to 8 bit
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 5th March 2012, 21:38
  4. strange A2D 5V scaling result - 16F819
    By Max Power in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th April 2010, 03:28
  5. Scaling ADC values
    By purkolator in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 29th November 2007, 06:14

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