Shop OBEX P1 Docs P2 Docs Learn Events
Looking for suggestions for a blinking led object or method — Parallax Forums

Looking for suggestions for a blinking led object or method

Don MDon M Posts: 1,652
edited 2012-10-31 08:52 in Propeller 1
In my latest project I'd like to utilize an led indicator (or maybe several) to indicate various modes or status of operation. I know how to blink an led in a repeat loop but how do I go about blinking an led (or leds) without having the repeat loop tied into the Main repeat loop? Do I need to have it run in its own cog and then pass parameters to it?

An example might be to indicate if an SD card is mounted and open. Or if data was being written to an SD card. One indication might be a solid on light whereas the writing mode might be a flashing mode. If there were an error maybe a predefined series of flashes to indicate the fault, etc....

Any suggestions or examples welcome.

Thanks.
Don

Comments

  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2012-10-31 06:05
    Hi Don M;

    You could blink the LED using the NCO counter in PWM mode.
    Once started the NCO runs independently until changed.

    Note! Each cog has 2 of these.

    Duane J
  • Don MDon M Posts: 1,652
    edited 2012-10-31 06:13
    Sorry for my ignorance here- what's "NCO" ? Is there an object for that?
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2012-10-31 06:29
    This should help:
    App Notes/AN001 Propeller P8X32A Counters

    And "NCO" = "Numerically Controlled Oscillator".

    A really cool effect is to put a slightly different frequency in the 2 counters and have both output on the same pin.
    Now the LED will slowly fade on and off.

    Duane J
  • Don MDon M Posts: 1,652
    edited 2012-10-31 07:11
    I was looking in the Propeller manual and didn't see mention of it (NCO) so then I turned to the PEK manual and see there was some discussion. I'll also have a look at the App note you mentioned.

    My homework for this morning...

    Thanks for your suggestion.
  • Don MDon M Posts: 1,652
    edited 2012-10-31 07:15
    A really cool effect is to put a slightly different frequency in the 2 counters and have both output on the same pin.
    Now the LED will slowly fade on and off.

    Duane J

    I did a Google search on the forum and came up with a MultiCogTwinkleDemo from Duane Degn, Rick Post and Kye. I ran that on the Quickstart board and while it is neat it's not quite what I was looking for. That's what gave me the initial idea that I maybe needed to run it (my method) in it's own cog.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-10-31 07:24
    Don,

    I have an object that will flash any number of LEDs at any rate for as many times as you want but it does use a cog.

    I think the object I just linked to is better than the "twinkle demo" one (though I don't remember what the twinkle one does).
  • Mike GMike G Posts: 2,702
    edited 2012-10-31 07:28
    The Propeller Education Kit has LED toggle examples starting on page 45. Page 70+ goes into Methods and COGs.

    You can find source code is in the Demo folder of the Propeller Tool install.

    You can find the PE kit in the Propeller Tool Help menu.
  • Don MDon M Posts: 1,652
    edited 2012-10-31 08:04
    Duane J- I played a bit with your suggestion on the Quickstart...
    CON
    
      _clkmode = xtal1 + pll16x     'Establish speed
      _xinfreq = 5_000_000          '80Mhz
    
      LED1 = 16                     ' LED's on Quickstart board       
      LED2 = 17
      LED3 = 18
      LED4 = 19
      LED5 = 20
      LED6 = 21
      LED7 = 22
      LED8 = 23
      
    PUB NCO_single_ended_mode
    
      ctra  := %00100_000 << 23 + 1 << 9 + LED1
      frqa  := 300
      dira[LED1] := 1
    
      repeat
      
    

    It works pretty slick however I am wondering why I need the "repeat". Your initial comment- "Once started the NCO runs independently until changed" had me thinking that it would run without a repeat. Unless my program is wrong somehow. I don't understand.

    @Duane Degn- That is exactly what I was looking for! Thanks for that.
  • JonnyMacJonnyMac Posts: 9,108
    edited 2012-10-31 08:40
    If you want to do a very simple coded output from a single LED you can do it in a Spin cog like this:
    pri blinker(pin, bpntr) | blinks, t
    
      outa[pin] := 0                                                ' clear pin
      dira[pin] := 1                                                ' make output
    
      repeat
        repeat
          blinks := long[bpntr]                                     ' get blink count
        until (blinks > 0)
    
        t := cnt                                                    ' sync
        repeat blinks
          outa[pin] := 1                                            ' on
          waitcnt(t += (clkfreq >> 3))                              ' 1/8th (125ms)
          outa[pin] := 0                                            ' off
          waitcnt(t += (clkfreq >> 3))                              ' 1/8th (125ms)
        waitcnt(t += clkfreq << 1)                                  ' finish 2s cycle
    


    Of course, you'll need to define a stack (16 longs is plenty) and create a variable that you will set (0 = off). Launch like this:
    cognew(blinker(16, @blinkcode), @stack)
    


    The code shown blinks the code every 2 seconds but is easy to adjust.

    For my professional projects I tend to use two pins and a Red-Green LED with a bicolor driver (I wrote about this in my Nuts & Volts column). The bicolor driver allows me to do color coded single and dual-color blinking. It's very effective. That driver, of course, is written in PASM
  • Don MDon M Posts: 1,652
    edited 2012-10-31 08:49
    JonnyMac wrote: »
    For my professional projects I tend to use two pins and a Red-Green LED with a bicolor driver (I wrote about this in my Nuts & Volts column). The bicolor driver allows me to do color coded single and dual-color blinking. It's very effective. That driver, of course, is written in PASM

    Do you remember which issue / column in N & V? I'll have a look at that.

    Edit: I found it. Column #1 July 2009...
  • JonnyMacJonnyMac Posts: 9,108
    edited 2012-10-31 08:52
    July 2009. Note that the PASM code is not to the same spec I write to today (i.e., only works with Spin, may not be compatible with GCC) but it does work. I have used it in several EFX-TEK products with great success.
Sign In or Register to comment.