MCP4728 synchronous Update

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
RoSch99
 
Posts: 7
Joined: Sun Jan 29, 2023 4:07 pm

MCP4728 synchronous Update

Post by RoSch99 »

Hello out there,
we are using a MCP4728 DAC to control galvo mirrors for a laser project.
The galvo mirrors are quite fast (20Kpps), so if we update the x and y channel asynchronously,
as described in the examples, the laser does not follow a straight line to the next point,
but first in y direction and only then in x direction.

Code: Select all

mcp4728.channel_a.value = int(mirror_pos[1]) #vertical movement, top = 65535 and bottom = 0
mcp4728.channel_b.value = int(mirror_pos[0]) #horizontal movement, left = 0 and right = 65535
So we assume, we have to update both channels at the same time.
"MCP4728.soft_update()" seems to do this job, but we could not find out how to use it properly.
https://docs.circuitpython.org/projects ... oft_update

Code: Select all

mCP4728.soft_update()
mcp4728.channel_a.value = int(mirror_pos[1]) #vertical movement, top = 65535 and bottom = 0
mcp4728.channel_b.value = int(mirror_pos[0]) #horizontal movement, left = 0 and right = 65535
How is soft_update() used, are there any examples or docs?
Any other hints how we should proceed?

thanks for any help!

User avatar
RoSch99
 
Posts: 7
Joined: Sun Jan 29, 2023 4:07 pm

Re: MCP4728 synchronous Update

Post by RoSch99 »

Since we did not find any code snippet or even info about the "soft_update" feature
we created are quick test to try the hardware variant via the LDAC pin.
Unfortunately we had no luck, this does not seem to work either. :-(

Code: Select all

# Test MPC4728 Quad-DAC synchronous update via LDAC pin
import time
from time import sleep
import board
import adafruit_mcp4728
from digitalio import DigitalInOut, Direction, Pull

MCP4728A4_DEFAULT_ADDRESS = 0x64

i2c = board.I2C()  # uses board.SCL and board.SDA
#  use for MCP4728A4 variant
mcp4728 = adafruit_mcp4728.MCP4728(i2c, adafruit_mcp4728.MCP4728A4_DEFAULT_ADDRESS)

LDAC = DigitalInOut(board.D5)  # set LDAC Pin to D5
LDAC.direction = Direction.OUTPUT 
#LDAC.pull = Pull.UP # does not work --> "Error: Pull not used when direction is output."
LDAC.value = True

# https://learn.adafruit.com/adafruit-mcp4728-i2c-quad-dac/python-circuitpython
# set Channel A and B to INTERNAL Vref (0V to 2,048V) or VDD (0V to VDD =5V)
mcp4728.channel_a.vref = adafruit_mcp4728.Vref.VDD
mcp4728.channel_b.vref = adafruit_mcp4728.Vref.VDD
#mcp4728.channel_a.vref = adafruit_mcp4728.Vref.INTERNAL
#mcp4728.channel_b.vref = adafruit_mcp4728.Vref.INTERNAL

# set Channel A and B gain=2 (0V to 4,096V) <- only working when using internal VRef
#mcp4728.channel_a.gain = 2
#mcp4728.channel_b.gain = 2

# optional save settings to eeprom
#mcp4728.save_settings()

while True:
    LDAC.value = True # Update VA and VB should be latched
    mcp4728.channel_a.value = 0
    mcp4728.channel_b.value = 0
    LDAC.value = False # Update VA and VB enabled
#    print ("bottom left position \n")
    sleep (0.005)
    mcp4728.channel_a.value = 65535
    mcp4728.channel_b.value = 65535
#    print ("top right position \n")
    sleep (0.005)
Output VA (yellow) and VB (blue)
Output VA (yellow) and VB (blue)
Ch1-VA__Ch2-VB.png (37.56 KiB) Viewed 132 times
VB is about 660usec behind VA at the rising and falling slope, where the falling slope should be synchronous.
So, there is no difference wether LDAC pin is HIGH or LOW.


Output VA (yellow) and LDAC (blue)
Output VA (yellow) and LDAC (blue)
Ch1-VA__Ch2-LDAC.png (39.01 KiB) Viewed 132 times
VA is updated immediately and does not follow the LDAC pin.


Has anyone tested/used the LDAC synchronous update successfully, are we something missing?

thanks in advance for your time
RS

User avatar
adafruit_support_carter
 
Posts: 29056
Joined: Tue Nov 29, 2016 2:45 pm

Re: MCP4728 synchronous Update

Post by adafruit_support_carter »


User avatar
RoSch99
 
Posts: 7
Joined: Sun Jan 29, 2023 4:07 pm

Re: MCP4728 synchronous Update

Post by RoSch99 »

Thank you for submitting a request to get a software solution, probably via the "soft_update" function!

However, according to our findings, there also seems to be a hardware problem.
As can be seen in the screenshots, the state of the LDAC pin is simply ignored.
Regardless of whether the pin is TRUE or FALSE, the outputs are updated immediately.
We have tested this with two different MCP4728 ( https://www.adafruit.com/product/4470 ) boards.

regards
RoSch

User avatar
RoSch99
 
Posts: 7
Joined: Sun Jan 29, 2023 4:07 pm

Re: MCP4728 synchronous Update

Post by RoSch99 »

Finally, we have a solution via the LDAC pin.
In short, the CircuitPython library (and also the Arduino library) clears the UDAC bit (0)
on every write command and, interestingly, this takes precedence over the LDAC hardware pin.

More can be found at:
viewtopic.php?p=962892#p962892

RoSch99

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”