Another Look…Wien Bridge Oscillator – Healthy EC Dev-Rev1

Tags

,

 

Simpson DOHI was not able to get Oscillation going on the Healthy EC Dev-Rev1 Shield in prior tests (link).  No wonder – since the circuit is wrong…OOPS! :-)  (I know it’s not funny, but for some reason I find my screw ups to be delightful.  I think because the only thing they “hurt” is my ego).  This is after spending several hours dedicated to understanding the electronics and circuit design of a Wien Bridge Oscillator (link).

Here’s the current design…

HealthyECDev-Rev1WienBridgeFilterParts

The Goal

The goal of this post is to get the Wien Bridge Oscillator to work on the Healthy EC Dev-Rev1 or know the specifics of why it won’t work without changes to the PCB.

Thanks to Those That Went Before

Some things should be thanked for every time.  This is the case with Chris Gammell.  If it wasn’t for his Contextual Electronics course and guidance, I would not be passionately enjoying this incredible learning experience.  I recently listened to a podcast where they noted in 1984 there was a significant drop in women who majored in computer science in the US.  One woman interviewed noted she felt exceptionally strong in math and had confidence going into her freshman year at college – a hopeful computer science major.  She remembers the day when she asked a question and the professor looked at her disdainfully and noted “you should already know this!”  Here confidence plummeted… WOW!  brings back memories…this is the EXACT experience I had with learning STEM subjects “back in the day!”  Now, there are teachers/mentors/professors (these terms merge for me) like Chris who do not make assumptions about a person’s ability.  Who brilliantly understand that most often not knowing/understanding can overwhelmingly be caused by a lack of context rather than an innate ability.  Aha – now to me it is about the mental model…not a judgement of mental incompetence.  Thanks to all those who set the passionate learner’s mental model in the direction of understanding.  Thanks to Chris for the mental model I am developing about electronics.

Ryan (Sparky’s Widgets) embraces the concept of Open Source in a way that makes it possible for me to learn more about the details of pH and EC sensors.  I would not be able to create these shields without Ryan’s Open Source minipH and miniEC projects.  Ryan also makes these available for sale.  I highly recommend buying these.  At least check out his offerings.

There has been a TON of great articles available through the “Google is Our Friend” of today’s Internet.  Thanks for all the information – particularly when stuff doesn’t work!  My biggest challenge is using the right search term.  Something I assume will always be a challenge.

101 – Characteristics of the Wien Bridge Oscillator

I understand the purpose of the Wien Bridge Oscillator – to be an AC power source for the EC probe.  I don’t understand some of the characteristics of a Wien Bridge Oscillator.  Reflecting on why, since I am self teaching, a challenge I run up against is understanding the theory behind a circuit.  Something that is covered in beginning electronics courses.  Well, this lack of knowledge of circuit theory is not the boss of me, so I’m:

  • watching videos on circuit theory.  After watching many on Youtube, I realized my skills in algebra – and sadly calculus also – were weak.  Proving once again, I am by far not smarter than a 5th grader.  OK, calculus is a stretch, after all I proudly point out our junior in high school is taking calculus – no, not 5th grade…I was hoping to find an online course on electronics theory that was as good as the iTunes course from Stanford University on iPhone programming (link).  Sadly, I did not.  Please let me know if you know of one!  I ended up getting the engineer series of downloadable DVDs – from mathtutorDVD.com.  I decided to buy and download all the DVDs in this section.  For many this must seem indulgent.  However, at my age time is more important than money.  For me, watching the DVDs – I’m still in the process… – has been a terrific way to understand fundamental/basic circuit theory – Ohm’s law, Kirchoff’s voltage and current laws, and the Thevenin equivalent circuits (wow – the Thevenin stuff is amazingly insightful.  Let’s hear it for sharp folks that figure this stuff out!).
  • reading as much as I can swallow and understanding a little of what is being written in the art of electronics and Practical Electronics for Inventors.
Based on my random google readings on the Wien Bridge Oscillator (such as this link):
  • The frequency of oscillation is determined by a bandpass filter.  The bandpass filter’s circuit goes between the non-inverting input of the op amp and the output of the op amp.  THIS is where I screwed up with Healthy EC Dev-Rev1.  I split the band pass filter between the inverting and non-inverting ends of the op amp.  As I’ve noted before- for EC measurements, the desired frequency is 1.6KHz. The equation for determining the frequency based on the resistor/capacitor choice (see the kicad EC.sch schematic found at this GitHub location) R14 = R19 = R= 1K and C9 = C11= C=100n…. f = 1/(2∏RC) = 1/(2*3.14*1000*.0000001) ~= 1.6KHz.  If the circuit was set up right, the output frequency should be very close to 1.6KHz.
  • The gain loop circuit goes between the inverting input of the op amp and the output of the op amp.  The “twist” in this gain loop is a way to adjust the gain once the oscillation (AC Waveform) has started in order to keep the oscillation going.

The Wien Bridge Oscillator Circuit without VGND

Here is the schematic of the Wien Bridge Oscillator without introducing VGND.  This means the op amp requires a + and – voltage source.  In the schematic, a +5V and -5V power source is used:

 

WienBridgeWithoutVGND

As I said earlier in this post, the frequency of the AC Waveform is 1.6KHz. 

The Gain Loop

What about the Gain Loop. This is what I *think* is going on based on what I understand.  Please let me know if I need to correct my understanding.

The VROOM-VROOM Stage

I like to get a picture in my mind (hopefully a cartoon that makes me smile) of what is going on.  Thus, I call starting the oscillation the VROOM-VROOM stage because it reminds me of applying gas when getting a car going from steady state to moving.  

VROOM-VROOM-Stage

VROOM – VROOM: Start Your Oscillator: Gain Slightly Greater than 3

