Go Down

Topic: Voltage Erratic behavior (Read 892 times) previous topic - next topic

ksp1717

#10
Mar 20, 2012, 11:34 pm Last Edit: Mar 23, 2012, 12:43 am by ksp1717 Reason: 1
i have run the following code on just the D/A converter and the output of it is ~3V no matter which conversion I use.

Code: [Select]
byte Program = 64;
byte Device = 96; // This hardwired into the IC and the BoB, in other words, it is a given.

int maxValue = 4095;
int minValue = 0;
int value = 4092;
int dir = 250;

#include <Wire.h>

void setup()
{
 Wire.begin();
 Serial.begin(9600);
}

void loop()
{
//  byte b1 = value >> 4;
//  byte b2 = (value & 15)<< 4;
//  byte b1 = byte(value/16);
//  byte b2 = byte((value % 16) << 4);

 byte b1 = byte(value/10);
 byte b2 = byte(value % 10);
 
 Wire.beginTransmission(Device);
 Wire.write(Program);
 Wire.write(b1);
 Wire.write(b2); // Needed twice, since the 4 lowest bits (of 12) are in the fourth byte
 Wire.endTransmission();
 Serial.print(value);Serial.print("\t");Serial.print(b1);Serial.print("\t");
 Serial.print(b2);Serial.print("\n");
//  value = value + dir;
 if(value > maxValue) dir = -250;
 if(value <= minValue) dir = 250;

 delay(3000);
}

Magician

Code: [Select]
  byte b1 = byte(value/10);
  byte b2 = byte(value % 10);


There are  commands to get HighByte LowByte from the int.
http://arduino.cc/en/Reference/HomePage

MarkT

Can I just re-state that the 741 is not guaranteed to work at all with the inputs/outputs within 3V of a supply rail (make that 4V if the outputs are loaded by lower than 10k impedance).  Its a very poor choice of opamp with rail-to-rail 5V-compatible ones abound these days.
[ I won't respond to messages, use the forum please ]

ksp1717

#13
Mar 23, 2012, 12:42 am Last Edit: Mar 23, 2012, 12:44 am by ksp1717 Reason: 1
@MarkT
This program worked and the problem was the device address. Once I have put in the address it the D/A converter was working good. But as you have said I think the OPAMP is causing problems. I should change it in the next iteration.
Can you suggest a replacement for the 741 opamp.
I will post the output I am currently receiving in the next post.
Code: [Select]

byte Program = 64;
byte Device = 100;
int maxValue = 4075;
int minValue = 0;
int value = 4075;
int dir = -250;

#include <Wire.h>
void setup()
{
 Wire.begin();
 Serial.begin(9600);
}
void loop()
{
 byte b1 = value >> 4;
 byte b2 = (value & 15)<< 4;
 Wire.beginTransmission(Device);
 Wire.write(Program);
 Wire.write(b1);
 Wire.write(b2); // Needed twice, since the 4 lowest bits (of 12) are in the fourth byte
 Wire.endTransmission();
 Serial.print(value);Serial.print("\t");Serial.print(b1);Serial.print("\t");
 Serial.print(b2);Serial.print("\n");
 value = value + dir;
 if(value >= maxValue) dir = -250;
 if(value <= minValue) dir = 250;
 delay(1000);
}


Thanks
Shyam

Go Up