Severson-Group / AMDC-Firmware

Embedded system code (C and Verilog) which runs the AMDC Hardware
http://docs.amdc.dev/firmware
BSD 3-Clause "New" or "Revised" License
30 stars 5 forks source link

Rewrite Eddy Current Sensor FPGA & Drivers #304

Closed codecubepi closed 1 year ago

codecubepi commented 1 year ago

This PR is a request to merge in the new version of the Kaman Eddy Current Sensor FPGA and C drivers, This applies to both the REV D and REV E AMDC. This resolves #302.

Changes to AMDC block designs:

The amdc_eddy_current_sensor IP block has had new ports added to it. These additions apply to both REV E and REV D:

REV E

image

REV D

image

New IP Blocks

This PR does not add any new IP blocks, it only provides revisions to the existing eddy_current_sensor IP.

Driver C Code

The driver C code (located in /sdk/app_cpu1/common/drv/eddy_current_sensor.c) gives a layer of abstraction by providing functions that the user can call to initialize and read the eddy current sensor data.

OLD

void eddy_current_sensor_init(void);

void eddy_current_sensor_enable(uint32_t base_addr);
void eddy_current_sensor_disable(uint32_t base_addr);

void eddy_current_sensor_set_sample_rate(uint32_t base_addr, double sample_rate);
void eddy_current_sensor_set_divider(uint32_t base_addr, uint8_t divider);

double eddy_current_sensor_read_x_voltage(uint32_t base_addr);
double eddy_current_sensor_read_y_voltage(uint32_t base_addr);

NEW

void eddy_current_sensor_init(void);

void eddy_current_sensor_trigger_on_pwm_high(uint32_t base_addr);
void eddy_current_sensor_trigger_on_pwm_low(uint32_t base_addr);
void eddy_current_sensor_trigger_on_pwm_both(uint32_t base_addr);
void eddy_current_sensor_trigger_on_pwm_clear(uint32_t base_addr);

void eddy_current_sensor_set_timing(uint32_t base_addr, uint32_t sclk_freq_khz, uint32_t propogation_delay_ns);

double eddy_current_sensor_read_x_voltage(uint32_t base_addr);
double eddy_current_sensor_read_y_voltage(uint32_t base_addr);

The enable driver function has been removed, as the IP sampling is enabled by a module input now as decribed above.

The set_sample_rate and set_divider driver functions have been removed, the sampling rate is now synced to the PWM carrier instead of the old free-running method.

The trigger_on_pwm driver functions have been added, which allow the user to configure in their C code if they want the sampling to occur on the PWM carrier's max, min, or both.

The set_timing driver function has been added:

Finally, the init driver function has changed. Previously, it configured the eddy_current_sensor to sample at a rate of 20 kHz. It now configures the IP to sample on the PWM carrier's peak, and sets the SCLK frequency to 2 MHz.

Command Interface

The eddy current sensor did not previous support any serial commands, but due to the new configutation options, the following new commands were created:

Documentation:

These new changes have been documented in this IP block's README.

codecubepi commented 1 year ago

@npetersen2

So I think I have a theory of what's happening now... I can show you on the scope next week, but I think sampling right on the falling edge of SCLK is too early. It's catching a previous bit or something that is sometimes high and sometimes low. I will have to find someway to delay the samples so they don't happen too soon.

codecubepi commented 1 year ago

Hey @codecubepi , this is a to-do:

codecubepi commented 1 year ago

Things to look at in the lab with @npetersen2 on Monday:

codecubepi commented 1 year ago

I'm restoring the branch so I can open a new PR on it. This new PR will update the IP to version 2.0 and update the AMDC REV D block design.

See #307