When the current initially starts up, it can’t go through the diodes.  I use SparkysWidgets 10K (R6 – above diagram) and 22K (5) design in the minieC  to set the initial gain at 3.2 (Gain = 22K/10K + 1 – 3.2).  3.2 satisfies “some math” – which I take for granted is right because it will take me many (many) hours to understand – which says a gain of slightly greater than 3 is needed to get to VROOM-VROOM oscillation.

The PUTT-PUTT Stage

Once the oscillation has started, I picture it as puttering along (maintaining).  I like to picture this as the PUTT-PUTT stage…like a car moving at a constant speed down the road…in fact, the car I visualize is the one from “Who Framed Roger Rabbit?”

Who Framed Roger Rabbit

PUTT-PUTT Keep Your Oscillator Going

I have been befuddled by my lack of knowledge in circuit theory to figure out how the Gain Loop did this.  After searching through the books and googling, I’ve come to the following conclusion:

  • The parallel circuit in the Gain loop includes the diodes.  This circuit won’t contribute to the Gain Loop until the Vpp is around .7V (this is a silicon diode) – the forward Voltage.  So until then, the Gain is 3.2.
  • Once the Vpp of the AC Waveform is around .7V, the diodes + capacitor part of the circuit adds a parallel resistor to the 22K R5.  OK, so what is the resistance contribution of the capacitor?  Bumbling on this gem in section 3.6.5 in Practical Electronics for Inventors - the capacitive resistance = 1/2πfC = 1/(2*π*1600*.0000001) ~= 995ohms.  So now the Gain Loop Circuit looks like this:
GainLoopWithParrallelcircuit
Simplifying the resistors in parallel = (product of resistors)/(sum of the resistors) = (22000*995)/(22000+995) = 952Ω.  
 
So once the diodes kick in, the capacitor’s capacitive resistance is 952Ω, settling the gain loop to 952Ω/10K + 1 = 1.095.  A gain of 1 on an op amp feedback loop builds a buffered copy of the input voltage.  Given the gain is very close to 1, the diodes + capacitor contribute to the gain by backing it off to a gain close to 1 once the Vpp crosses the forward voltage of the diodes (at around .7Vpp).
 
OK – that’s my mental model.  On to the breadboard (once again).  
 

 Back to the Breadboard

Perhaps the equivalent of writing “I will not split the band pass filter between the non-inverting and inverting input” 100 times on a blackboard, I set about below to create the circuit on a breadboard, similar to what I did in this post.

I’ll build up the breadboard in these steps:

  • Implement VGND.  I’m using a VGND in the design of the Healthy EC Shield so that only one power source (+5V) is needed.  VGND is set to ~2.5V
  • Implement bandpass filter so the frequency of the waveform is 1.6KHz.
  • Implement feedback loop so that the AC Waveform putt-putts along.
I use the MCP6244 (data sheet) in the schematic.  The chip I use has a 14-SOIC footprint (digikey link has picture).  Ideally, this would be the op amp I would use on a breadboard.  According to digikey (link), the component does come in a DIP footprint.  Unfortunately, digikey does not have any in stock.  My soldering skills aren’t good enough to dead bug a 14-SOIC, so I turn to Sparkfun’s SOIC to DIP.  Alas – silly me – the width of the MCP6244 is much smaller than that on Sparkfun’s SOIC to DIP:
Sparkfun SOIC to DIP

So I’ll be using the TL072 op amps that I have favored in previous bread boards.  Since I forget the TL072’s pin layout, I’ll post a picture of it here:

TL072 pins

Implement VGND

From the Healthy EC Dev-Rev1 schematic (kicad files available at this GitHub location):

 

VGNDFromHealthyECSchematic

the first op amp is used to implement VGND.
 
 

1st Op Amp is VGND

The bench power source reads 5.1V.  The DMM reads 2.45V at pin 1 – the output pin of the first op amp.  In the “ideal”, the VGND would be 1/2 5.1V, or 2.55V.  Breadboard copper, extremely inexpensive (in this case 1K) resistors make me believe 2.45V is within an expected value for VGND given R17 = R18 = 1K.

Implement Bandpass Filter

The bandpass filter goes from the non-inverting input pin of the 2nd op amp – pin 5 – to the output pin of the 2nd op amp – pin 7.  One 1K R and 100nC are n parallel, and one 1KR and 100nC are in series.  The circuit is tethered to VGND.  I’m finding drawing colored lines showing which components share a wire is useful when implementing on a breadboard:

bandpassFilterWithWireColors

 

Adding the bandpass filter to the breadboard:

bandpassfilteraddedtobreadboard

 

Implement The Gain Loop

The Gain loop goes from pin 6 of the TL072 – the inverting input – to pin 7 – output of the second op amp.

 

SkitchOfWienBridgeGainLoop

 

 

breadboard with Wien Bridge

 

Hooking up my scope, the waveform I see:

ScopeOfWienBridgeWithDC

 

I count 550µS between positive peaks -> frequency = 1/.000550S = 1.8KHz, slightly higher than the expected 1.6KHz, but close enough given the quality of parts used in the prototype.  Here is the results from running the LTSpice simulation:

LTSpiceSimulationWienBridge

in the simulation, Vmax is ~= 2.92V, vMin ~= 2.05V making the Vpp ~= .87V. 

At the VROOM-VROOM stage, the simulation showed this waveform:

WaveForm at VROOM VROOM Stage

the Vpp on the second to last peak/valley ~ = .66V -> when the diodes start letting current through.  It is at this point the waveform gets to a consistent VPP ~= .87V.

 

I *think* hope? I am understanding this correctly!  If not, I anticipate the next rev of the Healthy EC Shield will show this.

 

 

Thanks for reading this far.  Please find many things to smile about.

 

 

 

 

 

 

 

Weird AC Waveform on VGND? – Healthy pH Dev-Rev2

Tags

,

Well that was (NOT :-) ) exciting.  Why was I seeing this:

ACWaveForm on VGND NO probe attached

when the scope probe was in TP 18 relative to AGND?  Yuk…..

The Goal

The goal of this post is to become familiar with the characteristics of the all important VGND – used as the GND for the pH probe readings.  With a VGND, the op amp can use a single power source since all voltage readings will be positive.

Thanks to Those That Went Before

I just can’t thank Chris Gammell enough.  His Contextual Electronics courses and mentorship have given me the ability to rapidly grow my abilities in designing and building PCBs.  Something I find I have quite a passion for when applied to growing healthy food (through hydroponics).  I look back to last year…I am amazed and exceptionally grateful for all I have learned.  This would not have been possible without Chris.

Given my thirst for learning from those that went before, Ryan – of Sparky’s Widgets – is another whom I am hugely thankful for.  Ryan has made some wonderful breakout boards, like the minipH and minieC that I highly recommend.  The circuit design of the Healthy Shields are an evolution of the open source schematics and advice from Ryan.  He truly knows his stuff.  I am very grateful that Ryan open sourced the minipH and minieC hardware.  In addition, Ryan has been extremely thoughtful in response to what must be naive questions from me given his level of expertise!

Observations of VGND

As I noted earlier, I was seeing a strange sine-like waveform when the scope probe was in TP 18 relative to VGND.  Not good…

What was happening – and this took me awhile to figure out and get right (although I am not sure why!) – the probe’s GND was loosely connected AND I had too many external electrical doo-dads and wires running around, under, and above my Healthy pH Shield Dev-Rev2 I was testing.  I let out a sigh of relief after removing the excess electronics and wires, revisiting how the probe’s GND was connected to AGND and saw:

ACWaveForm on VGND  probe attached better

in this case, the Healthy pH Shield is inserted into the Arduino.

Healthy pH Shield With Probes

When the Healthy pH Shield is not plugged into the Arduino, there is (relatively much) less noise:

ACWaveForm on VGND  detached from Arduino

 

More noise occurs when the pH probe is connected through the BNC:

ACWaveFormAnotherWithArduinoAttached

 

Lessons Learned

  • Observations are important but are only as good as the method used to measure.  In this case, I was not seating the scope probe correctly.  AND…I repeatedly was not doing this.  Certainly, slowing down, triple checking is very important when using tools and observing.  Sounds obvious, but something I need to constantly remind myself to do.
  • How well the BNC/probe is attached to the Healthy pH Shield will make a significant difference in the noise picked up on VGND.
  • A capacitor should be added close to the voltage dividers (R3 and R4) to smooth out the noise – especially since the Arduino adds additional noise – even when not plugged in.

 

Well – that’s that!

 

Thanks for reading this far.  Please find many things to smile about.

Testing the Temperature Reading Using Voltage Values – Healthy pH Dev-Rev2

Tags

, ,

I use a thermistor to calculate the temperature of a bath.  I started testing in a prior post, but ran into an issue because I was using a 10K resistor for R15.  See this link for more details.

The Goal

The goal of this post is to do a litmus test on the temperature that would be calculated prior to conversion of the voltage to digital through the ADC.  While I don’t expect the temperature to be spot on, I do expect the reading to be within the ballpark.  If needed, further improvements will be done to improve readings.

Thanks to Those That Went Before

Thanks to Gerald Rectenwald for his excellent class notes on thermistors.  They were easy to read and useful.

As always – a huge thank you to Chris Gammell.  His Contextual Electronics and additional guidance has made it possible for me to even attempt this effort.

Thanks to the people behind the Wikipedia entry on Thermistors.  The article was very helpful.

The Test

Due to lack of soldering skill on my part, I managed to tear off the pads from R15 – the resistor that acts with the thermistor to divide the voltage.  The kicad files are located at this GitHub location.  OshPark provides 3 boards so I was able to only solder what was needed.  This time, I used a 1K resistor for R15.  Using 1K instead of 10K should read voltage values that can be digitized by the MCP3901 – which can handle voltage values between +/-.79V.

YIPPEE! Simple:

PCBThermistorTest

Measuring Temperature

I noted in the previous post (link), going from a voltage reading to a temperature reading (either in C or F) is a three step process:

1. The thermistor (Rtherm) is a variable resistor.  What is it’s current value?

2. The temperature has a linear relationship with Rtherm.  Use the B parameter method to solve for the temperature in Kelvins.

3. Convert from Kelvins to either C and/or F.

Solving for Rtherm

From the previous post, I first solve for the value of Rtherm (plugged into holes 3 and 4 of the holes for the 8 position terminal block).  In order to do this, I need to measure Vo then use the formula:

Rtherm = R15/(Vs/Vo – 1)

I measured Vs = 5.18V and Vo = .42V relative to AGND.  Plugging into the above equation, Rtherm = 1000/(5.18/.42 – 1) = 11,333.  At least the calculated value was not completely out of range – say if it had been 113,330…

Solving for Temperature in Kelvins

Perhaps you have become friendly with formulas.  Frankly, formulas intimidate me.  But if I take it r-e-a-l SSSSSLLLLLLLOOOOWWWW …..

As noted in the Wikipedia article on thermistors:

T = B/ln(Rtherm/r∞)

It also notes r∞ to be:

r∞ = Roe^(-B/To)

Where Ro = the thermistor value that the thermistor is spec’d at.  Mine is a 10K thermistor.

To = 298.15K (25˚C in Kelvin)

B comes from the data sheet.  For the thermistor I am using (link), B  = 3977.

Plugging in, I get:

r∞ = 10000*e^(-3977/298.15) = 0.029259

T (Kelvins) = 3977/ln(11333/298.15) = 295.25

Solving for Temperature in ˚C or ˚F

To go from Kelvins to C, just subtract 273.15.  This gets to: 295.25 – 273.15 = 22.1˚C.

The formula to go from C to F is ˚C*2 – 30, 74.2˚F

While this is not extremely accurate, the temperature where I am at is about 70˚F.  This makes the reading I got with the thermistor about 4˚F higher.  I feel this is good enough to pass my litmus test.  Now I need to better understand:

  • resistor values vary.  How important is precision of R15 or the thermistor?  It seems that thermistor tutorials suggest 5% – which is what I am using.  Should I pay more for 1% precision?  How much do small changes in temperature affect the pH value measurement?
  • How accurate are the voltage measurements for Vs and Vo?  Is there enough noise to cause inaccurate results?  I need to get a better feel for the noise on the voltage line.

Next Time

For this pass, I am focusing on knowing if the results I measure are within a litmus test of expected results.  I am not as concerned with accuracy.  And in this case, I am not sure how accurate I want to be.  Because of the relationship between the pH value and temperature, accuracy will depend on the affect of a small (say 1˚F) change of temperature on the pH value.

 

 

Thanks for reading this far.  Please find many things to smile about.

Testing Reading the pH – Healthy pH Dev-Rev2

Tags

, ,

 

In a previous post (link), I was happy with the voltage reading results I was able to get from a test environment in which the value being measured – a DC voltage from a voltage divider – had a very low impedance.  As discussed earlier (link), pH probes have a very high impedance.  Too high to be measured with a DMM.  So one handy debugging tool is no longer available…..in this post I will test hooking up a pH probe submersed in 3 pH calibration solutions for pH levels 4, 7, and 10.

HealthypHDev-Rev2pHProbeTest

The Goal

The goal of this post is to determine how close voltage measurements recorded from a pH probe submersed in a pH calibration solution to expected values.  I look at it as a litmus test for whether I should go to more specific pH testing including probe calibration and pH measurement of a bath relative to the minipH and Atlas-Scientific pH stake.

Thanks to Those That Went Before

  • I constantly – and rightly – thank Chris Gammell.  Chris has been an exceptional mentor/guide as well as provides the Contextual Electronics courses that I took.  I have learned more from Chris’s courses, the other students, and Chris than I have through any other learning process.  For a person that loves to learn new things – that says A LOT!
  • Ryan (Sparky’s Widgets) open sourced and provided background on his minipH breakout board.  The Healthy pH Shield is based on Ryan’s work.  In addition, Ryan has kindly answered my questions.  Answering questions from a n00b like me is very time consuming.  It shows the openness and dedication to learning/community.  I highly recommend Sparky’s Widgets.
  • We’ve all benefit from the tremendous amount of shared knowledge folks have posted on the web. This post is no exception.  Google is my friend.  

The Test

I do not expect to get accurate pH readings.  This requires calibration of the pH probe (discussed here) and adjustment for the bath’s temperature.

I do expect to get voltage readings that are within the values I expect for pH 4, pH 7, pH 10.  I need more testing to know if a repeatable reading is “good enough” to determine the pH reading or precise readings are important.  My current knowledge makes me think that given the high impedance of the pH probe and the noise in the circuit, there will be a higher STDEV in results than I would like.  This then goes to the smoothing technique.  My current technique is to take multiple readings multiple times and then average the averages.

In this post (link) I had a table that listed the voltage reading for each pH level.

pH Signal(s)
0 0.414
1 0.359
2 0.309
3 0.249
4 0.189
5 0.129
6 0.069
7 0.009
8 -0.069
9 -0.129
10 -0.189
11 -0.249
12 -0.309
13 -0.369
14 -0.419

I am interested in pH 4, 7, and 10.  Here is a table of results:

pH Expected Volts Measured Volts, n=25 STDEV Measured Volts, n=50 STDEV Measured Volts, n=100 STDEV
4 0.189 0.16 0.1 0.17 0.1 0.17 0.1
7 0 0.03 0.08 0.01 0.09 0.02 0.08
10 -0.189 -0.14 0.09 -0.14 0.09 -0.14 0.09

Plotting the ideal line and drawing a line between the points that were measured:

plot_ideal_phVolts_initial_measured

the measurements appear close!  This is without adjusting for temperature or taking into account the current quality of the probe.  A very very excited YIPPEE! But of course – it is the last 20% of a project that takes 80% of the time and work.  Still, I have a big smile on my face (for at least one minute :-) ).

 Reading just one value would be too noisy so I took a variety of readings.  The first time, I averaged 25, then 50, then 100.

Negative Numbers and 24 Bits

Previous tests assumed adc values would be positive.  pH voltage values range from +/- .414V.  I changed the test code to handle negative values.

A challenge I had due to my lack of background in computer science, was reading negative numbers.  As pointed out in the MCP3901 data sheet – Section 5.6 – negative numbers are stored in two’s complement.  This would be easy-peasy if I was dealing with a 32 or 16 bit value.  But the adc value is 24 bits.  Perhaps there is an easier way, but I translate a 24 bit negative adc value into a 32 bit value doing the following:

    //start with the 2nd byte since this is a 24 bit number and bit twiddling is needed if the number is negative.

    for (byte i=1;i<4;i++){

        adc_value_bytes[i] = SPI.transfer(0xFF);

    }

#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))

    if (CHECK_BIT(adc_value_bytes[1],7)) {

        adc_value_bytes[0]  = 0xFFFF;

        adc_value_bytes[1] &= ~0x8000;

    }

    adc_value =   (long)adc_value_bytes[0] << 24 | (long)adc_value_bytes[1]<<16 | (long)adc_value_bytes[2] << 8  | (long)adc_value_bytes[3];

See the code at this GitHub location – it includes all of the above in the MCP3901 library.

Reflection

As a litmus test, I am happy with these readings.  While they are not accurate enough to determine the pH level with .1 accuracy, the voltage readings are “close enough” to tell me the voltages are being recorded.  What I do not know is what is causing the voltage readings to be the STDEV they are.  And why the values aren’t equivalent to the expected values.  I am ok with the results for the rev of the Healthy pH Shield.  I will do further testing and refinement in future revs.  I have enough to change in this rev to move incrementally to better results.  This will give me spacing in the testing process to figure out how to improve results

Thanks for reading this far.  Please find many things to smile about!

Soldering with a Toaster Oven – Healthy EC Dev-Rev1

Tags

, ,

The Healthy EC Dev-Rev1 PCBs came in the other day.  I wanted to know how our old toaster oven would work as a reflow oven without any modifications.  Using an old toaster works well enough that I’ll use this technique again!  The tedious part continues to be -and will always be without a pick and place machine – is the placement of solder and placing of chips.  Although it is a great time to relax and listen to music.

I set the toaster to 475˚F and warmed it up for 10 minutes.  After putting the solder mask and placing the chips, I popped it in the toaster for ~ 90 seconds….and out comes….

Healthy EC Oven Reflow

not bad.  There were two 0805’s that needed to be re-soldered, like the tombstone job on R18:

tombstone Chip

and my old friend the MCP3901 needed cleanup:

 

MCP3901 cleanup

but these were minor – and easy – to clean up.

To evolve my soldering technique, I note:

  • I used too much solder.  I tend to place a glop that covers a pad.  After playing with a stencil, I believe a better method would be a light covering – more like a smear – than a glop.  
  • The paste I am using – as Brent from Osh Stencils noted based on an earlier post on using stencils is very (very) liquid.  I was hoping it was because I had removed the solder paste from the refrigerator an hour before so that it would be at room temperature as Dave (EEVBlog) advised in this video.  No, the paste I am using – Chip Quik Low Melting Lead Free Solder Paste – is liquid.  
Brent suggested Kester EP256 solder paste.  I plan to try this solder paste.
 
After I ran this experiment, I asked the question on the /Ask/Electronics subreddit:
Yesterday I placed chips (on top of solder paste) on a pcb and stuck it in my toaster oven for 90 seconds. Everything seemed to work great. I just turned the toaster to 475F. There was no profile.What are the problems I will run up against with a PCB who has had its chips attached in such a “pop tart” like way?
I got some great advice (link) that I will apply moving forward.  I also ordered a new toaster oven for my family :-).
 
 

 

Noise on VGND – Healthy pH Dev-Rev2 testing

Tags

,

 Chris pointed out to me that the VGND buffer (op amp) – takes every incoming change – including noise – drive low impedance as hard as it can.  Any noise will affect that.  Will this be a problem in the measurement of pH?  Given the below – I don’t think so.  However I do not have the context to know if I am correct.  So I leave this post as something to be evolved as I learn more about noise on the power wires.

 I wanted to quantify  how much noise on the power wires affects the pH measurements.  Here are measurements for the power coming from my test regulated power source.  The first one is run without the Arduino also plugged in.  The second image was taken with the Arduino plugged in.


V+ WallWart

V+ WallWart + Arduino plugged in

 Both Vpp are the same = 160mV.  I was expecting a higher Vpp when the Arduino was plugged in because the power source is coming over USB from my computer.  I would think a measurable amount of noise would be introduced.

I made similar readings on VGND relative to AGND.

VGND

VGND + Arduino plugged in

“zoomed in” a bit
 
 
In this case, the Vpp were pretty much the same at 24mV.  I then ran the test code that turned one of the pumps on and off.  The Vpp only changed when the pump was turned on or off, going to 36mV when switching to on or switching to off.

 

Testing the Pumps on Healthy pH Dev-Rev2

Tags

,

Besides the pH and temperature, the Healthy pH Shield turns two pumps on and off. The purpose of these pumps is to allow the person writing the software the ability to adjust the amount of pH UP or DOWN depending on the pH measurement (adjusted for temperature) and the type of plant being grown.  Different plants are healthiest at different pH values.

Well guess what?  IT JUST WORKS! YIPPEE!!!

The Goal

The goal of this post is to determine if two peristaltic pumps connected to the Healthy pH Shield can be turned off or on.

Thanks to Those that Go Before

It is important to remember who has enabled me to do this stuff.  Thanks to Chris Gammell for his training and mentoring.  I highly recommend his Contextual Electronics course if you want to build PCBs.

The author of this post on a solenoid circuit.  It was clearly written.  This is the circuit I used for the pumps.

The Pump Circuit

The pump circuit can be found in the Pumps.sch kicad schematic at this GitHub location.

Pumps Schematic

The circuit design is basically the one in the image below.  There are two, one for pH UP and one for pH DOWN.  

Solenoid Circuit

I found this article covering the circuit to be extremely useful.  Refer to the article for a walk through of the circuit.

The pumps use connectors 5 through 8 of the 8 connector terminal block.

Pumps Relative To TB

While pins 5 and 6 reference the DownPump and pins 7 and 8 reference the UpPump in the schematic, it doesn’t matter if the DownPump is really hooked up the pH UP solution. I just use the naming convention to keep track of the wires and nodes in the circuit.  

The Tests

  • TP14 – Arduino’s 5V power source relative to Arduino GND.  Measuring this test point = 4.99 – 5V.  The readings would go between these two values.
  • Test the down and up pump circuits.  I attached a peristaltic pump to each and ran a simple sketch.  Here is the sketch for the down pump. The test code is located at this GitHub location.

Down Pump Circuit

  • The voltage across TP12 and TP15 will show that Q1 is drawing power.  Measuring this, on the DMM measurements jump around .4V.  Because of all the noise, I also measured on the scope:

   while (Serial.available () == 0) {

        analogWrite(pump_down,255);

        Serial.println(“Down pump is ON”);

        delay(2000);

        analogWrite(pump_down,0);

        Serial.println(“Down pump is OFF”);

        delay(2000);

    }

Additional Cleanup

  • The Arduino has two GND pins next to each other.  Connect the GND pin that is not connected to the GND net (GND_ARD).
  • The Arduino 5V power source can be checked through the shield’s pins for GND and 5V.  TP14 duplicates this, but is further down the wire.  I don’t think being further down gives additional information, since the schematic/layout will show whether there is copper between the two points.  Given that, TP14 can be removed.
  • TP12 text is underneath D5.
  • I am not sure any of the test points are “interesting.” 
  • Put “1” close to the 1st connector of the 8 terminal block.
  • Along the way…tested the RGB LED.  255,255,255 turns off. 0,0,0 turns on.  This means blue = 255,255,0 but 0,0,255 goes blue as does 0,255,255.  Green does not seem to be working.  I could not determine the pin/wire placement.  This is most likely off.

What’s Next

Just a little more to do – test the RGB LED.  I also need to revisit the thermistor.  Then on to soldering the Healthy EC Dev-Rev1 Shield that arrived today.

Time/Cost for Prototype PCBs

Tags

This post is here to record the turn around time and prices I paid for PCB prototypes from OshPark.

Healthy pH Shield Dev-Rev1

Gerbers sent out on Thursday PM.  I received them 15 days later at a cost of $28.50.

3 boards at $28.50 per batch of three. $28.50
Sub total $28.50

United States: Free Shipping $0.00
TOTAL (paid) $28.50

 

Healthy pH Shield Dev-Rev2

I sent the Gerbers in on a Monday in the afternoon.  I wanted to try out the Super Swift Service as well as some for shipping to see what the time difference is.

3 boards at $28.50 per batch of three. $28.50
Super Swift Service $89.00
Sub total $117.50

USPS – Priority Mail $5.00
TOTAL (paid) $122.50

It took 2 days for shipping. I received the boards 9 days later on Wednesday.

According to the great folks at OshPark, panels go out each day at 11AM. If I had been able to submit the Gerbers prior to 11AM Monday, there is a good chance I would have received the boards two days earlier. Perhaps if I paid for overnight shipping I would receive the PCBs on Saturday – a total of 6 day turnaround.

Healthy EC Shield Dev-Rev1

I sent gerbers out on a Tuesday AM.  

3 boards at $28.50 per batch of three. $28.50
Sub total $28.50

USPS – Free Shipping $0.00
TOTAL (paid) $28.50

I got a notice from OshPark of shipment 8 days later.  The boards arrived 10 days after I sent the gerbers.

Testing the Thermistor on Dev-Rev2 of the Healthy pH Shield

Tags

,

One of the sensors on the Healthy pH Shield is a thermistor.  The thermistor is used to read the temperature of the bath.  As noted in other posts (like this one), the pH is relative to the temperature.

The Goal

The goal of this post is to walk through the implementation of the thermistor for taking temperature readings and describe the diagnostic tests that will be used to make sure temperature readings are available.

Thanks to Those That Went Before

Adafruit provides great tutorials.  I used their thermistor tutorials for this effort.

Thanks to Gerald Rectenwald for his excellent class notes on thermistors.  They were easy to read and useful.

As always – a huge thank you to Chris Gammell.  His Contextual Electronics and additional guidance has made it possible for me to even attempt this effort.

Ryan (Sparky’s Widgets) has provided us with an open hardware pH and E.C. sensors as well as incredibly useful guidance.

A Voltage Divider Circuit

A drawing and explanation of the circuit was done in this post.  

Thermistor Schematic to Real

Finding the temperature means figuring out what the resistance value is of the thermistor….yet another example of a voltage divider circuit.  

ThermistorVoltageDividerCircuit

Solve for Rtherm

I found a wonderful document written as class notes by Gerald Rectenwald: “Temperature Measurement With a Thermistor and an Arduino.”  The document does a great job in explaining what I’ll state in summary.

Measuring Temperature

There are two steps to getting to a temperature reading:

  • Solve for Rtherm
  • Use an equation from a really smart person (people?) to convert Rtherm  to a temperature.

Solve for Rtherm

I can see the first step since finding Rtherm  is an application of Ohm’s law and keeping in mind what Gerald Rectenwald states: “Electrical resistance is always measured indirectly, usually by inferring the resistance from a measured voltage drop”.  In this case the measured Voltage drop, Vo, is the voltage we get from the ADC.  Now I need an equation or two so that I can solve for Rtherm .  
since the resistors are in series, the current (I) is the same throughout the circuit…this leads to:
Vs= I(R+Rtherm)

Vo = IR
The two unknowns then are I and Rtherm. I can be substituted with Vo/R. This gives an equation with just Rtherm not known:
Vs = (Vo/R)(R+Rtherm)
Rtherm = R(Vs/Vo – 1)

Substituting in what is known and can be measured:
Rherm = 10,0000(5/M – 1)
where M = the voltage measurement read from the ADC.

Calculate the Temperature

In Gerald Rectendwald’s class notes, he says “the thermistor temperature can be computed with the Steinhart-Hart equation:

Steinhart-Hart Equation

…GULP…if you say so…Now I just plug in…hey wait – first I would need to find C1, C2, and C3….luckily, there is a simpler way as noted in Adafruit’s thermistor tutorial, there is a B parameter equation.  

AdafruitBParamThermistor

