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.

Learning MCU's: What to learn when you don't know much...

Status
Not open for further replies.

keny

New Member
This is more of an article than a request for technical support. I have been getting assistance from you all and wanted to summarize my study and learning of the basics of MCU's. A few months ago I didn't know much about MCU's at all, and now I want to document those early stages of learning because I think there are things I know now that could have helped me along the way.

I'd like to open a discussion – not about the specifics of electronics or microcontrollers – but to talk about those frustrating moments when you’ve been trying to figure out something for hours if not days, patiently hacking away at whatever it happens to be.

I have got to be the single most patient person in the world. I am a relatively social guy, but I have a need and a passion for electronic engineering. I do it as a hobby. I enjoy technical things and little nitty gritty details that have relatively no purpose in life. The obscure details one would only know after discovering them ten hours after endeavoring into some kind of sustained, frantic, aggravated assault on pdf files, google searches, web sites in foreign languages, youtube videos and “hunt and peck” trial and error attempts at resolving the problem du jour.

In learning the Microchip MCU I have found these obscurities in just about every task I have encountered. Couple that with my self-taught EE background and previous programming experience in PERL, I can say the last three months have been challenging and at times hell. I Don’t have mentors and I know no one who is into electronics engineering, and everyone into programming is doing internet stuff.

The existence of these forums is a great asset to the self-taught like me. In my previous audio career, when I was studying audio engineering I found the “Digidesign User Conference” and 6 months later I had learned a LOT. After three months of intense learning, I feel as if I’m a tenth of the way there this time.

It may be that there are so many different iterations and options that make it so you can’t walk directly into doing this because you end up tripping over the fifty other related (yet impossible to realize immediately) things you need to learn - to do your simple task.

There must be some sort of progressive learning order or “way”. Once you get used to turning off the Analog to Digital converters (ADCON) and setting up your tristate ports, once you get past the configuration word you still have no idea what all those acronyms by the pin diagrams mean. You probably don’t understand what a special function register is (SFR), and the data sheets look more like a foreign language than a helpful thing. I have two tips that would have helped me immensely at the beginning: 1. Learn what a Register is. 2. Learn where to find the definitions for them. Print the Special Function Register Map and the include file for your MCU.

These key pieces of information made everything click for me. I still am a novice at this, but I have finally found the comfort zone I was looking for. Three quarters of the acronyms in programming an MCU are defined in those library files, (that define the SFR’s) and practically nothing on the internet points the way to them. Also, look in the Hi-Tech C folder in your programs folder. In addition to the manuals there, you can find in the include folder definitions for your configuration words and special function registers. Sometimes HI Tech types the SFR’s different from the Microchip manual, so you need to use those as a guide to reference the SFR’s described in the manual.

Then there are other big decisions that need to be made early in learning about all this that are missing from the guides of the novices: Which compiler to use? Which MCU to use? Assembler or C? These three decisions square out to exponentially confusing options, leading to a maddening learning curve that daunts even the most patient. First you are looking for examples of the things you want to do. You may find an example that does what you want to do but it uses a different compiler. Then you find one that uses assembly language and you don’t know assembly language. Then you get in to your project and realize that you have been using the wrong chip the whole time because you didn’t plan ahead – or worse, the compiler doesn’t support that chip completely. These things aren’t your fault – you are winging it to begin with. So you end up swapping out chips and starting from the beginning with what you learned looking more like a battlefield with dead bodies strewn throughout. Then to make things worse, god help you if your MCU is a bit old and out of date.

I have been dealing specifically with the Hi Tech C compiler. Optionally I could have used the C18 compiler or who knows what else. Occasionally an example is made for these other compilers which confuse everything even more. You end up asking yourself questions like “Am I using the wrong compiler?” and “Should I have just learned Assembly Language to begin with?” There are issues with Hi Tech C, but I have no doubt there will be intense issues with any other compiler.

Getting a little further into the programs I have been writing, I recently arrived at the point where I wanted to use a debugger for real. And with it came an entire set of learning curve lessons. The compiler optimizations really threw me off big time. If you haven’t paid $500 dollars for the real Hi tech compiler like me, and want to use a debugger, good luck. You have no control of optimizing the code, FWIG. Basically you write code and then the compiler rewrites your code in an intermediate language, and then rewrites it again. This process may make your program work better or not. I want to turn all optimizations off, so I can test my weak C knowledge as well as the functionality of the chip. My attitude towards this is leaning to: If you want to test something because you aren’t sure how to write it in C to begin with, you are almost better off working out the nitty gritty of academic C language related issues in a separate compiler (like mvs) that does not optimize like these do. As for learning C versus Assembly, I am getting to know assembly language now, not by choice but because you really do need to learn C and Assembler to pull this off. It’s just another lesson no one taught me.

In the concept of getting “taught” I went looking for literature that would help me out. I found the book “Designing Embedded systems with PIC Microcontrollers” by Tim Wilmshurst to be a useful point of reference when you are trying to do something and need the basic concept behind it. It gives a good general conceptual view of all the basics and can be read in any order without getting too over your head.

Unfortunately, Most bookstores around me stock the book “Programming and Customizing the PIC Microcontroller” by Myke Predko, which goes from “I can handle this” to “We are no longer on the planet EARTH” in a heartbeat. His “123 Microcontroller experiments for the evil genius” is a little better at going at basic things but is out of date. He also leads you to HI-Tech C. I’m guessing that more than half of the people use HTC because they probably read these books. I have unanswered questions: Is MCC18 better? Are there better compilers out there? Why do people use Hi Tech C over another compiler? Why do some people use MCC18 or other compilers? It’s free right? Why would I pay 500 bucks for Hi Tech when MCC18 is free?

