0
\$\begingroup\$

Not great at electrical engineering, doing this for a school project. my circuit Tried using a 4013b, but output voltage is fluctuating, which resets the microcontroller (essentially it keeps turning on and off). Was wondering if there was any easy enough way to have the PTM switch toggle the power input of the microcontroller with a consistent voltage.

\$\endgroup\$
13
  • 3
    \$\begingroup\$ Contact bounce is a likely culprit. Try putting 10 nF across R5 and please do put 100 nF on the MCU supply line to ground. \$\endgroup\$
    – Andy aka
    Feb 10, 2022 at 8:57
  • 3
    \$\begingroup\$ There is no easy way. The CMOS 4013B chip output is extremely weak and is not intended to be a source of power to a subsystem which draws a lot of power (microcontroller and the LEDS) compared to how weak the output is. \$\endgroup\$
    – Justme
    Feb 10, 2022 at 9:05
  • \$\begingroup\$ what should I use instead of the 4013b? \$\endgroup\$
    – bbqribs
    Feb 10, 2022 at 9:06
  • \$\begingroup\$ @Justme "No easy way", well, a high side switch transistor isn't very advanced. \$\endgroup\$
    – Klas-Kenny
    Feb 10, 2022 at 9:06
  • \$\begingroup\$ @Klas-Kenny how should i integrate the high side switch transistor, and would it even work in my circuit? \$\endgroup\$
    – bbqribs
    Feb 10, 2022 at 9:08

1 Answer 1

0
\$\begingroup\$
  • You need a stable 5V to power all of this. I don't know what this "5V battery" is supposed to be but batteries can't provide a steady voltage. You'll need a voltage regulator between the battery and the digital logic.

    Depending on what battery voltage range you can expect, it will either have to be a step-down or step-up regulator, which aren't trivial to design, so I'd strongly recommend getting something pre-made. It needs to be able to source at least some ~200mA by the look of this schematic.

  • Toggling a MCU on/off with a switch by cutting its supply isn't really recommended. Better to use the /reset pin for such, or better yet, take the switch as a GPIO input pin. Also, if there's a microcontroller, then the flip flop function could as well be achieved by the software.

  • There is just no way you can source a MCU plus all of those LEDs through a plain standard flip flop. A 4013B can only source a few mA, you need some 50 to 100 times that current, depending on how much the MCU and LEDs draw. You could in theory have the flip flop activate a BJT which supplies the MCU, but it's still questionable design.

  • Can the MCU source enough current for those LEDs? You need to look at current sourcing abilities per pin as well as the total current sourcing. If it can't source it, you'll need something in between which can, like a LED driver or some octal buffer IC. Always mind the LED forward voltages when deciding how to drive them.

  • All switches come with an electromechanical signal bounce. "Debouncing" is typically addressed in the first embedded beginner classes, so there should be plenty of material regarding it on the web. The easiest solution for it in hardware is a RC low pass filter.

  • All integrated circuits need decoupling caps close to their supply pin. 100nF is standard, unless the MCU datasheet says otherwise.

\$\endgroup\$
9
  • \$\begingroup\$ the MCU is capable of powering the LEDs, as it was working before when connected to a much simpler SPST switch. And about the software solution, I have tried connecting the output of 4013b to a digital input pin on MCU, but realised that I couldnt continuously check if the input was high or low, so would have to awkwardly check inbetween areas in my code. My school also makes us use flowcharts for the coding, which I still don't fully know all syntax for. \$\endgroup\$
    – bbqribs
    Feb 10, 2022 at 9:41
  • \$\begingroup\$ @bbqribs "It's working" doesn't prove anything, that's not how engineering works. It might work today and burn up tomorrow. You need to check how much current it can source, there is no way around it. \$\endgroup\$
    – Lundin
    Feb 10, 2022 at 9:43
  • \$\begingroup\$ solved the issue I was having in software, also how would i ensure that it doesn't "burn up"? \$\endgroup\$
    – bbqribs
    Feb 10, 2022 at 10:01
  • \$\begingroup\$ @bbqribs By reading the datasheet of the MCU. Below electrical characteristics somewhere (might be called IO or GPIO characteristics), it will be stated how much maximum output current in mA each pin can source, as well as how much the whole MCU can source. Similarly, it should state how much it can sink - some MCUs can sink more current than they can source, and then you have the alternative option to connect the LED anodes to +5V, LED cathode to MCU pins, then have the MCU pulling them to ground (zero). \$\endgroup\$
    – Lundin
    Feb 10, 2022 at 10:09
  • \$\begingroup\$ Basically, quality MCU GPIO can source/sink 20mA per pin, which is kind of an industry standard. Lower quality GPIO peripherals can maybe source some 5-6mA and then you have to be very careful with how you drive the LEDs. \$\endgroup\$
    – Lundin
    Feb 10, 2022 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.