ADC measurements using TC65T

407 views
Skip to first unread message

Thomas Hermansson

unread,
Aug 28, 2011, 5:45:33 PM8/28/11
to java...@googlegroups.com
Hi all!

I´ve been developing a minor weather station for a few years of spare time now. :) It´s been running fine, but recently I started to question the measurements I have received from the ADC converter.

When logging it with an Oscilloscope and debugprintouts at the same time I can see on the Oscilloscope that the inputvoltage is solid at 0.3V. Most of the time my nice little program also returns 0.3V but aproximately 1 out of 10 readings is crazy. I can get values ranging from anything from 0.3 to 2.8V. I see on the Oscilloscope that there is no spike at all so the reading should be 0.3V.

Is there anyting special that I need to think of when using the ADC converter?

I am using the TC65Terminal rev 3.
Measurements are done on request (not periodically). One reading aproximately every 0.5 second.

I´m using the second ADC channel, and the ADC2_N is connected to GND. ADC1 is not used at all, so ADC1_N is NOT connected to anything? I guess I don´t need to connect it when not using it?

Have anyone else seen any inconsistency with ADC measurements on TC65 or TC65T devices? Any hints? :-)

--
vänligen
Thomas Hermansson
TNA Software AB
http://www.tna.se

Thomas Hermansson

unread,
Aug 28, 2011, 6:11:50 PM8/28/11
to java...@googlegroups.com
Hi again!

Let me add some of the code also:

package main;

import util.Utility;

import com.siemens.icm.io.ATCommand;
import com.siemens.icm.io.ATCommandFailedException;
import com.siemens.icm.misc.Watchdog;