I assume this way of calculating the temperature is “good enough” because – hey both Adafruit and Wikipedia talk about it :-).  Whether this works well will ultimately be determined by the temperature values I read when compared to other ways of reading the temperature.  Adafruit notes B = 3950.  For the 10K thermistor I am using, the data sheet notes B = 3977.  Adafruit uses Ro for Rtherm.  To is room temperature.  Adafruit uses 25˚C = 298.15K… At this point I’m going to be lazy and assume this value for To will “just work.”  Again, measurements will prove out whether my laziness is justified.

Testing the Circuit

I soldered together two wires to a 10K Thermistor so that I could easily hook the two wires up to pins 3 and 4 on the 8 pin terminal block.

pinsOn8TBForThermistor

 

 
I did this before I discovered Gerald Rectendwald’s “How To” on “Fabricating a (Reasonably) Waterproof Thermistor Probe“. 

The schematic for the thermistor is located in the kicad Temperture.sch file (located in this GitHub repository for Dev-Rev2).  

Thermistor Schematic

the schematic is pretty much a duplicate of the voltage divider circuit I showed a picture of earlier.  Before figuring out the temperature, I calculate Rtherm.  I used a DMM to get Vo and then calculated Rtherm (Rtherm = R(Vs/Vo – 1) ).

Hooking my DMM to TP11 relative to AGND, the voltage reading I get for Vs and Vo:

Vs = 5.07V Vo = 2.01V…hmmm…Vo should be much closer to 2.5V since it is 10K at room temperature.

Plugging these values into:

Rtherm = R(Vs/Vo – 1) = 10,000(5.07/2.01 – 1) = 15224

Hmmm…given 2.01V, I am not surprised the calculation for Rtherm is quite a bit larger than expected.

What’s Going on With R15?

The first thing I do is check the value of R. Is it 10K? On the schematic, R is R15. I look at the reading for R15…and weird – it reads 5.4K. Yet the label on R15 is 103 – which is the 3 digit code for 10K. Maybe my probes are not getting a good enough connections on the ends of the resistor. I could have damaged the resistor during soldering, but if I did, wouldn’t the resistor just not work and I would get no reading? Could quality control be bad enough to allow a 10K impostor? Could this resistor have been damaged during shipment? Could I have zapped it?….While my curiosity remains piqued as to why I am getting a 5.4K, I’m going to remove and replace.

After I removed, it looked like I had removed the copper from the pad. The image is a bit blurry, but what concerns me is the white pad – this should be copper:

R15

 

I measured the resistance of the resistor I removed…hmmmm…it read 10K. I’m thinking I’ve damaged the pad too much. I’m going to stop testing using this circuit…even if it did work…

Simpson DOH


D’OH… while testing the pH circuit (covered in this post), I realized the MCP3901 can read voltages between +/-.79V.  I wouldn’t be able to read Vo! 

 

 

Testing the Thermistor

Using a DMM

I tested the thermistor with a bread board.  I measured the actual resistance of the 10K resistor I am using.

Breadboard Thermistor with DMM

 

 

 It measured 9.9K.  Vo measured 2.64.  With these values, Rtherm = 9,900(5.07/2.64-1) = 9,112.5.  When I put the thermistor between my thumb and first finger (added heat), the voltage decreased to 2.44 -> 10671Ω.  This indicates to me that the thermistor is working.

Using an Arduino

Taking a reading on the Arduino using Adafruit’s sketch (see this post for why analogReference(EXTERNAL) is used):

// the value of the ‘other’ resistor
#define SERIESRESISTOR 10000
// What pin to connect the sensor to
#define THERMISTORPIN A5
void setup(void) {
Serial.begin(9600);
analogReference(EXTERNAL);
}
void loop(void) {
float reading;
reading = analogRead(THERMISTORPIN);
Serial.print(“Analog reading “);
Serial.println(reading);
// convert the value to resistance
reading = (1023 / reading) – 1;
reading = SERIESRESISTOR / reading;
Serial.print(“Thermistor resistance “);
Serial.println(reading);
delay(1000);
}

I got the following readings:

ArdThermistorReadings

Rtherm ~= 11313.

hmmm….not 10K….

So…

Additional Cleanup

A few more changes in Dev-Rev3.

Get Rid of Multiple Test points

  • Remove TP11: The Thermistor can be measured from the 3rd pin of the 8 Terminal Block Connector.

What’s Next

At this point, I am not getting a good enough reading for Rtherm .  I have ordered more thermistors.  When these come in, I’ll:

  • test on breadboard
  • test on arduino
  • set a plan for the thermistor given the MCP3901 cannot handle its voltage.  This most likely means using the Arduino.  I am concerned with this choice because of the inherent noise using the Arduino can introduce.
I’ll be back!
 

 

Soldering and Board Test of the Healthy pH -> MCP3901 ADC

Tags

,

I just finished testing out the pH probe connection with the shield.

Healthy pH Shield With Probes

The Goal

The goal of this post is to discuss how I tested the MCP3901 and document what I have learned about communicating with it from an Arduino.

Thanks To Those That Go Before

I was more comfortable working with the SPI on the MCP3901 since this is the chip Chris Gammell used in Section 1B of the Contextual Electronics course.  In the course, he walked us through sending/receiving ADC values and converting these to digital volt readings.  Heck, he provided me with all the knowledge I needed!  

I spent a lot of time understanding Ryan’s (Sparkys Widgets) design of the minipH and minieC break out boards for the Arduino.  His schematics got me craving to understand more about electronics.  In addition, Ryan eagerly shares what he knows.  This is totally amazing.  The Healthy Shields are an evolution from the minipH and minieC shields.   It is my way on testing what I have learned from Ryan’s work, with the added benefit that I will use these shields to help grow vegetables (hydroponically).   Ryan really knows his stuff.  I highly recommend his products!

