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 to program microcontrollers

Status
Not open for further replies.

misterT

Well-Known Member
Most Helpful Member
These are just my thoughts after few years of teaching embedded systems. I am a student myself and I have learned a lot when teaching others.

My philosophy has always been "By following instructions, you learn to follow instructions". So, we designed all exercises to be very simple with "traps". One example is to sample ADC and output the result as a percentage from 0% to 100%. Most students managed to output figures from 0% to 99%.. and then they had to find out why.

My favorite exercise was the "dice" where you had to generate random numbers from 1 to 6. We gave students a hint that there is a library function called "rand()".. haha.. I know, pretty evil :)

This is what most students wrote first:

C:
int dice;
while(1)
{
    if (button_pressed())
    {
        dice = rand();
        dice = (dice % 6) + 1; /* Limit the range to 1...6 */
        display(dice);
    }
}

I could have won lot of money playing against that code. Every game gave the same sequence of numbers every time.

So.. ~10 lines of code and we had one hour allocated for this one particular exercise. The question was, after the naive approach, how can you make it "more random"?.

The first real "eureka-moment" to students was the realisation of the "while(1)" loop.. and how fast it is.. and it runs "all the time". So, the next version of the program was:

C:
int dice;
while(1)
{
    dice = rand();
    if (button_pressed())
    {
        dice = (dice % 6) + 1; /* Limit the range to 1...6 */
        display(dice);
    }
}

Now the program "throws" the die all the time.. very fast. The moment the user pushes the button catches the current value of the rand(). Good..

But we wanted to push this even further.. do it without the "rand()" -function!
I leave it to you.. Thanks for listening.
 
Last edited:
Excellent! :) The loop runs so fast that the moment you push the button acts as a random event.. better than any pseudorandom generator.
And this is the moment when students understand the nature of programming microcontrollers. Many of them know C, Java etc. but have only programmed desktop computers. Microcontrollers need a completely different "state of mind".

.. One hour class that ends up with ~5 lines of code. I think I've earned my salary.

Tutorials are ok, but you really learn from making mistakes with goal in mind. Teachers should encourage students not to be afraid of making mistakes.
 
Last edited:
Haha this brings me back about five or six years. I got back in programming and figured i'd play with micro started with a stamp but to much money so i ordered some pic 18f1220 cheap and easy to program. I wrote a simple code to read a button. Easy right lol not that easy and why not like you just pointed out that dang thing can run a loop a lot of time between press. So one time the led lights like you want and the next it didn't. So you debonce the button works for me but i'm slower then some. Why is this not working then I sit in the basement thinking I'm a micro what am in doing I got a 8 mhz clock and I'm running in a loop just wait to have my button pressed my mind is running very fast they hit the button i'm thinking about some thing else. It didn't take long to see I had to do more then a just wait 50 ms to test my switch :)
 
Tutorials are ok, but you really learn from making mistakes with goal in mind. Teachers should encourage students not to be afraid of making mistakes.

Hola Mister T,

I agree.

I feel that where many teachers / instructors fail is when stressing the shame conveyed/implied? by a mistake instead of making it just a step in the way to a better (and hopefully free of errors) procedure. After all, what "debugging is" ?
 
Good teacher needs to confuse and challenge their students, so that the students learn to think outside the box. Many will fail, but the ones who get through, will know a thing or two. That's how it's been for years.

Unfortunately, in the world where teacher's performance is judged by his popularity among students and the percentage of the students who pass, such approach is not possible. As a result, bad students pass too, but the talanted ones get bored and never reach their potential.
 
misterT said:
These are just my thoughts after few years of teaching embedded systems. I am a student myself and I have learned a lot when teaching others.

When teaching one-on-one, call it training if you will, I'll try to figure how how people learn or even ask them: visual, verbal or Kinesthetic?

Inevitably, we'd end up at a blackboad/white board.
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top