Author Topic: Starting with PIC Microcontrollers  (Read 988 times)

0 Members and 1 Guest are viewing this topic.

Offline jane willTopic starter

  • Newbie
  • Posts: 3
  • Country: gb
Starting with PIC Microcontrollers
« on: January 21, 2025, 06:27:21 pm »
Hi everyone, 

I’m working on a simple automation project and plan to use a PIC microcontroller to control sensors and actuators. I found this excellent guide: Getting Started with PIC Microcontrollers (https://www.theengineeringprojects.com/2014/10/getting-started-with-pic-microcontrollers.html), which explains the basics really well. 

I’m looking for advice on which PIC microcontroller is best for beginners, especially for handling I/O and UART communication. Also, what common issues should I watch out for when programming or debugging? Any tips or tools you recommend for a smooth start would be super helpful. 

Thanks in advance for your help!
 

Online Gyro

  • Super Contributor
  • ***
  • Posts: 10309
  • Country: gb
Re: Starting with PIC Microcontrollers
« Reply #1 on: January 21, 2025, 06:43:42 pm »
You might want to look at this very recent thread, which discusses some of your questions... https://www.eevblog.com/forum/beginners/program-pic-microcontrollers-and-coding-language/

EDIT: (By very recent, I mean up to date. The page you referenced is from 2014)
« Last Edit: January 21, 2025, 06:52:28 pm by Gyro »
Best Regards, Chris
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2820
  • Country: us
Re: Starting with PIC Microcontrollers
« Reply #2 on: January 21, 2025, 07:12:16 pm »
Without knowing anything that you're planning on doing, I would stay away from the PIC32 and others with 'peripheral pin mapping'.  Trying to get your head around being able to assign I/O peripherals to different pins is daunting.

I think one of the PIC16 or PIC18 family would be a good place to start.  One of the newer ones that you can use the internal oscillator instead of the need to mess with crystals.  I have been using the PIC18F2525 and 4525 chips but there are other much cheaper PIC16 for $2 to $3 to get started.

For development, download MPLAB X and the XC8 compiler.  I use the built-in MPLAB configuration bit tool to setup the PIC.  I stay away from all their other tools: harmony, etc.  Just learn to talk directly to the PIC registers.  And program in C.  None of this assembly non-sense.  I did enough assemble programming in the '80s to last a life time.

Hardware wise you need to decide if you'll be doing 5V or 3.3V logic levels.
You'll also need a programmer.  I recommend one of the PICKit's 3 or 4.  I use a PICKit 3 clone myself.
Some will recommend the SNAP programmer but it's limited.

I also bought this USB-to-TTL serial cable for 3.3V operation with a PIC32MX.  Look for the 5V version if you plan on doing 5V logic.

I'm a bit old school and my projects have all required 5V logic.  One thing I've noticed with the PIC(LF) 3.3V variants is that you can NOT run them at their full clock speed.  Maybe I'm wrong here but that's my understanding.  With 5V power levels and the built-in PLL you can expect typical master clock speeds of 32MHz from their internal clock.  Which is plenty for most projects.
 

Online jpanhalt

  • Super Contributor
  • ***
  • Posts: 4189
  • Country: us
Re: Starting with PIC Microcontrollers
« Reply #3 on: January 21, 2025, 07:29:38 pm »
I have been using the PIC16F1xxx (enhanced midrange) series and Assembly with MPLab 8.92 for 20+ years in my hobbies.  The only reason I haven't migrated to some newer versions is that I never needed to.  Some questions are, how may I/O's do you need?  Do you need IOC?  Do you need OD (open drain outputs).  Will you be reading a keyboard that is not serial (e.g., a 4x4 will use up 8 pins unless you have some other buffer to reduce it to SPI or other serial protocol.  Do you need DIP or SOIC size for development?  There are a lot of possibilities in that group, including some very small 10Fxxx devices. 

EDIT:  I missed the UART question.  Most of the range I mentioned have USART.  It's simple to set up and uses a 1-wire interface to a character display.
« Last Edit: January 21, 2025, 08:33:46 pm by jpanhalt »
 

Offline woody

  • Frequent Contributor
  • **
  • Posts: 443
  • Country: nl
Re: Starting with PIC Microcontrollers
« Reply #4 on: January 21, 2025, 07:36:22 pm »
Not sure about your budget, but take a look at

www.ccsinfo.com

Ide, c-compilers, programmers/debuggers, development kits. Their forum contains a lot of good info.

Their compiler comes with a load of drivers and functions which makes blinking your first led a simple affair. Looking at the generated assembly code teaches a lot about how a pic and its peripherals work under the hood.
 
The following users thanked this post: djsb

Offline AussieBruce

  • Regular Contributor
  • *
  • Posts: 77
  • Country: au
Re: Starting with PIC Microcontrollers
« Reply #5 on: January 21, 2025, 11:56:49 pm »
I'd suggest you at least take a look at Arduino before getting going.  The whole platform is designed for beginners and hobbyists, the programming language is simpler than C (although very similar), copious support plus a wide range of processor and interface boards available. I used to do things on PICs but after my first Arduino project would never go back.
« Last Edit: January 21, 2025, 11:58:33 pm by AussieBruce »
 
The following users thanked this post: djsb

Online fchk

  • Frequent Contributor
  • **
  • Posts: 301
  • Country: de
Re: Starting with PIC Microcontrollers
« Reply #6 on: January 22, 2025, 09:04:19 am »

I’m looking for advice on which PIC microcontroller is best for beginners, especially for handling I/O and UART communication. Also, what common issues should I watch out for when programming or debugging? Any tips or tools you recommend for a smooth start would be super helpful. 

The easiest is PIC24/dsPIC33. These are 16 bit processors. Since the C language was designed for processors with at least 16 bit register width it's a better fit. And although this processor also has separate address spaces for code and data it is less visible here than on the 8 bit processors thanks to the PSW feature.
Using any other series (PIC16, PIC18) is also perfectly fine. Peripherials are very similar across the product lines.

Top Pitfalls:
- Data Direction registers TRISx: On most platforms 0 is input 1 is output. On PIC 0=o as output and 1=I=i as input.
- ANSELx: If a pin has got analog functions, the analog functions are enables by default. You must clear the corresponding bit in the ANSELx register first in order to make it a digital pin.
 

Offline woody

  • Frequent Contributor
  • **
  • Posts: 443
  • Country: nl
Re: Starting with PIC Microcontrollers
« Reply #7 on: January 22, 2025, 09:45:50 am »
The easiest is PIC24/dsPIC33. These are 16 bit processors. Since the C language was designed for processors with at least 16 bit register width it's a better fit.
I fail to see why this would be a better fit, seen from the user perspective. Apart from that I think pic16/18 will give OP many more (and cheaper) devices to choose from with much more on-line material available to get the help they might need.
 

Online voltsandjolts

  • Supporter
  • ****
  • Posts: 2656
  • Country: gb
Re: Starting with PIC Microcontrollers
« Reply #8 on: January 22, 2025, 09:45:57 am »
If it has to be PIC, then I would recommend PIC24.
Nice arch and peripherals, quite capable range of devices, gcc compiler, datasheets very readable, not as overwhelming as some 32bit mcu datasheets.
But also a great stepping stone to 32bit.
 

Offline SteveThackery

  • Frequent Contributor
  • **
  • Posts: 948
  • Country: gb
Re: Starting with PIC Microcontrollers
« Reply #9 on: January 22, 2025, 09:59:19 am »
I'm with @Aussie Bruce on this.  Why start with PIC?  Arduino is so much better for beginners.  And cheap, too.
 

Online jpanhalt

  • Super Contributor
  • ***
  • Posts: 4189
  • Country: us
Re: Starting with PIC Microcontrollers
« Reply #10 on: January 22, 2025, 10:01:21 am »
The TS hasn't picked a device or responded yet.  Along with what's been suggested for PICs, on some chips you need to turn off comparators, watch for input voltage levels (TTL or CMOS), turn off LVP (if present, default is on as you might expect), and decide on output (OD or push-pull).  I don't see those as inconvenient, but rather as enhancements.
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2820
  • Country: us
Re: Starting with PIC Microcontrollers
« Reply #11 on: January 22, 2025, 01:22:34 pm »
The TS hasn't picked a device or responded yet.  Along with what's been suggested for PICs, on some chips you need to turn off comparators, watch for input voltage levels (TTL or CMOS), turn off LVP (if present, default is on as you might expect), and decide on output (OD or push-pull).  I don't see those as inconvenient, but rather as enhancements.

Turn off Low Voltage Programming (LVP) with caution.
If I remember correctly, the SNAP programmer can ONLY do LVP.  Turning off LVP will prevent the SNAP from programming the PIC.  That's why I recommend one of the PICkit programmers.

BTW:  I always turn LVP off to have use of the extra I/O pin.
 

Online jpanhalt

  • Super Contributor
  • ***
  • Posts: 4189
  • Country: us
Re: Starting with PIC Microcontrollers
« Reply #12 on: January 22, 2025, 01:35:10 pm »
Sorry, I should have said to turn it off if you are not using it.  That applies to all of the things I mentioned.
 

Offline Geoff-AU

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: au
Re: Starting with PIC Microcontrollers
« Reply #13 on: January 23, 2025, 10:07:50 pm »
Do you want top-down learning or bottom-up learning?

If you're more interested in solving the problem (top-down) then Arduino 100%.  It's easy, approachable, and fast to do basic things like twiddle IO and talk UART.

If you're more interested in learning how microcontrollers work (bottom-up) then start with a basic 8-bit MCU (PIC or Atmel or maybe MSP430).  Learn how to fiddle the right registers to make an IO pin twitch and build up from there.
 
The following users thanked this post: djsb

Offline djsb

  • Super Contributor
  • ***
  • Posts: 1002
  • Country: gb
Re: Starting with PIC Microcontrollers
« Reply #14 on: January 23, 2025, 11:32:44 pm »
I help to teach PIC and Arduino MCU's on an embedded systems course. We use PIC16F819 (NO UART), PIC16F1827/47 (USART,SPI,I2C ADC etc). We use CCS C PCM compiler, and it is very easy to use with VERY good support on the official CCS info forum (but not in many other places. XC8 is well-supported on the official Microchip forum and here on EEVBLOG. It is, however, quite difficult to use for a beginner (which I still consider myself to be). I started out by using PIC assembly language on a PIC16F628A in 2014. We switched over to CCS C and have never looked back. Other compilers (Great cow Basic and Oshonsoft Basic) are available. Microchip has good support for DIP packages and is easy to use in a breadboard and on simple custom PCB's (using KiCad mainly) which is why we use them. Their programmers can be a bit more expensive for older chips, but the SNAP programmer at around £15 is good value (BUT can ONLY use LVP programming from the beginning (set in fuse config word/s) and newer chips with MPLABX 6.20+). There is one open source programmer available online and many cloned versions around.
Arduino's are a separate topic I won't cover here in depth even though I also use the UNO, NANO and have started with the ESP32 platform recently.
« Last Edit: January 23, 2025, 11:41:08 pm by djsb »
David
Hertfordshire, UK
University Electronics Technician, London, PIC16/18, CCS PCM C, Arduino UNO, NANO,ESP32, KiCad V8+, Altium Designer 21.4.1, Alibre Design Expert 28 & FreeCAD beginner. LPKF S103,S62 PCB router Operator, Electronics instructor. Credited KiCad French to English translator
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6322
  • Country: 00
Re: Starting with PIC Microcontrollers
« Reply #15 on: January 24, 2025, 06:13:46 pm »
I wonder why you decided on a PIC rather than an Arduino, either original or from a third party.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf