Pages: [1]   Go Down
Author Topic: Smartec UTI  (Read 3027 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

Code:
#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
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is the connections i have made:



Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can somebody help me?
Logged

United States (Texas)
Offline Offline
God Member
*****
Karma: 3
Posts: 525
Arduino socks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

did you connect pin 8 to ground?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No isnt pin 8 power supply?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The values should look something like this:

Code:
9933 9938 30212 31151 19881
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Isnt there anyone who knows what im doing wrong?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Finally got it working smiley



Code:
#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;
    }
}
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I dont really understand that statemask part myself i saw that in another function and just used it in my code.
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;
    }
}
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you!
Logged

Pages: [1]   Go Up
Jump to: