what should happen when you plug in a PIC microcontroller? - Page 1
Forum section: electronics / general

author: eigenvektor
author_rank: Contributor
timestamp: December 09, 2022, 02:38:18 pm
content: I'm currently designing a custom keyboard and want to use a pic18f24k50. This bootloader project (https://hackaday.io/project/63204/instructions) had me believing that I don't need to program the pic with a pickit and ICSP pins, but could instead simply connect the board via usb and it would appear as a writeable usb drive.I ordered the pic in a qfn28 package and soldered it on my board, however nothing happens when I plug it into my computer via usb. I was wondering if anything is supposed to happen and I screwed up the soldering? Or do I have to go the "old-fashioned" route with a pickit programmer and ICSP pins?Thanks in advance

author: Doctorandus_P
author_rank: Super Contributor
timestamp: December 09, 2022, 02:57:08 pm
content: Start by downloading and reading the datasheet.That what it's for. the datasheet is always your first reference in case of doubt.And in these modern times those datasheets do not only have an index, but the text itself is searchable too...

author: eigenvektor
author_rank: Contributor
timestamp: December 09, 2022, 03:15:54 pm
content: I don't think the hackaday project was intended by the manufacturer, I know that the official method is going through a dedicated hardware programmer. From a similar post I made on stackexchange (https://electronics.stackexchange.com/questions/644259/programming-pic18f24k50-over-usb) it seems that nothing is supposed to happen with an unprogrammed pic so I'll be waiting for my pickit to arrive.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: December 09, 2022, 03:57:02 pm
content: sites like hackaday, stackeschange ane 95% of the rest of internet is nice for boosting your inspriation and it can save you lots of time if you find a similar project to what you want to do yourself.But for reliable info there is simply no substitute for a datasheet.Downloading the datasheet, and searching it for "bootloader" and/or "programming" would have taken you about as much time as writing these posts.

author: Ian.M
author_rank: Super Contributor
timestamp: December 09, 2022, 03:57:17 pm
content: IIRC, eight bit PICs don't come with a factory pre-programmed bootloader, unless you specifically order them from MicrochipDirect, programmed with a user-supplied firmware image with that functionality (the set up fee is significant so this is only really an option if you don't want the hassles of production line ICSP programming).If you are too impatient to wait for your PICkit, and you still have a PC with legacy ports, your PIC18F24K50 should have low voltage programming enabled by default, so provided you can access the required pins on your board, you could cobble together a DIY LVP programmer and use it with the PICpgm software. See:http://picpgm.picprojects.net/hardware.html

author: eigenvektor
author_rank: Contributor
timestamp: December 09, 2022, 05:04:45 pm
content: @Doctorandus_P: I know it was my mistake when designing the original PCB, but I'd rather spend a couple minutes on posts to make sure there's no alternative I'm missing before redesigning my PCB and waiting for it to arrive from china (or trying to solder wires to a qfn package and building my own programmer)

author: SiliconWizard
author_rank: Super Contributor
timestamp: December 09, 2022, 07:37:10 pm
content: This MCU doesn't come with a bootloader allowing to flash from USB. I've never seen this kind of feature on 8- and 16-bit PICs. Actually, the built-in "bootloader" (if we can call it that) is pretty limited. It just allows to boot from the internal Flash, and that's it. AFAIK. What you need here is to flash your own bootloader, which is possible. Yes, see datasheet. But you need to flash it first, so you need ICSP. Once your custom bootloader is programmed, you could do without ICSP.Note that this chip only has 16KB of Flash, so a USB bootloader may take a sizable chunk of that.

author: westfw
author_rank: Super Contributor
timestamp: December 09, 2022, 09:13:28 pm
content: QuoteI'm pretty sure those instructions refer to how to proceed with putting applications on your PIC (without programmer) AFTER you've put the bootloader on the chip using a programmer. Sort of the way the Arduino works - normally you just upload the "sketches" over USB/Serial, but the bootloader has to be on the Arduino chip to start with, and THAT requires a device programmer.There was a project - theUSB BitWhackerthat came out right about the same time as the original Arduinos, that featured a PIC with bootloader that was directly uploadable over USB (because it already had the bootloader.) I've always found it interesting that Arduino was so much more of a success. I guess the "language" and the "IDE" made a significant difference.

author: Ian.M
author_rank: Super Contributor
timestamp: December 09, 2022, 11:14:08 pm
content: Note that the UBW was based on a PIC18F2553, then later upgraded to higher pin count parts in the same family, which did not, and still do not, come with a bootloader installed as standard when shipped from the factory. Most versions of it had a 5 or 6 pin Microchip ICSP header (or footprint for the same) on the board for initial programming with a USB bootloader.Atmel did things a bit better: Their ATmega_U_ family of 8 bit AVRs with USB came factory pre-programmed with a DFU bootloader, and unless you did something dumb with the fuses or erased the chip by ISP, you wouldn't need to reinstall it with a hardware ISP programmer.@eigenvektor,Whether or not your existing board is salvageable without replacing the PIC with one programmed with a bootloader depends on if you've got tracks to or enough visible pad at the edge of the QFN footprint to get access to the ICSP pins. You need the three adjacent pins /MCLR, RB7 and RB6, + Vdd and Vss (Gnd) from anywhere convenient, brought out to a trailing 6 pin 0.1" pitch header (see your PICkit manual for pinout), with not more than 6" of wire between it and the board, and nothing active driving the ICSP pins, no capacitors on any >100pF, no /MCLR pullup<5K, and no pullups on RB6 or RB& or loads < a few K. If you can access those pins you can program the chip without desoldering it and avoid respinning the board. For your sanity, use Kynar wirewrap wire to add the trailing header, strain relieve the header end with hot glue or epoxy and anchor the wire bundle to the PCB.

author: Nominal Animal
author_rank: Super Contributor
timestamp: December 10, 2022, 10:51:24 am
content: Paul Stoffregen created theHalfKay bootloader–– so called because it fit in 512 bytes or so of Flash on AVRs –– for AVRs (AT90USB162, AT90USB646, ATmega32U4, AT90USB1286) with native USB interface, for the first Teensy development board models (1.0, ++1.0, 2.0, ++2.0). The bootloader is proprietary, but theprotocolis very simple (and works quite well). I do believe one could implement a similar PIC bootloader for those PICs with hardware USB support.

author: eigenvektor
author_rank: Contributor
timestamp: December 10, 2022, 12:17:08 pm
content: Thank you all for the replies, I'll try my best to salvage the board first, maybe I'll discover some more errors I madeMaybe I should switch to a ATmega32u4 considering this is my first project with a microcontroller? Seems to be more user friendly, and there is open source code for keyboards based on the 32u4, which means less coding for me.also @Ian.M just wondering why specifically kynar wire?

