Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 00:36 28 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : PIC32 code

     Page 1 of 2    
Author Message
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 01:14pm 19 Jun 2013
Copy link to clipboard 
Print this post

I would like to write code for the PIC 32 chip.

I have downloaded the MPLAB X package and tried to set up for a new project. I never used to have any problems setting up a project for 8 bit pics using MPLAB IDE in the past.

In the set up, I get as far as selecting the compiler but system says none available.

Is there anything specific I need to do to get a project running.

Has anyone used MPLAB X or is there a better(another) way of writing C code for the PIC 32??


David M.
 
kiiid

Guru

Joined: 11/05/2013
Location: United Kingdom
Posts: 671
Posted: 01:42pm 19 Jun 2013
Copy link to clipboard 
Print this post

Unless you are using some OS different from Windows, I would recommend keep going with the MPLAB 8.x
MPLAB X may look much fancier, but in fact is a typical example of overdoing options and controls and you will not experience any improvement in the way you write with it.
http://rittle.org

--------------
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 05:10pm 19 Jun 2013
Copy link to clipboard 
Print this post

Hi David,
Geoff has a rundown on 'C' compilers for the PIC on his website C reviews. You might want to check that out.It doesn't talk about the old and new MicroChip IDE's but then MPLAB X wasn't out then.
Greg
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 08:32pm 19 Jun 2013
Copy link to clipboard 
Print this post

Thanks Greg,

I'll have a look at Geoff's c review after this. In the meantime today, I downloaded a C compiler for PIC32 from microchip. I called it up using MPLABX and at least it now lets me create a project.

One small step - more to come.

Any input is gold!!

Even if I can get the pic32 to just flash a led it will be a big start.
David M.
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 08:48pm 19 Jun 2013
Copy link to clipboard 
Print this post

I think MPLab X is the way forward, future chips for instance.
The support for the IDE 8 will stop someday.
I have to bite that bullet too as i am used to the IDE 8 version.

Microblocks. Build with logic.
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 09:07pm 19 Jun 2013
Copy link to clipboard 
Print this post

  TZ said  I think MPLab X is the way forward, future chips for instance.
The support for the IDE 8 will stop someday.
I have to bite that bullet too as i am used to the IDE 8 version.


I had a read through Geoff's review and since I now have the microchip compiler, I'll try and stick with it until the brick wall wins.

For the 8bit pics I use assembler anyway.

Meanwhile, I'll need to find an example or two to see how to get started. Microchip's documentation as I have nearly always found it is vague and inadequate to the extreme. It is a wonder that I still have any of my greying hair left.

If anyone has "flashed a LED" on a PIC32 I'd be grateful of the guidance.
David M.
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3802
Posted: 09:19pm 19 Jun 2013
Copy link to clipboard 
Print this post

Olimex sell various PIC32 boards and provide such samples free on their web site - no need to buy any boards.

John
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 02:25am 20 Jun 2013
Copy link to clipboard 
Print this post

  MOBI said  If anyone has "flashed a LED" on a PIC32 I'd be grateful of the guidance.


Flash a LED

1: // Configure for 20MHZ using the 8MHz internal oscillator
2: #pragma config FNOSC=FRCPLL, FPLLIDIV=DIV_2, FPLLMUL=MUL_20, FPLLODIV=DIV_4
3:
4: #include <plib.h> // include PIC32 peripheral library
5:
6: main() {
7: int i;
8:
9: SYSTEMConfigPerformance(20000000); // optimise for speed
10: mPORTDSetPinsDigitalOut(BIT_1); // make RD1 (LED) an output
11:
12: while(1) {
13: mPORTDToggleBits(BIT_1); // flip the LED off/on
14: for(i=0; i<416000; i++); // 250mS delay at 20MHz
15: }
16: }

