Working with Microcontrollers, Tips

Discussion in 'The Projects Forum' started by jwilk13, Jul 18, 2011.

  1. jwilk13

    Thread Starter Member

    Jun 15, 2011
    228
    12
    I'm simply wondering what tips everyone can offer when working with microcontrollers (from a circuits standpoint). I know most people here have more experience than I do, so I'm wondering what "rules of thumb" there are for powering microcontrollers, unused pins, etc.

    For my project, I already have all of the code working and running on Microchip's PIC18F45K20 development board. The project takes input from 4 different analog sources using the A/D converter and creates a PWM signal of varying duty cycle, response time, etc based on these inputs. I'm waiting on parts to prototype it, but I know there is more to the actual construction of the circuit than simply hooking stuff up and hoping it works.

    I'm familiar with the concept of decoupling and bypass capacitors (occasionally I read stickies :p) and I'm planning on using two 0.1 uF capacitors from Vdd to GND (that's what Microchip did on their demo board). Is there anything else I should be aware of before I try my luck? Thanks all!

    And for anyone wondering, the analog inputs are just a constant voltage level source (voltage regulator output) varied by a voltage divider using a potentiometer. Not sure if that matters, or maybe there's a better way of doing it.
     
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    You seem to be in pretty good shape where you are. You have a working board with tested code on it so when you fire up your proto and it doesn't work you can concentrate on hardware issues and not software. I'm not saying you'll bite the pooch building it, I'm saying you've got good chance of pairing down problems to just one area.

    You have an example of a working board so you have something good to copy. Probably the worst thing you can do is put the caps or crystal too far from the device.

    Assuming you bang it on and nothing works (kinda common in my world)...

    First thing I check is if the oscillator is working! Seems simple but its a deal breaker if it ain't. If you can scope on the crystal or resonator that's good, if you're using an internal oscillator then make a test program to wiggle just one pin.

    Then try to get up each function in turn. If you set the PWM to a constant, build and program do you see the proper outputs? Can you add in the A2D and get the PWM to follow?

    I've seen threads going dozens of posts on unused inputs, as there are several thoughts here. The only thing you do not want to do is leave then as unconnected inputs, there is the slight possibility they will drift to 1/2 Vdd and consume huge currents. If you make them inputs either tie them to Vdd or Vss, a resistor is optional. I prefer to make them floating outputs set to zero, that way I have free pins available to grab for more functions. If you short them as inputs you have to remove the short to use them!


    If you run into trouble bang us back here with code and schematics and we'll see what we see.
     
    jwilk13 likes this.
  3. praondevou

    AAC Fanatic!

    Jul 9, 2011
    2,936
    488
    Everything what Ernie and you said + you should not pass any high-frequency current carrying traces near the MC. If the power supply for your MC for example supplies power to another board where you have a small SMPS, the current to this board shouldn't pass near the MC, neither on the + side and especially not through the ground plane.

    Also, depending on what load you are sitching, the MC itself will generate switching currents on it's power supply lines that can influence other circuitry which is why sometimes a small ferrite bead is placed near the the MC in series with the power supply.

    have a look at the attached pdf.
     
    jwilk13 likes this.
  4. simo_x

    Member

    Dec 23, 2010
    200
    6
    I love micros. Congratulations for the A/D >> PWM circuit, looks like interesting project. Are you driving a motor?

    The 100n capacitor between Vdd & Gnd is needed to make the supply voltage more stable, but it's not only used in micros, also with logic gates. Digital ICs are sensible to little voltage variations, so the capacitor helps to avoid them if they would be present.
    In every project where I used digital logic gates and micro I put one for each IC.

    Regards,
    simo_x

    I add that if you search in google for "PIC (or microcontroller) tips 'n tricks" you get some useful result.
     
    Last edited: Jul 18, 2011
  5. jwilk13

    Thread Starter Member

    Jun 15, 2011
    228
    12
    Thanks for the replies!

    @Ernie: I am using an internal oscillator, and the only problem I've run into so far with that is not setting the configuration bits properly, so hopefully I won't run into trouble there. The only thing I could see becoming an issue is that I'm using a different package IC than the demo board, but the demo board schematic has all the info on how to connect the MC for programming. I'll let you know how it goes Wednesday when I have it finished.

    @praondevou: That's great information that I wasn't aware of. That document you posted is extremely helpful, especially since I'm developing for a "noisy" environment. I forgot to mention that the load I'm switching is inductive. I'm trying something new and using a "Smart Power High Side Switch" instead of a MOSFET to handle the current requirements of the load (less than 1 amp). The data sheet can be found here. Think this calls for a ferrite bead? To be perfectly honest, I'm not even sure this device is going to work the way I want. I haven't found anyone who has used them or is even slightly familiar with them. I just figured it looked interesting and simple (no snubber).

    @simo_x: I am driving the coil on a proportional valve. I've become very fond of microcontrollers after this project too. My first inclination was to use analog circuitry, but I decided to learn something new and make this my first big PIC project.

    Thanks again for the replies.
     
  6. praondevou

    AAC Fanatic!

    Jul 9, 2011
    2,936
    488
    jwilk13 likes this.
  7. praondevou

    AAC Fanatic!

    Jul 9, 2011
    2,936
    488
    This one talks even about "Preventive Software Programming", thus bypassing possible hardware problems.
     
  8. jwilk13

    Thread Starter Member

    Jun 15, 2011
    228
    12
    Another pair of great references! I'd better save these now before I forget.
     
  9. jwilk13

    Thread Starter Member

    Jun 15, 2011
    228
    12
    Update:

    First, thanks for the advice from everyone. I only ran into one problem with the programming of the MC. Tip for others, MCLR has to be tied to Vdd through a pair of resistors (I used a 270 ohm and 10 kohm) with a capacitor (0.1 uF) from where the two resistors connect, to ground. Oddly enough, the datasheet for the 18F45K20 didn't have that in there. I'm sure it's somewhere else, but I managed to figure it out with the help of uncle Google. The thing that tipped me off was that everything was working fine with the ICD, but not when I programmed it without the debugger.

    Also, for those who haven't used them, the high side switch device (BSP762T) works the same as if I had used a P-channel MOSFET with the load connected to ground from the drain. And for $2.40, it's not a horrible alternative, especially when considering the space it saves (and the switching protection for inductive loads). The only problem is that it only comes in a surface mount package, making it difficult for regular hobbyists.

    Hope this information is helpful to others :)
     
    praondevou likes this.
Loading...