Schematic question - The proper way of connecting a PIC microcontroller - Page 1
Forum section: electronics / general

author: newtekuser
author_rank: Frequent Contributor
timestamp: September 12, 2021, 06:24:42 pm
content: How should I interpret this schematic in respect to the 10K resistor and Ddd/Vcc pins in the attached picture? It's clear that the MCLR pin is connected to the 10K resistor, but are Ddd/Vcc also connected to the 10K resistor?Looking at the junctions (dots), I reckon that Ddd and Vcc pins are connected to the 10K resistor, or maybe I just don't understand reading basic schematics. (I must admit I'm a beginner)

author: SL4P
author_rank: Super Contributor
timestamp: September 12, 2021, 06:40:48 pm
content: The resistor isn’t the relevant part you should be considering…The top ‘rail’ is the logic +supply, and the +Vdd pins are tied to that rail.The RESET pin is ‘pulled up’ to the supply via the 10K - until the push button -drags it- momentarily to 0V/ground, to effect the ‘reset on low’ feature.

author: David Hess
author_rank: Super Contributor
timestamp: September 12, 2021, 06:46:43 pm
content: Connections between crossing lines are only made where there is a dot.-MCLR (it is marked wrong, the "-" means active low), is connected to the junction of the 10 kilohm resistor and the switch. Ddd and Vdd are connected to 5 volt Vcc.

author: newtekuser
author_rank: Frequent Contributor
timestamp: September 12, 2021, 10:17:53 pm
content: Thank you both! Looks like I read the diagram wrong. So, the 10K resistor, Vdd and Ddd are connected to the common Vcc rail, but only the MCLR pin and the lead of the push button are connected to the 10K resistor.On the same token, the 100uF cap, voltage regulator and 10uF cap are all connected to the common Vss and Vcc rails and not that the 10uF cap and voltage regulator are connected both to the 100uF cap... not sure why I interpreted the diagram this way, probably because I'm a noob.About the MCLR reset pin and unused pins in general I've read they must be connected with a pull-up or pull-down resistors depending on whether they are input or output pins and not leave them floating, so the 10K resistor makes sense here, but I've also seen diagrams where the push button is missing entirely with only the 10K R connected.I take this is to pull-up the MCLR pin and prevent accidental resets, but what about the watch-dog or POR where a reset is needed, would this resistor prevent a rightful reset (i.e.: to correct the MCU from a bad state)?Btw, the diagram I attached is from mikro electronica:https://www.mikroe.com/ebooks/pic-microcontrollers-programming-in-c/basic-connectingLE: I think I've found my answer after doing some more reading on pull-up/pull down resistors. If I understood correctly, as per this diagram, the MCLR pin is connected via a resistor to ground which makes it a pull down resistor, so pin is in logic 0 state (i.e.: not reset). If it was connected via pull up resistor (resistor connected to Vcc), then pin would have been in logic 1 state (i.e.: in reset). Please correct me if I got it all wrong.

author: jpanhalt
author_rank: Super Contributor
timestamp: September 13, 2021, 03:56:28 am
content: MCLR is usually shown with a line over it to indicate active low: (snippet from datasheet attached)However, that is not a standard keyboard character, so there are workarounds. I happen to like a preceding exclamation point, like !MCLR. In Eagle, that gives the overline. I suspect your source didn't have the ability.

author: fchk
author_rank: Frequent Contributor
timestamp: September 13, 2021, 10:59:12 am
content: The schematics is actually misleading.Ddd should read Vdd. So you have two Vdd/Vss pairs. Each one needs a 100n capacitor in direct proximity (important!). Always. MCLR usually requires 10k to Vdd.fchk

author: Ian.M
author_rank: Super Contributor
timestamp: September 13, 2021, 12:09:47 pm
content: Also the OSC1, OSC2, crystal and associated capacitor connections need to be as short as reasonably possible. If your board doesn't have a ground plane, use the Vss pin next to the OSC pin for the ground to the crystal's capacitors.N.B. don't be tempted to skimp on the Vss and Vdd connections just because the PIC has more than one of each. PICs can malfunction if you miss out any Vss or Gnd conections or fail to decouple each pair locally as described by Fchk. Run tracks under the chip to link the Vss pins on opposite sides and the same for the Vdd pins. Exception: QFN packages, where the thermal pad gets in the way so you cant run a track under the chip for Vdd.

author: newtekuser
author_rank: Frequent Contributor
timestamp: September 13, 2021, 02:59:34 pm
content: Quote from: fchk on September 13, 2021, 10:59:12 amI was wondering if Ddd was a typo or not. Thank you for mentioning the 100nF caps, I am actually using two of them tied to each Vdd pin in my project. This schematic only shows one but I assumed it had to be two of them.About MCLR connection, did you mean 10k to Vcc instead of Vdd?

author: newtekuser
author_rank: Frequent Contributor
timestamp: September 13, 2021, 03:13:51 pm
content: Quote from: Ian.M on September 13, 2021, 12:09:47 pmThat's good to know, thanks! I'm actually using a breadboard (read that this in itself may cause issues) where space is tight so the crystal is not very close. I do have both Vss and Vdd pins connected and Vdd pins decoupled with 100nF caps each.Currently I'm trying to troubleshoot why the 16x2 LCD I have hooked up doesn't display anything but blocks in the first row (I do have a pot connected which controls the contrast just fine) and I'm assuming there's something else going on. My thoughts:1. I don't have a 10K resistor hooked up to MCLR pin (MCU is resetting?)2. Crystal is not very close to the MCU (clock probably is not working, probably time to hook it to my scope and check)3. Oscillator configuration is not correct (I'm using the HS setting with 8Mhz crystal... maybe I need XT setting here, unclear)4. Sample program I'm using doesn't have ports configured correctlyAlso, I connected unused pins on the LCD to ground (shorted to ground?) as I've read somewhere online, but unused pins on the MCU are still floating.I was thinking that maybe my breadboard is bad but I checked every connected pin for continuity and it checks out.Very possible there are other subtleties I'm not aware of which is causing this so I removed the LCD from the picture to eliminate unnecessary variables for now.

