Fix adc and dac initialization #55

Merged
sb10q merged 1 commits from fsagbuya/nix-servo:adc_dac into master 2024-06-11 13:59:38 +08:00
Collaborator

Description

Fix the spi readback errors in adc.py and unrecognized device in dac.py, by configuring the following:

  • set spi.cshigh to False as per adc and dac datasheets.
  • introduce a delay to properly reset adc

See #49 log for comparison.

ADC init log:

Spi readback register 0x01: 0x20
Spi readback register 0x02: 0x15
Spi readback register 0x03: 0x81
Spi readback register 0x04: 0x1f
No bitslip required; Currernt frame = 0x0c
Tap delay: 0
Current frame: 0x0c
Tap delay: 1
Current frame: 0x0c
Tap delay: 2
Current frame: 0x0c
Tap delay: 3
Current frame: 0x0c
Tap delay: 4
Current frame: 0x0c
Tap delay: 5
Current frame: 0x0c
Tap delay: 6
Current frame: 0x0c
Tap delay: 7
Current frame: 0x0c
Tap delay: 8
Current frame: 0x0c
Tap delay: 9
Current frame: 0x0c
Tap delay: 10
Current frame: 0x0c
Tap delay: 11
Current frame: 0x0c
Tap delay: 12
Current frame: 0x0c
Tap delay: 13
Current frame: 0x0c
Tap delay: 14
Current frame: 0x0c
Tap delay: 15
Current frame: 0x0c
Tap delay: 16
Current frame: 0x0c
Tap delay: 17
Current frame: 0x0c
Tap delay: 18
Current frame: 0x0c
Tap delay: 19
Current frame: 0x0c
Tap delay: 20
Current frame: 0x0c
Tap delay: 21
Current frame: 0x0c
Tap delay: 22
Current frame: 0x0c
Tap delay: 23
Current frame: 0x0c
Tap delay: 24
Current frame: 0x0c
Tap delay: 25
Current frame: 0x0c
Tap delay: 26
Current frame: 0x0c
Tap delay: 27
Current frame: 0x0c
Tap delay: 28
Current frame: 0x0c
Tap delay: 29
Current frame: 0x0c
Tap delay: 30
Current frame: 0x0c
Tap delay: 31
Current frame: 0x0c
No edge detected; setting iDelay to: 11
ADC_CH0: 0x[65, 0, 0, 0]
Final ADC_CH0: 0x41aa
Final ADC_CH1: 0xf055
Spi readback register 0x02: 0x11
12

DAC init log:

=== Contents of spi buffer after DAC VERSION read back: ===
0x9F0A
0x8234
0x82B4
0x94D3
0x94D3
0x94D3
0x94D3
0x94D3
0x94D3
0x94D3
0x94D3
0x94D3
0x94D3
REG contents: 0b000
REG contents: 0b000

