PIC: Beginning with PIC microcontroller programming - Page 1
Forum section: electronics / general

author: Omrieinbar
author_rank: Newbie
timestamp: December 22, 2019, 09:22:26 pm
content: I would like to program a microcontroller to control a DDS based function generator, I got a couple of PIC16F18875 micros, a PICKit 4 and a Microchip Curiosity HPC board to get me started. can anyone recommend a beginners guide to programming microcontrollers (Books\ Videos)?They don't need to be specifically about a PIC16F18875 but I want to get a general idea for how to program PIC micros for future projects.I already know how to use an Arduino and I don't want to use an Arduino for this project since I want to learn something new.Also, A Raspberry pi is also not an option since I don't want to buy one, I know it is much more powerful but it also cost a lot more than a micro.Thanks.

author: MarkF
author_rank: Super Contributor
timestamp: December 22, 2019, 09:53:13 pm
content: All you really need is a basic knowledge of C programming and the PIC datasheet.Your program will read/write directly to the PIC registers.You will need the datasheet for the register names and bit assignments.The PIC16F18875 you choose will only allow you to do basic control for testing.However, it does NOT have enough memory for your complete project.In my Function Generator, I used a AD9834, MCP4812 and PIC18F2550.I had used 95% of the PIC memory when finished. You will need at least 32M byte.However, here are a few tutorials of general PIC programming:And code for a PIC18F4520 to blink a LED:

author: Lunasix
author_rank: Regular Contributor
timestamp: December 22, 2019, 10:14:54 pm
content: Hi,I don't know if a PIC16 is big enough for your project, but if you look, you can see that you can find PIC32MM or PIC32MX at same prices. So, don't waste your time with PIC16 and go directly to PIC32.

author: nctnico
author_rank: Super Contributor
timestamp: December 23, 2019, 12:49:15 am
content: Quote from: Lunasix on December 22, 2019, 10:14:54 pmBetter move on to ARM then if you are going for 32 bit. And unlike many seem to think ARM doesn't have to be very difficult. Personally I find NXP's LPC series ARM controllers well documented an easy to use (relatively simple to program & use peripherals).

author: SmokeyTheElectrician
author_rank: Contributor
timestamp: December 23, 2019, 02:03:28 pm
content: Quote from: MarkF on December 22, 2019, 09:53:13 pmI do not get the notion the OP wants to build a DDS function generatorso much as control one, after all he wrote:Quote from: Omrieinbar on December 22, 2019, 09:22:26 pm( insert puzzled emoji here --- not )ah, maybe the OP will clarify.Thanks for the zip file with the awesome PIC Programming short course.

author: rvalente
author_rank: Frequent Contributor
timestamp: December 23, 2019, 05:59:43 pm
content: I would definitely recommend you to check application notes, they often show in very simple examples how to config the oscillator, handle the ports, using all kinds of peripherals, they have commented code to download and sometimes, some theory too.Try to filter them to show only MPLAB X IDE (there are some old examples that would use retired libraries and compilers like hitech/ccs)https://www.microchip.com/wwwcategory/taxonomysearch/

author: Omrieinbar
author_rank: Newbie
timestamp: December 26, 2019, 09:38:41 pm
content: Thank you for your replies!My function generator probably won't be based around the PIC16F18875, I thought of it as more of a intro to PIC programming as I don't know much about programming micros I'll see what I can accomplish on the PIC16F18875 and move on from there once I have a clearer picture of what I want the function generator to do.If anyone have any more tips I will be glad to hear them.

author: MarkF
author_rank: Super Contributor
timestamp: December 27, 2019, 02:29:47 am
content: Quote from: Omrieinbar on December 26, 2019, 09:38:41 pmSome additional things to think about:My Function Generator is based on the AD9834.I choose it because I could use the 'FS_Adjust' pin to control the amplitud.Also, I added additional capabilities not built into the AD9834.- I implemented a frequency sweep, up and down, by updating the AD9834 from a fixed 500Hz interrupt in the PIC.- I multiplexed the 'Sign_Bit_Out' pin with a PWM pin on the PIC. A PWM waveform is a nice ability to have.You need to be careful not to drive both the 'Sign_Bit_Out' pin on the AD9834 and the PWM pin on the PIC at the same time.The PIC18F2550 just barely met my requirements. One of the driving factors is the display graphics. I used a small OLED display and the graphics library used almost 50% of the PIC memory. A PIC18f2620 is another option with 64B of memory. If you use a display that needs to buffer the display memory, you will need a MCU that has a LOT of RAM memory.

author: mpgmike
author_rank: Newbie
timestamp: December 29, 2019, 07:46:33 pm
content: As for learning C and more specifically MPLABX, Microchip has a tutorial site that covers a myriad of topics at:https://microchipdeveloper.com/training-self:startAlso, as for the OLED display eating up bunches of memory, I've been playing with the Nextion displays (Nuts and Volts current issue includes an article on this). The Nextion IDE allows you to create the look & function you want while the built-in MCU takes care of all the memory needs:https://www.itead.cc/display/nextion.html