I want to create a flexible signal shape that can be viewed using an oscilloscope by making a program. I am using an array to form the signal, such as {2048, 4026, 2048, 0}, where 2048 represents the flat line I want to adjust, 4026 represents the peak, and 0 represents the valley. I want to adjust the value of 2048 flexibly; for example, if I input x=3, it should output {2048, 4026, 2048, 2048, 2048, 0}. However, I am confused about how to use the for loop or if statements because I want to place the value in the middle. I need help with my code; please provide suggestions or possibly an example code.
the result i want
That is the description of what I want to create, and here is my code.
The code like 2048 is the part that I want to make flexible.
#define NS 4
uint32_t Wave_LUT[NS] = {
2048,4026, 2048,0
};
HAL_DAC_Start_DMA(&hdac, DAC_CHANNEL_1, Wave_LUT, 4, DAC_ALIGN_12B_R);
HAL_TIM_Base_Start(&htim4);
Please help me, I really can’t analogize this anymore.
1
Answers
You did not show how
NS
andx
are related. In this example I will assume thatNS
is always large enough to hold the resulting array.From your examples I get a few fixed values.
Your array layout is always like this:
That means, you have in total
x+3
elements in your array and all but 2 have the same value.Let’s fill the values in:
If you really want to save every nanosecond you could modify the filling part like this: