Author Topic: Getting slightly beyond blinky  (Read 2389 times)

0 Members and 1 Guest are viewing this topic.

Offline kfitch42

  • Frequent Contributor
  • **
  • Posts: 299
  • Country: us
Getting slightly beyond blinky
« on: July 23, 2016, 02:32:25 am »
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?
 

Online Kleinstein

  • Super Contributor
  • ***
  • Posts: 4716
  • Country: de
Re: Getting slightly beyond blinky
« Reply #1 on: July 23, 2016, 02:46:53 am »
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.
 
The following users thanked this post: kfitch42

Offline MosherIV

  • Frequent Contributor
  • **
  • Posts: 989
  • Country: gb
Re: Getting slightly beyond blinky
« Reply #2 on: July 23, 2016, 02:47:51 am »
Hi

Most 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.
 
The following users thanked this post: kfitch42

Online Kilrah

  • Supporter
  • ****
  • Posts: 1517
  • Country: ch
Re: Getting slightly beyond blinky
« Reply #3 on: July 23, 2016, 02:50:38 am »
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.
 
The following users thanked this post: kfitch42

Online Kilrah

  • Supporter
  • ****
  • Posts: 1517
  • Country: ch
Re: Getting slightly beyond blinky
« Reply #4 on: July 23, 2016, 02:52:03 am »
Most microcontrollers cannot source more than 40mA from the GPIO ports total.
He 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)
 
The following users thanked this post: kfitch42

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 7079
Re: Getting slightly beyond blinky
« Reply #5 on: July 23, 2016, 03:38:23 am »
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 Midrange PIC16F1826.  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.
 
The following users thanked this post: kfitch42

Offline kfitch42

  • Frequent Contributor
  • **
  • Posts: 299
  • Country: us
Re: Getting slightly beyond blinky
« Reply #6 on: July 23, 2016, 04:05:27 am »
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.

Good 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.


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.
I 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 friends :) OK, so more like 8000 hours or ~0.9 years.  Not atrocious, but not great.

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 Midrange PIC16F1826.  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.

Hmm, 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.
« Last Edit: July 23, 2016, 04:18:47 am by kfitch42 »
 

Offline ebclr

  • Super Contributor
  • ***
  • Posts: 1637
  • Country: 00
Re: Getting slightly beyond blinky
« Reply #7 on: July 25, 2016, 05:27:09 am »
Cd 40106

Two resistor one low value capacitor, and you can blink a led on a very easy and cheap way
 

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 2620
Re: Getting slightly beyond blinky
« Reply #8 on: July 26, 2016, 05:09:28 am »
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.
« Last Edit: July 26, 2016, 05:14:36 am by KL27x »
 
The following users thanked this post: kfitch42

Offline pyroesp

  • Regular Contributor
  • *
  • Posts: 163
  • Country: be
    • http://www.nicolaselectronics.be/
Re: Getting slightly beyond blinky
« Reply #9 on: July 26, 2016, 05:43:41 am »
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.

From 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
« Last Edit: July 26, 2016, 05:46:55 am by pyroesp »
 
The following users thanked this post: kfitch42

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 7079
Re: Getting slightly beyond blinky
« Reply #10 on: July 26, 2016, 06:12:26 am »
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.
 
The following users thanked this post: kfitch42

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 2620
Re: Getting slightly beyond blinky
« Reply #11 on: July 26, 2016, 09:05:21 am »
^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.pdf
page 4

There's a diagram showing the diode, if you look it.
Quote
The MCLR/VPP pin is normally connected to an RC circuit. The pull-up resistor is tied to VDD and
a capacitor is tied to ground. This circuit can affect the operation of ICSP depending on the size
of the capacitor since the VPP voltage must be isolated from the rest of the circuit (in most cases
a resistor is not capable of isolating the circuit).
It is, therefore, recommended that the circuit in
Figure 28-1 be used when an RC is connected to MCLR/VPP. The diode should be a Schottky-
type device.
Another issue with MCLR/VPP is that when the PICmicro device is programmed,
this pin is driven to approximately 13V and also to ground. Therefore, the application circuit must
be isolated from this voltage provided by the programmer.

OP, 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.
« Last Edit: July 26, 2016, 09:41:51 am by KL27x »
 
The following users thanked this post: kfitch42

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 7079
Re: Getting slightly beyond blinky
« Reply #12 on: July 26, 2016, 10:32:00 am »
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. See http://www.microchip.com/forums/m692754.aspx
 
The following users thanked this post: kfitch42

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 2620
Re: Getting slightly beyond blinky
« Reply #13 on: July 26, 2016, 11:46:24 am »
Well, hell. I must have wasted hundreds of diodes somewhere in 2011!   :-DD 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.
« Last Edit: July 26, 2016, 11:54:22 am by KL27x »
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 7079
Re: Getting slightly beyond blinky
« Reply #14 on: July 26, 2016, 12:43:43 pm »
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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf