02-23-2014 03:13 AM
Hey sorry for the delay in the kode and translation.
Has been a lot of work for a while now, but now I'll grab this.
It is Temp1 and Temp2 value I want into Labveiw.
#include <stdio.h>
#include "pins_arduino.h"
#include "TimerOne.h" //TimerOne er for pin 9 og 10 SSR
#include <string.h> /* Inkludera memset */
#define UTI_PIN 5
#define UTI_RESISTANCE_REF 100 // denne er 100 hvis du har pt100 og 1000 hvis du har pt1000
double Temp1;
double Temp2;
double temp1Korreksjon = -6.5; // correction sensor1
double temp2Korreksjon = 0; // correction sensor2
double pumpetemp;
const unsigned int NofSamples = 200;
unsigned long milli, oldmilli;
static double doseringsPumpeTemp1Array[NofSamples];
static double magnetVentilTemp1Array[NofSamples];
static unsigned int NextSampleIndex = 0;
void setup()
{
Serial.begin(9600);
pinMode(UTI_PIN, INPUT);
Timer1.initialize(1000000); // initialize timer1, and set a 1 second period
oldmilli = millis();
}
void loop()
{
double res1,res2,res3; // denne kan bare stå sånt i tilfelle du vil ha 3 pt100 senere
// Moving average:
/* Add a new value and move the pointer one step foreward for your next test */
ReadUTI(UTI_PIN,&res1,&res2,&res3,UTI_RESISTANCE_REF);
doseringsPumpeTemp1Array[NextSampleIndex] = GetPlatinumRTD(res1,100)+ temp1Korreksjon;
magnetVentilTemp1Array[NextSampleIndex] = GetPlatinumRTD(res2,100)+temp2Korreksjon;
NextSampleIndex = (NextSampleIndex == NofSamples - 1) ? 0 : NextSampleIndex + 1;
/* Calculate the average of the values in the arrays */
Temp1 = 0.00;
Temp2 = 0.00;
for (int j=0; j < NofSamples; j++)
{
Temp1 += doseringsPumpeTemp1Array
Temp2 += magnetVentilTemp1Array
} /* for j */
Temp1 /= (double)NofSamples;
Temp2 /= (double)NofSamples;
pumpetemp = Temp1;
/* this is for data sent on the most favorable time */
/* timer loop sees that it will only be sent information on a certain interval */
milli = millis();
if (milli > oldmilli + 50) // 500 is 1/2 sec delay between data packets
{
Serial.print("Medel temp1 ");
Serial.println(Temp1); //mottar "d"
Serial.print(" ");
Serial.print(" Medel temp2 ");
Serial.print(Temp2); //mottar "f"
Serial.print(" ");
oldmilli = milli;
}
}//END LOOP
// read Pt100 from UTI chip
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};
for(i=0;i<12;i++) {
while ( (*portInputRegister(port) & bit) == stateMask)
width++;
while ( (*portInputRegister(port) & bit) != stateMask)
width++;
}
for(i=1;i<12;i++) {
if(i<7) {
if(width<width[i+2]&&width<width[i+3]&&width<width[i+4]&&width<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;
}
Sorry but the code is not integrated with Lifa right now
Michael