public class test {

void programLoop() throws InterruptedException {
    ATCommand mainCommand = null;
    try {
        mainCommand = new ATCommand(false);
        System.out.println("at commands created");
    } catch (ATCommandFailedException atcfe) {
        handleError("Unable to instantiate atCommands" + atcfe);
        return;
    }
    mainCommand.addListener(this);
    
    // Create sensors instance
    sensors = new Sensors();
   
    String result;
    int PORT1 =0;
    int PORT2 =1;
    int PORT3 =2;
    
    try {
        // Activate the GPIO bus
        result = mainCommand.send("at^spio=1\r");
        result = mainCommand.send("at^scpin=1," + PORT1 + ",1\r");
        result = mainCommand.send("at^scpin=1," + PORT2 + ",1\r");
        result = mainCommand.send("at^scpin=1," + PORT3 + ",1\r");
        result = mainCommand.send("at^scport=" + PORT1 +"," + PORT2 + "," + PORT3 + "\r");
        sensors.portNumber = sensors.parsePort(result); //Just extract the port nbr that is returned.
    } catch(ATCommandFailedException atcfe) {
        System.out.println("Sensors::configurePort: " + atcfe);
    }
    
    System.out.println("Port configured!");
    
    try {
  mainCommand.send("AT^SCPIN=1,8,1,1\r\n");
        /* enable watchdog */
        String res = mainCommand.send("AT^SCFG=\"Userware/Watchdog\", 1\r\n");
        Watchdog.start(5 * 60);
        
        String imei = mainCommand.send("at+gsn\r\n");
        imei = imei.substring(9, imei.length() - 8);
        System.out.println("Start OK: " + VERSION + " imei:" + imei);
    } catch (ATCommandFailedException atcfe) {
        handleError("Unable to start - " + atcfe);
        return;
    }
    
    try {
        /* Setup pulsecounter */
        mainCommand.send("AT^SCCNT=1,0\r\n");
        
        //Get the static ADC constants for calculating the real Voltage when doing the real ADC measurements.
String result = command.send("at^saadc?"+ "\r");
 // result is e.g. ^SRADC: 3,8533,2,8000
 /* Locate the first ',' */
 int start = result.indexOf(",");
 /* Locate the second ',' */
 start = result.indexOf(",", start+1);
 int end = result.indexOf(",", start+1);
 String partString = result.substring(start+1, end);

 
 ofs2 = Integer.parseInt(partString);
 
 
 start = end+1;
 end = Utility.findLastDigit(result.substring(start));
 end += start;
 partString = result.substring(start, end);
 
 
 amp2 = Integer.parseInt(partString);
    }catch(ATCommandFailedException atcfe) {
        handleError("Unable to setup pulsecounter - " + atcfe);
    }
    
    while (isRunning) {
        try {
  /* First calculate the amount of pulses received on the pulsecounter.  (To calculate windspeed)*/
  
  //Turn on GPIO 9 to pull up the pulsecounter.
    try {
       
    result = mainCommand.send("AT^SSIO=8,1\r\n");
   
    Thread.sleep(200); // Sleep 10 sec.
    
    
    /* Reset pulsecounter and start counting */
    mainCommand.send("AT^SSCNT=0\r\n");
    
    
    
    mainCommand.send("AT+CFUN=0\r\n"); // Sleep
        Thread.sleep(10000); // Sleep 10 sec.
    mainCommand.send("AT+CFUN=1\r\n");
    /*
     * Now get the amount of pulses. Display the amount of pulses. The result
     * will be received as an ATEvent
     */
    /*result =*/ mainCommand.send("AT^SSCNT=3\r\n");
    
    Thread.sleep(200); // Sleep 10 sec.
    
    result = mainCommand.send("AT^SSIO=8,0\r\n");
    
    
/*
*  Now this is where the ADC reading is done (To read the other sensors, humidity, temperature etc). The ADC2 port is connected to an analogue mux which is controlled by three of the GPIO signals (as seen above)
* when changing the value of the GPIO:s I get the ADC connected to different sensor. */
  
                /* Read from ADC2. This is configured to contain up to 8 sensors */
                System.out.print("Reading sensors: ");
                for(int i = 0; i < sensors.NBR_OF_SENSORS; i++) {
                    if(!selectSensor(mainCommand, sensors)) {
                        handleError("Unable to open sensor port");
                    }
                    try {
Thread.sleep(500); //Just to make sure that the GPIO signals have had time to change and the external circuit is stable
 readDataADC2(mainCommand);
 Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
                    
// Increment sensor index
                    sensors.getNextSensor();
                }
                System.out.println();
                Watchdog.kick();
            }
        } catch (ATCommandFailedException atcfe) {
            handleError("Unable to read data - " + atcfe);
        }
    }
}

  /**
   * Read data from ADC2. Store the value from the read in the sensor associated
   * with the current sensor
   */
  private void readDataADC2(ATCommand command) throws ATCommandFailedException {
      String result, partString;
      int measuredVoltage, actualVoltage, start, end;
      
      
      result = command.send("at^sradc=1\r");
      if(result.indexOf("ERROR") >= 0) {
          return;
      }
      /* result e.g. ^SRADC: 0,1,433 */
      start = result.indexOf(",");
      start = result.indexOf(",", start+1);
      start += 1;
      end = Utility.findLastDigit(result.substring(start));
      end += start;
      partString = result.substring(start, end);
      measuredVoltage = Integer.parseInt(partString);
      /* Value = (<value> from AT^SRADC - <ofs1>) * <amp1> / 4096 */
      actualVoltage = (measuredVoltage - ofs2) * amp2 / 4096;
      System.out.print(actualVoltage + "V ");
      sensorValues.addToSensor(sensors.getCurrentSensor(), actualVoltage);
      
     
  }

Hope this may help somebody, and that somebody may help me too :-)

kind regards
Thomas

Nikita Kapitonov

unread,
Aug 29, 2011, 2:42:28 AM8/29/11
to java...@googlegroups.com
Hello, Thomas!

I also use ADC channels to read voltage, but I'm using TC65i Java interface to get the voltages.

The issue I faced was that - you cannot open both channel at a time. If you need to get values from both channels, you should open one channel, read the value, close the channel, then open other channel, read the value, and so on ... If you open both channels and read values from each channel simultaneously, there will be high level of erronous readings.

As for me, I didn't measured the stability of readings, but to get stable value for sure, I read the values of each channel for 40 seconds, 1 measure per second, then throw away 10 highest and 10 lowest measurements, then get mean value from remaining 20 measurements.

If you have tc65i chip inside, at first you can probably try to use java interface.

If nothing will help you, you can probably try to get mean value, with throwing away some highest and lowest values, like I do.

Best regards,
Nikita

2011/8/29 Thomas Hermansson <thomas.h...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Cinterion Java enabled chips support" group.
To post to this group, send email to java...@googlegroups.com.
To unsubscribe from this group, send email to javacint+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/javacint?hl=en.


Ondřej Janovský

unread,
Aug 29, 2011, 3:43:27 AM8/29/11
to java...@googlegroups.com
Hi Thomas,

I have similar problem. Our devices sometime creates alarm by low
voltage, but batteries are OK.
It can be caused ADC, because this ADC is multiplexed.
Now I am doing simple filter and I am doing discarding extreme values.

I use only AT commands for ADC, IO, SPI, I2C.

Best regards
Ondrej

Dne 08/28/2011 11:45 PM, Thomas Hermansson napsal(a):

Thomas Hermansson

unread,
Sep 5, 2011, 3:11:38 PM9/5/11
to java...@googlegroups.com
Dear Nikita and Ondrej!

Thanks for your replies. I am now quite certain that it must be some problem with the TC65 ADC channels that is causing this problem, as I have spent too much time debugging. :-) And it is interesting to hear that Ondrej has had a similar problem.

