arduino-uno


DAC0808 doesn't want tranfer to analog


my lecture gave us DAC lab. He asks to make a sawtooth waveform in 8 bit from Arduino and then connect it DAC0808 to produce an analog signal with an amplifier. So we made an a circuit. Checked it. It works. Then started to do the calculations and expected results. We have done that. And the last we make a program in the wiring language. I wanted to make a step further and made a program which accepts different inputs from serial and changes the types of waveforms. But when we tried to check the working circuit for somereason it didn't want to work. I checked the program on 8 LEDS and they all workign perfect. But we put i ht ecircuit and check on osciliscope it shows 9.7 volts when it should have 0 or 5 volts. The bits still went to DAC inputs but DAC didn't translate them to analog output.
The lecturer sure the problem is in my complex problem rather then in my circuit or maybe with my processor, but I noticed very strange voltage output. When I touch the HIGH input voltage on DAC by multimeter it gives that value out. He still thinks it's problem with the code because his simple version works. :c
So if it is I want to know where?
Or why i doesn't?
The code:
//Global Variables
enum wave {SAWTOOTH = 49, TRIANGLE, SQUARE, SINE, TANGENT};
int incomingByte;
int lastState = 0;
int calcResult;
int binaryOutput;
int triangleCheck;
int squareCheck;
int squareCount;
int sineOutput;
int tangentOutput;
int pin[8];
//Prototypes
int bitConversion(int);
//Setup
void setup() {
Serial.begin(250000);
for (int i = 2; i < 10; i++)
{
pinMode(i, OUTPUT);
pin[i - 2] = i;
}
}
void loop() {
if (Serial.available())
incomingByte = (int)Serial.read();
Serial.print("Incoming Byte: ");
Serial.write(incomingByte);
Serial.println();
Serial.print("Last State: ");
Serial.write(lastState);
Serial.println();
if (incomingByte != lastState)
{
lastState = incomingByte;
calcResult = 0;
triangleCheck = 0;
squareCheck = 0;
squareCount = 0;
sineOutput = 0;
tangentOutput = 0;
Serial.println("State changed!");
}
Serial.print("STATE: ");
switch (lastState)
{
case (SAWTOOTH):
Serial.println("SAWTOOTH WAVE");
Serial.println("------------------------------------------");
if (calcResult == 255)
calcResult = 0;
calcResult++;
break;
case (TRIANGLE):
Serial.println("TRIANGLE WAVE");
Serial.println("------------------------------------------");
if (calcResult == 255 || !calcResult)
{
Serial.println("Triangle changed!");
Serial.println();
triangleCheck++;
}
if ((triangleCheck % 2))
{
Serial.print("ODD ");
calcResult++;
}
else
{
Serial.print("EVEN ");
calcResult--;
}
break;
case (SQUARE):
Serial.println("SQUARE WAVE");
Serial.println("------------------------------------------");
if (squareCount == 255 || squareCount == 0)
{
Serial.println("Square changed!");
Serial.println();
squareCheck++;
}
if ((squareCheck % 2))
{
Serial.print("ODD ");
calcResult = 0;
squareCount++;
}
else
{
Serial.print("EVEN ");
calcResult = 255;
squareCount--;
}
break;
case (SINE):
Serial.println("SINE WAVE");
Serial.println("------------------------------------------");
calcResult = 128+128*sin(2*PI*100*(sineOutput/10000.0));
sineOutput++;
break;
case(TANGENT):
Serial.println("TANGENT WAVE");
Serial.println("------------------------------------------");
calcResult = 128+64*tan(2*PI*100*(tangentOutput/10000.0));
tangentOutput++;
break;
default:
Serial.println("DEFAULT");
Serial.println("------------------------------------------");
calcResult = 0;
break;
}
binaryOutput=calcResult;
Serial.print("Binary Output: ");
Serial.println(binaryOutput, DEC);
if (binaryOutput)
{
for (int i = 7; i >= 0; i--)
{
if (binaryOutput >= bitConversion(i))
{
digitalWrite(pin[i], HIGH);
binaryOutput -= bitConversion(i);
Serial.print(1);
Serial.print(" ");
}
else
{
digitalWrite(pin[i], LOW);
Serial.print(0);
Serial.print(" ");
}
}
}
else
{
for (int i = 7; i >= 0; i--)
{
pinMode(pin[i], LOW);
Serial.print(0);
Serial.print(" ");
}
}
Serial.println("\n\n");
delay(50);
}
int bitConversion(int n)
{
int result = 1;
for (int i = 0; i<n; i++)
result *= 2;
return result;
}
Some things about your project
For a wave generator it's not a good idea to generate the signal in the main loop. The right way to do it is using timers and counters (and interruptions if it's necessary). This is because in a digital signal generator is important the sample frequency and the wave frequency, and generating the wave in the main loop could make delays that alters the frequency. Using counters you could also control the frequency of your output signal.
By the way, you can do this the way you're doing it but as I say, it has its limitations.
Because you are using 8 bits for the output and it is represented with the calcResult variable, maybe you can consider making it a byte or an unsigned char (both are basically the same).
In the calcResult calculation for the sine wave, it says calcResult = 128+128*sin(2*PI*100*(sineOutput/10000.0)) but it should be calcResult = 128+127*sin(2*PI*100*(sineOutput/10000.0)) because other way you will have calcResult=256 some times.
The variable triangleCheck is always increasing, this will cause you overflow. Although this could also give you the right behavior, it's a better way to use a boolean or a char taking 0 and 1 values. This also happens with squareCheck.
It seems that you are printing the text about the incomingByte all the main loop's iterations, I think this could be annoying (and also takes processing capacity).
Take a look at the tangent wave, there is the same problem with the overflow that I've mentioned in the sine wave. You should use the periodicity of the signals to do this. You should also consider that the tangent is an unbounded function so it will have lot of values over the 255 that your DAC accepts.
For the bit conversions you do in the final part, maybe you can do it with bit masks. This would be cleaner and easier to handle.
If you're not sure about your DAC, you could test it using a dip switch. Or if you have the possibility, use a signal generator, then an ADC, then your DAC and finally the oscilloscope. This way you'll be 100% that your DAC is working.
Have you tested your Arduino's outputs? You can connect leds with a resistance to your output pins and with the square signal you should see some pretty clear behavior.
For sin wave and tangent wave I suggest to take a look at the casting of the variable (float to int). Maybe there's no issue about how it's done, but is good to be sure about the information that you're handling.
Hope this can help you with your project a little at least.
Greetings!

Related Links

arduino uno R3 input pins with gsm shield
Light weight machine to machine communication with Arduino
Interfacing RM5 evolution coin acceptor with arduino
Arduino-ESP8266 Sending URL from a client browser connected to the esp8266 AP and receiving the entered URL in the arduino board
Need explanations about a code relative to MPU6050
Arduino Programmer only works after unlugging and plugging back in
How do I communicate between Arduino board and Intel Edison Arduino board using XBee S2?
I cannot solve my arduino program error
2.4 inch TFT LCD SPFD5408 with Arduino Uno - touch not working
DAC0808 doesn't want tranfer to analog
Trouble in programming arduino with esp8266
How to control a servo motor with Windows Remote Arduino?
Set baud rate to esp8266 at 9600
Arduino AC Dimmer - serial communication lost due to interrupt
connection error with arduino etherent shield and apache localhost
Arduino, johnny-five, can it work without connected computer?

Categories

HOME
java
pdf
jdo
amazon-ec2
omnet++
nullpointerexception
react-virtualized
view
objectgears
programming-languages
rdf
windows-server
django-imagekit
tostring
jsdoc
footer
aurigma
apache-metamodel
reactive-cocoa
database-replication
language-agnostic
php-openssl
restful-authentication
hammerspoon
trading
firebase-crash-reporting
sqlcipher
spring-mybatis
opentype
log4js-node
oracle-fusion-middleware
grails-3.1
webtest
picasso
host
libraries
streamsets
objectlistview
ibpy
import-from-excel
long-polling
ionicons
veracode
mu
knpmenubundle
qtwebview
akka-cluster
pillow
sqldf
webdriverjs
specrun
objective-c-swift-bridge
parallel-data-warehouse
multi-level
pcf
merge-conflict-resolution
paypal-express
php-parse-error
associative-array
netmq
kendonumerictextbox
t4mvc
cannon.js
django-unittest
drawbitmap
operation
vstest.console.exe
processmodel
bigbluebutton
android-imagebutton
markers
valuechangelistener
datagridviewcolumn
mbr
tidy
blending
soundtouch
xamlparseexception
itmstransporter
anonymous-methods
dmoz
jquery-knob
libstdc++
funscript
javaspaces
hgsubversion
hirefire
mod-auth
tomcat-valve
calling-convention
disclosure
gamequery
dmx512
preference
avatar
xetex
spec#
wsdl.exe

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App