DAC121C085 && Odroid C2 Problem
07/06/2019
Posted by:
DmitryK
I have some problem with DAC121C085 Odroid C2 controlling.
I control two DAC's with using I2C bus (DAC1 slave addr = 0x48, DAC2 slave addr = 0x4e).
There is Python source code below. I use Smbus-library, for the generating onepolar-SIN analog sygnal on the DAC output pin (pin 6 of DAC121C085).
Analog sygnal, wich corresponded to this situation is represented in Fig.1.
When I changing row DAC1_sin_val=DAC_value_array[Time_count]
on DAC1_sin_val=DAC_value_array[Time_count]/4, I get analog sygnal wich is represented in Fig.2.
In the second case the volue of DAC's digital input sygnal are less then 256, and corresponds to the one-byte digital sygnal.
Thus, when I write one byte -signal in DAC I have success - I generate correct analog sygnal (one-polar SIN). But when I use more than one-byte input digital sygnal - I generate incorrect analog sygnal
So, it seems like I incorrect use bus1.write_word_data() - istruction.
What is the problem? How can I correct use bus1.write_word_data() - istruction?
Thanks
Fig_1 => https://cdn1.imggmi.com/uploads/2019/6/10/b0c65d6deee51a50551a29084e682269-full.jpg
Fig_2 => https://cdn1.imggmi.com/uploads/2019/6/10/9a69f5bfdd6b5a352dec2279a54852ae-full.jpg
#!/usr/bin/env python
import numpy as np
import cv2
import smbus
import time
def nothing(x):
pass
DAC1_value=0
K_calib_adc=1.0
DAC_value_array = [ 19, 36, 55, 72, 91, 108, 125, 144, 161, 179,
196, 213, 231, 248, 266, 283, 301, 318, 334, 352,
368, 384, 401, 417, 434, 450, 465, 482, 497, 512,
529, 543, 559, 574, 588, 603, 617, 631, 646, 659,
673, 687, 699, 712, 725, 738, 750, 762, 774, 786,
797, 808, 819, 830, 840, 850, 860, 870, 879, 888,
896, 905, 914, 921, 929, 936, 944, 951, 957, 963,
969, 975, 980, 986, 990, 995, 999, 1003, 1006, 1009,
1012, 1015, 1017, 1019, 1021, 1022, 1023, 1023, 1023, 1023,
1023, 1023, 1022, 1021, 1020, 1019, 1017, 1015, 1012, 1009,
1006, 1003, 999, 995, 990, 986, 980, 975, 969, 963,
957, 951, 944, 936, 929, 921, 914, 905, 896, 888,
879, 870, 860, 850, 840, 830, 819, 808, 797, 786,
774, 762, 750, 738, 725, 712, 699, 687, 673, 659,
646, 631, 617, 603, 588, 574, 559, 543, 529, 512,
497, 482, 465, 450, 434, 417, 401, 384, 368, 352,
334, 318, 301, 283, 266, 248, 231, 213, 196, 179,
161, 144, 125, 108, 91, 72, 55, 36, 19, 2 ]
#------Peremennie--------------
Time_count = 1
DAC_arr_index = 0
#------------------------------
cv2.namedWindow('frame', cv2.WINDOW_OPENGL)
# create trackbars for PWM
cv2.createTrackbar('DAC_man','frame',0,50,nothing)
cap = cv2.VideoCapture(0)
#---------------I2C_debug-------------
bus1 = smbus.SMBus(1)
DAC1_i2c_addr = 0x48 #Motor driver_DAC1 slave addr
DAC2_i2c_addr = 0x4e #Motor driver_DAC2 slave addr
#-------------------------------
while(True):
Time_count = Time_count + 1
#------DAC_setting----------
DAC1_manual_value= cv2.getTrackbarPos('DAC_man','frame')
DAC1_sin_val=DAC_value_array[Time_count]
bus1.write_word_data(DAC1_i2c_addr, 0x00, DAC1_sin_val)
bus1.write_word_data(DAC2_i2c_addr, 0x00, DAC1_sin_val)
#---------------------------------------
# Capture frame-by-frame
__, frame = cap.read()
#----------Result_showing-------
cv2.putText(frame, "DAC_1",(10,30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 1)
cv2.putText(frame, "{:.0f}".format(DAC1_sin_val),(170,30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 1)
if (Time_count == 179) :
Time_count = 1
##------------------------------
cv2.imshow('frame',frame)
k = cv2.waitKey(5) & 0xFF
if k == 27:
break
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
24/06/2019
Posted by:
DmitryK
I solved my probleb. There is right code below.
#!/usr/bin/env python
import numpy as np
import cv2
from smbus2 import SMBus, i2c_msg
import time
import threading
Time_counter = 0
DAC1_value=0
K_calib_adc=1.0
DAC_value_array = [ 19, 36, 55, 72, 91, 108, 125, 144, 161, 179,
196, 213, 231, 248, 266, 283, 301, 318, 334, 352,
368, 384, 401, 417, 434, 450, 465, 482, 497, 512,
529, 543, 559, 574, 588, 603, 617, 631, 646, 659,
673, 687, 699, 712, 725, 738, 750, 762, 774, 786,
797, 808, 819, 830, 840, 850, 860, 870, 879, 888,
896, 905, 914, 921, 929, 936, 944, 951, 957, 963,
969, 975, 980, 986, 990, 995, 999, 1003, 1006, 1009,
1012, 1015, 1017, 1019, 1021, 1022, 1023, 1023, 1023, 1023,
1023, 1023, 1022, 1021, 1020, 1019, 1017, 1015, 1012, 1009,
1006, 1003, 999, 995, 990, 986, 980, 975, 969, 963,
957, 951, 944, 936, 929, 921, 914, 905, 896, 888,
879, 870, 860, 850, 840, 830, 819, 808, 797, 786,
774, 762, 750, 738, 725, 712, 699, 687, 673, 659,
646, 631, 617, 603, 588, 574, 559, 543, 529, 512,
497, 482, 465, 450, 434, 417, 401, 384, 368, 352,
334, 318, 301, 283, 266, 248, 231, 213, 196, 179,
161, 144, 125, 108, 91, 72, 55, 36, 19, 2,
19, 36, 55, 72, 91, 108, 125, 144, 161, 179,
196, 213, 231, 248, 266, 283, 301, 318, 334, 352,
368, 384, 401, 417, 434, 450, 465, 482, 497, 512,
529, 543, 559, 574, 588, 603, 617, 631, 646, 659,
673, 687, 699, 712, 725, 738, 750, 762, 774, 786,
797, 808, 819, 830, 840, 850, 860, 870, 879, 888,
896, 905, 914, 921, 929, 936, 944, 951, 957, 963,
969, 975, 980, 986, 990, 995, 999, 1003, 1006, 1009,
1012, 1015, 1017, 1019, 1021, 1022, 1023, 1023, 1023, 1023]
#-----Procedures----------------
def nothing(x):
pass
def time_coun():
global Time_counter
threading.Timer(0.005, time_coun).start()
Time_counter = Time_counter + 1
if (Time_counter == 90) :
Time_counter = 1
#------DAC_setting----------
DAC1_manual_value= cv2.getTrackbarPos('DAC_man','frame')
DAC1_sin_val=DAC_value_array[Time_counter*2]
DAC2_sin_val=DAC_value_array[Time_counter*2+90]
val=DAC1_sin_val*DAC1_manual_value
bus1.write_byte_data(DAC1_i2c_addr, val>>8, val&0xff,force=False)
val=DAC2_sin_val*DAC1_manual_value
bus1.write_byte_data(DAC2_i2c_addr, val>>8, val&0xff,force=False)
#---------------------------------------
#------Peremennie--------------------------------
DAC1_arr_index = 1
DAC2_arr_index = 1
#---------------I2C_debug------------------------
#bus1 = smbus.SMBus(1)
bus1 = SMBus(1)
DAC1_i2c_addr = 0x09 #Motor driver_DAC1 slave addr
DAC2_i2c_addr = 0x4e #Motor driver_DAC2 slave addr
#----Creating new window and trackbar for PWM------
cv2.namedWindow('frame', cv2.WINDOW_OPENGL)
cv2.createTrackbar('DAC_man','frame',0,4,nothing)
cap = cv2.VideoCapture(0)
#--------------------------------------------------
time_coun()
while(True):
# Capture frame-by-frame
__, frame = cap.read()
#----------Result_showing-------
cv2.putText(frame, "DAC_1",(10,30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 1)
cv2.putText(frame, "{:.0f}".format(Time_counter),(170,30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 1)
##------------------------------
cv2.imshow('frame',frame)
k = cv2.waitKey(5) & 0xFF
if k == 27:
break
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
Forum Notice – Closure to New Posts
As part of our compliance with the UK’s Online Safety Act, the AB Electronics UK support forum is now closed to new posts and replies.
We understand the importance of continued support for our products, so if you have a technical query or require assistance, please use the Contact Form or consult our Knowledge Base for helpful articles and documentation.
We appreciate your understanding and continued support.
Note: documents in Portable Document Format (PDF) require Adobe Acrobat Reader 5.0 or higher to view.
Download Adobe Acrobat Reader or other PDF reading software for your computer or mobile device.