Shop OBEX P1 Docs P2 Docs Learn Events
Need help with a PE Labs Fun Book project — Parallax Forums

Need help with a PE Labs Fun Book project

turbosupraturbosupra Posts: 1,088
edited 2011-07-18 00:52 in Propeller 1
Using this project from page 59 of the Pe Labs Fun Book
http://www.parallax.com/Portals/0/Downloads/docs/prod/prop/PELabsFunBook-v1.1.pdf

'' File: ShiftRightP9toP4.spin
'' Demonstrates the right shift operator and if statement.
PUB ShiftLedsLeft
dira[noparse][[/noparse]9..4] ~~
repeat
if outa[noparse][[/noparse]9..4] == 0
outa[noparse][[/noparse]9..4] := %100000
waitcnt(clkfreq/10 + cnt)
outa[noparse][[/noparse]9..4] >>= 1




How would I get it to then cycle back from pin 4 to 9 and then start over?

I'd like for it to end up looking like KITT ( )

Thanks for reading

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-10-07 00:57
    turbosupra,

    My first car in 1983 was a 1967 red firebird convertible ... I put KITT lights in the front grill and designed a mechanical rotor to control the lights. Wish I had a Stamp back then to play with.

    Kitt lights
    PUB KITT
        dira[noparse][[/noparse]9..4] ~~
        outa[noparse][[/noparse]9..4] := %100000
        repeat
          repeat 5
            waitcnt(clkfreq/10 + cnt)
            outa[noparse][[/noparse]9..4] >>= 1
          repeat 5
            waitcnt(clkfreq/10 + cnt)
            outa[noparse][[/noparse]9..4] <<= 1
    
    





    Edit... where are my priorities? ... heck, I wish I still had that car! smilewinkgrin.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 10/7/2009 1:02:41 AM GMT
  • turbosupraturbosupra Posts: 1,088
    edited 2009-10-07 01:51
    Thanks Beau! This is awesome!

    I couldn't even ride a bike in 83, but having a firebird with kit lights would have been awesome, especially if you did it with a mechanical rotor? Wow!

    I loaded your program and it worked, and I would like to ask why you put the number next to the nested repeat commands. Is this so that it had a finite amount of times to add 1, before it executed the next repeat loop? And then it went to the other direction for a finite about of times, and then started over?

    Thanks again btw, this made my night! Think it'd be sacrilegious to have KITT lights on a Toyota?



    Beau Schwabe (Parallax) said...
    turbosupra,

    My first car in 1983 was a 1967 red firebird convertible ... I put KITT lights in the front grill and designed a mechanical rotor to control the lights. Wish I had a Stamp back then to play with.

    Kitt lights
    PUB KITT
        dira[noparse][[/noparse]9..4] ~~
        outa[noparse][[/noparse]9..4] := %100000
        repeat
          repeat 5
            waitcnt(clkfreq/10 + cnt)
            outa[noparse][[/noparse]9..4] >>= 1
          repeat 5
            waitcnt(clkfreq/10 + cnt)
            outa[noparse][[/noparse]9..4] <<= 1
    
    





    Edit... where are my priorities? ... heck, I wish I still had that car! smilewinkgrin.gif
  • turbosupraturbosupra Posts: 1,088
    edited 2009-10-07 02:05
    Now to figure out how to code for a small piezo or speaker to output this sound repeatedly!

    http://www.soundamerica.com/sounds/tvshows/Knight_Rider/KScanr1.wav


    *evil laugh*
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2009-10-07 02:14
    Piece of cake..

    Propeller WAV players from OBEX
    obex.parallax.com/objects/324/

    Be careful rigging that up.. Ohio laws (where I live) prohibit use of red or blue lights
    in any fashion (except obvious brake/tail lights) as they are used by emergency/police
    vehicles. Traveling with KITT lights could get you a ticket here..

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Visit the: The Propeller Pages @ Warranty Void.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2009-10-07 02:16
    Beau Schwabe (Parallax) said...


    Kitt lights
    PUB KITT
        dira[noparse][[/noparse]9..4] ~~
        outa[noparse][[/noparse]9..4] := %100000
        repeat
          repeat 5
            waitcnt(clkfreq/10 + cnt)
            outa[noparse][[/noparse]9..4] >>= 1
          repeat 5
            waitcnt(clkfreq/10 + cnt)
            outa[noparse][[/noparse]9..4] <<= 1
    
    



    @Beau:

    That's much more elegant code that what I was coming up with, but I thought KITT
    had more PWM in the light movement that you used. [noparse];)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Visit the: The Propeller Pages @ Warranty Void.
  • turbosupraturbosupra Posts: 1,088
    edited 2009-10-07 04:06
    Thanks! This code is a bit over my head at the moment?

    It looks like it says pinL and pinR are set to the sound outputs for the speaker, but which pins are assigned to pinL and pinR?




    
    '  SPIN WAV Player Ver. 1a  (Plays only mono WAV at 16ksps)
    '  Copyright 2007 Raymond Allen   See end of file for terms of use.    
    '  Settings for Demo Board Audio Output:  Right Pin# = 10, Left Pin# = 11   , VGA base=Pin16, TV base=Pin12
    
    
    CON _clkmode = xtal1 + pll16x
        _xinfreq = 5_000_000       '80 MHz
    
        buffSize = 256
    
    VAR long parameter
        long buff1[noparse][[/noparse]buffSize]
        long buff2[noparse][[/noparse]buffSize]
        long stack1[noparse][[/noparse]100]
        word MonoData[noparse][[/noparse]buffSize]
        
    OBJ
        text : "vga_text"    'For NTSC TV Video: Comment out this line...
        'text : "tv_text"    'and un-comment this line  (need to change pin parameter for text.start(pin) command below too).
        SD  : "FSRW"
        num : "numbers"
    
    PUB Main|n,i,j
      'Play a WAV File
    
      'Start up the status display...
      text.start(16)    'Start the VGA/TV text driver (uses another cog)
                        'The parameter (16) is the base pin used by demo and proto boards for VGA output
                        'Change (16) to (12) when using "tv_text" driver with demo board as it uses pin#12 for video                    
      text.str(STRING("Starting Up",13))
    
      'open the WAV file  (NOTE:  Only plays mono, 16000 ksps PCM WAV Files !!!!!!!!!!!!!)
      'access SD card 
      i:=sd.mount(0)
      if (i==0)
        text.str(STRING("SD Card Mounted",13))
      else
        text.str(STRING("SD Card Mount Failed",13))
        repeat
    
      'open file
      'i:=sd.popen(string("test1.wav"), "r")                '   <---------  Change .wav filename here !!!!!!!!!!!!!!         
      'i:=sd.popen(string("test2.wav"), "r")                '   <---------  Change .wav filename here !!!!!!!!!!!!!!
      'i:=sd.popen(string("test3.wav"), "r")                '   <---------  Change .wav filename here !!!!!!!!!!!!!!
      i:=sd.popen(string("test4.wav"), "r")                 '   <---------  Change .wav filename here !!!!!!!!!!!!!!      
      text.str(STRING("Opening: "))
      text.str(num.toStr(i,num#dec))
      text.out(13)
    
      'ignore the file header (so you better have the format right!)
      'See here for header format:  http://ccrma.stanford.edu/CCRMA/Courses/422/projects/WaveFormat/
      i:=sd.pread(@MonoData, 44) 'read data words to input stereo buffer
      text.str(STRING("Header Read ",13))
    
    
      'Start the player in a new cog
      COGNEW(Player(10, 11),@stack1)      'Play runs in a seperate COG (because SPIN is a bit slow!!)
      text.str(STRING("Playing...",13))
    
    
      'Keep filling buffers until end of file
      ' note:  using alternating buffers to keep data always at the ready...
      n:=buffSize-1
      j:=buffsize*2
      repeat while (j==buffsize*2)  'repeat until end of file
        if (buff1[noparse][[/noparse]n]==0)
          j:=sd.pread(@MonoData, buffSize*2) 'read data words to input stereo buffer   
          'fill table 1
          repeat i from 0 to n
             buff1[i]:=($8000+MonoData[i])<<16
        if (buff2[noparse][[/noparse]n]==0)
          j:=sd.pread(@MonoData, buffSize*2) 'read data words to input stereo buffer  
          'fill table 1
          repeat i from 0 to n
             buff2[i]:=($8000+MonoData[i])<<16
    
    
      'must have reached the end of the file, so close it
      text.str(STRING("Closing: "))  
      sd.pclose
      
      'shut down here
    
    PUB Player(PinR, PinL)|n,i,nextCnt,j
      'Play the wav data using counter modules
      'although just mono, using both counters to play the same thing on both left and right pins
    
      'Set pins to output mode
      DIRA[noparse][[/noparse]PinR]~~                              'Set Right Pin to output
      DIRA[noparse][[/noparse]PinL]~~                              'Set Left Pin to output
    
      'Set up the counters
      CTRA:= %00110 << 26 + 0<<9 + PinR         'NCO/PWM Single-Ended APIN=Pin (BPIN=0 always 0)
      CTRB:= %00110 << 26 + 0<<9 + PinL         'NCO/PWM Single-Ended APIN=Pin (BPIN=0 always 0)   
    
      'Get ready for fast loop  
      n--
      i:=0
      j:=true
      NextCnt:=cnt+1005000
    
        'Play loop
        'This loop updates the counter with the new desired output level
        'Alternates between buff1 and buff2 so main program can keep buffers full
        repeat 
          repeat i from 0 to buffSize-1
            NextCnt+=5000   ' need this to be 5000 for 16KSPS   @ 80 MHz
            waitcnt(NextCnt)
            if (j)
              FRQA:=buff1[i]~
              FRQB:=FRQA
            else
              FRQA:=buff2[i]~
              FRQB:=FRQA  
          NOT j
           
     
    
    {{
                                TERMS OF USE: MIT License
    
     Permission is hereby granted, free of charge, to any person obtaining a copy
     of this software and associated documentation files (the "Software"), to deal
     in the Software without restriction, including without limitation the rights
     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     copies of the Software, and to permit persons to whom the Software is
     furnished to do so, subject to the following conditions:
    
     The above copyright notice and this permission notice shall be included in
     all copies or substantial portions of the Software.
    
     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,ARISING FROM,
     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     THE SOFTWARE.
    }}
    
    
    [/i][/i][/i][/i][/i][/i]
    



    Oldbitcollector said...
    Piece of cake..

    Propeller WAV players from OBEX
    obex.parallax.com/objects/324/

    Be careful rigging that up.. Ohio laws (where I live) prohibit use of red or blue lights
    in any fashion (except obvious brake/tail lights) as they are used by emergency/police
    vehicles. Traveling with KITT lights could get you a ticket here..

    OBC
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-10-07 04:28
    turbosupra,

    You are correct about the number next to the nested repeat commands, it simply indicates how many times you want to repeat.

    Here is a slight variation of the code that allows you to select any number of contiguous pins and also increase the number of pins


    OBC,

    "...but I thought KITT had more PWM in the light movement that you used..." - I didn't use no 'stinkin LEDs' - you get that warm PWM effect with incandescent bulbs and a RED filter naturally.

    Good point though about putting this on a car now days... back then there was no such law in effect.


    Kitt lights
    CON
      _CLKMODE = XTAL1 + PLL16X
      _XINFREQ = 5_000_000
    
    
    Low = 4        'Lowest Pin number
    High = 9       'Highest Pin Number
      
    PUB Kitt|Switch                                         
        dira[noparse][[/noparse]High..Low] ~~                                  'Set Pins as OUTPUT
        outa[noparse][[/noparse]High..Low] := 1                                'Set Lowest pin HIGH and all the rest LOW
        repeat                                              'Endless repeat loop
          Switch ^= 1                                       'Toggle Switch value using XOR
                                                            '... equal to:  Switch := 1 - Switch
    
          repeat High-Low                                   'Based on the number of Pins used, repeat that number of times
            waitcnt(clkfreq/10 + cnt)                       'Wait 1/10th of a second
            if Switch == 1                                  
               outa[noparse][[/noparse]High..Low] <<= 1                        'If Switch == 1 shift high OUTPUT to next pin up
            else 
               outa[noparse][[/noparse]High..Low] >>= 1                        'If Switch == 0 shift high OUTPUT to next pin down
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • turbosupraturbosupra Posts: 1,088
    edited 2009-10-07 19:16
    Thanks Beau

    I figured out how to last night have 15 LED's cycling, I'll compare this code to my code when I get home



    Beau Schwabe (Parallax) said...
    turbosupra,

    You are correct about the number next to the nested repeat commands, it simply indicates how many times you want to repeat.

    Here is a slight variation of the code that allows you to select any number of contiguous pins and also increase the number of pins


    OBC,

    "...but I thought KITT had more PWM in the light movement that you used..." - I didn't use no 'stinkin LEDs' - you get that warm PWM effect with incandescent bulbs and a RED filter naturally.

    Good point though about putting this on a car now days... back then there was no such law in effect.


    Kitt lights
    CON
      _CLKMODE = XTAL1 + PLL16X
      _XINFREQ = 5_000_000
    
    
    Low = 4        'Lowest Pin number
    High = 9       'Highest Pin Number
      
    PUB Kitt|Switch                                         
        dira[noparse][[/noparse]High..Low] ~~                                  'Set Pins as OUTPUT
        outa[noparse][[/noparse]High..Low] := 1                                'Set Lowest pin HIGH and all the rest LOW
        repeat                                              'Endless repeat loop
          Switch ^= 1                                       'Toggle Switch value using XOR
                                                            '... equal to:  Switch := 1 - Switch
    
          repeat High-Low                                   'Based on the number of Pins used, repeat that number of times
            waitcnt(clkfreq/10 + cnt)                       'Wait 1/10th of a second
            if Switch == 1                                  
               outa[noparse][[/noparse]High..Low] <<= 1                        'If Switch == 1 shift high OUTPUT to next pin up
            else 
               outa[noparse][[/noparse]High..Low] >>= 1                        'If Switch == 0 shift high OUTPUT to next pin down
    
    

  • turbosupraturbosupra Posts: 1,088
    edited 2009-10-07 23:37
    Here is what I wrote, it appears yours is more modular? What do you think?

    
    
    '' Test Knight Rider Lights
    
    
    PUB KITT
        dira[noparse][[/noparse]15..4] ~~
        outa[noparse][[/noparse]15..4] := %10000000000
        repeat
          repeat 10
            waitcnt(clkfreq/11 + cnt)
            outa[noparse][[/noparse]15..4] >>= 1
          repeat 10
            waitcnt(clkfreq/11 + cnt)
            outa[noparse][[/noparse]15..4] <<= 1
    
    
    



    Beau Schwabe (Parallax) said...
    turbosupra,

    You are correct about the number next to the nested repeat commands, it simply indicates how many times you want to repeat.

    Here is a slight variation of the code that allows you to select any number of contiguous pins and also increase the number of pins


    OBC,

    "...but I thought KITT had more PWM in the light movement that you used..." - I didn't use no 'stinkin LEDs' - you get that warm PWM effect with incandescent bulbs and a RED filter naturally.

    Good point though about putting this on a car now days... back then there was no such law in effect.


    Kitt lights
    CON
      _CLKMODE = XTAL1 + PLL16X
      _XINFREQ = 5_000_000
    
    
    Low = 4        'Lowest Pin number
    High = 9       'Highest Pin Number
      
    PUB Kitt|Switch                                         
        dira[noparse][[/noparse]High..Low] ~~                                  'Set Pins as OUTPUT
        outa[noparse][[/noparse]High..Low] := 1                                'Set Lowest pin HIGH and all the rest LOW
        repeat                                              'Endless repeat loop
          Switch ^= 1                                       'Toggle Switch value using XOR
                                                            '... equal to:  Switch := 1 - Switch
    
          repeat High-Low                                   'Based on the number of Pins used, repeat that number of times
            waitcnt(clkfreq/10 + cnt)                       'Wait 1/10th of a second
            if Switch == 1                                  
               outa[noparse][[/noparse]High..Low] <<= 1                        'If Switch == 1 shift high OUTPUT to next pin up
            else 
               outa[noparse][[/noparse]High..Low] >>= 1                        'If Switch == 0 shift high OUTPUT to next pin down
    
    

  • edited 2011-07-17 23:23
    turbosupra,

    My first car in 1983 was a 1967 red firebird convertible ... I put KITT lights in the front grill and designed a mechanical rotor to control the lights. Wish I had a Stamp back then to play with.

    Kitt lights
    PUB KITT
        dira[noparse][[/noparse]9..4] ~~
        outa[noparse][[/noparse]9..4] := %100000
        repeat
          repeat 5
            waitcnt(clkfreq/10 + cnt)
            outa[noparse][[/noparse]9..4] >>= 1
          repeat 5
            waitcnt(clkfreq/10 + cnt)
            outa[noparse][[/noparse]9..4] <<= 1
    
    





    Why is it when i input this code and any other code that has outa[4..9] that the last two pins are left out?? in this case pins 8 and 9 dont light at all.
  • edited 2011-07-18 00:52
    ok... so I kinda figured out some info. If I reroute the outputs for the KITT code to pins 10-15 it works fine. Does the propeller chip have a problem jumping over the GND, BOEn, RESn, and 3.3v pins? also a weird thing, the full code does not execute (proper language?) heres how it looks when routed with pins 4..9 pin 4 (on,off) pin 5 (on,off) pin 6 (on,off) pin 7 (on,off) and thats it! it just keeps repeating that sequence. where as when i use pins 10-15 it acts just as KITT should and cycles back and forth. Any ideas?? sorry if this is hard to understand, its all hard for me to understand.
Sign In or Register to comment.