What to Solder

The components to solder are shown in the DigitalAccess kicad schematic (GitHub repository).

Digital Access Schematic

Tests

Rather than list code here, I uploaded the code I used for testing to the GitHub repository.  The code is not complete.  The only code that should be considered “working” is the code that tests the SPI bus.

Healthy pH SPI Test Setup

(Rather messy?) Test Setup

 

Config Registers

It worked, it worked!  I ran a simple test program that reads CONFIG1 and CONFIG2, then writes to CONFIG1, and then sets CONFIG1 back to the defaults.  Here are the results I get on a serial monitor:

**** Read CONFIG registers ****

->Bits in config 1 register: 00010000| 0X10

->Bits in config 2 register: 00001100| 0XC

the values are what I expected based on the MCP3901 data sheet.

Change Default Config 1 Settings

 Looking at Register 7-6 of the data sheet,

Config Registers Table

Config1’s defaults set the ADC bit width to 16 and the OSR (Over Sampling Ratio) to 64.

I believe I’ll get the “best” readings with an ADC bit width of 24 and an OSR of 256.  Thus, future tests will set Config 1 to 0011 1100 (0x3C).

Digital Voltage Values

I was thinking the “easiest” way to test the analog voltage going in with values going out was to use an AWG (discussed in last post) to generate an incoming sine wave then see what the MCP3901 gave as the digital voltage result. 

Chris recommended a much better testing approach.  Send in various DC values.  So I set up the power source to provide 5V to the pH circuit as well as a voltage divider with a potentiometer to adjust the DC value simulating a result from a pH probe.  Bummer! The values I was getting were significantly higher than the values read by my DMM.  The reason:

Simpson DOH

 

D’OH…RTFM.  Now this is doubly sad on my part – Besides being stated in the data sheet, Chris had explained this in Contextual Electronics Session 1B!  Epic failure to research on my part.  HAD I watched the Contextual Electronics videos where Chris was testing the MCP3901 in the BenchBudEE, I would have known that calculating the digital voltage is not what is was for the minipH, e.g.: 

float volts = (((float)adc_value/65536)*vRef)

where vRef’s typical value is 2.37 (MCP3901 data sheet).  But as pointed out in figure 5.3 of section 5.6 (ADC Output Coding) of the data sheet ****read section 5.6 carefully! *** the equation to convert a 24 bit ADC value in either CH 0 or CH 1 is:

float volts = (float)adc_value/(G*8388608*3)*vRef

The default for the gain is 1 (see register 7.4), which is what I have designed for.

Simpson DOH

D’OH…figure out the Vpp the ADC can handle before buying the chip.  I went into this test thinking the ADC had a Vpp of 0 – 5V.  WRONG!  As stated in section 5.6:

In case of positive saturation (CHn+ – CHn- > VREF/3),the output is locked to 7FFFFF for 24 bit mode…In case of negative saturation (CHn+- CHn- <-VREF/3)

This means the maximum  voltage that can be translated to a digital representation is +/- 2.37 / 3 = .+/-79V.  And indeed, this was true in tests I ran.  Values coming in from the pH probe will range ~ +/- .415.  Within the range for this ADC.  So that’s good!

ACVRange of ph

Resolution

The process of going from an analog to digital signal involves chopping up the analog signal into steps.  

ADCImage

VRef and resolution define the step size.  The lower the VRef / the higher the resolution means more steps which means a higher accuracy translating an analog value into a digital value.  As noted earlier, I’ll use 24-bit resolution, the VRef of 2.37.

Voltage Readings

I took 10 different voltage readings by adjusting the potentiometer such that the DMM was < 79V.  Here are the results I got:

ADC Value ADC -> Volt DMM Scope ADC-> Volt – DMM
5026041 0.47 0.458 0.462 0.012
3819007 0.36 0.347 0.349 0.013
1053439 0.1 0.082 0.082 0.018
6307071 0.59 0.58 0.584 0.01
  0.73 0.714 0.724 0.016
6669600 0.63 0.615 0.618 0.015
4377335 0.41 0.399 0.4 0.011
2458268 0.23 0.216 0.215 0.014
757361 0.07 0.055 0.054 0.015
2514621 0.24 0.221 0.221 0.019
         
      average: 0.0143

 I compared the voltage calculated from the ADC value with readings from my DMM and scope.  While the DMM and scope readings vary within less than 4mV, the ADC calculated voltage averaged a positive difference of 14.3mV.  Many posts ago I noted the pH reading resolution I am shooting for is .1.  Since there is a voltage change of 59.16mV per pH unit, a resolution of .1 would mean a voltage change of 5.92mV – which is slightly less than half of what I noted as the difference between the ADC calculated voltage value and the voltage value read from the DMM.  While I need to check the circuit for noise, this still could be ok since the readings are calibrated to the circuit.

When I woke up in the morning, I added averaging and taking the STDEV on n readings.  With 100 readings, I consistently got the same reading with a STDEV of 0.  I expected to see some variability.  The ADC values were not the same, but vary close.

Additional Cleanup

A few more changes in Dev-Rev3.

Get Rid of Multiple Test points

Each additional test point adds complexity to the layout and debugging process.  Multiple places to insert a probe for the same reading include:

  • Remove TP2, TP3, TP4, TP5:  These test points are for SPI testing.  It is easier to just connect probe wires to the SPI pins on the stackable headers.
RGB LED – not sure which way is cathode on the layout…the footprint doesn’t give an indication.

What’s Next

On to testing the temperature probe and pumps!  Also – just got email the Healthy EC Dev-Rev1 PCBs are being shipped.  So off I go.

 

Thanks for reading this far.  Please find many things to smile about.

 

 

 

 

 

Follow

Get every new post delivered to your Inbox.