SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By waltr
#92917
Try putting your scope probe onto the scope ground connection on the board. Seeing high frequency, low amplitude noise on a scope is very common due to the length the the scope probe's ground lead. Use a very short ground clip in the tip of your scope probe to minimize the noise pick-up.
By riden
#92956
lukemalpass wrote:I'm using MCLR as internal pullup so would I still need to try pulling it low?
MCLR does not have an internal pull-up resistor. However, you can disconnect MCLR from the outside world with a configuration bit. Is that what you did? If so, that's fine. My idea about pulling MCLR low was to force the internal oscillator on the PIC to stop and see if the noise cleared up. To do this, requires that MCLR be connected to GP3 with an external pull-up.

BTW, as you might be disabling external MCLR and using the internal oscillator, it would be a really good idea to incorporate a short delay upon reset before setting any of the I/O ports to outputs. There have been issues reported trying to reprogram devices with this configuration if they don't have a short delay on start up.
By lukemalpass
#92960
Right I'll try connecting the probe to ground clip when I get home and see if the noise is still there.

With regards MCLR yes I disconnect it using the MCLRE configuration bit.

I was also thinking, perhaps the amp is actually damaged. What behaviour would a damaged amp have? This one has been re-soldered 3 times now as it has been used on 3 different trial boards, so I don't know whether before I go any further to re-make the entire board with new bits, and to leave the transformer off to begin with, power up the new circuit and see if the nosie is there, if not, add the transformer and check again. If it appears then its the circuit and something to do with the transformer, and if not then its good I presume and must mean something on the existing board is faulty or bad. What do you think?
By lukemalpass
#94061
Just to keep you updated I got around to trying my board again. Removed the transformer and diodes and made no difference, amp was still railing.

Rebuild the board identical and put everything on but transformer, and all is good no noise. So I presume the amp was damanged from the third reflow so a fresh one was used.

Something interesting regarding this 46kHz noise too, it seems to be injected into my circuit if my skin touches any part of the amplifier stages where it is amplifying the inputs, and I get the full rail 46 to 52kHz noise that I seem to see on a few circuits, so am wondering if it is anything to do with my body, or just the fact that my skin is changing the resistance or impedence of the stage and causing it to amplify any noise? Any thoughts on this.

I will solder the transformer on later and re-scope to check it is ok, then if that goes well hopefully program the pic and have a working circuit!
By lukemalpass
#94066
Interesting, I added the transformer, no difference. Add the PIC, no difference. Programming the PIC16F615 with a basic program doing nothing, and the rail to rail was instantly there... very odd. So I erased the PIC and it went away.

The noise is coming from the PIC just running. This is very confusing because it wasn't there on the previous circuit that was identical expect without the transformer and driving transistor, and it never had this issue.

I tried setting GPIO to all outputs, all inputs, setting ANSEL all on and all off, none made a difference. All TRISIO to all high and all low, when all low the noise went. I pinned it down to when the pin that should receive the analogue output from the amp (GP4) is set as an input the noise is there... which is a problem as I won't be able to read the value. The PIC has the 0.1uF cap over its power pins and the amp has a lot of caps so I doubt it is a smoothing issue, and it only appears once a program is on the PIC. Any ideas?
By riden
#94079
Here are some thoughts that you may help your debugging. Relative to the CPU clock speed (8MHz?), 45 KHz is fairly low frequency. So I would examine these areas:

1) Your main programming loop is doing something that tickles a register when it doesn't have to (i.e., reinitializing some registers that only need initializing once at reset).

2) Watchdog timer running

3) PWM module running, but not connected to output pin.

I'd try a very simple program (LED blink?) and see if you can duplicate the problem, and then work from there.

Edit: Also try changing the oscillator frequency and see what happens. You might be able to shift the unwanted noise out of your amplifier's bandwidth.
By lukemalpass
#94285
Nope I tried altering the clock speed from 4Mhz to 8Mhz and the noise doesn't change frequency. I tried altering every register in the PIC12F615 and all prescalars of the TMR0, T1CON, T2CON, PWM, CCP, and oscillators and nothing at all changes the noise. I've changed the additional functions register to reassign the GP4 pin to other things and that changes nothing either.

What is puzzling me is the other board that is identical except without the transistor and transformer doesn't have this issue and the amplifier circuit is the same, the output pin goes to the same pin, the program is the same, and the layout is as near as can be the same. And yet I tried removing the transformer and BAV99 so nothing was on the amplifier input line and the noise was still there.
By lukemalpass
#94289
I've just had a brain storm! I remember months ago back in the early design stages I kept getting random railing of the amplifier. I finally figured it out and it was because I was running my input copper wire of the amplifier right next to the output line. As soon as I moved this away the problem went away. Albeit it was on a breadboard so the metal was much thicker and less isolated than a copper trace on a fibreglass board so I wouldn't think it would cause an issue but see what you think...

