Resistor divider doubt


hello barcelona

in company have dinamometer measure load of compression springs produce.

it can measure forces form 0g 5000g , works 2 scales. first scale can measure 0g 500g 0,5g steps , second scale let's measure 5000g 5g steps.

the first scale fine our porposes second 1 not accurated need.
we have notice machine has 2 outputs can voltage increases compressing springs:







on each scale max value can in segment's light screen is


when reach value have pass second scale if @ first 1 , stop compressing spring if in second one. if keep compressing spring higher values voltimeter while dinamometer screen freezed:


so wanted create voltimeter using 1 arduino uno able measure voltage changing int second scale , determinate load of springs same precision loads bigger 500g.

as uno able give 1024 steps of resolution using analog inputs found on ebay 24bits adc module give 6 decimal places values:

http://cgi.ebay.es/ws/ebayisapi.dll?viewitem&item=111005456125&frommaketrack=true&sspagename=vip:watchlink:top:es



one of thing of module can 17v inputs, had not afraid using resistors protect our arduino. allow 17v measures have shorter jumper. our dinamometer can output 15,6 volts when blocking against load cell.

with module comes sketch:
code: [select]
//ltc2400 24bit adc module
//
//application demo: 7 digit voltmeter
//24bit adc ic: ltc2400
//4.096 precision reference: ti ref3040
//by coldtears electronics
//ltc2400 code adapted martin nawrath
//kunsthochschule fuer medien koeln
//academy of media arts cologne
//
#include <stdio.h>
#include<stdlib.h>
#ifndef cbi
#define cbi(sfr, bit)     (_sfr_byte(sfr) &= ~_bv(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit)     (_sfr_byte(sfr) |= _bv(bit))
#endif

#define ltc_cs 2         // ltc2400 chip select pin  on portb 2
#define ltc_miso  4      // ltc2400 sdo select pin  on portb 4
#define ltc_sck  5       // ltc2400 sck select pin  on portb 5


void setup() {

cbi(portb,ltc_sck);      // ltc2400 sck low
sbi (ddrb,ltc_cs);       // ltc2400 cs high

cbi (ddrb,ltc_miso);
sbi (ddrb,ltc_sck);

serial.begin(38400);

// init spi hardware
sbi(spcr,mstr) ; // spi master mode
sbi(spcr,spr0) ; // spi speed
sbi(spcr,spr1);  // spi speed
sbi(spcr,spe);   //spi enable

}
float volt;
float v_ref=4.094;          // voltaje de referencia. viene indicado por un chip que lleva la plaquita que siempre devuelve 4.094v
         
long int ltw = 0;         // adc data ling int
int cnt;                  // counter
byte b0;                  //
byte sig;                 // sign bit flag
char st1[20];             // float voltage text
/****************/
void loop() {

cbi(portb,ltc_cs);             // ltc2400 cs low
delaymicroseconds(1);
if (!(pinb & (1 << 4))) {    // adc converter ready ?
  //    cli();
  ltw=0;
  sig=0;

  b0 = spi_read();             // read 4 bytes adc raw data spi
  if ((b0 & 0x20) ==0) sig=1;  // input negative ?
  b0 &=0x1f;                   // discard bit 25..31
  ltw |= b0;
  ltw <<= 8;
  b0 = spi_read();
  ltw |= b0;
  ltw <<= 8;
  b0 = spi_read();
  ltw |= b0;
  ltw <<= 8;
  b0 = spi_read();
  ltw |= b0;

  delaymicroseconds(1);

  sbi(portb,ltc_cs);           // ltc2400 cs low

  if (sig) ltw |= 0xf0000000;    // if input negative insert sign bit
  ltw=ltw/16;                    // scale result down , last 4 bits have no information
  volt = ltw * v_ref / 16777216; // max scale
  char tmp[10];
  dtostrf(volt,6,6,tmp);
  tmp[8]='v';
  tmp[9]='\n';
 printfloat(volt,6);           // print voltage floating number
 serial.println("  ");

 
}
sbi(portb,ltc_cs); // ltc2400 cs hi
delay(20);

}
/********************************************************************/
byte spi_read()
{
spdr = 0;
while (!(spsr & (1 << spif))) ; /* wait spi shift out done */
return spdr;
}
/********/
//  printfloat  tim / arduino: playground
// printfloat prints out float 'value' rounded 'places' places
//after decimal point
void printfloat(float value, int places) {
// used cast digits
int digit;
float tens = 0.1;
int tenscount = 0;
int i;
float tempfloat = value;

// if value negative, set tempfloat abs value

  // make sure round properly. use pow from
//<math.h>, doesn't seem worth import
// if rounding step isn't here, value  54.321 prints as

// calculate rounding term d:   0.5/pow(10,places)
float d = 0.5;
if (value < 0)
  d *= -1.0;
// divide ten each decimal place
(i = 0; < places; i++)
  d/= 10.0;
// small addition, combined truncation round our

tempfloat +=  d;

if (value < 0)
  tempfloat *= -1.0;
while ((tens * 10.0) <= tempfloat) {
  tens *= 10.0;
  tenscount += 1;
}

// write out negative if needed
if (value < 0)
  serial.print('-');

if (tenscount == 0)
  serial.print(0, dec);

(i=0; i< tenscount; i++) {
  digit = (int) (tempfloat/tens);
  serial.print(digit, dec);
  tempfloat = tempfloat - ((float)digit * tens);
  tens /= 10.0;
}

// if no places after decimal, stop , return
if (places <= 0)
  return;

// otherwise, write point , continue on
serial.print(',');

(i = 0; < places; i++) {
  tempfloat *= 10.0;
  digit = (int) tempfloat;
  serial.print(digit,dec);
  // once written, subtract off digit
  tempfloat = tempfloat - (float) digit;
}
}


our problem when try read vin2 (the pin allows 17v) not realistic data
(for example, 1,2 volts rechargeable battery gives 0,30567v , when trying on vin1 1,31677v.)

with module there pdf explaining when allow vin2 shortening jumper value of voltage (up 17v) obtained doing resistor divider opertion, haven't seen of in code provided (i'm total newbie arduino, i'm going send data via serial port work program writted in autoit, wich i'm not newbie)

the pdf comes board claims:
quote
if input source connect voltage_in2, measured voltage
multiplied value of resistor divider ( around (33k+10k)/10k)


and there electrical schematic:


but don't have idea of how resistor division inside code
i have tried contact seller of board no results.

any kind of trully apreciatted.

greets barcelona

divide result of vin2 reading 4.3 ?


Arduino Forum > Using Arduino > Programming Questions > Resistor divider doubt


arduino








Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support