Can i measure 2 secs with pulsin?


+ Reply to Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Feb 2010
    Posts
    15

    Default Can i measure 2 secs with pulsin?

    just like that, Can I measure 2 seconds with pulsin? or what is the max value that i can store in a variable with pulsin?

    what i want to do is, hold a button just when i turn on the pic, and if the button is 2 seconds-hold or more do something

    And another question,

    if i want to store more tan one byte with serin this will work?

    serin porta.1,N2400,["A"], var1, var2, var3 'for 3 vars???
    Last edited by lugo.p; - 9th March 2010 at 00:23. Reason: correcting

  2. #2
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323

    Default

    No, 2 seconds is too long for pulsin.

    According to the manual:
    "The resolution of PULSIN is dependent upon the oscillator frequency. If a 4MHz oscillator is used, the pulse width is returned in 10us increments. If a 20MHz oscillator is used, the pulse width will have a 2us resolution. "

    Since the pulsin will return a WORD, the max pulse length is 65535 x 10uS (for a 4MHz clock) which is only 0.655 seconds.

    For a 20MHz osc it would only be 0.131 seconds.

    steve

  3. #3
    Join Date
    Feb 2010
    Posts
    15

    Default

    thanks steve, can you tell me how i can measure a 2 seconds button-pressed?

  4. #4

    Default

    I'll give you a hint... how many 1/2 seconds in 2 seconds? How many 1/10 of a second in 2 seconds? That's if you want to do it in the "foreground"... hmmm...

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405

    Default

    MyVar = 0 ' zero on entry
    WHILE INPUTPIN = desired state
    PAUSE 500 ' 1/2 second delay
    MyVar = MyVar +1
    WEND

    When it exits just check the value in MyVar.

    if i want to store more tan one byte with serin this will work?

    serin porta.1,N2400,["A"], var1, var2, var3 'for 3 vars???
    Yep.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    Join Date
    Sep 2007
    Location
    USA, CA
    Posts
    270

    Default

    Quote Originally Posted by Byte_Butcher View Post
    No, 2 seconds is too long for pulsin.

    According to the manual:
    "The resolution of PULSIN is dependent upon the oscillator frequency. If a 4MHz oscillator is used, the pulse width is returned in 10us increments. If a 20MHz oscillator is used, the pulse width will have a 2us resolution. "

    Since the pulsin will return a WORD, the max pulse length is 65535 x 10uS (for a 4MHz clock) which is only 0.655 seconds.

    For a 20MHz osc it would only be 0.131 seconds.

    steve
    And what would be the problem with using a 1MHz clock?

    YES--Of COURSE you can use Pulsin for a 2 second pulse! Most PIC's have internal clocks that are capable of it. Heck, if you need a faster clock for other stuff, just slow down (i.e. change osccon) right before the pulsin and put it back after.

  7. #7
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323

    Default

    Quote Originally Posted by tenaja View Post
    And what would be the problem with using a 1MHz clock?
    Well heck... I never thought of just slowing the clock down for the pulsin measurement!

    Good idea!



    steve

  8. #8
    Join Date
    Feb 2010
    Posts
    15

    Default

    Thanks a lot Bruce and Tenaja, both ideas are great. Will tray both

    Bruce one thing, your while...wend statemet, will be a inifinite loop if I left the button pressed, doesn't? I did the next code, will work?

    Code:
            if PORTA.0 = 1 THEN
            PAUSE 2000
            if PORTA.0 = 1 THEN 
            gosub PROGRAMAR
            endif
    Last edited by lugo.p; - 9th March 2010 at 16:24.

  9. #9
    Join Date
    Feb 2010
    Posts
    15

    Default

    Quote Originally Posted by tenaja View Post
    And what would be the problem with using a 1MHz clock?

    YES--Of COURSE you can use Pulsin for a 2 second pulse! Most PIC's have internal clocks that are capable of it. Heck, if you need a faster clock for other stuff, just slow down (i.e. change osccon) right before the pulsin and put it back after.
    Tenaja there is a problem, when i code this:

    Code:
          OPTION_REG = $07                                                                                                                
          ANSEL      = $00     'para hacer funcionar todas las E/S como digitales
          TRISA      = $07     'Configura PORTA <5:3> salidas y PORTA <2:0> salidas
          TRISC      = $00     'Configura PORTC <5:0> todas salidas
          INTCON     = $00     'Interrupciones deshabilitadas
          OSCCON     = $47     'Oscilador 8MHz
          DEFINE OSC 1         '8MHz
          
    inicio:
          pulsout PORTC.5,25000
          pause 100
          goto inicio
    i get an Error:

    Error c:\picmicro\mcstud~1\pbp246\pbppic14.lib 6152 : [255] Unidefined Sybol 'PAUSEUSL'

    looking in pbppic14.lib it seems that the lowest frecuency that can be handled by PBP is 3.58MHz, but pic16f684 can handle since frecuency from 31KHz.

    But inclusive having that error I sumulate the HEX, and works, my question is, this error will give me headache????




    --EDIT--

    I took away the line

    DEFINE OSC 1 'for 1MHz oscillator

    and code was compiled just fine, the only thing is that PAUSE increments are bigger

    with DEFINE OSC 1

    PAUSE 100 'has a duration of 5mS

    without DEFINE OSC 1

    PAUSE 100 'has a duration of 400mS
    Last edited by lugo.p; - 9th March 2010 at 17:07. Reason: correcting

  10. #10
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,578

    Wink

    Hi,

    For pulsin,

    You also can play with the internal oscillator ... if your chip, like the 16F88 has a configurable internal osc ...

    use the " classic " 4 or 8 Mhz speed, and switch, on the fly, to 31 Khz or 125 Khz ... just changing osccon IRCF bits, when needed ...


    note the BUTTON command can be configured to have a 250ms debounce time ( DEFINEs ...) ... 8 x 250 ms make 2 seconds.
    which is much, much simpler !!! ( matches Bruce's idea ...)

    Alain
    Last edited by Acetronics2; - 9th March 2010 at 18:17.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  11. #11
    Join Date
    Feb 2010
    Posts
    15

    Default

    Acetronics,

    i really don't understand very well how it's works BUTTON, but, it will work if I use BUTTON just when PIC is turned on.

    By example the following flow,

    1. turn on PIC and if button is pressed 2 seconds GOTO X, or

    2. turn on PIC and if button is not pressed run normally.

  12. #12
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,578

    Wink

    Hi, Lugo

    let's suppose your button B is active LOW

    Code:
    DEFINE BUTTON_PAUSE 250
    
    .
    .
    .
    
    FOR I = 1 to 8 
    
       Delay = 0                                ' reset check time
       BUTTON B,0,255,0,Delay,1, Incr          ' Check if button pressed for 250 ms , IF yes, increment I and recheck
       GOTO Main                              ' If not jump to main
    
       Incr:
    NEXT I                                    ' If checked 8 times we enter Setup routine
    
    Setup_routine :
    .
    .
    .
    .
    Main :
    .
    .
    Note there's NO DELAY to enter main routine if button hasn't been pressed ... either test will be left as soon as button is released ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. Replies: 17
    Last Post: - 12th April 2014, 03:17
  2. Funny PULSIN values: what is going on???
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 30th April 2008, 09:02
  3. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 18:27
  4. CCP1 and CCP2 to measure 2 frequencies together
    By bobonapoletano in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 28th December 2005, 08:34
  5. PULSIN and RCTIME
    By Dwayne in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 4th November 2004, 15:45

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts