Getting slightly beyond blinky - Page 1
Forum section: electronics / beginners

author: kfitch42
author_rank: Frequent Contributor
timestamp: July 22, 2016, 04:32:25 pm
content: I am finishing up going through the "Getting To Blinky 4.0" series of videos. My first board order has been sent to OshPark and I am eagerly awaiting its arrival so I can badly solder it together.That being said I have been thinking about what I want to do for my second board. I was thinking of something I could suction cup to the bathroom mirror. It would have a single button that you would push and it would light an LED for two minutes. Or maybe flash a bunch of LEDs (LEDs are like googly-eyes... more is always better). My hope is that it will help prevent the kids from skimping out on toothbrushing.While I could probably do this with a 555/556 (1 monostable for the 2-minutes and a bistable for the blinking), it would require a rather large capacitor and/or high value resistors that would make it somewhat impractical.That being said I went to digikey and found the cheapest micro that is in a package I think I could handle: PIC16F54. I threw together a quick schematic on upverter to flesh out the concept, and hoped someone might be willing to give some feedback. In particular I want to make sure I could program this in circuit (with a PICKIT) and the button would work ( I based it on the scematic I found here:http://ww1.microchip.com/downloads/en/DeviceDoc/41584A.pdf).I only put a few LEDs on the schematic, but I am leaning toward adding more (maybe 8 total), but I would not put any on the ICSP pins. I will probably limit it to lighting only 1 or two at a time.I am planning on powering it from a CR2032 or similar.I have also attached some pseudo code to run on the PIC.My expectation is that everytime the button is pressed it will start executing from the top of main, is this right?

author: Kleinstein
author_rank: Super Contributor
timestamp: July 22, 2016, 04:46:53 pm
content: A CR2032 is a little weak to power several (even if only one active) LEDs. So I would go for something like 3 or maybe 2 AA cells. With low voltage take care of the LED colors - blue ones might not work well with a 2.7 V supply.For a one off project one does not have to look for the absolute cheapest parts. For the µC it may be more helpful to use a common type, so it is easier to get help. I don't know the PIC, so maybe the 16F54 is still a good choice.

author: MosherIV
author_rank: Super Contributor
timestamp: July 22, 2016, 04:47:51 pm
content: HiMost microcontrollers cannot source more than 40mA from the GPIO ports total.You can get away with sinking current into the GPIO port pins instead.What this means is putting the LEDs the other way around and swapping the polarity of the bits in software.

author: Kilrah
author_rank: Unknown
timestamp: July 22, 2016, 04:50:38 pm
content: This looks like the PIC is always powered, so it will drain your battery even when unused (didn't check the datasheet, but you can look for the current draw in sleep mode).Might be better to have a "soft power switch" circuitry that allows the PIC to cut its own supply once it's done with its thing.

author: Kilrah
author_rank: Unknown
timestamp: July 22, 2016, 04:52:03 pm
content: Quote from: MosherIV on July 22, 2016, 04:47:51 pmHe said one or 2 LEDs powered at the same time at most, so should be all good. PIC GPIOs are usually symmetric too (haven't checked for that particular one though)

author: Ian.M
author_rank: Super Contributor
timestamp: July 22, 2016, 05:38:23 pm
content: PIC I/Os are generally NOT symmetric. Although their Abs Max rated current is typically the same for sourcing and sinking, they have much less voltage drop when sinking.The PIC16F54 is an absolutely horrible baseline part and requires an external crystal, RC timing network or clock source to even run. Instead, look at the Enhanced MidrangePIC16F1826. Although its about $0.60 more, you save the cost of a crystal and associated caps as it has an internal oscillator. It also has extremely low sleep mode current (under 100nA is possible) and built-in debug support which vastly eases development.

author: kfitch42
author_rank: Frequent Contributor
timestamp: July 22, 2016, 06:05:27 pm
content: Quote from: Kleinstein on July 22, 2016, 04:46:53 pmGood points. I am definitely planning to avoid blue or white LEDs. I have a pile of greens with a forward voltage around 2.2V that I was going to try first. If they don't cut it I will dig up (or order) some reds.As for the micro, you have a very valid point. What would you suggest? The ATMEGA328P? Even at $3-4 each (as opposed to < $0.50 for the PIC) they might be cheaper than the PIC since I won't have to buy a PICKIT to program it. I have an arduino laying around that can be used to program the atmega.Quote from: Kilrah on July 22, 2016, 04:50:38 pmI was trying to avoid the extra complexity of a soft power switch. Do you have a reference to one that is easy?According to the datasheet it pulls a max of 2.5 uA in sleep mode with the WDT disabled. Lets call a coin cell 200mAh.That is roughly 80000 hours or 9ish years in sleep. So that is probably good enough.Err, me no math good. Whats an order of magnitude amoung friendsOK, so more like 8000 hours or ~0.9 years. Not atrocious, but not great.Quote from: Ian.M on July 22, 2016, 05:38:23 pmHmm, I didn't notice the need for the external RC network the first time I read the data sheet. OK, I think everyone has convinced me to rethink my choice of micro.

author: ebclr
author_rank: Super Contributor
timestamp: July 24, 2016, 07:27:09 pm
content: Cd 40106Two resistor one low value capacitor, and you can blink a led on a very easy and cheap way

author: KL27x
author_rank: Super Contributor
timestamp: July 25, 2016, 07:09:28 pm
content: Your ICSP probably won't work for high voltage programming. When Vpp is applied, it will leak current through the pull up resistor to Vcc rail, and your Vpp will be low and/or it will draw too much current, and/or Vcc will be too high. And the programmer will give you a Vpp/Vcc error.When adding an external pullup to the MCLR/VPP, you can add a diode in series with the pullup, if you want to be able to do ICSP.

author: pyroesp
author_rank: Regular Contributor
timestamp: July 25, 2016, 07:43:41 pm
content: Quote from: KL27x on July 25, 2016, 07:09:28 pmFrom microchip pickit3 51126A.pdf :I don't think there will be any problem with HVP, altough I do add a diode to prevent Vpp to go to Vdd.Not sure at what voltages the 16F54 can work at but the Vf of the diode might drop the voltage @Vdd a bit too much.EDIT: 16F54 can be powered from 2 to 5.5V

author: Ian.M
author_rank: Super Contributor
timestamp: July 25, 2016, 08:12:26 pm
content: If you use a 10K pullup, all currently supported general purpose ICSP capable Microchip programmers or debuggers, sink sufficient current from Vdd to prevent it rising even with Vpp at its maximum. If you use a 4.7K pullup, its a little less certain, and some Microchip programmers aren't rated to drive a load of less than 5K on Vpp, so I would strongly recommend not going below 10K.

author: KL27x
author_rank: Super Contributor
timestamp: July 25, 2016, 11:05:21 pm
content: ^Maybe that diagram is just for LVP/debugging? I know that doesn't work on any of the baseline or midrange PICs I have used. With Microchip programmers. You need the diode, or you need to disconnect the pullup before you program the chip.TBH, I have never had the need on any of the newer PICs I use, because they all have an optional internal pullup on MCLR. Maybe same for you guys. And it's been so long, you have forgotten?http://ww1.microchip.com/downloads/en/DeviceDoc/31028a.pdfpage 4There's a diagram showing the diode, if you look it.QuoteOP, another thing to note is that the capacitor on MCLR. If you look at the circuit diagram I linked there's a cap.. but it's on the other side of the shottky. If your value of capacitor is too large, a PK3 won't work. PK2 can handle a lot more capacitance on MCLR line. Even a decoupling cap circa 0.1uF can make the PK3 go wonky and can cause you some grey hairs. It won't even register and error. "No device detected." And it will drive you bonkers. This would be a second, completely unrelated reason to put the diode in there, to prevent the cap from making MCLR rise slower. Because that's what causes the PK3 to work... sometimes.

author: Ian.M
author_rank: Super Contributor
timestamp: July 26, 2016, 12:32:00 am
content: DS31028A is seriously obsolete. It was written in 1997. Take its circuit advice with a large pinch of salt, especially when using newer devices or programmers.We had a discussion about ICSP/ICD compatible PIC reset circuits last year on the Microchip forum. Seehttp://www.microchip.com/forums/m692754.aspx

author: KL27x
author_rank: Super Contributor
timestamp: July 26, 2016, 01:46:24 am
content: Well, hell. I must have wasted hundreds of diodes somewhere in 2011!Last time I used a "dino PIC" in a project with any volume.I cut my teeth on a homemade variant of the TAIT in early 2000's. Certainly, the TAIT didn't have any ability to sink current on Vdd. Not my versions. I guess I never caught up, until now.

author: Ian.M
author_rank: Super Contributor
timestamp: July 26, 2016, 02:43:43 am
content: e.g. if you take a look at the PICkit 3 schematics, you will find R58, a 1K load resistor between Vdd_target and Vss, which provides sufficient load on Vdd to keep it from rising.If you need to use legacy ICSP programmers, its simple enough to add a similar load resistor, either as part of the programming cable or as a mod to the programmer.