So I solved it as you suggest:
a) I will use the periodic reading and get aprox 40 values, discard the 10 extreme values and then get an average which I will use.
b) I will also include a filter to the ADC to prevent that any spike from my external circuit will be causing this. I connected a 5kOhm resistor and then a 10uF condensator which should remove any spikes that I don´t want. I first tried with a 400kOhm resistor, but as the ADC seems to draw some current it resulted in a significant voltage drop which in it´s worst case scenario reached 1V. But with the 5kOhm resistor it is small enough to disregard.

But even with this workaround I sometimes get all the 40 readings (40 readings in 2 seconds) to be really weird. This seems to me as there might be something weird in the ADC converter. As I have now tried with different units, and made several measurements with my Oscilloscope so that I can see that during these missreadings there is nothing wrong with the insignal. :-/

kind regards
Thomas



2011/8/29 Ondřej Janovský <janovsk...@gmail.com>
To unsubscribe from this group, send email to javacint+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/javacint?hl=en.
--
You received this message because you are subscribed to the Google Groups "Cinterion Java enabled chips support" group.
To post to this group, send email to java...@googlegroups.com.
To unsubscribe from this group, send email to javacint+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/javacint?hl=en.


--
vänligen
Thomas Hermansson
TNA Software AB
Jakthornsgränden 22
226 52  Lund
http://www.tna.se
Mobil:0702-313255

Florent Clairambault

unread,
Sep 5, 2011, 4:32:45 PM9/5/11
to java...@googlegroups.com
Hi,

I had some discussions with someone who has a similar problem. I looked at the code his developer made and couldn't find anything wrong. He identified a more precise pattern: The ADC measured value becomes exactly half the value of what it should be. I have to say this seems strange, but maybe he made the wrong assumptions from few sample values.

As pointed out Nikita, the two ADC are actually two inputs switched to the same ADC component. That's why you need to make a pause when you switch from one input to the other. Doing this only reduce the risk of erroneous values, but doesn't eliminate it.

Speaking of potential hardware problems... Did someone encountered issues with the pulse counter?

I'm glad some of you reported this to the javacint group because these issues and their potential solutions needs to be known and documented. Not knowing these issues can make developers lose days of work, project can be delayed by months and people start to lose confidence in their ability to rely on the TC65i for their future products.

Best regards,
--
Florent Clairambault


To unsubscribe from this group, send email to javacint+u...@googlegroups.com.

Thomas Hermansson

unread,
Sep 3, 2012, 8:23:28 AM9/3/12
to java...@googlegroups.com
Thanks Silviu!

It´s always good to know when more people have the same problem. :)

Kind Regard
Thomas

On Tue, Jul 31, 2012 at 9:35 AM, TSilviu <silviu....@gmail.com> wrote:
Hello,

I can confirm the problems with the ADC port. I have a 3.3V rechargeable battery connected to ADC1. Here are the measured values:

timestampvbatt
2012-07-31 10:01:45 1.6494
2012-07-31 09:01:463.33216
2012-07-31 08:01:453.31965
2012-07-31 07:01:463.31965
2012-07-31 06:01:461.65357
2012-07-31 05:01:473.30505
2012-07-31 04:01:463.30922
2012-07-31 03:01:551.64523
2012-07-31 02:01:563.30088
2012-07-31 01:01:513.30088
2012-07-31 00:02:003.29462
2012-07-30 23:01:493.29254
2012-07-30 22:01:503.29462
2012-07-30 21:01:493.27794
2012-07-30 20:01:523.26335
2012-07-30 19:01:563.24666
2012-07-30 18:01:523.22581
2012-07-30 17:01:543.20913
2012-07-30 16:01:523.16951
2012-07-30 15:06:433.06525
2012-07-30 14:03:152.81711
2012-07-30 13:43:272.61693
2012-07-30 13:37:012.37296
2012-07-30 13:35:012.37296
2012-07-30 13:33:392.48348

Silviu

--
You received this message because you are subscribed to the Google Groups "Cinterion Java enabled chips support" group.
To view this discussion on the web visit https://groups.google.com/d/msg/javacint/-/416t-X2EBs4J.
Reply all
Reply to author
Forward
0 new messages