Sorry, yet ANOTHER mod question


Closed Thread
Results 1 to 9 of 9

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: Sorry, yet ANOTHER mod question

    14 mod 10 = 4 mod gives you the remainder after the division ie ten goes into 14 once with 4 leftover , its not what you want
    frac = volts*10 mod 100 is what you want ie 1469 mod 100 = 69 but
    the following is easier
    forget the frac
    volts_in = (volts_in * 10) / 498

    try lcdout $fe, $c0, "voltage is: ", volts_in/100, ".", dec2 volts_in
    Last edited by richard; - 30th January 2014 at 03:39.

  2. #2
    Join Date
    Jan 2012
    Location
    Grid EN19MV
    Posts
    159


    Did you find this post helpful? Yes | No

    Default Re: Sorry, yet ANOTHER mod question

    Quote Originally Posted by richard View Post
    14 mod 10 = 4 mod gives you the remainder after the division ie ten goes into 14 once with 4 leftover , its not what you want
    frac = volts*10 mod 100 is what you want ie 1469 mod 100 = 69 but
    the following is easier
    forget the frac
    volts_in = (volts_in * 10) / 498

    try lcdout $fe, $c0, "voltage is: ", volts_in/100, ".", dec2 volts_in
    Hmmm, neither of those seemed to work for me - didn't get what I was looking for.

    Then I tried this:

    Code:
    MEASURE_VOLTS:
    	ADCIN 2, VOLTS_IN 'READ CURRENT VALUE OF INPUT VOLTAGE DIVIDER
    	VOLTS_VAL = (VOLTS_IN * 10) / 498
    	VOLTS_FRAC = (VOLTS_IN * 10)  MOD 100
    
    	
    	LCDOUT $FE, 1, "CURRENT INPUT"
    	LCDOUT $FE, $C0,   "VOLTAGE IS: ", DEC2 VOLTS_VAL, ".", DEC2 VOLTS_FRAC
    Still not right, so I modified the fraction line to: VOLTS_FRAC = ((VOLTS_IN * 10) / 498) MOD 100

    But that gives me 14.14 - still not right. Any other ideas? And thanks again for the help
    "I have noticed that even those who assert that everything is predestined and that
    we can change nothing about it still look both ways before they cross the street"


    -Stephen Hawking

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


    Did you find this post helpful? Yes | No

    Default Re: Sorry, yet ANOTHER mod question

    got that wrong
    frac = volts*1000/498 mod 100 is what you want ie 1469 mod 100 = 69 but it may cause overflows


    volts_in = (volts_in * 100) / 498 (should be ok internal mult/div is 32 bit in pbp3 anyway)

    try lcdout $fe, $c0, "voltage is: ", volts_in/10, ".", dec1 volts_in

Similar Threads

  1. Help with Pic Delay code mod please
    By g7jiq in forum General
    Replies: 1
    Last Post: - 26th March 2009, 01:06
  2. ERROR: Macro MOD?TCB not found in macro file.
    By JohnP in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th February 2009, 20:10
  3. 18F4620 HPWM Half Bridge Mod problem
    By showtime in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 2nd November 2007, 13:55

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