Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Tips for Starting dsPIC?

Status
Not open for further replies.

PICMICRO

New Member
I think I am now comfortable with PIC16F with Hi-tech C compiler. I have done, Timers, PWM, interrupts, LCDs, ADCs, Sleep and Wake-ups, UART etc.
Now, I would like to start learning dsPIC, the one which I have is dsPIC33FJ32MC202.
I chose it for its 16-bit operations, 12-bit ADC, Higher speed, 4 independent PWMs etc.
I think those are the things one seeks in digital signal Processors anyway.
So, where do I start? Any good online tutorial site you know?
Also what compiler do you suggest?
Is it fine to directly jump to dsPIC skipping the 18F family, or would it be difficult?

Any suggestion is appreciated.
 
dsPICs are a pleasure to deal with after playing around with 16F parts. up to 60MIPS (40 for yours), extra memory, no memory banking, unique interrupt vectors, many more working registers, peripheral pin select, etc., etc.

If you intend to use assembly, there will be some time needed to adapt to its instruction set. It's a lot more flexible than the 8-bit parts so there is more to remember. One of the major differences is the instruction rate is 1/2 the clock rate instead of the 1/4 ratio on the 8-bit parts. Keep that in mind when you write time sensitive code.

In terms of compilers, I've had no reason to use anything but C30 which is Microchip's compiler for 16-bit devices. They have it split now into 2 separate compilers with one servicing the PIC24 line and the other handling all the dsPICs. It's available for free with no important limitations for what the majority of people use it for.

If you don't have one, I would suggest getting a PICkit-3 or better to program it.
 
Thank you nsaspook for the helpful links. Thanks phalanx for the nice tip.
I don't (and can't) do assembly. So, it seems C30 is my choice. (What about its only Level-1 optimization after 60 day trial ?).
And Yes, I do have PK3.
Is it Ok to leap 18F series ?
Aren't there a list of common mistakes/misconception newbies from 16F do at dsPIC ? phalanx mentioned 1 and it was really helpful.
Managing to produce 3.3V seems trouble though. I think I would use LM317.
 
Managing to produce 3.3V seems trouble though. I think I would use LM317.
Strange choice. Why not just use a 3-pin 3.3v regulator - there are thousands available and they work just like the 5V regulator you use now. Be sure to follow data-sheet example circuitry for whichever regulator you choose.

Or use dsPIC30f4013. 5V like you are used to and nice easy 40 pin DIP package. Bit outdated though, but still quite powerful.

Go to the Microchip forum and read every post that MBedder ever wrote. Some of his replies are amusement only, but there is some really good information in other posts.

Is it Ok to leap 18F series ?
Yes sure. Only down side is that there is far less information around on dsPIC than PIC18, and what there is tends to be from advanced expert users.

You will find that the change from HiTech C compilers to Microchip C compilers is harder than changing PIC16 to dsPIC

or would it be difficult?
Hmmm... maybe. Depends how keen you are
 
Last edited:
Just finished scanning through the C30 manual. And I have few questions to ask
1. Do I need to understand and use the attributes like near / far / alligned / tight etc ? I would be mostly doing small and simple programs i.e. no need for tight optimization for code space and speed.
2. There seems to be two way of declaring ISRs, Fast (_ISRFAST) and Slow (_ISR) ? Why shouldn't I always use Fast ? Also, do I need to bother about context savings?
3. The datasheet for my dsPIC says it can do some nice mathematics like 32/16 bit divide, +-16 bit shifts for 40 bits data etc. How do take advantages of such?
Thanks.
 
1. You shouldn't have to worry about these attributes when you are just getting started with simple programs.

2. Your dsPIC33 has a single set of shadow registers that can save and restore the contents of W0, W1, W2, and W3 at the same time using a single instruction (PUSH.S and POP.S). _ISRFAST makes use of this functionality to reduce the context switching overhead for whatever ISRs you apply it to. _ISR saves and restores the W registers by pushing and popping them individually using a stack in memory.

Since there is only a single set of shadow registers, you can only use _ISRFAST on routines at the same interrupt priority level. If used on different priorities, a higher priority fast interrupt could wipe out the shadow registers being used by a lower priority one leading to erratic behavior of your program.

C30 takes care of context saving for you.

3. As the name implies, the dsPIC has a DSP engine integrated in it. It provides a hardware 17x17 bit multiplier, a barrel shifter, 40-bit adder/subtractor, 2 40-bit accumulators, and selectable rounding and saturation logic. It has the ability to concurrently fetch two variables from memory while performing a MAC (multiply and accumulate) instruction on 2 W registers in a single cycle It can work with both integer and fractional data and is set to fractional mode after a reset. Division is handled by silicon that isn't part of the DSP engine.

Making proper use of the DSP capabilities requires a good understanding of how it works at the hardware level since the typical ANSI-C instructions will not take advantage of it. There are a few ways to make use of the functionality though. First is to use inline assembly but this requires you to know all the details of where data needs to be located in the dsPIC. Second is to use the built in functions of the compiler (which can be found in the C30 users guide). The built in functions hide a lot of the setup details that are needed to make the DSP function properly and can be used to build higher level functions in your code. The last way is to make use of the DSP library that comes with C30. It's a highly optimized library written mostly in assembly that covers lots of higher level DSP operations and they make use of the DSP core.

Take a few days to read through the manuals for the dsPIC and C30. There is a lot of information that needs to be absorbed before you can use the DSP engine effectively. For a lot of what you probably have to do, it may not even be necessary!
 
1. For what you are doing you can just use near addressing, this allows you to use the first 32k of program memory and first 8k of data memory.
2. Fast ISRs use shadow registers instead of the stack to save the context and so if a higher priority interrupt comes along it will trash the shadow registers.
3. They are part of the instruction set and so the compiler will take care of it.

edit, Phalanx beat me to it with a more detailed explanation.

Mike.
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top