Shop OBEX P1 Docs P2 Docs Learn Events
Question About Circuit Simulation Programs — Parallax Forums

Question About Circuit Simulation Programs

NWCCTVNWCCTV Posts: 3,629
edited 2014-10-14 17:46 in General Discussion
Does anyone know of a free circuit simulation program that has RGB LED's within them? I am using these RGB LED's and I want to be able to simulate them to see if I can figure out why my continuous loop does not work. I have found the 4 Pin RGB LED's in Fritzing but I am not sure if Fritzing is suppose to simulate anything. If it is then I must be doing something wrong as I can not get the LED's to light up.

Comments

  • Heater.Heater. Posts: 21,230
    edited 2014-10-11 13:13
    I very much doubt you will find a simulator for the WS281x based LEDs. Or at least I have never heard of such a thing.

    Perhaps you can get some clues about creating the software to drive such LEDs from this nice video by Shahriar Shahramian on the SignalPath blog: https://www.youtube.com/watch?v=EXr2_zSfnFw&list=UUKxRARSpahF1Mt-2vbPug-g Where he goes through the creation of a driver for a ring of NeoPixels. And explains all the timing, and what you can get away with, as he goes.

    Perhaps rather than a simulator a scope or logic analyser on the pins would help debug your problems. Of course on can use other pins on a Prop as an analyser for free:)
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-10-11 13:58
    Andy, you probably ought to post your code.

    Which object are you using?

    These are some of AdaFruit's NeoPixel rings using code posted in this thread (the code uses JonnyMac's object).

    I made my own ring using the "B" version. My ring had the LEDs a bit closer together than the Adafruit ring.

    I attached the gerber files for my version of the ring to post #49 of the above mentioned thread.

    The code used to control the rings should also control the individual Adafruit LEDs.

    I think JonnyMac included a demo with his driver. His demo would probably be easier to understand than the "Hypno Rings" code.

    If you post your code, I'll take a look at it.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2014-10-11 14:40
    See this thread post#81. I have also tried Johnnymac's driver with pretty much the d=same results. The LED's will blink like they are suppose to but the loop stops after 5 or 6 sequences. I thought it was a power issue but I can not figure it out. I switched to pin 0 on my BOE board with the same results.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-10-11 15:02
    NWCCTV wrote: »
    See this thread post#81. I have also tried Johnnymac's driver with pretty much the d=same results. The LED's will blink like they are suppose to but the loop stops after 5 or 6 sequences. I thought it was a power issue but I can not figure it out. I switched to pin 0 on my BOE board with the same results.

    How set are you on using C?

    I think it's pretty clear you're having a software issue since the code someone else wrote apparently works.

    If you're set on using C, I'll still try to help but I'm more comfortable using Spin.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2014-10-11 15:07
    I think I figured the problem out but not sure why it works this way. When I program to RAM it only cycles 5 or 6 times. However, if I program to EEPROM it works like it is suppose to. Anyone know the reason for this?
  • NWCCTVNWCCTV Posts: 3,629
    edited 2014-10-11 15:31
    What I am wanting to do is to be able to have my 6 LED's light up one after another with various colors of the rainbow. So, LED 1 would be red, then go green and LED 2 would be red, and so on. I want to be able to easily add colors based on the RGB Table here. I do not care if it is SPIN or SimpleIDE, I just would like the color chasing option and also the option to add and remove various colors. I am able to use the program David Betz created here but when using colors I define all 6 LED's light up with the same color at once.
  • xanaduxanadu Posts: 3,347
    edited 2014-10-12 09:34
    NWCCTV wrote: »
    I think I figured the problem out but not sure why it works this way. When I program to RAM it only cycles 5 or 6 times. However, if I program to EEPROM it works like it is suppose to. Anyone know the reason for this?

    The RAM needs power to stay alive, the prom does not. A brownout will erase RAM and the program will no longer run.

    This is a very common problem for me, and I usually include a reboot warning at the top of my code that executes in a very obvious way. A dedicated pin with a piezo speaker is usually the best way.
    reboot warning
    initialization routines
    program
    
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-10-12 09:36
    xanadu wrote: »
    The RAM needs power to stay alive, the prom does not. A brownout will erase RAM and the program will no longer run.

    This is a very common problem for me, and I usually include a reboot warning at the top of my code that executes in a very obvious way.

    I was thinking the same thing.

    Andy, I'm working on a simple demo for your six LEDs. Hopefully I'll post it soon.

    What are you using as a power supply?
  • xanaduxanadu Posts: 3,347
    edited 2014-10-12 09:57
    These LEDs require a lot of care with power and signal. You will not have much luck without a good operating environment. They are very demanding of clean power and signal. I can't think of anything else I've used that was less forgiving.

    I would find a high current 5v DC source, tie the ground with your board and use it only for the LEDs.

    Also these LEDs retain their last setting when they lose signal, and that can complicate debugging. Sometimes I "reboot" the strip by killing power to it and I get different results. I read a lot of stuff online where people think their code is "locking up" when it seems to me it's just a lost signal.

    Anyway, keep playing with it and get used to all that stuff and be able to identify it. It helps a lot.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-10-12 10:49
    xanadu wrote: »
    These LEDs require a lot of care with power and signal. You will not have much luck without a good operating environment. They are very demanding of clean power and signal. I can't think of anything else I've used that was less forgiving.

    I agree but a few LEDs usually will run off of USB power.

    The attached code drew about 200mA on with the Activity Board using six LEDs.
    CON                                                                         
      _CLKMODE = XTAL1 + PLL16X                              
      _XINFREQ = 5_000_000
    
    
      CLK_FREQ = ((_clkmode - xtal1) >> 6) * _xinfreq
      MS_001   = CLK_FREQ / 1_000
      US_001   = CLK_FREQ / 1_000_000
    
    
      LED_PIN = 17     'prop port for di pin on ws2812's
    
    
      TOTAL_LEDS = 6
      MAX_LED_INDEX = TOTAL_LEDS - 1
      COLORS_IN_TABLE = 6
      MAX_COLOR_INDEX = COLORS_IN_TABLE - 1
    
    
    OBJ
    
    
      Leds : "jm_ws2812"
      Pst : "Parallax Serial Terminal"
                       
    PUB Main | addr, localIndex
        
      Leds.start(LED_PIN, TOTAL_LEDS)
      Pst.Start(115_200)  
    
    
      Leds.set_all(0)
      waitcnt(clkfreq / 4 + cnt)      
      MainLoop
      
    PUB MainLoop | ledIndex, tableIndex, firstColorIndex
    
    
    
    
      ledIndex := 0
      firstColorIndex := 0
      tableIndex := firstColorIndex
      
      repeat
        Leds.set(ledIndex, colorTable[tableIndex])
        ledIndex := AddWithRollover(ledIndex, 1, MAX_LED_INDEX)
        Pst.str(string(13, "ledIndex = "))
        Pst.dec(ledIndex)
        Pst.str(string(", tableIndex = "))
          Pst.dec(tableIndex)  
        if ledIndex == 0 '' Back at the start so use a differnt first color
          firstColorIndex := AddWithRollover(firstColorIndex, 1, MAX_COLOR_INDEX)
          tableIndex := firstColorIndex
          Pst.str(string(", firstColorIndex = "))
          Pst.dec(firstColorIndex)
        else  
          tableIndex := AddWithRollover(tableIndex, 1, MAX_COLOR_INDEX)
        
        waitcnt(clkfreq / 4 + cnt)  
    
    
    PUB AddWithRollover(presentValue, amountToAdd, maxValue)
    '' Assumes all parameters are positive.
    
    
      result := presentValue + amountToAdd
    
    
      if result > maxValue
        result := 0
     
    DAT ' color table
                                 ' red       yellow        green                blue
    colorTable              long $FF_00_00, $7F_7F_00, $00_FF_00, $00_7F_7F, $00_00_FF, $7F_00_7F
    
    
    

    The main loop sends one of the colors listed in "colorTable" to the a LED.

    @Andy, Let me know if this is close to what you want the LEDs to do.
  • xanaduxanadu Posts: 3,347
    edited 2014-10-12 11:41
    Annnnd I'm blind. Nice effect, are your first and last LEDs going completely out as it cycles through?
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-10-12 12:13
    xanadu wrote: »
    Annnnd I'm blind. Nice effect, are your first and last LEDs going completely out as it cycles through?

    The only time the LEDs are off is at the very beginning of the program.

    I'm uploading a video showing the code in action on an Activity Board.

    [video=youtube_share;T7QYz8MkuR8]

    YouTube says it will take another 21 minutes before it's available.

    The video is now available.

    My camera has a hard time with these LEDs. I used a sheet of white paper to diffuse the light a bit when I made the videos embedded in post #3. The white paper makes the colors easier to see but the camera still fails to capture how cool these things look.
  • xanaduxanadu Posts: 3,347
    edited 2014-10-12 12:45
    Interesting. I'm using a 12 LED section of the strip mounted type. If the code doesn't use all of the LEDs in the strip the first and last LED of the strip act strange.

    Do you get that effect?

    Edit: Never mind, it was my signal wire going to the strip. Seems a few inches too long causes some interesting effects lol.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-10-12 13:19
    xanadu wrote: »
    Edit: Never mind, it was my signal wire going to the strip. Seems a few inches too long causes some interesting effects lol.

    So I take it you haven't changed your mind about the following?
    xanadu wrote: »
    I can't think of anything else I've used that was less forgiving.

    If you have a ring of these, I hope you've given my "MirroredWheels" program a try.

    You'd just need to change:
    LEDS_IN_RING = 16
    

    To 12 and:
    RINGS_IN_USE = 3
    

    To 1 (assuming you're only using one ring).

    The program is attached to post #2 of my "Fun with NeoPixels" thread.
  • xanaduxanadu Posts: 3,347
    edited 2014-10-12 13:54
    I did see that, I have used it in some home lighting, thank you!

    Sometimes I don't take my own advice out of sheer laziness. I spent some time soldering leads and a connector to the strip and it was hard to bring myself to redo it. It seemed to me like it should be fine.

    This is also very interesting and reveals some key components of prior headaches when the same strip was on my robot. I have measured the max length of the signal wire between the Propeller's pin and the first LEDs DI pin to be around 5" before there is a problem. I think this is why I thought level shifters were required, I had never really used these without a signal wire.

    Does this seem right? Can you test using a longer signal wire to the strip please?
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-10-12 15:16
    xanadu wrote: »
    Can you test using a longer signal wire to the strip please?

    I linked several servo extension wires together to make a wire just under three feet long and the LEDs didn't have a problem.

    I've noticed big changes in how well these LEDs work when using different power supplies. I think they're very susceptible to noisy power.

    In the Fun Board thread, there was talk about powering the LEDs with 3.3V. I haven't tried this myself but I plan to.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2014-10-12 15:34
    @Duane, perfect!!!! Also, I mentioned in post# 3 that all works well when I send the program to EEPROM. It is only when I send to RAM that I have a problem. Also, with your code, how do I add more colors or is that not possible?
  • xanaduxanadu Posts: 3,347
    edited 2014-10-12 15:47
    Thanks. It was my bench power supply. 'ol trusty...
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-10-12 16:54
    NWCCTV wrote: »
    @Duane, perfect!!!! Also, I mentioned in post# 3 that all works well when I send the program to EEPROM. It is only when I send to RAM that I have a problem.

    This is usually an indicator your Propeller is resetting. (Which is why I asked about the power supply in post #9.)
    NWCCTV wrote: »
    Also, with your code, how do I add more colors or is that not possible?

    You can add as many colors as you like to the colorTable arrray.
    DAT ' color table
                                 ' red       yellow        green                blue
    colorTable              long $FF_00_00, $7F_7F_00, $00_FF_00, $00_7F_7F, $00_00_FF, $7F_00_7F
    

    You need to change the constant "COLORS_IN_TABLE" so the program knows how many colors are in the table.
    COLORS_IN_TABLE = 6
    

    I'm working on a demo of my "MergeColors" method. The MirroredWheels program uses this method to filling the colors of the rainbow. I'll post the demo once it's finished.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2014-10-12 19:17
    Gotcha. I have actually tried several types of power. I used a 12V wall wart connected to a 3.3V/5V bread board PS. When that did not work I used a 5V 1.5 A Wall Wart with the same results. I have tried with and without various resistors and with and without a 10uf cap.
  • xanaduxanadu Posts: 3,347
    edited 2014-10-14 17:46
    Add a piezo speaker to a pin and make it beep once when the program initializes for a reboot warning. There's nothing saying it's a brownout until you do that anyway.
Sign In or Register to comment.