Shop OBEX P1 Docs P2 Docs Learn Events
cylon eye sound — Parallax Forums

cylon eye sound

wirecutterwirecutter Posts: 22
edited 2011-02-07 11:32 in Propeller 1
does anyone have the code to create the cylon eye sound from the old series using 1 cog.
I was thinking of freq syth, as opposed to using a SD card.

wirecutter

Comments

  • TonyWaiteTonyWaite Posts: 219
    edited 2010-12-21 11:41
    Hi Wirecutter,

    Definitely do-able!

    Rayman has posted code for running soundfiles out of hub memory, so you could be up in minutes ...

    Here's the link from another thread:

    http://obex.parallax.com/objects/324/

    Regards,

    T o n y
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-12-21 13:08
    I wrote a version and then went to have a look at Ray's. By combining ideas from the two approaches I think you get the most flexibility and a "pop" that showed up in both original demos went away.

    In my version you can call the playsound() method with the pin to use for output, the address of an embedded WAV (8-bit, mono) file, and the number of times to play. If you set plays to 0 it will loop forever.

    The ZIP includes the project file and several versions of the WAV. The 22K sample (original) is too big to embed.
  • wirecutterwirecutter Posts: 22
    edited 2011-01-19 11:30
    Hello,
    been awhile since I been here. back to my project. I have the code from jonnyMac, its great. can someone replace the LED control section of the file "jm_Demo_Board_Cylon.spin" with this code (I don't know how to post code here yet:frown:). So I can get the 32 LEDs to sweep back and forth.
    PUB main | i
    dira[27..16] := %111111111111 'set the 12 portpins as output

    'write data from DAT to 12 port pins
    repeat
    repeat i from 0 to 63
    outa[27..16] := pattern1 'write word from DAT to port
    waitcnt(clkfreq/17 + cnt) 'short delay

    DAT
    pattern1 word %100000001000, %010000001000, %001000001000, %000100001000, %000010001000, %000001001000, %000000101000, %000000011000
    word %100000000100, %010000000100, %001000000100, %000100000100, %000010000100, %000001000100, %000000100100, %000000010100
    word %100000000010, %010000000010, %001000000010, %000100000010, %000010000010, %000001000010, %000000100010, %000000010010
    word %100000000001, %010000000001, %001000000001, %000100000001, %000010000001, %000001000001, %000000100001, %000000010001

    pattern2 word %000000010001, %000000100001, %000001000001, %000010000001, %000100000001, %001000000001, %010000000001, %100000000001
    word %000000010010, %000000100010, %000001000010, %000010000010, %000100000010, %001000000010, %010000000010, %100000000010
    word %000000010100, %000000100100, %000001000100, %000010000100, %000100000100, %001000000100, %010000000100, %100000000100
    word %000000011000, %000000101000, %000001001000, %000010001000, %000100001000, %001000001000, %010000001000, %100000001000

    ' a word has 16 bits, we use only the lower 12

    Thanks a bunch,
    wirecutter
  • wirecutterwirecutter Posts: 22
    edited 2011-01-19 19:23
    Hello,
    any help out there? I have tried several things but it always end up not working.

    thanks,
    wirecutter
  • StefanL38StefanL38 Posts: 2,292
    edited 2011-01-19 23:16
    Hi Wirecutter,

    my opinion about this forum is to learn. Not to ask for completed solutions.

    If you provide your code I will take a look inside and explain what's wrong and how to correct it.
    In the propellertool Choose from the mainmenu File - Archive-Project... and this will create a zip-file with all files that are nescessary to compile the code.

    Then you have to attach this code. Click on the "Go Advanced" button and upload the zip-file

    best regards

    Stefan
  • bsnutbsnut Posts: 521
    edited 2011-01-20 02:23
    I agree with Stefan's point on this. The goal is to learn from the posts.
  • wirecutterwirecutter Posts: 22
    edited 2011-01-20 07:20
    I am sorry if I came off in a bad way, Its just I have been working overtime, then trying to figure this out. I am so frustrated. I am at work now, so I will post with the code when I get home.

    Thanks for the info on posting code, just something else I needed to learn.

    wirecutter
  • wirecutterwirecutter Posts: 22
    edited 2011-01-20 10:25
    Hello,

    Attached is the latest code. this one only clicks, no lights, no sound other than repeat clicks. Perhaps I am still thinking on a DOS logic system, and not parallel processing. I seem to be able to get them to work as separate programs, but not together. what I am trying to do is to have the LED controller in cog0, and the wav player in cog1. perhaps its the cognew command? perhaps I am over designing again?. I am thinking of trying to separate the controls, and treat them as 2 parts instead of one. I am so confused :confused::blank::depressed:

    My hardware; 4 banks of 8 LEDs, common ground for each bank (see pic).
    There is 32 Leds total, P27-P20 control each LED in the bank, P19-P16 control which bank(module) is selected.

    The drive sequence:
    step 1.. P19 is high as P27-P20 sequence.
    step 2.. P18 then goes high and P27-P20 sequence again
    step 3.. P17 then goes high and P27-P20 sequence again
    step 4.. P16 then goes high and P27-P20 sequence again

    sequence reverses...

    step 5.. P16 then stays high and P20-P27 sequence
    step 6.. P17 then goes high and P20-P27 sequence again
    step 7.. P18 then goes high and P20-P27 sequence again
    step 7.. P19 then goes high and P20-P27 sequence again

    LED_module.jpg
  • SapiehaSapieha Posts: 2,964
    edited 2011-01-20 10:37
    Hi wirecutter

    Schematic You show in Yours post I think are not correct. If left side of it are same as Propeller ProtoBoad connector -- Last hole You have as small rectangle are +3.3V - hole before are GND.
    NEXT -- Never use LED's with Propeller without Current limiting resistors.

  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-01-20 11:05
    You'd do well to learn to output to a terminal for experimeinting -- saves having to connect things until you're ready (which prevents accidents). Since I don't have your hardware I wrote this little test ditty
    pub main | idx, row, col
    
      term.start(RX1, TX1, %0000, 115_200)
      pause(1)
    
      term.tx(CLS)
      term.str(string("Row/Col", CR, CR))
    
      repeat idx from 1 to 32
        row := %1000_0000 >> ((idx-1) & %111)
        col := %1000 >> ((idx-1) >> 3)
    
        term.bin(row, 8)
        term.tx(TAB)
        term.bin(col, 4)
        term.tx(CR)
    
        waitcnt(clkfreq / 200 + cnt)
    

    Once I saw the correct patterns in PST it was easy to create a method:
    pub out32(n)
    
    '' Enables one of 32 LEDs in matrix
    '' -- output is 0 (off), 1 to 32 (led on)
    
      outa[27..16]~                                                 ' clear to start
      dira[27..16]~~                                                ' all outputs
    
      if (n => 1) and (n =< 32)                                     ' if valid
        --n
        outa[27..20] := %1000_0000 >> (n & %111)
        outa[19..16] := %1000      >> (n >> 3)
    

    Easy-peasy. Now... I don't like to embed "magic numbers" in code but as you've defined them, they are in the method. The method also takes care of setting those pins to output mode.

    PS: Once you've modified code I've written for you -- as you have here -- please remove my name or use "based on code by..." so that I'm not held responsible for your changes (I have enough of my own trouble! <wink>).
  • wirecutterwirecutter Posts: 22
    edited 2011-01-20 11:08
    Hello,

    Sapieha, actual connection to the propeller is through resisters and NPN transistors. Attached is schematic if it helps. if it also means anything I am using the Propeller Professional Development Board, to work on the programing. The schematic is the final controller board that will be placed in the finished helmet.
    812 x 781 - 187K
  • SapiehaSapieha Posts: 2,964
    edited 2011-01-20 11:22
    Hi wirecutter.

    On last SCH -- It looks You have Propeller connected to RG1= 7805 = 5Volt -- Not good.
    Propeller are 3.3V device.
    Next -- Have connections to all GND, VCC-3-3V pins on propeller ---> important

    wirecutter wrote: »
    Hello,

    Sapieha, actual connection to the propeller is through resisters and NPN transistors. Attached is schematic if it helps. if it also means anything I am using the Propeller Professional Development Board, to work on the programing. The schematic is the final controller board that will be placed in the finished helmet.
  • wirecutterwirecutter Posts: 22
    edited 2011-01-20 11:33
    Hello,

    JonnyMac, where did you get the "term.tx(CLS)" and the other lines like that?
    I don't remember seeing the "term.XXX" in the propeller manual or the book I have on programing with spin.

    could you explain this line of code??
    " WavCog := cognew(playsound(10, @Cylon, 1), @stack) + 1 "

    and do I replace the entire PUB main block with the second code?
    where would I start to learn to output to a terminal (or are you referring to a demo board) for experimenting?

    sorry for all the big questions

    wirecutter
  • wirecutterwirecutter Posts: 22
    edited 2011-01-20 11:37
    Sapieha,

    My schematic is wrong :frown:

    my circuit capture program don't have the 3.3 volt regulator, so don't take the actual labels as fact. 3.3 volt to propeller, and 5 volt to LED transistors, and will be 10K ohms resistors between prop and transistor base.

    wirecutter
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-01-20 14:26
    wirecutter wrote: »
    JonnyMac, where did you get the "term.tx(CLS)" and the other lines like that?
    I don't remember seeing the "term.XXX" in the propeller manual or the book I have on programing with spin.

    In my program (attached) term is a serial object (fullduplexserial) and CLS is a constant for clearing the terminal window. You might want to start with the Propeller Education Kit Lab manual as it uses PST for output on most projects.
    wirecutter wrote: »
    could you explain this line of code??
    " WavCog := cognew(playsound(10, @Cylon, 1), @stack) + 1 "

    I could but I won't becuase you can lookup cognew in the manual and my source code is commented.
    wirecutter wrote: »
    and do I replace the entire PUB main block with the second code?

    No, that's a routine you insert into your application.

    wirecutter wrote: »
    where would I start to learn to output to a terminal (or are you referring to a demo board) for experimenting?

    As I indicated above, PEK Lab manual (download from Parallax) is a good place to start. The terminal program I'm using for my Propeller exeriments is PST (download from Parallax).
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-01-20 15:27
    wirecutter,

    You can also find the Propeller Education Kit Labs under the "Help" menu of the Propeller Tool.

    Jon has written some great artilcles for Nuts and Volts about programming the Propeller. Here's a link to the articles.

    Duane
  • wirecutterwirecutter Posts: 22
    edited 2011-01-21 06:23
    thanks everyone,
    time for more reading.

    wirecutter
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-01-21 09:44
    wirecutter,

    I hope you haven't given up on your project.

    I'm always hesitant to post code I haven't tried out myself but here I go anyway.

    Cylon32.spin

    I've changed Jon's code to control a 4 x 8 LED array (I think). From your schematic, it looks like the cathodes start with pin 16 and end at pin 20. The anodes start at pin 21 and end with pin 27. Right?

    I tried to keep the end LEDs from being on twice as long (since Jon did it that way).

    I moved the launching of the sound cog to outside of the main loop and set it to continous play.

    I don't use sound much myself yet, so I doubt I'll be much help if you have trouble with that part of the code.

    Let me know if the LEDs don't blink the way you want.

    It takes a bit to get ones head wraped around the Propeller but it's well worth the effort.

    What transistors are you using in your schematic? Are you sure they will work the way you intend?

    Do you have details on these LEDs? If they are relatively low power and you only need one at a time, you might not need the transistors. (The code I'm posting assumes you do have the transistors. It would need to changed to drive LEDs directly.)

    You can also control multiple LEDs with shift registers.

    Good luck,

    Duane
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-01-21 10:17
    With this method I provided earlier
    pub out32(n)
    
    '' Enables one of 32 LEDs in matrix
    '' -- output is 0 (off), 1 to 32 (led on)
    
      outa[27..16]~                                                 ' clear to start
      dira[27..16]~~                                                ' all outputs
    
      if (n => 1) and (n =< 32)                                     ' if valid
        --n
        outa[27..20] := %1000_0000 >> (n & %111)
        outa[19..16] := %1000      >> (n >> 3)
    

    ... all you have to do (from Main) is this:
    repeat
        for idx := 1 to 32
          out32(idx)
          waitcnt(clkfreq / 100 + cnt)
        for idx := 32 to 1
          out32(idx)
          waitcnt(clkfreq / 100 + cnt)
    

    Here's the updated program -- note that I had to test on my demo board so it may need some tweaks.
    -- jm_Cylon_32Leds.spin


    If he wanted to get fancy and support multiple pins on at the same time he could launch (with cognew) this multiplexer cog:
    pri out32bg(mask) | t, col, idx                                 ' launch with cog new
    
    '' Writes bits in mask to LEDs
    
      outa[27..16]~                                                 ' clear to start
      dira[27..16]~~                                                ' all outputs
    
      t := cnt
      repeat
        col := %1000
        repeat idx from 0 to 3
          outa[19..16] := %0000                                     ' blank output
          outa[20..27] := mask >> (idx << 3)                        ' load bank
          outa[19..16] := col >> idx                                ' enable
          waitcnt(clkfreq / 200 + cnt)                              ' 5ms
    

    With this one would pass a long (mask) that defines which bits are on (1) or off (0).
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-01-21 10:46
    Jon,

    Some how I forgot you already had fixed it for him. (How did I forget "Easy-peasy"?)

    Sorry about that.

    I'll have to look up a couple of items in your newer code. I don't understand all of it. (But I will.)

    Duane
  • wirecutterwirecutter Posts: 22
    edited 2011-01-21 16:45
    Hello,
    Duane Degn, I haven't given up on the project yet. I am still learning and I have a long way to go.
    I will have to wait till I get home to check the code, thanks jonnymac and Duane. I am currently reading the lab manual. The terminal program is that the one that came with the propeller tool? any manuals to help with it, other than the lab manual?

    thanks,
    wirecutter
  • wirecutterwirecutter Posts: 22
    edited 2011-01-22 05:49
    Hello,

    Had a chance to work with the new code from Jon and Duane. Jon's code works great. Duane's code worked but with only 4 LEDs out of the 8 in sequence, but it is repairable. I would like to thank everyone for the help. Now its back to the books and tear into Jon's code.

    wirecutter
  • wirecutterwirecutter Posts: 22
    edited 2011-02-07 11:32
    Hello everyone,

    I have been researching to find out how to use a potentiometer to control the speed of LED sequence in my project. The pot is on P5, and is a 10K with a .1uf capacitor. I attached the code I am using for this project, thanks Jon. In this line "delay := clkfreq / 1000 * (1507 / 32)" I believe the "1507" controls the speed of the LED sequence, raise to slower the speed. Anyone have a OBJ to do this?

    Edit.. I forgot to add that I have the RCTime OBEX and I am currently studying it.

    thanks
    jm_Cylon_32Leds - Archive [Date 2011.02.07 Time 14.20].zip
Sign In or Register to comment.