Line 1 Comments start with a double slash (//)

Line 2 This sets the configuration parameters for the chip (sometimes called the
"fuses"). The first entry (FNOSC=FRCPLL) sets the clock source to the internal
oscillator (8MHz) via the phase locked loop (PLL). The second entry causes the
oscillator to be divided by 2 before being applied to the PLL. The third entry sets
the PLL multiply ratio to 20. This means that the internal oscillator after being
divided by 2 will be multiplied by 20 thereby giving an output from the PLL of
80MHz. The last entry causes the PLL output to be divided by 4 before being used by
the core processor, which therefore runs at 20MHz. By varying this last entry you
can change the core speed with DIV_1 giving 80MHz and DIV_2 giving 40MHz.

Line 4 This includes standard code that defines the library functions that we will
use.

Line 6 The program starts running at the beginning of the function main(). The
curly bracket marks the beginning of the function and the closing bracket on line 16
marks the end.

Line 7 We define an integer for later use. Note that all integers default to a
signed 32 bit number.

Line 9 This calls a library function to optimize the chip for the clock speed that
we are running at (20000000 Hz). The optimisations include setting up the
instruction cache and wait states for memory access.

Line 10 This calls another library function to set RD1 as an output. RD1 is pin 49
on a 64 pin chip.

Line 12 This sets up an infinite loop so the LED will keep flashing forever.

Line 13 We call another library routine to toggle the state of the RD1 output from
high to low or vice versa. This is where the LED is turned on or off.

Line 14 This is a delay routine to prevent the LED from flashing too fast. Counting
to 416000 takes about 250mS when running at 20MHz.

Geoff
Geoff Graham - http://geoffg.net
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 02:43am 20 Jun 2013
Copy link to clipboard 
Print this post

Hi Geoff,

Thanks heaps for the demo and explanations. I've never programmed a PIC in C before Although I can programme in C++, the PIC version is a new and different ball game.

I've started making headway on the MPLAB X IDE and have got a couple of nonsense programmes to compile.

Getting there. Like Rome - not built in a day.

regards
David M.
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 04:30pm 20 Jun 2013
Copy link to clipboard 
Print this post

David, the book that Geoff recommends on his website is very good and works your way structurally through most aspects of the the PIC32, projects using those aspects and the 'C' code to do it (not that I've done it yet). It's also got a companion CD-ROM which has all the code/project examples in it to make life easier, and a 'C' compiler. There's a 'companion' website at PIC32 book.

The downside is that it isn't cheap but I think it's worth the money (or it was a few months ago). I chased around for the best price I could get then and that was $55 at Fishpond. I've just checked it and unfortunately it's now $75 - ouch, the difference between a 110c dollar and a 92c dollar. There's no postage at least, and mine arrived after about 10 days. The Fishpond link for it is: Fishpond PIC32
Greg
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 07:41pm 20 Jun 2013
Copy link to clipboard 
Print this post

That is a ridiculous price, no wonder there are illegal copies.
I bought mine for 400 baht (about 14US$) in a bookshop that went out of business.
The book is good as it collects all the necessary things and have many little projects.
Best you read it from top to bottom.
Microchips documents are not the easiest to follow and you need multiple pdf's open to get things together. As such the book is a real time saver and cuts through a lot of stuff that is not important when you are starting out.

Edited by TZAdvantage 2013-06-22
Microblocks. Build with logic.
 
djuqa

Guru

Joined: 23/11/2011
Location: Australia
Posts: 447
Posted: 07:45pm 20 Jun 2013
Copy link to clipboard 
Print this post

  TZAdvantage said   That is a ridiculous price, no wonder there are illegal copies.
I bought mine for 400 baht (about 14US$) in a bookshop that went out of business.


Actually it is a great price for a hardcover reference book in Australia.

VK4MU MicroController Units

 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 07:56pm 20 Jun 2013
Copy link to clipboard 
Print this post

Still you read it once and then you use the accompanying website.
I think a one time membership of his website for 10-20US$ and be able to access the information would be much better. Probably hundreds if not thousands would go for that offer. Straight into the authors pocket instead of being divided by many parties earning him maybe a few dollars a piece.
The website is were the most value is. Most books just collect dust, mine has already been given to someone else.
The Microchip forum is another great resource with helpful people if you get stuck with a problem.
Books are not really the best resource anymore as the content is static and you can not ask a book about a specific problem you have.
Which reminds me of something i wondered about. Geoff why you not have a "donate" button on your website? Supporting good work gives people (me) a good feeling.)


Edited by TZAdvantage 2013-06-22
Microblocks. Build with logic.
 
djuqa

Guru

Joined: 23/11/2011
Location: Australia
Posts: 447
Posted: 08:12pm 20 Jun 2013
Copy link to clipboard 
Print this post

  TZAdvantage said  
Books are not really the best resource anymore as the content is static and you can not ask a book about a specific problem you have.


Books are still valuable resources.
I have e-book readers, tablet computers, laptops, PC's and yet I still enjoy reading a REAL Book.
But each to their own.
VK4MU MicroController Units

 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 08:34pm 20 Jun 2013
Copy link to clipboard 
Print this post

That is why i said 'not really the Best' and in the context of the PIC32.
For the fast changing world of computers it is not really working very well.
Ask any university student.
Now for reading fiction, philosophy and more, nothing beats a book.Edited by TZAdvantage 2013-06-22
Microblocks. Build with logic.
 
djuqa

Guru

Joined: 23/11/2011
Location: Australia
Posts: 447
Posted: 08:38pm 20 Jun 2013
Copy link to clipboard 
Print this post

  TZAdvantage said  
Ask any university student..

Most can hardly read given the current state of education.

VK4MU MicroController Units

 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 08:40pm 20 Jun 2013
Copy link to clipboard 
Print this post

Boy do i agree with that.
University level now is like high school from the past.

Microblocks. Build with logic.
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 09:24pm 20 Jun 2013
Copy link to clipboard 
Print this post

  djuqa said  
  TZAdvantage said   That is a ridiculous price, no wonder there are illegal copies.
I bought mine for 400 baht (about 14US$) in a bookshop that went out of business.


Actually it is a great price for a hardcover reference book in Australia.

Well, the book I bought for $55 was just a paper back and so is the $76 one - still, by the time it wears out we'll all be into 64 bit micros! I bought myself a Kindle a couple of years ago David, thinking that I'd be able to access tech books for a lot less. They're certainly cheaper but after buying just one I gave it up because the diagrams were unreadable!

TZ, your idea sounds good, $10 access to the full book, and the forum - let me know if it happens! But yes, it presumably would be good for the author - but then where's the incentive for the publisher and the advertising of it. It would probably be a good option though for the authors that are already well established, like de Stasio, Jan Axelson etc.
Greg
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3802
Posted: 10:39pm 20 Jun 2013
Copy link to clipboard 
Print this post

The author may not have the right to do that, even if he wanted to, now that it's a book.

BTW, I would not be asking almost anyone now a student. Attention span, what's that?

John
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 12:30am 21 Jun 2013
Copy link to clipboard 
Print this post

Hi all,
Looks like I stirred up a bit of interest into PIC32 programming.

One of our TBS cobbers sent me an ebook on PIC32 by Lucio Di Jasio. I'm not too far into it yet as I have been travelling and only got home from ACT this evening. So far, it looks like a very handy book and written in an easy style.

I will need to do a bit of search/research into the various #include files and their functions.

How many of the members of TBS write C progs for PIC32?


David M.
 
     Page 1 of 2    
Print this page
© JAQ Software 2024