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
31 stars 5 forks source link

Release v1.3.0 #372

Closed npetersen2 closed 3 weeks ago

npetersen2 commented 5 months ago

This PR combines the work of @codecubepi and @annikaolson into a new feature release: v1.3.0. This is a pretty large release---it adds the most features of any release yet to the AMDC codebase. While it is technically a "feature" release, it does break some small things with new function renames and such. However, the aim is to predominately add the so-called "Timing Manager" functionality which interfaces to all parts of the system (sensors/FPGA, PWM/code callback timing, overall timing alignment / phasing).

The full changelog is forthcoming. In addition, we will also make a new discussion post on this repo which outlines the changes and the recommended pathway for users to upgrade to this release. We expect this to include these three steps:

  1. Checkout this new v1.3.0 release in git and rebuild your AMDC bitstream in Vivado
  2. If you are currently using the AMDS: the code is now called amds instead of motherboard---you need to rename all your user-space functions appropriately, and update include paths, etc.
  3. Configure the Timing Manager: in your user app init function, enable the relevant sensors for sampling, then set the desired ratio for control task callback. See the documentation for more info on this.
  4. Change the Timing Manager mode from "legacy" mode to "new" mode which time-aligns the scheduler and task callbacks to the sensor sampling. This is located in the usr/user_config.h file. See the documentation for more info on this.
codecubepi commented 4 months ago

Today, @npetersen2 and I did a lot of debugging in the lab with the current version of the code (see the previous commit) in the conversation.

Test Setup

image

As seen above, we configured a full system including an AMDC + AMDS + uInverter. The intent is similar to the Tutorial 4 from the AMDC docs website, i.e., an open-loop voltage source inverter. The addition is the AMDS which is using 4 Low Voltage Cards---BNC cables are used to connect the measured current (voltage) on the uInverter to the sensor card.

The point of this set up is so that we can:

  1. Use the AMDC PWM to create ac current
  2. Use both the AMDC ADC sensor and the AMDS to measure the uInverter ac currents
  3. Log both of these and ensure they match well

Results

For these results, we are using the v1.3-staging firmware which is the full integration of the new AMDS driver and the new Timing Manager. The timing manager is set in the "legacy" mode, i.e., the ISR is triggered regardless of the sensor complete signal. In other words, the scheduler starts running tasks RIGHT when the sensors start sampling, synchronized to the PWM.

In these tests, we created a task which reads from the AMDC ADC and the AMDS and stores to log variables.

Here are some results we captured:

No delay between ADC and AMDS sample

In this test, there is no delay in the task, and it uses high_priority scheduler registering such that the task runs first.

image

image

image

One cycle of delay between ADC and AMDS sample

In this test, the first code in the task is to run 3000 nop instructions in a for-loop, which translates to about 6 us of delay. Again, it uses high_priority scheduler registering such that the task runs first.

Note: as measured by the timing manager, the AMDC ADC takes 0.8 usec to sample, while the AMDS takes 10.8 usec. Therefore, this nop delay loop should make it so that we log the data between when the internal ADC is done and when the AMDS is done. This should cause a 1 timestep delay in the feedback.

image

image

image

Discussion of Results

These tests validate the Timing Manager functionality and the AMDS-AMDC interface.

In the first test, due to the fast speed of the scheduler ISR callback and C code, the data logged is "stale" i.e., it gets logged BEFORE the sensors are done sampling. We see this since the waveforms align nearly perfectly. Notice how well the AMDC ADC and the AMDS waveforms exactly match.

In the second test, we show that, if the callback code waits, it can get the NEW samples.

Next Steps

We will continue testing the new code, specifically the "new mode" of the timing manager where the callback happens AFTER the sensors are done sampling. In this new mode, we should never be able to make this "off-by-1-cycle" plot since any delay in the task callback should not matter.

codecubepi commented 4 months ago

We also talked to @anirudhupadhyaya to figure out when to get him running on this v1.3` "pre-release" code. He requested another feature (#398), so I will get to work on finishing that right away.

Remaining issues for full release of v1.3:

One last housekeeping PR... #412

Plus some thorough documentation, of course.

Related PRs in sibling repos:

npetersen2 commented 3 weeks ago

I reviewed all the files changed (118) to some degree, and everything is looking reasonable. Very nice.

I approve this to be merged to develop, thus effectively releasing v1.3.0. We will make another PR for the changelog as usual, then tag this as the official release commit.

npetersen2 commented 3 weeks ago

Let's merge this with a normal Merge commit (not the squash and merge)