The moral of the story, I think, is to have an open mind and be willing to accept global and sudden changes in plans during the beginning stages of learning this. If you are learning something but the solution isn’t coming to you, keep your focus and keep working at it. Once you begin to see the issues at a resolution you will know how to deal with them better. All of those little off shoots of learning, things that you tried but didn’t work, or things that just took forever to get going, are worth it. I am beginning to believe that learning to program a MCU without much experience is all about learning all of it at the same time, by trial and error, and by finding the sage advice of people you can come in contact with. I am very thankful I have found this, the Hi tech Forum, and the Forums on Microchip.com. Most of the time you can collect the information you need to solve the problem but it might just take that extra mind to pinpoint the problem and put a little bow tie on it.

Best Regards,
Keny
 
Well, I started on processors where you could key in a program in binary. Learned assembly language to the point that I could hand assemble a complete program. My FIRST "C" program was an operating system and my FIRST FORTRAN program was a DDC (Direct Digital Control) system with 7 PID loops. LISP was the most horrible language in the entire world. APL is just wierd. PASCAL is too restrictive. Still having issues with OOP. COBOL and SNOBOL aren't worth anything. BASIC can be cool.
Programming in G or LABVIEW can be really nuts. Most languages are procedural, but G is data-flow based. It makes it very easy to wite code that operates in parallel, A side effect is race conditions. The VI's (Virtual Instruments) as they are called execute when the data becomes available.

For starters, Boolean algebra is a usefull start. One needs to know howto set a bit and clear a bit. What sets processors apart is the archtecture. that's one way to choose. Yoou need to know about big and little endian. Say you needed a processor to make an IR remote contol. What's important? I'll let you think about this.

Time to market and development tools.

One should think about optimization. What does that mean? Time to market? Small code size? Low cost processor? The number of unitsproduced can help this decision.

Generally, one should write in "C" and use inline assembly code to optimize speed.

If you can take a "C" statement and write an assembly code equlivelent, youhave some understanding.

You need to understand A/D and D/A converters.

Let's add interfacing. There is a lot there. Thermocouples, RTD's, 4-20 mA sensors, 0-10 V, 0-5 V, 1-5 V, +-2.5 V etc.

You must understand GROUND and what a ground loop is.

There's a few things which have no order.
 
Thanks Keny, it makes me now think I am not the only one spinning in circles as I try to learn how to program pics.
 
My suggestion is to learn C on the PC first. Not C++ or C# but C. Maybe good old turboC or gnu C++ (ignore the C extensions).

It is a lot easier to transition from the PC to a micro controller then to learn both the language and the micro controlled at the same time.
 
I agree, but then again, that is something that makes so much sense only a school would make you do that. For the mercenary hacks, I doubt it. BUT learning C on a separate compiler keeps the MCU stuff at bay... Is turboC even available these days?
 
Last edited:
If u can program on a high level language that is not object oriented (VB is OO) you can come to grips with what you can do with MCU programming.

I have a background in non mcu programming...Fortran,Basic,Vbasic,VBA, 6502 assembly etc. So I started with Pics 5 months ago. Did the Pickit2 tutorials in asm and then jumped into a serious project. Made some mistakes, got help from this forum and online tuts and became self taught as I am in all my languages. Fortunately for me I have some digital logic design courses from University days as well as control systems theory and math as well as microprocessor architecture. With this background I am learning at a comfortable pace now. No longer stuck with not knowing which question to ask to get help.

These days I am optimising math algorithms etc that I wrote a few months back which seem like bloat code to me now. I figure after another year or so I'll be pretty good.

So u need
1) A bit of Digital logic design capability -Boolean algebra etc.
2) Some programming experience, preferably in C++ or an assembly.
3) Understand simple electronics, Vdd,Ground, capacitors, diodes, transistors, resistors, LEds.
4) Have a bit of elect. theory...V=IR, P=VI kinda stuff.
5) Some prototyping/breadboarding skills, some soldering skills. Understand ESD.
6) Plenty patience, an understanding wife. An account with Jameco,Digikey or Newark...LOL

That and this forum will fix u right!
 
I didn't want to drop a ton of money into this hobby at first, mostly because I wasn't sure if I had the time or how difficult it would be. Ended up spending less than $100 for a pickit2, breadboards, a bunch of components etc. Went through Nigel's tutorials and now I use Sourceboost. I've been doing some form of programming for the last twenty years, so I'm very happy to be back to C. ASM felt like a forced 10km march to me but I think it was important time spent.
 
I agree, but then again, that is something that makes so much sense only a school would make you do that. For the mercenary hacks, I doubt it. BUT learning C on a separate compiler keeps the MCU stuff at bay... Is turboC even available these days?

It is and it is both available and free!

Wikipedia said:
In 2006, Borland's successor, Embarcadero Systems, re-released the Turbo C compiler and the MS-DOS versions of the Turbo C++ compilers as freeware. It has since been widely adopted for educational use, especially in India, where the national educational systems have standardized on this compiler for classes teaching the C programming language.

You need to use a dos emulator to run it. HowTo

EDIT: I have been thinking about using MPLAB SIM in conjunction with one of the light compilers. One can ignore most of the PIC related issues and learn C. The problem is that
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top