Need 4 modes with just 3 switches - need all modes to be selectable QUICKLY!


Closed Thread
Results 1 to 40 of 68

Hybrid View

  1. #1
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Just an update (since you've all been so kind to chime in with your ideas...many thanks!)

    Last night got home & thought ok....ok, so let's learn about timers - so I went to Darrel's site & saw the timer based flashing LED example....absolutely perfect for one of my other needs -so I went off on a slight (but related) tangent!!

    I have a tri-colour LED - ie a green & red LED (which obviously also gives amber if they're both switched on at the same time).....so three possible colours. But with four operational modes, I also need a visual representation to the player when in the the fouth mode - that'd be a flashing LED!

    Previously, I was checking regularly within the main code to see if the player had selected the 4th mode - and if so, I'd flash an led. But as Darrel has mentioned to on his site, it's tricky using this method to have a flashing LED with stable, regular interval flashes.

    So Darrel's solution was a breath of fresh air (thanks Darrel - again )

    I then got waylaid trying to work out some wayof getting my program, to 'remember' whether switch3 was last selected in 'mode 3' or 'mode 4' (I have an involved switching arrangement, where any of the 3 switches will turn the device on...once on, you can freely press another switch to move to ther other modes - but for user practicality, if the unit was switched on in mode3, then say switch 2 was pressed, when going back to switch 3, I'd reckon the player would want whichever mode he was last in with switch3 to be recalled - eeeuggh ...this is getting wordy & hard to describe so I'll digress!).

    Darrel...good idea about 'any two...no matter which two' ....I'll mull that one over (might be better than me having to learn about timers for my situation!!). The wierd thing is that even though some ideas seem fine, when you come you actually use them ....they're not so good. My earlier example about holding swith3 longer to enter mode 4 - it just doesn't fit in with the intended applicated - fast switching for a guitarist going hell for leather!


    Mike....all my switches use diodes.
    Last edited by HankMcSpank; - 6th August 2010 at 10:57.

  2. #2
    Join Date
    Aug 2005
    Location
    Michigan, USA
    Posts
    224


    Did you find this post helpful? Yes | No

    Default

    Hi Hank',

    Got a schematic we could look at? Maybe there's a way to recover an extra pin that you haven't thought of.

    How are you sampling and managing your switches? Polling them in a loop or polling them via periodic interrupt?

    Are you using two pins for that tri-color LED or are you using any pins for LED mode indicators? If so, you might consider reclaiming those pins and using one of them for the fourth switch, then mux' the mode LEDs with the switches.

    Regards, Mike
    Attached Images Attached Images  
    Last edited by Mike, K8LH; - 6th August 2010 at 14:03.

  3. #3
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Mike, K8LH View Post
    Hi Hank',

    Got a schematic we could look at? Maybe there's a way to recover an extra pin that you haven't thought of.

    Are you using two pins for that tri-color LED? Or are you using any pins for LED mode indicators?

    How are you sampling and managing your switches? Polling them in a loop or via periodic interrupt?

    Here's the switching part....



    (I know some consider it bad form, but I use the PIC's internal weak pullups, for no other reason than it saves space - and believe me, I need all the space I can get!)

    ...there are a few spare pins Pin on the 16f690, Pin 4 is somewhat restricted in its use, so I stay clear of it, Pin 9 is 'forsaken' so I can use that bit of track/pcb real estate to 'conduit' the +4.1V onwards to the rest of the PCB, Pins 6, 15, 16 & 19 are essentially 'landlocked' from a PCB track routing perspective

    Yes, I'm using two pins (pins 2 & 3) for driving the LED (must remember to order common anode LEDs next time, so I can sink current from the main 9V VCC rail vs the PIC's 4V.1 rail ...puts less demand on the 100mA LDO regulator I've used!)

    Re how am I sampling the switches? - using DT's mighty fine interupt routine.

    There is no room for a fourth switch - likewise no room for illuminated switches - I'm only using 6mm square momentary push switches because they're the only ones I can shoehorn in.

    The problem of course is the more 'modes' I offer (and it would be lovely to offer 6 or 7), is providing the guitarist with meaningful (rememberable) visual indication of the modes with just one LED ...green, amber & red is fine. ....squeezing in a 'flashing LED' for the extra mode is pushing it - any more modes, that it's going to be hell to remember what the LED is telling you! (& there's no room for a lcd, 7 seg display etc)

    To give you some idea of my challenge, the pcb 'real estate' is about 40mm x70mm x 5.5mm high (1.5" x 3" x 0.2" high) - in that space I have to fit 2 x 20SOIC, 1 x 8 SOIC, 1 POT, 4 switches (the fourth switch is not at all related to this circuit), one single coil guitar pickup (that I make myself), one chunky electrolytic....and this is all on single sided pcb (along with a whole heap of 1206 SMD components) - it's crammed!
    Last edited by HankMcSpank; - 6th August 2010 at 14:40.

  4. #4
    Join Date
    Aug 2005
    Location
    Michigan, USA
    Posts
    224


    Did you find this post helpful? Yes | No

    Default

    Oh my! Some pretty nasty self-imposed restrictions there Hank'.

    There are smaller switches (see below, just left of the machined socket). And if you think about it, that tri-color LED actually has four states (off, red, green, and yellow).

    Good luck on your project.

    ** added **

    Someone just wrote to ask about the driver for that mux'd switch & LED drawing so I'll add it here if nobody minds. And sorry for the C code (I don't have PBP)...

    The routine sets the four pins to inputs to read the switches. Standard 'parallel' switch state logic filters out all but a "new press" state while ignoring the other three states (for each switch). 1-of-N logic (only 1 mode on at any time) dictates that we save the "new press" pattern as the new "mode". Since a pressed switch could short out a pin that is set to output '1' we cannot turn off the inactive LEDs by outputting a '1' and so we leave those pins tri-stated (RC3..RC0 output latch bits are maintained at '0').

    Code:
     /*                                                                 *
      *  isr debounce & switch state management (1-of-N switch logic)   *
      *  using 8 to 32 msec interrupt intervals                         *
      *                                                                 *
      *  swnew  ____---____-----___    new switch sample                *
      *  swold  _____---____-----__    switch state latch               *
      *  delta  ____-__-___-____-__    changes, press or release        *
      *  newhi  ____-______-_______    filter out new release bits      *
      *                                                                 */
      trisc |= 0x0F;                // set RC3..RC0 to inputs
      swnew = ~portc;               // sample active lo switches
      swnew &= 0x0F;                // on RC3..RC0 pins
      swnew ^= swold;               // changes, press or release
      swold ^= swnew;               // update switch state latch
      swnew &= swold;               // filter out new release bits
      if(swnew)                     // if "new press"
        mode = swnew;               // save 1000,0100,0010, or 0001
      trisc ^= mode;                // light the correct mode LED
    Attached Images Attached Images  
    Last edited by Mike, K8LH; - 6th August 2010 at 15:29.

  5. #5
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    Maybe I've got something wrong, but wont there be an awful lot of current flowing through those diodes when the buttons are pressed? Or at least, as much as the PIC I/O pin can deliver.
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  6. #6
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Mike, K8LH View Post
    Oh my! Some pretty nasty self-imposed restrictions there Hank'.

    There are smaller switches (see below, just left of the machined socket). And if you think about it, that tri-color LED actually has four states (off, red, green, and yellow).

    Good luck on your project.
    Hi Mike, yes, there maybe smaller switches out there, but I couldn't find them - in this scenraio the shaft of the switch needs to extend at least 7 mm vertically....to clear the case top & leave enough protuding for a finger to press on (& I'm not the one imposing the restrictions - it's the guitar that is ...the unit slides under the strings!)

    Kamikaze47 - I'm using the PIC's own weak pullups internally (to save using pullup resistors externally) - so for all it looks to be, it's not a 'short' of 4.1V to ground through the diode when the switch is pressed, but a path as follows...

    4.1V->PIC Internal Weak Pullup->Diode-> ground. (most of the voltage is dropped across the internal weak pullup)

    (and not all the PIC's pins have weak pullups internally ...this was something else that imposed a restriction on me!)
    Last edited by HankMcSpank; - 6th August 2010 at 15:17.

  7. #7
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by HankMcSpank View Post
    Kamikaze47 - I'm using the PIC's own weak pullups internally (to save using pullup resistors externally) - so for all it looks to be, it's not a 'short' of 4.1V to ground through the diode when the switch is pressed, but a path as follows...

    4.1V->PIC Internal Weak Pullup->Diode-> ground. (most of the voltage is dropped across the internal weak pullup)

    (and not all the PIC's pins have weak pullups internally ...this was something else that imposed a restriction on me!)
    Ahh, right. I was assuming you were setting that pin high. Makes sense now.
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  8. #8
    Join Date
    Aug 2005
    Location
    Michigan, USA
    Posts
    224


    Did you find this post helpful? Yes | No

    Default

    What's the purpose of diodes D2-D4 and their connection to RA2, please?

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts