Author Topic: what should happen when you plug in a PIC microcontroller?  (Read 3320 times)

0 Members and 1 Guest are viewing this topic.

Offline eigenvektorTopic starter

  • Contributor
  • Posts: 41
  • Country: ch
what should happen when you plug in a PIC microcontroller?
« on: December 09, 2022, 02:38:18 pm »
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 :)
 

Online Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3359
  • Country: nl
Re: what should happen when you plug in a PIC microcontroller?
« Reply #1 on: December 09, 2022, 02:57:08 pm »
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...
 

Offline eigenvektorTopic starter

  • Contributor
  • Posts: 41
  • Country: ch
Re: what should happen when you plug in a PIC microcontroller?
« Reply #2 on: December 09, 2022, 03:15:54 pm »
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.
 

Online Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3359
  • Country: nl
Re: what should happen when you plug in a PIC microcontroller?
« Reply #3 on: December 09, 2022, 03:57:02 pm »
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.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: what should happen when you plug in a PIC microcontroller?
« Reply #4 on: December 09, 2022, 03:57:17 pm »
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 
 
The following users thanked this post: eigenvektor

Offline eigenvektorTopic starter

  • Contributor
  • Posts: 41
  • Country: ch
Re: what should happen when you plug in a PIC microcontroller?
« Reply #5 on: December 09, 2022, 05:04:45 pm »
@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)
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14475
  • Country: fr
Re: what should happen when you plug in a PIC microcontroller?
« Reply #6 on: December 09, 2022, 07:37:10 pm »
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.


 

Online westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: what should happen when you plug in a PIC microcontroller?
« Reply #7 on: December 09, 2022, 09:13:28 pm »
Quote
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

I'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 - the USB BitWhacker that 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.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: what should happen when you plug in a PIC microcontroller?
« Reply #8 on: December 09, 2022, 11:14:08 pm »
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.   
« Last Edit: December 10, 2022, 11:07:46 am by Ian.M »
 

Online Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6261
  • Country: fi
    • My home page and email address
Re: what should happen when you plug in a PIC microcontroller?
« Reply #9 on: December 10, 2022, 10:51:24 am »
Paul Stoffregen created the HalfKay 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 the protocol is very simple (and works quite well).  I do believe one could implement a similar PIC bootloader for those PICs with hardware USB support.
 
The following users thanked this post: elecdonia

Offline eigenvektorTopic starter

  • Contributor
  • Posts: 41
  • Country: ch
Re: what should happen when you plug in a PIC microcontroller?
« Reply #10 on: December 10, 2022, 12:17:08 pm »
Thank you all for the replies, I'll try my best to salvage the board first, maybe I'll discover some more errors I made :P
Maybe 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?
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: what should happen when you plug in a PIC microcontroller?
« Reply #11 on: December 10, 2022, 12:42:30 pm »
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!)
« Last Edit: December 10, 2022, 12:46:54 pm by Ian.M »
 

Offline trinacria

  • Contributor
  • Posts: 22
  • Country: us
Re: what should happen when you plug in a PIC microcontroller?
« Reply #12 on: December 10, 2022, 01:31:36 pm »
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.
 

Online Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6261
  • Country: fi
    • My home page and email address
Re: what should happen when you plug in a PIC microcontroller?
« Reply #13 on: December 10, 2022, 02:21:29 pm »
Maybe I should switch to a ATmega32u4 considering this is my first project with a microcontroller?
It 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.
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8172
  • Country: fi
Re: what should happen when you plug in a PIC microcontroller?
« Reply #14 on: December 10, 2022, 02:33:29 pm »
Kynar wirewrap wire, because ... takes solder well

I'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.
 

Offline slugrustle

  • Frequent Contributor
  • **
  • Posts: 278
  • Country: us
Re: what should happen when you plug in a PIC microcontroller?
« Reply #15 on: December 10, 2022, 03:49:11 pm »
Quote
what should happen when you plug in a PIC microcontroller
It 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).

Quote
Start by downloading and reading the datasheet.
Excellent 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.

Quote
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.
I'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.

Quote
Kynar wire...
I 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 this
Quote
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.
or look for the purpose made strippers. Purpose made for Kynar, I hope.

Quote
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!)
This 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.



 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8172
  • Country: fi
Re: what should happen when you plug in a PIC microcontroller?
« Reply #16 on: December 10, 2022, 06:15:26 pm »
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.

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

Offline slugrustle

  • Frequent Contributor
  • **
  • Posts: 278
  • Country: us
Re: what should happen when you plug in a PIC microcontroller?
« Reply #17 on: December 10, 2022, 06:38:48 pm »
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.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: what should happen when you plug in a PIC microcontroller?
« Reply #18 on: December 10, 2022, 06:39:08 pm »
@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.
 
The following users thanked this post: slugrustle

Offline slugrustle

  • Frequent Contributor
  • **
  • Posts: 278
  • Country: us
Re: what should happen when you plug in a PIC microcontroller?
« Reply #19 on: December 10, 2022, 07:19:46 pm »
Good stuff.  I found and ordered some (have more than one wire gauge). Looking forward to a quality of life upgrade.
 

Offline eigenvektorTopic starter

  • Contributor
  • Posts: 41
  • Country: ch
Re: what should happen when you plug in a PIC microcontroller?
« Reply #20 on: December 12, 2022, 08:54:58 pm »
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-uC and 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?
 

Offline jaka

  • Contributor
  • Posts: 11
  • Country: fi
Re: what should happen when you plug in a PIC microcontroller?
« Reply #21 on: December 12, 2022, 09:07:22 pm »
Have you powered the PIC18F24K50 externally? If not, you must enable the PICkit3 to feed power to target.
 
The following users thanked this post: eigenvektor

Offline eigenvektorTopic starter

  • Contributor
  • Posts: 41
  • Country: ch
Re: what should happen when you plug in a PIC microcontroller?
« Reply #22 on: December 12, 2022, 09:15:28 pm »
yes that was it  :D
or 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
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5907
  • Country: es
Re: what should happen when you plug in a PIC microcontroller?
« Reply #23 on: December 12, 2022, 09:29:10 pm »
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.
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline eigenvektorTopic starter

  • Contributor
  • Posts: 41
  • Country: ch
Re: what should happen when you plug in a PIC microcontroller?
« Reply #24 on: December 12, 2022, 09:52:51 pm »
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
« Last Edit: December 12, 2022, 10:02:59 pm by eigenvektor »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf