Project works fine on a breadboard, but not on a PCB?

Discussion in 'General Electronics Chat' started by kris_maher, Oct 20, 2009.

  1. kris_maher

    Thread Starter Active Member

    Apr 24, 2009
    90
    0
    Hi everyone! I'm building an Ultrasonic Rangefinder that transmits a 5V p-p square wave at 40 KHz from PB3 (pin 4) of my MCU (Atmega32), goes through a voltage comparator to boost the signal to a higher voltage, such as 9-12V p-p square wave.

    The receiver then receives the signal and sends the amplified receive signal as 5V p-p back to PD5 on the MCU for distance measurement calculation and display onto the LCD.

    I'm using an external 16 MHz crystal. On the actual PCB itself I have a heat sink on the voltage regulator and I've soldered 2 bypass capacitors across the regulator on the bottom side to allow for a clean power signal since it was noisy in a test I did yesterday.

    My problem is that on the breadboard everything works just fine. The signal is transmitted successfully and is also received successfully and the correct distance is displayed onto the LCD. The transmit pin (PB3, pin 4) of the atmega32 transmits a 5V p-p signal while it's on breadboard correctly.

    On the breadboard the LCD displays:
    " Welcome to Rangefinder!"
    refreshLCD();
    *By Kris Maher*
    refereshLCD()
    #

    The last line is waiting for input cursor. On the breadboard when there's an object on the sensor say 50cm away the LCD displays:

    * Distance = 50cm

    The program then STORES this value and keeps this same value on the LCD, ie. It does not change the LCD or get a new distance unless there's no object at all. This is how it works on the breadboard and how it should work.

    However when it's all on PCB and it's powered up, it erratically changes to:
    Distance = 0cm --> Distance = 34cm --> Distance = 59cm etc...With object or no object.

    This is not a software problem, it is most definitely the hardware. When the Atmega32 is on the PCB there's no signal on PB3 (pin 4). It simply does not transmit anything and it remains at 0V when I checked with a probe. When it's on breadboard it works and sends a signal but on the PCB it does not. The suspect track is highlighted in red on the attachment "normal pcb layout (problem highlight)".

    What's funny enough all the voltages on the ICs including the MCU are as what is expected at 5V and the ground legs of these are at 0V, the reference voltage on the comparator is also as is expected at 8-9V (with a 9V battery).

    I used the "continuity beeper" feature of my multimeter on my PCB. When there's no power when I put a probe on ground and on the track that is connecting PB3 to input pin 2 of the LM311 there is no sound. That's correct since there is no ground connection.

    The voltage reference exists on pin 8 of LM311, pin 3 of the LM311 produces the 2.5V comparator reference correctly from the two 1k resistors, and I have the 330 Ohm resistor in place. It's only the input for the pin 2 (from pb3) that is not right.

    However when power exists via a battery when I do the same thing as above it beeps. I tested this with other areas of the PCB where there's no ground connection and they are all correct and do not beep.

    All the joints feel and look tight and seem to be all soldered on correctly (the technician at my uni checked the board personally).

    There was a problem with the 16 MHz crystal which the technician found out that it was only oscillating at around 1 Mhz and not 16 Mhz possibly due to some fault - since then I've replaced it and this issue no longer exists.

    We also thought perhaps the atmega32 chip is bust, however I have a brand new atmega32 chip which I've tried and it too is the same - it runs (the project) on the breadboard just fine with all signals coming out of the chip correctly but on the PCB there's no signal out of pb3. I used AVRDUDE for flashing the chip, it too reports that there's nothing wrong with both the chips.

    The thing is I can't really test drive the other part of the PCB if the actual thing does not transmit at all in the first place. I did a direct autoroute of the schematic which I've included using Altium Designer. However I manually routed the transmitter/receiver pins for the ultrasonic sensors shown as TX/RX on the PCB.

    Any help would be appreciated please :confused:

    Thanks all,

    PS: I've included the PCB layout schematics, the actual picture of the PCB and the schematic. Also note the values on the schematic are not the true representation of the values I used as I did my simulation using Multisim but for the purpose of making a PCB I used Altium Designer which is where all these pictures came from. It is the output of the LM393 that goes into PD5 of the atmega32 for processing.
     
    Last edited: Oct 20, 2009
  2. ifixit

    Distinguished Member

    Nov 20, 2008
    638
    108
    Some Thoughts...
    1) No decoupling on MCU power pins. It may not work right like this.
    2) You write about PD5 as the input but, PD2 is the one wired up.
    3) Does the program require any inputs to be in a certain state before the output of 40KHz is generated?

    Troubleshooting tips...
    a) Use some of the spare output pins as flags by programatically changing the pin state to indicate whether a peticular sub-routine has executed or not.
    b) Look for switching noise on the VCC pin to if the code is actually running or not. Use your breadboard version as a reference.

    Good Luck
     
  3. kris_maher

    Thread Starter Active Member

    Apr 24, 2009
    90
    0
    1) I can have a look into this. But there's no decoupling capacitors on the atmega32 that's on the breadboard but it still works?

    2) Ahh yes PD2 not PD5, that's a typo.

    3) No, it is constantly generating the 40KHz waves as bursts of 4 cycles with 2ms delay each time. Basically, after the welcome screen and my name are displayed, then and only then will the code to generate the ultrasonic waves begin. What's happening in my case on the PCB is that it reaches this stage but nothing comes out of PB3 at all, it's just 0V. However the *only* time it stops sending for a very short time is when an interrupt on PD2 occurs that causes the ISR controlling the distance calculation to begin, as soon as this ISR is complete normal operation of transmitting the waves resumes on PB3.

    I'm 100% sure that this is a hardware and not software issue, since on breadboard it's all fine.

    On the breadboard and the PCB: Both the GND pins work at 0V, the RESET is at a high of 5V, VCC = AVCC = 5V. Except the difference is that PB3 on breadboard switches and produces the signal (5V p-p) whereas on the PCB it does not (0V) even though it's the same chip.
     
  4. ifixit

    Distinguished Member

    Nov 20, 2008
    638
    108
    What signal is on PD2 compared to the breadboard? If it is stuck active, or switching randomly, then the ISR may be so busy there is no time to switch the output (PB3). Something is causing the random printouts of the incorrect results.

    Good Luck
     
  5. kris_maher

    Thread Starter Active Member

    Apr 24, 2009
    90
    0
    The sensors I'm using are really only receptive to 40khz and in all cases which I've tested on the breadboards it does not to react to any frequencies that are not at all around 40khz.

    I've written the code such that it samples 10 times before it displays the distance, hence on the breadboards it takes about 2 or do seconds before the distance comes up.

    In the pcb case it is showing eratic values of the distance, it's not even the distance, the value changes several times in a second which is incorrect. I can measure the value o pd2 but I can safely say right now that it too would be close to 0 in the mv range since the sensors complement each other (made from the same company).

    Does my schematic and the pcb layout look correct?
     
  6. kris_maher

    Thread Starter Active Member

    Apr 24, 2009
    90
    0
    Okay I checked pd2. Pd2 is high constantly at 5V which should not be. Pb3 of course is still on 0 volts. Another thing I want to add is on my breadboards version when there Is no signal at all (that is, no wire connection to pd2) it is of 0v, and since the software only treansmits when nothing I received, pb3 on my breadboards is transmitting a signal correctly. The problem on the pcb is that pd2 is going high to 5V when it should not, this is what's preventing pb3 from ever transmitting the 40khz square wave.

    The incorrect 5V on pd2 explains the junk values of distance I'm getting because I don't believe it is from the receiver circuit. So now my question is possibly where is pd2 picking up the 5V from?
     
    Last edited: Oct 21, 2009
  7. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    If you have the bread board version, you could use a scope and compare signals around the two boards. Also perhaps ad some caps at the voltage regulator. Also I am note sure how effective your decoupling is. Placement and routing do not look optional. I Also prefer to use 100nF. If you can not work out your problem, try to cut the GND and VCC track. Shown in picture. Then solder wires directly from the VR1 to GND and VCC pins on the circuits. Solder the decoupling caps between pin 4 and 8. Do this on solder side. Do this also on U3
     
  8. kris_maher

    Thread Starter Active Member

    Apr 24, 2009
    90
    0
    Hi, I updated my previous post with my latest findings. I do have caps on the voltage regulator thy're on the solder side, I'm using 100nF for all.
    I have decoupling caps already for u1 and u2. Their c2 and c3. Thanks also and for everyone else who replied here.
     
    Last edited: Oct 21, 2009
  9. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    On U2a have you swapped pin 2 and 3? If PD2 is high constant you should trace the reason for that this pin is high. U2 my also be goner ;)
     
  10. kris_maher

    Thread Starter Active Member

    Apr 24, 2009
    90
    0
    Ok I found something else out, there Is a jumper wire that connects pd2 to the receiver circuit (shown as R67 on the schematic and pcb layout), I snipped This off with a scissor. Now when the device starts up again it goes to the cursor screen and this time it does not at all change or affect the distance, it remains on the cursor screen with only the hash as it should!

    However pb3 still does not transmit and is on 0V, also pd2 is still on 5V even though the jumper connector wire was cut off. So this must mean perhaps there may be something wrong with the dip socket thy houses the mcu? It did lose a couple of legs but none of these legs are related to any pins that are being used. Could this be it? My multimeter did not find any short circuits around the mcu area though so why could it still be 5V?? Thanks
     
  11. kris_maher

    Thread Starter Active Member

    Apr 24, 2009
    90
    0
    What do you mean by swapped pins 2 and 3 on u2? I'm assuming your referring to u2 as u2a.
     
  12. kris_maher

    Thread Starter Active Member

    Apr 24, 2009
    90
    0
    I'll post a screenshot of the solder side around that area. But that still I think probably won't explain why I'm getting 5V even with the jumper wire cut off :-(
     
  13. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    By swapping pins it means that you have swapped signal going to pin 2 and 3 on U2. It is a common error to do then working with ECAD systems.
     
  14. kris_maher

    Thread Starter Active Member

    Apr 24, 2009
    90
    0
    No I dont actually have any pins swapped, I checked.
     
  15. ifixit

    Distinguished Member

    Nov 20, 2008
    638
    108
    a) There may be an internal pull-up on PD2 so it goes high when left floating. Temporarly short PD2 to 0V to see if the 40HKz appears.

    b) Is the interrupt programmed for "level" or "edge" sensitivity. Edge might be better in your case.

    Setup adjustments with no signal in...

    1) Adjust R15 for a 2.7 Volt bias at U1a pin 3. Pins 1 & 2 should follow and be 2.7V as well.

    2) Adjust R16 to maximum value so you have minimum hysterisis to start with.

    3) Check that U2a pin 3 is approx. 2.5V and that pin 2 is greater. ie 2.7V.

    U2a pin 1 should now be 0V DC with no signal in.
     
  16. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Just an observation:

    I have never seen crystal loading capacitors as high as 100 picofarads. These caps usually serve to insure that the crystal starts up on application of power and that it oscillates at its fundamental frequency rather some harmonic of its fundamental frequency. With 100 picofarad caps, I wonder if your crystal is taking an abnormally long time to start up and oscillate. If so then the AVR may be trying to execute its program before the cpu internal clock system has had time to stabilize.

    It is possible that the extra loading on the crystal brought on by these large loading capacitors have made the crystal oscillation more suceptible to noise running around on your board.

    You may have noticed that there are several fuses available to permit you to select a time delay from power up to start of program execution. This is to allow the crystal to reach a stable frequency before the AVR begins to execute code. I generally choose the longest delay available.

    All that said, you may want to consider dropping both 100 picofarad caps to something in the range of 15 to 27 picofarads. You really should not need more capacitance than this.

    hgmjr
     
Loading...