Author Topic: Does this make sense? Design question with micro  (Read 1167 times)

0 Members and 1 Guest are viewing this topic.

Offline rrinkerTopic starter

  • Super Contributor
  • ***
  • Posts: 2046
  • Country: us
Does this make sense? Design question with micro
« on: August 05, 2018, 01:54:35 am »
 My design has the following inputs and outputs:

2 pushbuttons, left and right
2 LEDs - left and right
1 servo output - push the left button, it moves to the left, push right button, it moves to the right
1 relay - arbitrarily configured but when the servo is left, the coil is not energized, when the servo is right, the coil is energized, since the left position is the more common.
I pin with a jumper that causes the servo to move to the center position if closed (jumper on)
2 input control lines coming from another circuit - one that locks out the pushbuttons so they do nothing, one that is a remote signal to move the servo

(2 complete sets of these I/Os)

 While the servo is moving, both LEDs are off, the left or right LED only lights when the servo completes travel.

 I want to add a second relay, contacts in series with the first relay's center contact, such that while the servo is moving, the coil is energized, cutting power to the contacts of the first relay. Once the servo reaches the end of travel, the first relay will be energized or de-energized, depending on position, and then this second relay would be de-energized, allowing power to flow through the NC contacts.

 Problem is, not enough output pins. I suppose I could add a shift register or port extender, but I also had the idea of possibly connecting the LED outputs also to a NOR gate and using that (with a transistor driver - unless there is a NOR gate with sufficient drive capacity to not need it) which would give me the correct logic - both LEDs off while the servo is moving would equal a high output on the NOR gate, turning the relay on. LEDs are active high.
 Does this make sense? Or is this just really bad design? This project is not for commercial use - although even if it's one of those "well, ok, but not something you'd do for production" I wouldn't want to do it. Switching to a different micro is kind of silly here - I am simply 2 lines short of being able to give the second relays their own dedicated outputs. I'm thinking so long as the total load on the LED output pin is well under the micro's limits, this should work fine at least from a technical point of view. My real question is, is this a reasonable design practice or should I investigate alternatives, like the port extender?
 
 

Offline MasterT

  • Frequent Contributor
  • **
  • Posts: 785
  • Country: ca
Re: Does this make sense? Design question with micro
« Reply #1 on: August 05, 2018, 02:13:06 am »
If uCPU has an adc, you can wire up 2 buttons and jumper (3 lines) to one adc input in "analog button" manner.
 

Offline Nusa

  • Super Contributor
  • ***
  • Posts: 2416
  • Country: us
Re: Does this make sense? Design question with micro
« Reply #2 on: August 05, 2018, 02:42:23 am »
What processor are we talking about?
I count 18 pins needed, even without pulling tricks.
The basic Arduino Uno has 20 (analog pins can be used as digital pins if that's what you configure them as).

Shift register with an ouput latch (e.g. 74595) is a pretty easy way to add output pins if you do need them.
As already mentioned, simple switch inputs can be put in an analog array. Or matrixed if you need a bunch.
LED's could be matrixed too, but with only 4 it's hardly worth it.
All the tricks require software support, of course.
 

Offline rrinkerTopic starter

  • Super Contributor
  • ***
  • Posts: 2046
  • Country: us
Re: Does this make sense? Design question with micro
« Reply #3 on: August 05, 2018, 04:17:06 am »
 It IS an ATMega328 - so yes, technically there are enough pins. However, as Paul Harvey (radio broadcaster of some note, to those not from the US) used to say, there's "the rest of the story"

 I really want to make the same circuit do double duty, depending on which components are populated - so i can spin just a single PCB for both variants. As described, this is the most common version. However (this is for a model railroad - I've actually shared an earlier iteration of the full schematic quite some time ago, just now getting back to it), there is another use where they will not have the 2 remote control inputs and the 2 button lockout inputs, as all control will be ONLY through the pushbuttons. That frees 4 pins, but that is not enough for another full set of 2 buttons, 2 LEDs, 2 relays, and a servo. 7 pins each (plus a centering jumper - but I would be fine with a single centering jumper that centers all 3 servos), so I need a total of 22 pins minimum. I have 20. Unless I switch to the QFP SMD version, which happens to have exactly 22 IOs. But I'm not comfortable with trying surface mount soldering with my vision issues, plus then I would need to add an ICSP header to the board to program it - I have a nifty programmer for the PDIP28 version with a ZIF socket and all. And face it, I'm just an old fart through-hole guy.

 I could just say the heck with it, and just make them all identical and drive two servos. That needs 14 pins, plus 4 for the remote IO in those so populated, and a centering jumper, plus a heartbeat LED, and I have exactly 20, the capacity of the PSIP AT328. With no fancy software tricks to multiplex inputs or outputs.

 If I go with port expanders, I could make one run 4 or 8 servos - but in many cases a lot of the outputs would go unused. I initially chose to have 2 servos per board both for the pin count available plus the fact that the most common usage would have 2 turnouts near each other, so rather than have one circuit with wires running all over to reach many turnouts, I would have more but simpler circuits distributed to where they are needed. This may be the best option of all - keep it simple. 


 

Offline Nusa

  • Super Contributor
  • ***
  • Posts: 2416
  • Country: us
Re: Does this make sense? Design question with micro
« Reply #4 on: August 05, 2018, 06:27:03 am »
The 2 extra pins on the QFP version of the 328p are analog-input-only pins, not full GPIO pins, so that might not help you much anyway.

You summed it up pretty well. You either use tricks or you keep it simple.
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: Does this make sense? Design question with micro
« Reply #5 on: August 07, 2018, 03:40:32 am »
There are tricks you can do to multiplex LEDs with switch inputs. In a nutshell you put a resistor in series with the switch so it can pull down the pin but not so much that it affects driving the LED. You turn the LED off just long enough to change the pin to an input and see if the switch is closed, then turn the LED back on. It can be done quickly enough that the blink is far too short to be visible.
 

Offline Muxr

  • Super Contributor
  • ***
  • Posts: 1369
  • Country: us
Re: Does this make sense? Design question with micro
« Reply #6 on: August 07, 2018, 03:50:05 am »
If you think you're low on pins for binary control (1/2, on/off) a common technique is to extend them with Shift Registers.

You can use this technique for both outputs [in your case LEDs] or inputs [buttons].

Look up SIPO shift registers.. Serial-in parallel-out.

And for inputs look up PISO shift registers.. Parallel-in Serial-Out.

You can find plenty of examples on how to make shift registers work with Arduino. Once you get the concept down it's fairly easy to use them.

For your particular use a PISO shift register 74LV165A is particularly nice since it also has Schmitt-trigger action at all inputs, which can debounce all your buttons as a nice added bonus.
« Last Edit: August 07, 2018, 03:52:58 am by Muxr »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf