Divide in C code for PIC

Discussion in 'Programmer's Corner' started by FroceMaster, Sep 21, 2014.

  1. FroceMaster

    Thread Starter Member

    Jan 28, 2012
    402
    4
    Hi
    Need to do this.
    1/25000*125000*60
    if i do like this,

    Code (Text):
    1. timer = (TMR1H << 8)| TMR1L;
    2.  
    3.   tid_rpm= timer *(timer_tick+1);
    4.  
    5. nyrpm =1/tid_rpm*125000*60;
    Any hint on doing this ?

    have define all as float.
     
    Last edited: Sep 21, 2014
  2. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,558
    517
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,508
    1,643
    Any hint on doing what?

    If you expect any help you need to state what you are trying to accomplish.

    Unless 1/187,500,000,000 = 5.3333333333333333333333333333333e-12 is the answer you need.
     
  4. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,715
    810
    And i thought the answer was 300.
    The correct order of operations would be 125000*60/25000 in order to prevent loss of precision.
     
  5. Brian Griffin

    Member

    May 17, 2013
    40
    14
    Which PIC is it you want to do a divide function inside? A PIC16F doesn't have hardware multipliers, only PIC18F and PIC24F have them.
     
  6. FroceMaster

    Thread Starter Member

    Jan 28, 2012
    402
    4
    Yes that way works. ☺
    16f690 is the Pic.
     
Loading...