Excited I quickly opened up my new design and low and behold the last design had the output line running around the input line (output is highlight in white, input is coming from SEN pin 1 to the amps pin 2):

Image

And now my new board has the output line running right along side the input line all the way on T10 lines 0.8mm apart (output highlight in white, input is from comm pin at top left running right along side it and into amp pin 2, output even runs under the inputs capacitor):

Image

What do you think? I will cut the output line trace and greenwire over to see if the noise goes away when I get time again, but I reckon that could definately be the issue!
By riden
#94310
You might be on to something, at least I hope so. Kudos for sticking with this project, even though I'm sure it is frustrating at times. I know that sharing your tales helps others as well.
By lukemalpass
#94440
Cool, I removed the trace and green wired and the nosie is 99.99% gone. Just a tiny 10mV ripple now which doesn't overly effect the function. Out of interest I took a look back at some of my previous posts and all the boards where I was having the 8Mhz noise, and 52kHz noise etc... were all boards where the input lines came close to the output lines, and the ones that didn't don't have the noise. So I MUST remember this for the next boards it is probably the source of all the little noises.

With the noise gone I reprogrammed the PIC to its usual function and took some scopes.

Here is the transducer being driven (using x10 scope). It starts at approx 90V and falls to as low as 40V by the end of the drive, and then self-resonates. A little interesting, perhaps my smoothing capacitor on the transistor is not big enough and running out of energy or causing anti-oscillation?

Image

And here is the amp output using the ProWave sensor from about 50cm away:

Image

At first I thought "oh great its no different than when it was driven at 5V"... so I took back at a look at the old scope of when I was driving it at 5V and using 7,500x amplification (this one is currently using 1,500x) and the scope was only 30cm away and at 2V drive. This one is almost twice the distance away and only at 1,500x amplification so I would say it is an improvement.

And here is the amp output using the sensor I have no details on, that is an outdoor sensor (presumably the same ProWave I just used) inside a rubber housing:

Image

The noise is definately dampened so it looks really nice and smooth, however so is the recieved signal. It never got rail-to-rail no matter how close I got, but at least I could see the signal this time and couldn't before.

I am surprised that driving it at 90V would improve the signal a lot and would not need any more than 1,500x amplification, but it looks like it still does. I will solder the other res and caps on so it is 7,500x amplification and hopefully fingers crossed that will be enough... finally.

Failing that if it still isn't enough I will try to drive both legs instead of one and get 150V or more drive, but it definately looks like it is getting there now as I am seeing signals back from the outdoor sensors from half a meter. With another good amplification boost I'm hoping I will get rail to rail from a good 5 meters or so.

Out of interest I put the indoor sensor on this circuit and driving it at 90V was so powerful for it that I could actually hear the sensor pulsing the ultrasound it was quite cool.
By lukemalpass
#94562
Increased the amplification to 7,500x and guess what?! It works!

Here is a scope from about 2 meters away.

Image

It flashes the LED whenever it detects. I tested and I have a range of just under 6 meters at the long end and I can get the noise down to 4.5ms so the minimum reading isn't great at about 30-50cm but thats not really an issue for this project.

This scope was with the least sensitive sensors the ones I have been trying to use all along that are in the rubber gromet. I have noticed that by adding the amplification that the dampening time has increased from 2ms to 4ms so a better solution would be to drive the sensor harder, perhaps by driving both legs of the sensor, but for now I am just happy that it works.

I could not test the other outdoor sensor or the indoor sensor now though because the amplification was too sensitive and whenever I connected the sensors with clips or jumper wire lots of noise was introduced. The only reason the rubber gromet ones worked was because the sensor cable has a ground shield. Again I don't think this will be an issue on the final board as I will solder the sensors to them or make a ground shield for them.

My final part to finish this now is to convert the distance to a DC voltage level. So I plan to use PWM through an RC low pass and a unity gain stage to the final output pin. What is the rule for the resistor and capacitor sizes based on the PWM frequency to get a smooth DC output? I think I have seen somewhere that a 4.7k resistor and a 1uF cap have been used. I will be using the PICs PWM with either 19kHz or 153kHz whichever will be best.

Once this is done I will make a tutorial for everyone else as there is so much I have learned that I could share from all of this and it has been such a long and insightful journey to finally get a working circuit. There are still improvements but they can be built upon once I have finished this one.