I知 having a problem with getting the correct remainder using // remainder.


Closed Thread
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Mar 2016
    Posts
    2

    Default I知 having a problem with getting the correct remainder using // remainder.


    I知 having a problem with getting the correct remainder using // remainder.

    I have a 10K res connected to the power rail using the centre pot connected to AN2 of a 16F690.

    With the pot at VDD I get a reading of 1023 which I divide by 213 to get the 4.79 voltage rail.

    I have a volt meter connected to the wiper of the pot to compare the displayed LCD results.

    The remainder does not display correctly.

    What am I doing wrong?
    '***************************************************** ***********
    ANSEL = %00000100
    ANSELH = %00000000
    TRISA = %11111110 'All digital except PortA 0
    TRISB = %00000000
    TRISC = %00000000

    DEFINE OSC 4

    ' Define LCD registers and bits
    DEFINE LCD_DREG PORTC
    DEFINE LCD_DBIT 0
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 5
    DEFINE LCD_RWREG PORTB
    DEFINE LCD_RWBIT 4
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 6
    DEFINE LCD_BITS 8
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50
    '################################################# ######################
    ' Set up AD
    DEFINE ADC_BITS 10 ' Set number of bits in result
    DEFINE ADC_CLOCK 2 ' Set clock source (rc = 3)
    DEFINE ADC_SAMPLEUS 50
    ANSEL = %00000100 'enable AN2, ALL THE REST DIGITAL
    ANSELH = %00000000 'AN8-11 DIGITAL
    adcVal var word '
    adcVal1 var word
    adcVal2 var word
    adcVal3 var word
    ADCON0 = %10001000 ' ADC Control 1
    ' 7=1 -1 = Right just, 0 = Left just
    ' 6=0 -1 = Vref pin, 0= Vdd
    ' 5=0 -Analog Channel Select Bits
    ' 4=0 -Analog Channel Select Bits
    ' 3=1 -Analog Channel Select Bits
    ' 2=1 -Analog Channel Select Bits
    ' 1=1 -1 = A/D in progress, 0 = Compleated
    ' 0=0 -1 = ADC enable, 0 = Disable
    ADCON1 = %00000000 ' 7=0 -Unimplimented read as 0
    ' 6=0 -A/D clock conversion bots
    ' 5=0 -A/D clock conversion bots
    ' 4=0 -A/D clock conversion bots
    ' 3=0 -Unimplimented read as 0
    ' 2=0 -Unimplimented read as 0
    ' 1=0 -Unimplimented read as 0
    ' 0=0 -Unimplimented read as 0
    Pause 500 ' Wait .5 second LCD Stablise
    start:
    Display:
    ADCIN 2, adcVal
    pauseus 50
    adcVal1 = adcVal / 213 'Voltage
    adcVal2 = adcVal // 213 'Remainder
    Lcdout $fe, $80, "A/D Conversion"
    lcdout $fe, $C0, dec adcval,"_",dec adcVal1, ".",dec adcVal2
    Pause 500 ' Wait .5 second
    Goto Display ' Do it forever

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    966


    Did you find this post helpful? Yes | No

    Default Re: I知 having a problem with getting the correct remainder using // remainder.

    Using integer math

    1023 / 213 = 4 remainder 171
    remainder 171*100 / 213 = 80

    So, adcVal1 = adcVal / 213
    adcVal2 = ((adcVal // 213)*100)/213

    Then print the value
    This is the quick and easy way. Others might suggest more optimal techniques using PBP

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: I知 having a problem with getting the correct remainder using // remainder.

    maybe like this

    100/213 *256 = 120

    using the */ operator
    1023 */ 120 = 479

    so
    adcVal1 = adcVal */120

    lcdout $fe, $C0, dec adcval1/100 ".",dec1 adcVal1//100

  4. #4
    Join Date
    Mar 2016
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Re: I知 having a problem with getting the correct remainder using // remainder.

    Sorry about the delay in replying I'm the other side of the pond and only just had my breakfast.
    I will try you codes out and let you know

Similar Threads

  1. Remainder (Modulus, Modulo)
    By PICn-It in forum General
    Replies: 3
    Last Post: - 12th January 2010, 02:16
  2. Is this the correct PIC?
    By The Master in forum Off Topic
    Replies: 8
    Last Post: - 6th May 2008, 16:44
  3. Correct syntax please ?
    By malc-c in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 11th June 2006, 09:09
  4. Mathematics and remainder for PLL MC145158
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 24th August 2005, 04:32
  5. Retrieving Div32 Remainder
    By Darrel Taylor in forum Code Examples
    Replies: 4
    Last Post: - 20th August 2003, 03:53

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