HDL-Coder Delay Balancing in Feedback-Loop workaround
35 views (last 30 days)
Show older comments
Niklas Weis on 26 Jan 2021
Commented: Steven Hatcher on 19 Jan 2023
I am trying to generate HDL-Code from a Subsystem that looks like this:
Inside Subsystem 2 and 3 there is some combinatorial logic with multipliers, adders etc. that need Delay-Balancing and Pipelining to achieve the desired Clock-Frequency.
Unfortunately hdlcoder refuses to perform delay-balancing and pipelining. It tells me:
"Delay balancing unsuccessful because Delay introduced in feedback loop cannot be path balanced"
"Unable to insert required number of pipeline registers because the Block is in a feedback path"
Is there a way to perform these optimizations in Subsystem 2 and 3 as if there was no Feedback-Loop involved?
There is an optimization that can leverage a faster clock in regions of logic running at a slower rate. It looks like your model's clock rate is 100 MHz, and subsystems 2 and 3 leverage 10x and 100x slower rates, respectively. If you are clocking these with a single clock (which generates a timing controller), then HDL Coder can optimize your slower rate logic in the feedback loop by upsampling it to 100 MHz and introducing latency from optimizations at the clock rate while leveraging any existing slower rate state/delays to avoid adding any data rate latency. This optimization is called Clock-Rate Pipelining. The extra data rate latency in the loop is the reason for the delay balancing errors you are experiencing.
Since this feedback loop contains multiple data rates, you will need to use the latest version of HDL Coder (R2022b) which adds support to Clock-Rate Pipelining for multi-rate designs which use Rate Transition, Downsample, and Repeat blocks. I also believe there is no need to request any oversampling by HDL Coder on your design since the faster 100 MHz rate should let Clock-Rate Pipelining know it has an opportunity to optimize the slower logic in subsystems 2 and 3.
If you are still experiencing delay balancing errors after following this suggestion, then you will need to look into the highlightClockRatePipelining.m file which is generated to help identify any obstacles to Clock-Rate Pipelining that may exist in your model.
Feel free to share any more findings or questions you may have.
In general, we've made a lot of improvements to Clock-Rate Pipelining in R2022a and R2022b, as well as many other optimizations (you can check the release notes). I would highly recommend using a newer release if you are experiencing issues with delay balancing and feedback loops.
More Answers (1)
Alan Moses on 29 Jan 2021
In some cases, when you have blocks inside a feedback loop, adaptive pipelining is unable to insert the required number of pipeline registers at the output. Delay balancing can then fail.
You may have to manually add/balance the delays in the loop. Refer this link for a similar explanation.
Code Generation HDL Coder HDL Code Generation from Simulink Speed and Area Optimization Speed Optimization
Find more on Speed Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!