Shop OBEX P1 Docs P2 Docs Learn Events
Beginners Program — Parallax Forums

Beginners Program

TyroneRTyroneR Posts: 22
edited 2013-06-27 12:14 in Propeller 1
Im new to microcontrollers and
I have been messing around with the Sound Impact Sensor ,and the IR motion senser to create a secuirity system.
As I am sure that you all know that the Sound impact sensor, and the IR motion senser sends a high signal to their assigned pins when there is change in the enviroment (what they are monitoring).
I belive that their is a better way to monitor sound , and motion by keeping track how often the assigned pin recieves a high signal .
This way mySound Impact sensor will not sound the alarm if it hears one little thing over a long period of time(lets say 15 min). But rather if it stayes high continously for a period of time(lets say 2 sec.), or if it goes high and low more than one time in a time frame of lets say 2min. The alarm will sound.
What I am asking is. Is there an example out there that monitors the state of an I/O pin and stores a value if high , starts a count down (desired time) while waiting for the I/O pin to go high again.
If the I/O pin does not go high again with in that time frame set. The Propeller will clear that value and start over, but if it the I/O pin doesgo high again before the count down ends and the Propeller resets itself.
I would like the alarm to sound, or light an LED.
I hope what I am trying to do makes sense to you all,


_clkmode = xtal1 + pll16x ' Set clock mode
_xinfreq = 5_000_000

VAR
byte state ' Variable for storing PIR output
OBJ
pst : "Parallax Serial Terminal" ' Use Serial Terminal object

PUB PIR
dira[18]~ ' Set pin 18 (Sound impact sensor) to input
dira[19]~ ' Set pin 19 (IR sensor) to input
pst.start(115200) ' Start Terminal at 115200 baud
pst.str (string("Warming up..."))
waitcnt(clkfreq * 20 + cnt) ' PIR "warm-up" time
pst.clear ' Clear the screen
repeat
if ina[18] == 1 'Waiting for P13 to recieve a high signal
dira[1]:= outa[1] :=0 'If P13 is high,turn off green LED (P1)
dira[0]:= outa[0] :=1 'If P13 is high,turn on red LED (P0)
waitcnt(clkfreq/4 + cnt) 'Wait 1/4 of a second before moving on to the next line of code

else
dira[0] := outa[0] :=0 'If P13 is Low,turn off red LED (P0)
dira[1]:= outa[1]:=1 'If P13 is high,turn on green LED (P1)

waitcnt(clkfreq/6 + cnt) ' Wait 1/7 of a sec before moving on


state := ina[19] ' Save state of PIR Sensor
pst.home ' Move cursor to upper left
pst.str(string("IN0 = "))
pst.bin(state, 1) ' Display results
waitcnt(clkfreq/200 + cnt) ' Small delay

Comments

  • PliersPliers Posts: 280
    edited 2013-06-25 17:58
    Hi
    I'm surprised not to see anybody helping this guy.
    To TyroneR.....
    I can't help you right now because I don't know the code that well. I just browse this forum because I find it interesting.
    It has been over a year since I did anything with the Propeller, but I'll download your program and take a look.
    I'm not sure where my propeller is. I should have some results Thursday night.


  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-06-25 21:55
    I'm going to guess that nobody is offering help because this forum is not for technical questions. It is for posting projects, typically completed. If the original poster would like me to I can move the thread to the Propeller Forum where the thread would be on topic and could be answered.
  • TyroneRTyroneR Posts: 22
    edited 2013-06-26 09:22
    Please do move it to the appropriate forum Chris.
    Thanks

    BTW, should I use to cogs? I noticed when I combined the IR senser with the Sound impact sensor. It seemed a little slower ( the response).
  • TyroneRTyroneR Posts: 22
    edited 2013-06-26 18:47
    Thanks Chris.
  • cavelambcavelamb Posts: 720
    edited 2013-06-26 19:34
    This may help get you started in the right direction.

    My LCD display project had a sorta similar requirement - to turn off the back lighting in a few seconds
    of inactivity. I used a second cog with the job of counting down the time-out period.
    That would normally be done with an interrupt handler, but the Prop is more advanced!

    Anyway, take a look at this and see if it gives you any ideas...

    Edit: The attached ZIP file has the other drivers if you need them.
    {{ QS_LCD_IR_TimeOut.spin }}
    
    CON
      _CLKMODE = XTAL1 + PLL16X        ' 80 Mhz clock
      _XINFREQ = 5_000_000
      IRpin     =    2                       ' IR Receiver - Propeller Pin
      LcdTimeOut    = 3                 
      LcdOn1        = $16               ' LCD on; cursor off, blink off
      LcdLine0      = $80               ' move to line 1, column 0
      LcdLine1      = $94               ' move to line 2, column 0
      POL           = 15                   ' proof of life LED
    
    OBJ
      ir      : "IR_Remote"
      lcd     : "serial_lcd"
      num     : "simple_numbers"
       
    VAR
      byte IRcode                        ' keycode from IR Receiver here
      byte LCDtime                      ' timeout counter
      long IRcog                           ' cog id#
      long Stack1[6]                     ' Stack space for LCDtimeout cog
      
    PUB Init | freq, index, cog, lcode
    
    'init LCD
      if lcd.start(0, 9600, 4)
        lcd.putc(lcd#LcdOn1)              ' no cursor
        lcd.cls
        lcd.backlight(1)
        lcd.str(string(LcdLine0, "IR Remote"))
    
    'Proof of Life       
      dira[pol]~~
      !outa[pol] 
    
    'Start Timeout down counter cog
      LCDTime := LCDTimeout              ' reset timeout each time a key is pressed
      cognew (TimeOut, @stack1 )
    
    'Init IR remote
      IRcog := ir.Start(IRpin, @IRcode)  ' Pin of IR receiver, address of variable
    
      if IRcog > 0
          repeat
    
            If LCDtime >0
               LCD.backlight(1)          ' turn it on        
            else                         ' timed out
               LCD.backlight(0)          ' turn if off
               
            If IRcode <> ir#NoNewCode    ' we have a key code
               lcode := IRcode
               ir.Start(IRpin, @IRcode)  ' set up for next code
    
               if LCDtime := 0           ' if it was off, 
                  LCD.backlight(1)       '    turn it back on
    
              LCDTime := LCDTimeout      ' reset timeout each time a key is pressed            
    
               lcd.gotoxy(1,1)           
               case lcode
                  ir#one     :  lcd.str(string("<1>   "))
                  ir#two     :  lcd.str(string("<2>   "))
                  ir#three  :  lcd.str(string("<3>   "))
                  ir#four    :  lcd.str(string("<4>   "))
                  ir#five     :  lcd.str(string("<5>   "))
                  ir#six      :  lcd.str(string("<6>   "))
                  ir#seven :  lcd.str(string("<7>   "))
                  ir#eight   :  lcd.str(string("<8>   "))
                  ir#nine    :  lcd.str(string("<9>   "))
                  ir#zero    :  lcd.str(string("<0>   "))
                  ir#chUp  :  lcd.str(string("chUp "))
                  ir#chDn  :  lcd.str(string("chDn "))
                  ir#volUp :  lcd.str(string("volUp"))
                  ir#volDn :  lcd.str(string("volDn"))
                  ir#mute  :  lcd.str(string("mute "))
                  ir#power:  lcd.str(string("power"))
                  ir#last    :  lcd.str(string("last "))
                  other     :  lcd.str(string("      "))
    
            waitcnt((clkfreq / 1000) * 30 + cnt) 
            !outa[pol]
    
    PUB Timeout
      Repeat                            ' loop forever
          waitcnt(clkfreq + cnt)        ' wait one second
    
         if  byte[@LCDtime] =>   1      ' keep counting        
             byte[@LCDtime] --             '    down
    

    [
  • TyroneRTyroneR Posts: 22
    edited 2013-06-27 07:49
    Cavelamb,

    Thanks for the reply. This will definetly keep me busy this weekend.
  • cavelambcavelamb Posts: 720
    edited 2013-06-27 12:14
    FWIW, this was my first shot at writing new cog code.
    So it may be a case of the blind leading the blind here?

    While all of the above code is in a single source file, run time is not that way.
    The second cog stuff is really running on a different computer (so to speak).
    Thinking about it that way really helped.

    At first I was trying to get the timeout code to shut down the back-lighting by itself
    and a quick call to send a control code looked like the simplest way to do this.
    But I couldn't get the objects that were loaded by the first cog to work for me.
    - ir : "IR_Remote"
    - lcd : "serial_lcd"
    - num : "simple_numbers"

    There was no indication of a problem from the compiler.
    It simply did not work correctly.
    Serial.LCD wrote seriously strange stuff to the display.
    It looked like it WAS sending something.
    But what?

    In the end, I started thinking about this project as an interrupt handler.
    While this example has all day (waits one second) to do anything,
    faster functions wouldn't. Sending serial bytes would definitely
    impact timing for a servo driver or some such.

    So just do the down-count and let the main program deal with it
    as it wants.

    I didn't have to FORMALLY pass the address of LCDtime to the second cog.
    It was defined as a VAR, the compiler had it handy and it worked as expected.

    To ACCESS that variable, the second cog must refer to is by address (pointer).
    byte[@LCDtime]

    But would that still work if the code were in a different file?
    Sharing methods between cogs?
    I don't have a handle on that yet.
Sign In or Register to comment.