How long a variable has the same value?


Closed Thread
Results 1 to 3 of 3
  1. #1

    Question How long a variable has the same value?

    Hi Guys,

    I'm reading a value from pulsin (pic12f675), I want to know if that value is greater than 150, but I also want to know if that value stays greater than 150 for over than 3 seconds.

    --------------------
    value var byte

    loop:

    PulsIn GPIO.0, 1, value

    IF (value > 150) Then
    'do something here
    EndIF

    GoTo loop

    ----------

    The first part it's easy, the second part, well, still looking on how to do it.

    I searched the forum, but no luck. Could someone give me a hand?

    Thanks!

    Daniel.

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Have a look at this;

    Modify as desired.

    Code:
    <font color="#000000">Value <font color="#000080"><b>VAR BYTE
    
    </b></font>T1CON  = <font color="#FF0000"><b>%00110100  </b></font><font color="#000080"><i>'TMR1GE enabled, Prescaller 1:8, LP OFF, No Sync, Internal Clk
    </i></font>TMR1IF    <font color="#000080"><b>VAR </b></font>PIR1.<font color="#FF0000"><b>0  </b></font><font color="#000080"><i>'Timer1 Overflow bit.
    </i></font>TMR1ON    <font color="#000080"><b>VAR </b></font>T1CON.<font color="#FF0000"><b>0 </b></font><font color="#000080"><i>'Timer1 Start/Stop bit. 
    
    </i></font>Pulsepin  <font color="#000080"><b>VAR </b></font>GPIO.<font color="#FF0000"><b>0
    </b></font>Limit     <font color="#000080"><b>CON </b></font><font color="#FF0000"><b>150 </b></font><font color="#000080"><i>' Desired Pulse limit. 
    </i></font>TimeDone   <font color="#000080"><b>CON </b></font><font color="#FF0000"><b>6   </b></font><font color="#000080"><i>' Desired Time. Each unit is 524mS. 6 = approx. 3 secs.
    </i></font>CountTime <font color="#000080"><b>VAR BYTE
    
    </b></font>Loop:
    
        TMR1L  = <font color="#FF0000"><b>0
        </b></font>TMR1H  = <font color="#FF0000"><b>0
        </b></font>TMR1IF = <font color="#FF0000"><b>0
        </b></font>TMR1ON = <font color="#FF0000"><b>0
    
        </b></font><font color="#000080"><b>PULSIN </b></font>Pulsepin, <font color="#FF0000"><b>1</b></font>, Value
        
        <font color="#000080"><b>IF </b></font>Pulsepin &gt; Limit <font color="#000080"><b>THEN </b><i>' Incoming pulse is greater then desired pulse limit.
           </i></font>TMR1ON = <font color="#FF0000"><b>1            </b></font><font color="#000080"><i>' Start Timer.
           </i></font>CountTime = <font color="#FF0000"><b>0         </b></font><font color="#000080"><i>' Clear time variable.
        
           </i><b>WHILE </b></font>Pulsepin &gt; Limit <font color="#000080"><i>'Loop while the incoming pulse is greater then limit.
             </i><b>PULSIN </b></font>Pulsepin, <font color="#FF0000"><b>1</b></font>, Value
        
             <font color="#000080"><b>WHILE </b></font>TMR1IF = <font color="#FF0000"><b>0                 </b></font><font color="#000080"><i>' Wait about 524ms.
                </i><b>PULSIN </b></font>Pulsepin, <font color="#FF0000"><b>1</b></font>, Value     <font color="#000080"><i>' Keep reading.
                </i><b>IF </b></font>Pulsepin =&lt; Limit <font color="#000080"><b>THEN </b></font>Jump <font color="#000080"><i>' In case Pulse changed then exit!
             </i><b>WEND
             </b></font>TMR1IF = <font color="#FF0000"><b>0                           </b></font><font color="#000080"><i>'Clear timer1 overflow bit.
             </i></font>CountTime = CountTime + <font color="#FF0000"><b>1            </b></font><font color="#000080"><i>' Count Timer1 ticks,
             </i><b>IF </b></font>CountTime = TimeDone <font color="#000080"><b>THEN </b></font>Dothings <font color="#000080"><i>' ...Exit loop if time is out. 
                                                      'and do your stuff.
    
           </i></font>Jump:
            
           <font color="#000080"><b>WEND
            
        ENDIF    
        
    
    GOTO </b></font>Loop
    
    
    Dothings:
    
    
    <font color="#000080"><i>' do somethings here.
    
    
    </i><b>GOTO </b></font>Dothings
    Last edited by sayzer; - 22nd February 2008 at 11:13.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Great!!! Thanks a lot!!!

    I'll read it and test it this weekend.

    Daniel.

Similar Threads

  1. EEPROM Variables (EE_Vars.pbp)
    By Darrel Taylor in forum Code Examples
    Replies: 79
    Last Post: - 26th October 2012, 00:06
  2. High Resolution Timer & Speed Calculator
    By WOZZY-2010 in forum Code Examples
    Replies: 4
    Last Post: - 7th February 2010, 16:45
  3. signed long (32-bit) variable
    By Stephan in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th September 2007, 03:40
  4. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36
  5. Long varible strings
    By flashg in forum Serial
    Replies: 0
    Last Post: - 14th October 2006, 04:40

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