bs2 PLC analog problems ? usb to serial noise ?
Cheese
Posts: 29
Cheese said...
Hello:
My name is Gene, I'm having difficulty with my bs2 stamp PLC reading analog temperature.
{ the output from the temperature probe = 1 mV per Deg.F} = 16 Deg. accuracy!
www.omega.com/manuals/manualpdf/M2813.pdf
I have been racking my brains on this for two weeks and these results are the best to date.
The power supply to the PLC is industrial quality omron s82k-10024 4.2 amps @ 24v.
I have installed ferrite cores (tdk zcat3035) on the serial line, power line, analog input
and a capacitor across the analog input that has removed some HF noise.
Help would be greatly appreciated!!!
The goal for this project seamed simple, heat cycle followed by blower assisted cool-down,
then repeat, chart plotting and saving each cycle.
Post Edited (Cheese) : 1/22/2008 11:04:21 PM GMT
Comments
I'm not sure about the ripple you're seeing on the input, but I think the stamp plot problems might be because the sample code is still reading the inputs of all 4 ADC channels, writing over the mVolts value with data from the unconnected inputs. If you take out the loop and just read the single channel the probe is connected to does the plot data look any better?
Mike
Thanks for the Idea I will check that out. I will let you know as soon as I get back on it tonight.
I have used the stamps for about 10 years but only as a glorified switch. this is the first time
I will be using one with more than 15 - 20 lines of code and I easily get lost.
Thanks again for the time.
Gene
I started by taking readings with the PLC power off. usb to serial converter disconnected.
The multimeter and the scope readings are identical. peak to peak = 1.0 mV.
The second test PLC power off , usb to serial converter connected.
The multimeter = 83.2 mV. but the scope has droped to 63.94 mv . Peak to Peak =5. mV.
Not sure exactly where to go from here?
Post Edited (Cheese) : 1/22/2008 11:10:34 PM GMT
I'm still not sure I understand the noise problem. In the code you've configured the sensor for 0-5V, so I'm not sure the millivolt-level noise would impact the reading enough to matter. Perhaps I'm just not understanding your project requirements well enough.
Either way, if you get weird results plugging into a USB/Serial converter is there some way to take that out of the equation? Maybe find an older computer with a regular serial port and give that a shot. It wouldn't be the first time a USB/Serial converter was the cause of weird issues...
Mike
Thanks again for your time.
Based on your suggestion I pulled out another computer which is why this reply took so long ,installing file's, transfers,settings ....
Any way this is where its at.
PLC serial connected to sony lap. (real serial port)
USB O-scope on Campaq lap.
I do think we may be narrowing it down.
With all filtering capacitors removed the mulitmeter and scope are back in line, mV readings the same on both.
Power supply off: peak to peak = 1.0mV. noise (no ripple)
Power supply on: peak to peak = 3.3mV. noise (no ripple)
installed USB to serial converter on the sony and retested using the converter,
Results are identical!
Power supply off: peak to peak = 1.0mV. noise (no ripple)
Power supply on: peak to peak = 3.3mV. noise (no ripple)
The problem must be in the power supply?
If I can get it figured out how to filter the power supply so that it dosent affect the scope readings? peak to peak
Will get back soon!
Post Edited (Cheese) : 1/22/2008 11:13:06 PM GMT
The multimeter reading is rock steady, Oscilloscope confers with the multimeter, The StampPlot PLOT is identical to the first in this post! (measurements all over the place)
www.eugenius.com/igoodies/Scope3.JPG
Could it be in the way the PLC processes the ADC signal?
Could it be in your code? If you debug the raw value returned from the ADC immediately after it is received, it is too fluctuating or only after being processed/converted in code?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
I'm not exactly sure "The code" is the demo code that came with the PLC .
I am not code savy enough to decifer it well enough to be sure.
The Demo reads an input then switches the corrisponding output .
The code for analog seams to read,
(1) 0 -5 v 11110000 = channel 1, range 0 to +5 VDC
The others I commented out.
(2) +/- 5 v
(3) 0 -10 v
(4) +/- 10 v
(5) 4-20 mA
I will be testing from 70deg F to 1700deg F = 70 to 1700 mV , (+/- .5 mV would be fine)
This is my first time with the Basic stamp PLC.
As stated in an earler post I have used stamps for years only as fancy switching,
to test stepper drives and trigger simple events. I moved up to the PLC mainly for industry
standard 24Vdc compatability ( All of the sensors and relays valves ... I have are 24 vdc. )
Thinking it might be the best choice for a simple testing logging device.
After viewing the code I realized I stepped into something else. But I am Trying!
OLD DOG NEW TRICK THING.
Post Edited (Cheese) : 1/23/2008 8:16:14 PM GMT
Okay, well eliminating the code the next thing I would look at is the source…However, if you want to send the PLC in for testing, I will connect is exactly as shown in the documentation for testing the ADC.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
I have another that I could swap it out with if you think that could be the problem!
I havent removed it from the shipping bag yet but I will try that now and insert another ADC chip and try.
A'm I correct in figuring I should be able to get .5 mV resolution with a 12 bit chip 0-/+5 v range?
Exausted:
Have tried another ADC chip, same thing!
Tried the 2nd PLC, same thing!
Went to the parallax link www.parallax.com/detail.asp?product_id=30064 and the link is no good!
Very carefully went thru the steps in the manual page 10 and the code has 1 or 2 errors. (ref LOW CDadc with out defining it or
a typo and should read LOW Csadc) ?
Tried it both ways, same thing!
Over $900.00 and 4 months tied up in this project (parallax parts alone) and cant get a stable reading!
Where am I going wrong ?
This can not be the first time this has come up.
I see far more sofisticated projects than this on the site.
Hundreds of viewers?, There must be a simpler solution than the effort put into this.
Lastly:
setup is identical to the Manual with the exception I did not Have a 24k ohm pot so I just used 2 (12K Ohm resistors) making a voltage divider.
' {$STAMP BS2}
' {$PBASIC 2.5}
'
CLkAdc PIN 0
CsAdc PIN 3
CDadc PIN 3
AoutAdc PIN 4
AinAdc PIN 5
adResult VAR Word
Main:
DO
LOW CsAdc
PAUSE 100
SHIFTOUT AoutAdc, ClkAdc, MSBFIRST, [noparse][[/noparse]%11100000]
HIGH CsAdc
LOW CsAdc
SHIFTIN AinAdc,ClkAdc, MSBPRE, [noparse][[/noparse]adResult\12]
HIGH CsAdc
DEBUG SDEC adResult, CR
LOOP
Results:
www.eugenius.com/igoodies/resistorPlot.bmp
BurnedOut
Post Edited (Cheese) : 1/24/2008 11:23:32 PM GMT
Thanks for the read!
The The dinrail is grounded to all, power supply, filter,scope,The PLC does not seam to have seperite grounding.
However on your suggestion I verified voltages between all points.
I am concerned about ground loop?
Between laptop and dinrail voltage = 6.0 mV 0Hz
Between laptop and filter voltage = 9.2 mV 0 Hz
Between laptop and power supply voltage = 15.3 mV 26 Hz
Between laptop and ground lug voltage = 14.5 mV 23 Hz
Between laptop and dinrail 36" away from where the laptop grounds to rail = 10 mV 20 Hz
WOW!! Didn't expect this. Not sure exactly what it all means but it cant be good.
Next I measured from the laptop ground to the PLC analog ground and came up with 6.5 mV 100 Hz
From 24Vdc- to laptop ground = 72 mV 66 Hz
Don't Know if the that was the proper way to check? it is noise any suggestions on cleaning it up if this is the problem ??
Thankx For the BOOST!!
Post Edited (Cheese) : 1/25/2008 5:52:28 AM GMT
Maybe, the laptop ground is sufficiently isolated from the PLC ground that this voltage difference doesn't matter. I believe USB is designed as a "differential" standard, so small "common mode" voltage differences shouldn't matter.
But the probe and the equipment measuring the probe MUST have a well-filtered, stable DC supply with a common ground.
OK since the temp probe is self powered via internal battery. Possibly removing the battery
and powering the probe from the +5v. of the PLC or just connecting a wire from Battery- to analog ground?
Just curious as to why the multimeter and scope get it right but PLC would need a separate ground?
I will 1st try a common ground via single wire to Battery -.
·
·· The link you tried is for our old website. ·If you go to www.parallax.com and enter that stock code (30064) you will get the current product page in the search results. ·And yes, it is the first time this has come up that I am aware of. ·We have a lot of customers that use this device and not once has someone reported such an issue. ·I cannot answer for what is happening on your end, however we can have you send a unit in and we can test it ourselves to see if we get the same results.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
Thankx for your Time.
Before connecting the grounds together on the probe to the PLC I contacted Omega to see if that would be OK, he had me test it with a
100k resistor from the battery - to the K thermocouple - first,(since that is effectively what would happen if we used a common ground with the analog input) there was a 3.6mV drop in output voltage (the voltage that the PLC would be seeing) so it was suggested that it wouldn't be a good idea. (however since you think grounding is the problem)
He suggested a better solution might be to use a tx251 thermocouple transmitter 4-20mA setting on the ADC chip because the signal has a
High RFI Immunity and is more stable than using mV. setting! also with the 4-20 mA we would get a much better resolution.
Thankx allanlane5
www.omega.com/Temperature/pdf/TX250.pdf
I wonder if the Parallax DS2760 Thermocouple Module would work better here though, I am using a BS2 and not the BS2p
For the cost of 8 omega tx's is more than 8 DS2760's, + changing out the BS2's for BS2p's
Its not over yet But I would like you all to know I appreciate your guidance
MinimumWage,
Chris Savage
Parallax Tech Support,
allanlane5
Post Edited (Cheese) : 1/26/2008 12:27:40 PM GMT
If we have you send the unit in it would be just the PLC. Again, this would be just to help narrow things down. We sell a power supply for this module and that is what I would be using. Let me know if you decide to go this route and I will issue you an RMA number. In the meantime I hope something comes up and you do find the source of this noise. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
Thankx : I will take you up on that.
I will send whatever you need.
Then I will continue my work with the other one.
I have ordered a couple of transmitters from omega to try out, however I would like to Know where this problem is coming from!
The newly ordered transmitters are linear to the input not to the Temperature, therefor it will require more code.
I wonder if the Parallax DS2760 Thermocouple Module would work better? IF so would I be better off with a different stamp than the BS2 in the PLC?
Gene
You will need to contact us directly for an RMA number to send it in. As for the Thermocouple, it will not work with the Stamp PLC for two reasons. First of all it is a one wire device. Second, it requires a BS2p or higher to handle the communication. I’m not sure this is what you would need anyway since the resolution would be less by default. Probably +/- 3 degrees using the current tables.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
If you're using a 5V range then you need to calculate what voltage the ADC count corresponds with. The direct equation would be
millivolts = 5000mV * adc_count·/ 4096.
Since the reference voltage and adc range don't change, you could simplify by doing 5000/4096 ahead of time and using the literal result directly.
millivolts = 1.220703125 * adc_count
I haven't used stamp basic for a long time but I do remember that there is no floating point math. So you have to use those funky tricks with >>'s and stuff. Can't help with that part as I never did figure them out - just copied and pasted from examples.
Also be careful with your variable types. Word sized variables can only hold values up to 65535 so if a multiplication results in a larger number you lose lots of bits and get wrong results.
I can't imagine that two PLCs would have aggregious electrical problems and not see more people with the same problems. There isn't much wiring for the sensors or the potentiometer experiment so its not likely to be your wiring either. That leaves code as the most obvious suspect (not necessarily guilty though of course).
Perhaps post your entire code for perusal so the stamp basic grognards can check the math?
·
[noparse][[/noparse]quote]Main:
DO
LOW CsAdc
PAUSE 100
SHIFTOUT AoutAdc, ClkAdc, MSBFIRST, [noparse][[/noparse]%11100000]
HIGH CsAdc
LOW CsAdc
SHIFTIN AinAdc,ClkAdc, MSBPRE, [noparse][[/noparse]adResult\12]
HIGH CsAdc
DEBUG SDEC adResult, CR
LOOP
[noparse][[/noparse]/quote]
This doesn't look right. The Stamp PLC uses the Max 1270 according to the Parallax page and the 1270 requires that CS stay low during the entire conversaton.· You can even continuously poll the ADC without toggling CS. First thing to do is remove the two bolded lines!
Second, in addition to the control byte the 1270 also needs four more clocks after the control byte·before the conversion is ready to be read. Add four zeros to your shiftout (ADC actually ignores the extra four bits it just needs the clocks)
So try something like this:
[noparse][[/noparse]quote]
Main:
· Do
··· pause 100
··· Low CsADC
··· SHIFTOUT AoutAdc, ClkAdc, MSBFIRST, [noparse][[/noparse]%111000000000]
··· SHIFTIN AinAdc,ClkAdc, MSBPRE, [noparse][[/noparse]adResult\12]
··· HIGH CsAdc
··· DEBUG SDEC adResult, CR
· LOOP
[noparse][[/noparse]/quote]
This is the code I use for the Max 1270 (Bascom AVR basic) and it works perfect. The important code is bolded. I read back 16 bits only because I've always had a problem with reading in only 12 bits. Never seems to work right in Bascom (though its probably just me).
[noparse][[/noparse]quote]
Function Read_adc(channel , Range , Clockmode)
·· Local Command As Word
·· Local Result As Word
·· Command = 128··········································· ' set start bit
·· Shift Channel , Left , 4································ ' move channel bits to position
·· Command = Command Or Channel···························· ' OR sets the bits without changing anything else
·· Shift Range , Left , 2·································· ' Move range bits to position
·· Command = Command Or Range······························ ' OR sets the bits without changing anything else
·· Command = Command Or Clockmode·························· ' bits already in right place, just OR
·· Shift Command , Left , 8································ ' shift into high byte
·· Reset Spi_cs······························································· ' start conversation
·· Shiftout Spi_mosi , Spi_clk , Command , 1 , 12·····' Send 12 bits 8 highest is command byte, next 4 just for timing
·· Shiftin Spi_miso , Spi_clk , Result , 0 , 16·············· ' Recieve 16 bits adc will fill past 12th bit·with zeros
·· Set Spi_cs···································································· ' Chip select high conversation over
·· Shift Result , Right , 4················································ ' Move bits to position (overwrite the extra zeros)
·· Read_adc = Result······································· ' set function to return the result
End Function
[noparse][[/noparse]/quote]
N.B.
Yes, I really do code with all those comments. I have a mind like·a steel seive so without them I'm lost if I'm away from the code for more than 10 minutes! 8)
In my example I'm using external clock mode (hence the four extra bits). Just change the shiftout to:
SHIFTOUT AoutAdc, ClkAdc, MSBFIRST, [noparse][[/noparse]%111000010000]
and things should work (I hope)
Wow, you're up to 10 minutes! My Hero!
I am not code savvy so to this point, most of the code is cut-n-paste. I will try the extra 0's though.
The first sensor we used was Omron SMCJ-K www.omega.com/pptst/SMCJ.html and I like these because their output is linear to the temperature, i.e 1mV = 1 deg. 1500mV = 1500 deg..... (so no code conversion necessary) ... no lookup tables no additional wiring, it just works!! Celsius or Fahrenheit. But due to noise, Omron suggested the tx251 4-20mA transmitter www.omega.com/Temperature/pdf/TX250.pdf , however the tx251 will require lookup tables and that scares me to no end!!!
I will reread all your input then execute them 1by1, the (millivolts = 5000mV * adc_count / 4096) seems necessary for use with the 4-20mV sensor (tx251), The other one is just 1mV = 1deg.
Still have the question though: WHY powering the PLC creates so much noise? Using the oscilloscope to read the sensor output prior to turning on the PLC the signal is GOOD!! (NO NOISE! ) even went so far as to try separate power supplies, one for the sensor and the other for the PLC.
Both power supplies on, no noise, power the PLC = Noise??? Can't help but to think it's got to be RF or EMI. BUT if the fix can be coded in then OK by me!!
Pat Thanks a million for the input I will let you know the results!
Post Edited (Cheese) : 2/27/2008 12:16:46 AM GMT
I will reread all your input then execute the 1by1, the (millivolts = 5000mV * adc_count / 4096) seems necessary for use with the 4-20mV sensor (tx251), The other one is just 1mV = 1deg.
[noparse][[/noparse]/quote]
Because the ADC does not return millivolts, it returns the ADC count which will be 0-4096 with a five volt input resulting in a return value of 4096. You have to convert to the 5v scale if you want to read millivolts.
Noise is unavoidable in any digital system. The trick is to keep it away from the analog circuits as much as possible and filter out whatever makes it though.
A voltage return sensor automagically deals with a lot of the noise on its power supply - it regulates the voltage output so ripple in does not necessarily mean ripple out.
I'm 98% sure your problems stem from talking to the 1270 incorrectly. You were using internal clock but not waiting for the ADC to signal that it was finished its conversion so the last few bits are just random.
·
Sorry! Didn't mean to keep you in suspense!
Did try the additional 0000,s (AoutAdc, ClkAdc, MSBFIRST, [noparse][[/noparse]%111000010000]) but that just gave me a reading of 0 in the debug so nix on that. However I was surprised that changing the ADC code callout from 12 to 16 as you suggested ( SHIFTIN AinAdc,ClkAdc, MSBPRE, [noparse][[/noparse]adResult\12] ) to (SHIFTIN AinAdc,ClkAdc, MSBPRE, [noparse][[/noparse]adResult\16] )did give me more stable numbers, also commented out the ( HIGH CsAdc LOW CsAdc ) THIS LOOKS PROMISING!! Now I need to do some more reading to figure out the formula.
In a pinch for time and didn't have more time to devote to it and for that I apologize.
You gave me a reason to smile when I got the email of inquisition 8) "mush-mush doggie" I will do better .....
Thanks again.
Change the shiftout byte to %101100010000 and change the shiftin back to just 12 bits then try again.
The command byte bits have to be set properly. Here's the byte (just 8 bits, omitting the padding for timing). The underscores just visually seperate the bits to make it easier to see. You can't use them in the byte you actually send.
1_111_11_11
-Reading from left to right, the first bit is the start bit, it must be 1. No options here.
-The next three bits select the ADC channel with 000 being channel 0 , 010 being channel 2, and 111 being channel 7 (normal binary counting). The PLC only brings out ADC channels 0 to 3 which it numbers in reverse and doesn't use zero (000=4, 011=1). So for channel 1 you need 011 in this spot. The example code shows 110 which is 6 on the ADC and that's not brought out for connections.
- The next pair of bits select the voltage range and polarity to use. 00 = 0-5V, 01 = 0-10V, 10 = -5v - +5V and 11 = -10V - +10V
- The last pair on the right selects the clock mode. 00=internal always on, 01 = external always on, 10 = internal standby, 11 = external standby. Since we don't want to watch the data out from the ADC to see when the conversion is finished we're using the external clock (the sclk signal) and sending four extra bits. So this needs to be 01
So to build the command byte just join them all together, left to right.
1_011_00_01
We need four extra bits so it ends up as 1_011_00_01_0000.
I'm quite suprised that the PLC manual example code would be so wrong. According to the analog input channel to ADC channel table, 011 is channel 1. If channel one still gives zeros, connect the sensor to channel 4 (to see if the channel to adc input table is backwards).
If you do get the reading the number might not make sense to you still. If I remember correctly (no guarantee that I do! ) the 12 bits will be left aligned in the word variable: that means a 4095 (5V) return would be %1111111111110000 (65520) instead of %00001111111111111111 (4096). You just need to shift the result to the right by 4 bits. I think in pbasic it's Adcval = adcval >> 4 (can you see the rust on my pbasic skills?). In bascom I have to shift the bits right so I might just be confusing that with pbasic.
The 12 or 16 bit shiftin shouldn't really matter on the stamp. I was always able to get the expected numbers in pbasic. Its only with bascom that I seem to have troubles.
P.S. The CS changes between the shiftout and shiftin turned out to actually be ok as the chip basically ignores the toggle. No use wasting the programming space though so leave them out.