Author Topic: PIC: Beginning with PIC microcontroller programming  (Read 3656 times)

0 Members and 1 Guest are viewing this topic.

Offline OmrieinbarTopic starter

  • Newbie
  • Posts: 4
  • Country: il
PIC: Beginning with PIC microcontroller programming
« on: December 22, 2019, 09:22:26 pm »
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.
 

Online MarkF

  • Super Contributor
  • ***
  • Posts: 3302
  • Country: us
Re: PIC: Beginning with PIC microcontroller programming
« Reply #1 on: December 22, 2019, 09:53:13 pm »
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:
 
The following users thanked this post: Omrieinbar

Offline Lunasix

  • Regular Contributor
  • *
  • Posts: 163
  • Country: fr
Re: PIC: Beginning with PIC microcontroller programming
« Reply #2 on: December 22, 2019, 10:14:54 pm »
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.
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 30371
  • Country: nl
    • NCT Developments
Re: PIC: Beginning with PIC microcontroller programming
« Reply #3 on: December 23, 2019, 12:49:15 am »
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.
Better 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).
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline SmokeyTheElectrician

  • Contributor
  • Posts: 25
  • Country: us
Re: PIC: Beginning with PIC microcontroller programming
« Reply #4 on: December 23, 2019, 02:03:28 pm »
...

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:

I do not get the notion the OP wants to build a DDS function generator
so much as control one, after all he wrote:
 
I would like to program a microcontroller to control a DDS based function generator, ...

( insert puzzled emoji here   --- not )

ah, maybe the OP will clarify.

Thanks for the zip file with the awesome PIC Programming short course.

"We must stick them with quills! It's the only way!"
-- Scott Adams
 

Offline rvalente

  • Frequent Contributor
  • **
  • Posts: 831
  • Country: br
Re: PIC: Beginning with PIC microcontroller programming
« Reply #5 on: December 23, 2019, 05:59:43 pm »
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/
 
The following users thanked this post: Omrieinbar

Offline OmrieinbarTopic starter

  • Newbie
  • Posts: 4
  • Country: il
Re: PIC: Beginning with PIC microcontroller programming
« Reply #6 on: December 26, 2019, 09:38:41 pm »
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.
 

Online MarkF

  • Super Contributor
  • ***
  • Posts: 3302
  • Country: us
Re: PIC: Beginning with PIC microcontroller programming
« Reply #7 on: December 27, 2019, 02:29:47 am »
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.

Some 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.
 
The following users thanked this post: Omrieinbar

Offline mpgmike

  • Newbie
  • Posts: 4
  • Country: us
Re: PIC: Beginning with PIC microcontroller programming
« Reply #8 on: December 29, 2019, 07:46:33 pm »
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:start

Also, 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
 
The following users thanked this post: Omrieinbar


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->