author: Lindley
author_rank: Regular Contributor
timestamp: September 13, 2021, 04:14:45 pm
content: If using a Crystal and Caps on a breadboard their leads are so thin they often make poor contact, so problems with the Pic running.The way around that is to solder those parts to some thicker wire and plug those into the breadboard.Also as mentioned they should be very close to the Pics pins.All that said, its a bit pointless using one when you have a perfectly good internal oscillator on the Pic chip, 8 mhz can be readily selected in your program code and is good for most typical diy projects.You can select MCLE function from the Config Settings if you do not want to have a pull up and reset switch, though a useful feature when starting off.Never found any problems leaving d0-3 or d4-7 pins of a lcd floating, the most common problem is in soldering the wires to the LCD, usually shorts between two pads etc.Post up your full schematic and program code so we can better see what you are doing, we all started with similar setups and problems.Often its better to prove your hardware and program code with a simple flashing led, before the more complex LCD.

author: MarkF
author_rank: Super Contributor
timestamp: September 13, 2021, 08:25:32 pm
content: What are your configuration bits?It looks like your crystal is 8MHz, so just use the internal oscillator instead.And if you're not using the MCLR, disable it in the config. bits by making it an i/o bit.Also, the 'watchdog timer' may be enabled and resetting the MCU (disable it).If you want an external clock to get 20MHz, use a clock module instead of a crystal (much easier).Wire clock out pin to MCU pin 13 (OSC1/CLKIN).https://www.digikey.com/en/products/detail/abracon-llc/ACH-20-000MHZ-EK/675368?s=N4IgTCBcDaIIIGEASBaMAGAdOnBZJAWigKIDSIAugL5ASuggested conf. bits:Code:// PIC16F887 Configuration Bit Settings// 'C' source line config statements// CONFIG1#pragma config FOSC = INTRC_NOCLKOUT// Oscillator Selection bits (INTOSCIO oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN)#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)#pragma config MCLRE = OFF // RE3/MCLR pin function select bit (RE3/MCLR pin function is digital input, MCLR internally tied to VDD)#pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled)#pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled)#pragma config BOREN = OFF // Brown Out Reset Selection bits (BOR disabled)#pragma config IESO = OFF // Internal External Switchover bit (Internal/External Switchover mode is disabled)#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is enabled)#pragma config LVP = ON // Low Voltage Programming Enable bit (RB3/PGM pin has PGM function, low voltage programming enabled)// CONFIG2#pragma config BOR4V = BOR40V // Brown-out Reset Selection bit (Brown-out Reset set to 4.0V)#pragma config WRT = OFF // Flash Program Memory Self Write Enable bits (Write protection off)Select frequency in main() function:The default is 4MHz. See section 4.2 of the datasheet.Code:void main(void){OSCCON = 0x71; // Select internal oscillator for 8MHz. . .}

author: newtekuser
author_rank: Frequent Contributor
timestamp: September 14, 2021, 05:39:06 am
content: Quote from: MarkF on September 13, 2021, 08:25:32 pmI only have the capability to configure these bits via GUI since I'm using MikroC PRO but most are set to same values as suggested with some exceptions.The project I'm using asks for an external 8Mhz crystal, not sure why the internal one is not used.

author: newtekuser
author_rank: Frequent Contributor
timestamp: September 14, 2021, 05:47:18 am
content: Quote from: Lindley on September 13, 2021, 04:14:45 pmI'm trying to follow this project (no changes to code):https://electrosome.com/digital-clock-pic-microcontroller-ds1307/The only changes I've made was to add two 100nF decoupling capacitors to Vdd pins, 10K pot to LCD anode pin (has backlight) and omitted the resistor for the MCLR pin.Program was flashed using MikroProg onto 16F887 and 16F877A with same results.

author: Lindley
author_rank: Regular Contributor
timestamp: September 14, 2021, 08:38:29 am
content: The Pic16F877A does not have an Internal oscillator, unlike the later 16F887.Not sure about MicroC but generally you cannot just port code from one chip to another without at least some changes to the Config Settings and perhaps your program code.As that project is set for a 877A chip stick with that until you you have the full circuit working.Not sure why you want to remove the 10k resistor from MCLE, its an important part , so just fit it !As already mentioned, when having such problems much better to build things up in steps, first build your voltage regulator and pic as a Led flasher, then add the LCD and finally with switches and RTC.There are lots of code examples for a led flasher and then a lcd out there with a 877A chip, though any example using the 873/a,876/a and 877 family will work on the 877A chip

author: jpanhalt
author_rank: Super Contributor
timestamp: September 14, 2021, 09:22:00 am
content: I have never used the 16F87XA chips and have been following the dialog on MCLR. The way I think about !MCLR is that it serves 2 functions: 1) MCLR Reset; and 2) ICSP programming when VPP (high voltage) is used to get into programming mode. Those functions have somewhat competing requirements (see below).Will you be using LVP and PGM(RB3) or VPP?If the latter, then the two functions have somewhat conflicting needs. Reset needs a somewhat debounced switch to ground and a controlled rise according to Microchip (MCC) . Thus the larger resistor and capacitor. The documentation mentions protection from static and noise too. On the other hand VPP programming needs a rapid rise in voltage on that pin. PICKIT's have a very weak supply, and ICD is a little better, but if you look at other chips without PGM, you will see caveats against have any capacitor on !MCLR and a recommendation to have only one resistor to VCC. Since you have turned !MCLR function off, why keep that capacitor and worry about programming in VPP mode?Generally, I follow MCC's recommendation for the MCLR pin in accord with how I will program the chip. With what you show, and if you are programming with VPP and something like a PICKIT3, it may work fine. If you have problems, consider eliminating the capacitor.

author: Ian.M
author_rank: Super Contributor
timestamp: September 14, 2021, 04:22:23 pm
content: All HV ICSP capable Microchip programmers are rated to drive a minimum load on Vpp/MCLR of 5K. In practice there's enough margin to allow you to use a 4K7 isolation resistor between /MCLR at the PIC + ICSP header, and your reset timing capacitor, even if that capacitor is very large. It isn't advisable to use less than a 10K pullup to feed the timing capacitor, as reverse current through the pullup during programming exceeding the additional load on Vdd provided by the programmer can cause Vdd to rise.If you are using a 3rd party programmer YMMV as it may well not meet the (unofficial) Microchip specs of min. 5K load Vpp drive capability and min. 1mA additional load on Vdd (@5V).See my comments here:https://www.microchip.com/forums/m692754.aspxfor the background.Note that Microchip have historically published several reset circuits that either aren't ICSP compatible, or if built with the component values shown aren't compatible with newer ICSP capable programmers. Be careful if wading through old documents for example circuits!