### Description Fix the `spi readback errors` in adc.py and `unrecognized device` in dac.py, by configuring the following: - set `spi.cshigh` to `False` as per [adc](https://www.analog.com/media/en/technical-documentation/data-sheets/219543f.pdf) and [dac ](https://www.analog.com/media/en/technical-documentation/data-sheets/ad9114_9115_9116_9117.pdf) datasheets. - introduce a delay to properly reset adc See #49 log for comparison. ADC init log: ``` Spi readback register 0x01: 0x20 Spi readback register 0x02: 0x15 Spi readback register 0x03: 0x81 Spi readback register 0x04: 0x1f No bitslip required; Currernt frame = 0x0c Tap delay: 0 Current frame: 0x0c Tap delay: 1 Current frame: 0x0c Tap delay: 2 Current frame: 0x0c Tap delay: 3 Current frame: 0x0c Tap delay: 4 Current frame: 0x0c Tap delay: 5 Current frame: 0x0c Tap delay: 6 Current frame: 0x0c Tap delay: 7 Current frame: 0x0c Tap delay: 8 Current frame: 0x0c Tap delay: 9 Current frame: 0x0c Tap delay: 10 Current frame: 0x0c Tap delay: 11 Current frame: 0x0c Tap delay: 12 Current frame: 0x0c Tap delay: 13 Current frame: 0x0c Tap delay: 14 Current frame: 0x0c Tap delay: 15 Current frame: 0x0c Tap delay: 16 Current frame: 0x0c Tap delay: 17 Current frame: 0x0c Tap delay: 18 Current frame: 0x0c Tap delay: 19 Current frame: 0x0c Tap delay: 20 Current frame: 0x0c Tap delay: 21 Current frame: 0x0c Tap delay: 22 Current frame: 0x0c Tap delay: 23 Current frame: 0x0c Tap delay: 24 Current frame: 0x0c Tap delay: 25 Current frame: 0x0c Tap delay: 26 Current frame: 0x0c Tap delay: 27 Current frame: 0x0c Tap delay: 28 Current frame: 0x0c Tap delay: 29 Current frame: 0x0c Tap delay: 30 Current frame: 0x0c Tap delay: 31 Current frame: 0x0c No edge detected; setting iDelay to: 11 ADC_CH0: 0x[65, 0, 0, 0] Final ADC_CH0: 0x41aa Final ADC_CH1: 0xf055 Spi readback register 0x02: 0x11 12 ``` DAC init log: ``` === Contents of spi buffer after DAC VERSION read back: === 0x9F0A 0x8234 0x82B4 0x94D3 0x94D3 0x94D3 0x94D3 0x94D3 0x94D3 0x94D3 0x94D3 0x94D3 0x94D3 REG contents: 0b000 REG contents: 0b000 ```
Owner

Where is this coming from? Is the elhep code incorrect?

Where is this coming from? Is the elhep code incorrect?
Author
Collaborator

Where is this coming from? Is the elhep code incorrect?

This needs to be verify with the current elhep code, since the datasheet indicate this as default setup. Will inquire on it.

> Where is this coming from? Is the elhep code incorrect? This needs to be verify with the current elhep code, since the datasheet indicate this as default setup. Will inquire on it.
Owner

What datasheet?
Any answers from Jakub?

What datasheet? Any answers from Jakub?
Owner

What's the status of this?

What's the status of this?
Author
Collaborator

What's the status of this?

This was mentioned in this issue comment, and it seems Jakub hasn't responded yet. However, from the datasheets referenced in the description, the CS pin is active low. Additionally, testing with spidev_test shows it seems to read fine after applying this patch.

> What's the status of this? This was mentioned in [this issue comment](https://github.com/elhep/Fast-Servo-Firmware/issues/1#issuecomment-2056430293), and it seems Jakub hasn't responded yet. However, from the datasheets referenced in the description, the CS pin is active low. Additionally, testing with [spidev_test](https://github.com/torvalds/linux/blob/master/tools/spi/spidev_test.c) shows it seems to read fine after applying this patch.
sb10q reviewed 2024-05-24 15:30:23 +08:00
@ -61,3 +62,4 @@
rx_buffer = [0x00, 0x00]
spi.xfer2(spi_buffer)
time.sleep(0.1)
Owner

What about this?

What about this?
Author
Collaborator

This one I added and got:

No bitslip required; Currernt frame = 0x0c.

as compared with the previous:

Performing bitslip (bitslip iteration: 0). Reason: current_frame is 0x00 instead of 0x0C

This one I added and got: ``` No bitslip required; Currernt frame = 0x0c. ``` as compared with the previous: ``` Performing bitslip (bitslip iteration: 0). Reason: current_frame is 0x00 instead of 0x0C ```
Owner

Okay, and? Please investigate.

Okay, and? Please investigate.
fsagbuya force-pushed adc_dac from d4cd5cd689 to 59237af8b7 2024-06-07 16:46:07 +08:00 Compare
Owner

What's the latest status of this?

What's the latest status of this?
sb10q reviewed 2024-06-08 11:36:36 +08:00
@ -19,6 +19,7 @@
import mmap
import os
import time
Owner

This import is not used.

This import is not used.
fsagbuya force-pushed adc_dac from 59237af8b7 to c9d34348bc 2024-06-10 10:02:50 +08:00 Compare
sb10q merged commit c9d34348bc into master 2024-06-11 13:59:38 +08:00
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/nix-servo#55
No description provided.