Shop OBEX P1 Docs P2 Docs Learn Events
Pulse Measurement Help — Parallax Forums

Pulse Measurement Help

lardomlardom Posts: 1,659
edited 2018-06-11 11:28 in Propeller 1
I want to be able to measure 2.4ms, 1.2ms and 0.6ms. I looked at 'pos detector' and counter mode 24 26. They both look the same to me but I'm trying to figure out how to get it to return once the i/o pin goes low.
Will this work?
PUB test_counter_mode   

   frqa := 1
   ctra := 0
   dira[1]~       
  
   repeat      
     ctra := (%11010 << 26 ) | (1)                    ' accumulate while A = 1   
     waitpne(0 << 1, |< 1, 0)                                                   
     waitpeq(0 << 1, |< 1, 0)                                                                                                      
     pulseWidth := phsa  
     phsa:=0
649 x 664 - 113K

Comments

  • BeanBean Posts: 8,129
    I think you want something like:
    PUB test_counter_mode   
    
       frqa := 1
       ctra := 0
       dira[1]~           
       ctra := (%11010 << 26 ) | (1)                    ' accumulate while A = 1   
       repeat
         waitpne(0 << 1, |< 1, 0)    ' wait for pin to go low
         phsa = 0                            ' Reset count
         waitpeq(0 << 1, |< 1, 0)    ' wait for pin to go high                                                                                                
         waitpne(0 << 1, |< 1, 0)    ' wait for pin to go low
         pulseWidth := phsa            ' Get the count
    

    Bean
  • JonnyMacJonnyMac Posts: 9,104
    edited 2018-06-11 12:42
    You want to use POS DETECT mode like this:
    pub main | pw                                                        
                                                                     
      setup
    
      ctra := (%01000 << 26) | PG_PIN                               ' POS DETECT mode
      frqa := 1
    
      repeat
        waitpne(PG_MASK, PG_MASK, 0)                                ' wait for low
        phsa := 0                                                   ' clear accumulator
    
        waitpeq(PG_MASK, PG_MASK, 0)                                ' wait for pulse                                                           
        waitpne(PG_MASK, PG_MASK, 0)
        
        pw := phsa / US_001                                         ' convert to microseconds
    
        term.dec(pw / 1000)                                         ' display as x.xxx
        term.tx(".")
        term.rjdec(pw // 1000, 3, "0")
        term.tx(13))
    
    The attached program (tested on Propeller Activity Board) starts a pulse-generator in in a background cog so that the foreground code (above) can measure it. This is one of my favorite things about the Propeller: I can use a spare cog to simulate an input from a device that I don't have connected.
  • @Bean and @JonnyMac, Thanks very much. I see the similarity in some code that I got from the OBEX. It used 'counter mode 21' which looks like it returns a differential result. I have a difficult enough time wrapping my brain around 'single ended' results.
    @JonnyMac, thanks for the zip. I'll be testing both IR and ASK. Testing wireless communication with only a single Propeller will make life 'so' much easier!
  • BeanBean Posts: 8,129
    So is there any difference between "POS DETECT" mode and "LOGIC A" mode ?

    Bean
  • So is there any difference between "POS DETECT" mode and "LOGIC A" mode ?
    I don't think so -- either works in the little demo I wrote.

    @lardom Are you wanting to do this for SIRCS coms? If yes, I have an object that you're welcome to. I'm sitting in the Dallas office of a laser-tag client at the moment. The product using SIRCS type packets in the IR coms ("bullets" and command and information packets)
  • @JonnyMac
    "@lardom Are you wanting to do this for SIRCS coms?"
    Yes, kind of. I plan to tweak it a bit.
    "If yes, I have an object that you're welcome to. I'm sitting in the Dallas office of a laser-tag client at the moment. The product using SIRCS type packets in the IR coms ("bullets" and command and info`rmation packets)"
    Yes, I would appreciate it. I had success with the nRF24L01 transceivers even though my modules turned out to be clones. I would have posted the code but I didn't get the sense that there's much interest in the project that I built with it.
    Now I want to see what I can do with 433Mhz modules.


  • I think I found this one on the forum
  • Yes, kind of. I plan to tweak it a bit.
    Here's my generic SIRCS receiver -- do with it what you will!
  • @JonnyMac, thank you.
    I don't know why wireless transmitters that use data as opposed to multiple channels aren't more popular but I think there are definite advantages. I can imagine some pretty amazing things if the code is written in PASM!
Sign In or Register to comment.