author: Lindley
author_rank: Regular Contributor
timestamp: September 14, 2021, 04:35:50 pm
content: Had an old project box using a 877a and lcd so was able to program it up with that projects .hex file and as you can see it does work.Good old Pickt2 v2.61 still working !

author: jpanhalt
author_rank: Super Contributor
timestamp: September 14, 2021, 05:18:25 pm
content: Apparently there is a difference of opinion. I follow Microchip's recommendation for chips (Capture1), unless there is a reason not to.An early ICSP reference from MIcrochip (DS91016B (2003)) gives a work-arond, namely adding a diode. I have done that too, on accasion. (Capture)

author: Ian.M
author_rank: Super Contributor
timestamp: September 14, 2021, 05:38:30 pm
content: The DS91016B (2003) circuit doesn't actually work for newer PICs that have an internal weak pullup for their /MCLR pin,e.g. the PIC16F887 on the O.P.'s schematic. It permits ICSP, but the RC /MCLR reset delay circuit is ineffective as the 'isolation' diode is permanently reverse biassed except when the ICSP programmer is holding /MCLR low.

author: jpanhalt
author_rank: Super Contributor
timestamp: September 14, 2021, 06:24:38 pm
content: Thank you for clarifying something I never suggested.

author: DavidAlfa
author_rank: Super Contributor
timestamp: September 15, 2021, 06:51:50 pm
content: You have PWRT/PWRTE for that, it delays the code execution at boot for ~64-72ms (Depending on the PIC model).No need of the RC delay for MCLRE. If you need more time, then use a sw delay.MCLRE can be disabled in the config bits, and used as a regular input (So no pullup needed).Adding a series diode will avoid the 12V from VPP going to the connected circuit.A schottky diode have very low dropout spoe can get below 150mV at low currents.

author: Ian.M
author_rank: Super Contributor
timestamp: September 15, 2021, 07:30:19 pm
content: My point was the diode is worthless no matter what reset or signal circuit is connected the far side of it. If its oriented to block Vpp then the external circuit cant drive the pin low - if its configured as /MCLR with an internal pullup, it will have no effect, if its configured as an input, it will allow the circuit to drive the pin high, but any attempt to drive it low leaves it floating.Microchip have a certain reputation for unchecked 'copy-pasta' content in some of their datasheets, and some others, typically tech briefs and application notes have circuits that show less design competence than would be expected from a typical summer intern. Some have even had to be withdrawn as unsafe to the user. (e.g. the infamous TB008)

author: kripton2035
author_rank: Super Contributor
timestamp: September 15, 2021, 07:44:23 pm
content: then how can you safely separate vdd from the icsp connector, from vdd of the board ?for example I have an lcd display on vdd, and I must disconnect it in order to program the chip with icsp, or the current consumed by the lcd prevents from programming.what is the best schematic to have an isolated icsp port on a recent pic device ?

author: DavidAlfa
author_rank: Super Contributor
timestamp: September 15, 2021, 07:50:08 pm
content: You have plenty of options:- Program the board using its own power.- Isolate the PIC VDD using a series schottky diode.- Switch the lcd power using a pic pin driving a P-ch mosfet.

author: jpanhalt
author_rank: Super Contributor
timestamp: September 15, 2021, 08:06:50 pm
content: Quote from: Ian.M on September 15, 2021, 07:30:19 pmIf you are referring to the Application note in post #18 as shown from 2003, of course a programmer or reset switch on !MCLR can pull it low. It is also overkill as the resistor protects and isolates Vdd. I happened to be using a chip at the time to which that circuit applied and tend to follow the manufacturer's recommendations, unless I have a reason not to do that. It worked. I have no problem with a company updating its recommendations. Isn't that why we all check the errata?As for Microchip's reputation, its stock is up 60% in the past year, which outperforms its market sector. How has your stock done?