Math operations & Syntax?


Results 1 to 8 of 8

Threaded View

  1. #1
    Join Date
    Aug 2007
    Posts
    67

    Default Math operations & Syntax?

    I'm a bit confused on the actual use and syntax when using WORD sized variables.

    I'm going to measure a timed event, then use that time as a basis for a pass/fail trial of another timed event. I need to measure the time (16-bit), then manipulate it (subtract a few microseconds), then use that manipulated result to continually pre-load the timer and see if the event happens again within the similar allotted time frame.


    Here is what I plan to do and how I will syntax it - wanted to see if I'm doing this correctly?

    Using TMR1 ...

    Code:
    'Variables
    '-------------
    tMeasure VAR WORD   'Holder for the time
    tResult VAR WORD      'Holder for modified time
    tSet VAR WORD	    'Holder for timer set value
    
    
    'Measure event, manipulate Data
    '-------------
    T1CON.0=0           'Stop timer
       TMR1H = %00000000   'Reset the timer
       TMR1L = %00000000    '......
       PIR1.0=0            'Clear timer overflow bit
       T1CON.0=1           'Start timer
    
            ''' Wait for event to measure
    
       T1CON.0=0     'Stop Timer
    
    tMeasure = TMR1   		'Should put timer stop value into tMeasure
    tResult = tMeasure - 100 	'Subtract 100 cycles
    tSet = 65025 - tResult          'Setpoint for timer
    
            '' If I pre-load the timer with this tSet number, then wait
            '' for it to time out, it should run for a time period in cycles
            '' equal to tResult - right?
    
    
    'Perform trial timeout
    '--------------------
       T1CON.0=0           'Stop timer
       TMR1 = tSet
       PIR1.0=0            'Clear timer overflow bit
       T1CON.0=1           'Start timer
       WHILE PIR1.0=0 : WEND
       TOGGLE probe     'Should happen about tResult cycles after 
                              'starting the timer, yes?
    
    '

    My real questions are with the manipulation of the 16-bit variables. When I write "TMR1 = tSet", the TMR1H and TMR1L registers are filled correctly with the high byte and low byte of tSet - correct?

    Normally I would set TMR1 by manually setting the TMR1H and TMR1L with binary code like "TMR1H = %11101100".

    Also, do I need to worry about which direction the data is justified? I know it's important, but if I do it as written, is PBP smart enough to get the justification correct for me?


    Thank you!
    Last edited by kevj; - 22nd February 2008 at 08:13.

Similar Threads

  1. Resolution integer math assistance?
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 14th January 2010, 03:01
  2. PBPL Math...new math takes more cycles...Always?
    By skimask in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 10th February 2008, 10:22
  3. instruction cycles for math operations
    By Michael Wakileh in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th July 2007, 11:03
  4. Math Operations on pbp
    By Jannia04 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th May 2007, 15:33
  5. PIC18Fxx math 24 & 32 bit
    By ronsimpson in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 2nd December 2006, 12:52

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