Smartec UTI

Hi!

I need help im trying to read the values from Smartec UTI (http://server3.uswdh.com/~myfavou/intl/docs/dsuti.pdf) with 3 PT1000 connected to it.

The signal from the UTI looks like this:

But the values im getting looks like this:

19856 19857 19876 19881 19860 19893

the code im using for now is:

#include <stdio.h>

#define UTI_PIN 5
#define UTI_RESISTANCE_REF 1000

void setup()
{
  Serial.begin(9600);
  pinMode(UTI_PIN, INPUT);
}

void loop()
{
  int i=0,x=0;
  long total=0;
  int values[12]; 
  while(i<12) {
    values[i]=pulseIn(UTI_PIN,HIGH);
    values[i]+=pulseIn(UTI_PIN,LOW);
    i++;
  }
  
  while(x<12){
    Serial.print(values[x]);
    Serial.print("\t");
    total+=values[x];
    x++;
  }
  Serial.print(" = ");
  Serial.print(total);
  Serial.print("\n"); 
  delay(2000);
}

/PeterT

This is the connections i have made:

Can somebody help me?

did you connect pin 8 to ground?

No isnt pin 8 power supply?

Ok Vss is negative power supply = GND i did not know that, but i get exactly the same values!

http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=268826 this is someone who uses avr tor read the output from UTI

The values should look something like this:

9933 9938 30212 31151 19881

Isnt there anyone who knows what im doing wrong?

Finally got it working :slight_smile:

#include <stdio.h> 
#include "pins_arduino.h" 

#define UTI_PIN 5 
#define UTI_RESISTANCE_REF 1000 

void setup() 
{ 
  Serial.begin(9600); 
  pinMode(UTI_PIN, INPUT); 
} 

void loop() 
{ 
  double res1,res2,res3; 
  
   if(ReadUTI(UTI_PIN,&res1,&res2,&res3,UTI_RESISTANCE_REF)) { 
      Serial.print("Resistance 1: "); 
      Serial.print(res1); 
      Serial.print("\t"); 
      Serial.print("Resistance 2: "); 
      Serial.print(res2); 
      Serial.print("\t"); 
      Serial.print("Resistance 3: "); 
      Serial.print(res3); 
      Serial.print("\t"); 
    } 
    else { 
      Serial.print("Not Found"); 
    } 
    Serial.print("\n"); 
   delay(2000); 
} 

int ReadUTI(uint8_t pin, double * res1,double * res2,double * res3,int refRes) 
{ 
    int state = HIGH; 
    int i,startindex=-1; 
    uint8_t bit = digitalPinToBitMask(pin); 
    uint8_t port = digitalPinToPort(pin); 
    uint8_t stateMask = (state ? bit : 0); 
    unsigned long width[12] = {0,0,0,0,0,0,0,0,0,0,0,0}; 
    double nOff=0,nAB=0,nCD=0,nBC=0,nDF=0; 
        
    while ( (*portInputRegister(port) & bit) != stateMask) 
        ; 
    
    for(i=0;i<12;i++) { 
      while ( (*portInputRegister(port) & bit) == stateMask) 
          width[i]++; 
      while ( (*portInputRegister(port) & bit) != stateMask) 
          width[i]++; 
    } 
    for(i=1;i<12;i++) { 
      if(i<7) { 
        if(width[i]<width[i+2]&&width[i]<width[i+3]&&width[i]<width[i+4]&&width[i]<width[i+5]&&width[i+1]<width[i+2]&&width[i+1]<width[i+3]&&width[i+1]<width[i+4]&&width[i+1]<width[i+5]) { 
          startindex=i; 
          i=12; 
        } 
      } 
    } 
    if(startindex!=-1) { 
      nOff=width[startindex]+width[startindex+1]; 
      nAB=width[startindex+2]; 
      nCD=width[startindex+3]; 
      nBC=width[startindex+4]; 
      nDF=width[startindex+5]; 
      
      *res1=((nBC-nOff)/(nAB-nOff))*refRes; 
      *res2=((nCD-nOff)/(nAB-nOff))*refRes; 
      *res3=((nDF-nOff)/(nAB-nOff))*refRes; 
      
      return 1; 
    } 
    else { 
      return 0; 
    } 
}

Hi PeterT
Can you please comment your code a little bit? I am also interested in using the UTI in my project and I would like to understand your code better...

Why there is a stateMask = (state ? bit : 0)? It is always = bit...

regards

I dont really understand that statemask part myself i saw that in another function and just used it in my code.

int ReadUTI(uint8_t pin, double * res1,double * res2,double * res3,int refRes)
{
    int state = HIGH;
    int i,startindex=-1;
    uint8_t bit = digitalPinToBitMask(pin);
    uint8_t port = digitalPinToPort(pin);
    uint8_t stateMask = (state ? bit : 0); //State HIGH
    unsigned long width[12] = {0,0,0,0,0,0,0,0,0,0,0,0};
    double nOff=0,nAB=0,nCD=0,nBC=0,nDF=0;

    while ( (*portInputRegister(port) & bit) != stateMask) //While state is LOW
        ;

    for(i=0;i<12;i++) { //Count 12 cycles so you are sure you get the whole.
      while ( (*portInputRegister(port) & bit) == stateMask) //Count the HIGH time
          width[i]++;
      while ( (*portInputRegister(port) & bit) != stateMask) //Count the LOW time and add them together
          width[i]++;
    }
    for(i=1;i<12;i++) { //Find the Index for Toff cycle
      if(i<7) {
        if(width[i]<width[i+2]&&width[i]<width[i+3]&&width[i]<width[i+4]&&width[i]<width[i+5]&&width[i+1]<width[i+2]&&width[i+1]<width[i+3]&&width[i+1]<width[i+4]&&width[i+1]<width[i+5]) {
          startindex=i;
          i=12;
        }
      }
    }
    if(startindex!=-1) {
      //Save the cycles (Makes it easier to know what you are calculating
      nOff=width[startindex]+width[startindex+1];
      nAB=width[startindex+2];
      nCD=width[startindex+3];
      nBC=width[startindex+4];
      nDF=width[startindex+5];

      //Do the calculations according to the UTI manual.
      *res1=((nBC-nOff)/(nAB-nOff))*refRes;
      *res2=((nCD-nOff)/(nAB-nOff))*refRes;
      *res3=((nDF-nOff)/(nAB-nOff))*refRes;

      return 1; //Return 1 if the cycles where found
    }
    else {
      return 0;
    }
}

Thank you!