author: Ian.M
author_rank: Super Contributor
timestamp: December 10, 2022, 12:42:30 pm
content: Kynar wirewrap wire, because its tough enough to stand up to routine handling if strain relieved at or near the ends, and is 30 AWG silver plated solid core wire, so thin enough to solder to fine pitch pads and pins, takes solder well and has strippable insulation.(Hint: it can help to first crush the insulation using a pair of miniature smooth jaw flat nose pliers, so it can be peeled away from the wire core, rather than risking notching the wire with strippers that aren't purpose made for it. Its also helpful to avoid pulling on the joint when cutting to length and stripping the end after the other end has been soldered.)You *could* use fine magnet wire, but that doesn't stand up to handling as well, and depending on the insulation, can be a PITA to strip without hazardous chemicals and extreme heat.(e.g. a molten caustic salt bath of Sodium hydroxide mixed with Potassium nitrate!)

author: trinacria
author_rank: Contributor
timestamp: December 10, 2022, 01:31:36 pm
content: The way I got started was an 8-bit PIC in a DIP package, the MPLAB Snap programmer, a breadboard, and a few through-hole passives. The setup was easy to debug, and the documentation was good enough, if a bit scattered.

author: Nominal Animal
author_rank: Super Contributor
timestamp: December 10, 2022, 02:21:29 pm
content: Quote from: eigenvektor on December 10, 2022, 12:17:08 pmIt is my favourite AVR microcontroller, and I particularly like it for HID uses. My preferred keyboard/keypad arrangement uses diodes (duals in SOT23-3) for unlimited rollover. Right now, the chips are rather expensive, however.ATmega32u4 is simple enough for even a learner to program in a bare-metal environment, although of course Arduino/PlatformIO etc. are also possible.

author: Siwastaja
author_rank: Super Contributor
timestamp: December 10, 2022, 02:33:29 pm
content: Quote from: Ian.M on December 10, 2022, 12:42:30 pmI'm sceptical. I had access to a few rolls of Kynar wirewrap wire and it was colossal pain in the ass to solder. Which is totally understandable, as the one thing this wire is NOT designed for, is soldering. It's wirewrap wire, after all.Maybe you have had better luck with wirewrap wires, but for me, never again. There is no shortage of hookup wires of different diameters and insulation options, so I nowadays buy anything except wirewrap wire.

author: slugrustle
author_rank: Frequent Contributor
timestamp: December 10, 2022, 03:49:11 pm
content: QuoteIt really depends what you plug it into, but assuming reasonable conditions, the MCU should set the program counter to the reset vector (0x0000 except for PIC10F20X in which case, the last address in program ROM to load the oscillator calibration value into W).QuoteExcellent advice, but perhaps a heavy lift for someone seeking an answer to one particular question. Your later suggestions of quick searching are 100% on point and are apparently what you implied here too. Based on some experiences at work, I do question the general familiarity of people with research skills like using indices and searching... This is not about anyone in this thread, just a general thing that pains my metaphorical soul.QuoteI'm right there with you on the use of scare quotes, westfw. For MCUs, give me an assembler and a good set of documentation. It's a truism these days that no one in their right mind should use assembly for pretty much anything, but I question whether those who hold such views have programmed anything significant in assembly. Fred Brooks did once remark that a high level language isn't that different from a macro assembler.That said, it seems like the things the software / firmware people care about at work are making large, complex codebases easier to read, understand, maintain, and update on a deadline with a team of people who have differing levels of familiarity with the code and different levels of experience generally. I'm not sure that's a problem with a solution, but more layers of abstraction and avoiding special features of the MCU where possible seem to be attempts at it. Personally, I am glad to be on the hardware side. And for personal projects, it's just me and the MCU, so assembly FTW. It's amazing what you can accomplish with modern MCUs when operating at that level.QuoteI use Kynar wire for modifying boards and hooking up instruments to test points because the insulation doesn't melt during soldering. This is the big selling point for this kind of wire. I do find it difficult to strip and will try Ian.M's trick for thisQuoteor look for the purpose made strippers. Purpose made for Kynar, I hope.QuoteThis is a new one to me. I've seen videos from a transformer manufacturer, and it appears the insulation on the magnet wire they use is designed to boil or burn off when dipped into the solder pot.

author: Siwastaja
author_rank: Super Contributor
timestamp: December 10, 2022, 06:15:26 pm
content: Quote from: slugrustle on December 10, 2022, 03:49:11 pmMaybe some special snowflake small scale audio transformer manufacturer or something?Normal power transformers use enamels that are not designed to burn in soldering temperatures, because they are tougher and can withstand higher temperatures, desirable in transformers.But you totally can buy magnet wire with "solderable" enamel. But it's a specialty thing.

author: slugrustle
author_rank: Frequent Contributor
timestamp: December 10, 2022, 06:38:48 pm
content: Pretty sure they were making commodity transformers.Here's an excerpt from totoku's catalog for triple insulated transformer wire that indicates direct solderability without stripping. The insulation is class B. I can see how this would be desirable from a manufacturing standpoint.

author: Ian.M
author_rank: Super Contributor
timestamp: December 10, 2022, 06:39:08 pm
content: @slugrustle,Purpose made stripper for 30 AWG Kynar, with a blade with a notch the width of the core diameter, unsuitable for any thinner or thicker wire. Normally found on the side of a manual wire-wrap tool for 0.025" square pins.

author: slugrustle
author_rank: Frequent Contributor
timestamp: December 10, 2022, 07:19:46 pm
content: Good stuff. I found and ordered some (have more than one wire gauge). Looking forward to a quality of life upgrade.

author: eigenvektor
author_rank: Contributor
timestamp: December 12, 2022, 08:54:58 pm
content: Ok so not sure if this is still the right thread for this but following problem:I soldered some wires to the PIC (PGD, PGC and MCLR, as well as VDD and VSS at a closeby usb port) and connected it to my PICkit 3.Then I downloaded the hex files from here:https://github.com/johnnydrazzi/USB-uCand imported the fitting one (PIC18F24K50 no xtal) into MPLAB.When trying to "make and program device" following errors appear:high voltage mode: Target device was not found (could not detect target voltage VDD). You must connect to a target device to use PICkit 3.low voltage mode: The low voltage programming feature requires the LVP configuration bit to be enabled on the target device. Please enable this configuration bit and try the operation again.wires seem to be connected to something as they each have a couple megaohm resistance between them (actually thinking back that might have been my body impedance, I'll check again tomorrow, makerspace is closed and don't have a multimeter handy).Am I missing something obvious or is my PIC dead / wires not soldered correctly?

author: jaka
author_rank: Contributor
timestamp: December 12, 2022, 09:07:22 pm
content: Have you powered the PIC18F24K50 externally? If not, you must enable the PICkit3 to feed power to target.

author: eigenvektor
author_rank: Contributor
timestamp: December 12, 2022, 09:15:28 pm
content: yes that was itor rather one of the problems... At least I'm getting a new error now: "Too much current has been drawn on VDD. Please disconnect your circuit, check the CLK and DATA lines for shorts and then reconnect."Looks like I'm gonna have to recheck my soldering tomorrow :S

author: DavidAlfa
author_rank: Super Contributor
timestamp: December 12, 2022, 09:29:10 pm
content: The pickit can only supply a small amount of current, anything else connected to VDD will easily overload it.Simply power the entire board from the USB port.

author: eigenvektor
author_rank: Contributor
timestamp: December 12, 2022, 09:52:51 pm
content: should I still enable "power target circuit from PICkit 3"? when off and connected by usb it still throws the error "could not detect target voltage VDD", when I tried it with the option on my laptop screen started flickering, so I got scared and unplugged it...obviously should be off according to instructions... I don't have any of the "improper circuit components" so I'm thinking improper soldering is most likely

author: bson
author_rank: Unknown
timestamp: December 13, 2022, 02:25:09 am
content: Quote from: eigenvektor on December 09, 2022, 05:04:45 pmIt probably wouldn't be overly difficult to connect a few traces or pins to an ICSP connector while waiting for updated boards. Still need a PICKit or such, though.

author: eigenvektor
author_rank: Contributor
timestamp: December 14, 2022, 06:51:00 pm
content: Ok I redid all my wiring, double checked that vdd and vss were indeed connected and the board is getting power when plugged in to usb (measured 5.2V with multimeter), but was still receiving the error:Target device was not found (could not detect target voltage VDD). You must connect to a target device to use PICkit 3.once (without changing anything) I tried again, it seems to be connecting to the chip, but following error shows up:Device Erased...Programming...The following memory area(s) will be programmed:program memory: start address = 0x0, end address = 0x1fffconfiguration memoryprogram memoryAddress: 0 Expected Value: e Received Value: ffFailed to program devicethen it goes back to the could not detect target voltage vdd error even though I still measure 5.2v with a multimeter.from what I can find online its still probably a bad connection? Thinking it would be easier by now to just order new boards from china with smd assembly (they'd probably do a better job than me) and proper easy to solder to breakout pins.

author: Ground_Loop
author_rank: Frequent Contributor
timestamp: December 18, 2022, 04:20:19 am
content: I was plagued by similar errors using a Pickit 4 and a similar header pin arrangement. I ended up pulling the header apart and very carefully soldering the crimped wires. Problems vanished.

author: james_s
author_rank: Super Contributor
timestamp: December 18, 2022, 04:30:18 am
content: Quote from: Siwastaja on December 10, 2022, 02:33:29 pmI've used it for many years, and I've soldered it a lot more often than I've wire wrapped it. Never had any trouble at all getting it to solder.

author: Smokey
author_rank: Super Contributor
timestamp: December 18, 2022, 05:34:15 am
content: This whole thread strikes me as an assumption only made by the Arduino generation. Plug it in, the IDE does some sort of magic, and my LED blinks. Embedded is easy!If I plug something in for the first time and it "just works as expected" I buy a lottery ticket.

author: eigenvektor
author_rank: Contributor
timestamp: December 18, 2022, 01:09:44 pm
content: Quote from: Ground_Loop on December 18, 2022, 04:20:19 amCould you elaborate? Did you solder wires to the header on the pickit itself or to your board. Arrangement on my Pickit 3 is: female header, male-male header, female-female wire, male - male header, soldered to wires soldered to pic (see pics)

author: Ground_Loop
author_rank: Frequent Contributor
timestamp: December 18, 2022, 01:33:28 pm
content: Quote from: eigenvektor on December 18, 2022, 01:09:44 pmI removed each pin from the plastic carrier and soldered the wire to the pin. This operation takes a really light touch. Just 'breath' a bit of solder onto the connector. Too much and the pin will not go back into the carrier. Note that these were not factory assemblies. I crimped and built them up myself.

author: Tnixsw
author_rank: Contributor
timestamp: December 21, 2022, 10:01:34 pm
content: The PICkit's work fine, I've used them for ages. The only problems likely (assuming that the PICkit and PIC actually work) are improper connections to the target board which also may have circuitry that interferes with the programmer.Have you looked in the PICkit manual? It has a small discussion on how to properly connect a PIC while programming and what not to do, and also programming with the PICkit supplying power or from external power. If you follow these fairly simple guidelines, then the programmer should work.Starting with any new microcontroller is a big ask, especially if you want to start with a bootloader. There are lots of things to learn. Just considering the bootloader, you need to know how the chip operates, how to connect to it, how it is set up internally, how to program it, decide how the bootloader will operate, learn how to write code for the device, write and debug the code, create an interface that can read HEX files and transfer the data to the PIC via some link and deal with errors.This is not trivial. If you are new to programming these devices, please start small and work up to something larger as you gain knowledge, otherwise you will get into all sorts of frustrating trouble. The PIC 18 series have a lot of internals to set up, depending on what you want, so the best advice has already been given - read the data sheet. It is easy to breadboard a PIC and start with the infamous LED flasher. Just getting to that stage can be an interesting journey.Bear in mind also, that the PICs have a limited program rewrite capability, but in practice good enough to develop code with.cheersTony