Max Hold reset time
I'd like to use the Abs Max Hold block with a DC source to periodically read the peak value of a signal with a microcontroller over SPI from an ADAU1452, like this:
The microcontoller reads the output of AbsMax1 (param name "heldMax")
Then it resets the peak hold by setting DC1 to 0 and then to 1 again.
The quesion is, how long do I need to hold DC1 at 0 to reset the hold function.
Additionally, given that I can read heldMax can I just reset the hold by setting heldMax to 0, and what side effects might there be?
Thanks
Alex
Audio Signal Processors
adau1452
microcontroller
adau1452 sigmastudio
SigmaDSP Audio Processors
Hello Alex,
Sorry for the delay in my response.
Since these programs in the SigmaDSP are run once every sample period, you would want to set the DC cell to zero for at least one full sample period to be certain it was zero when the program was looking at the parameter. Since you are writing the parameter from the SPI port ( or I2C) you have the time it takes for the message to be transmitted. This will always be much longer than one sample period (unless you are running at a really slow sample rate).
So basically, you can write the zero then right away send a new message writing back to a "1" and it will have been zero for more than one sample period.
Now I think I should describe the behavior of this cell in a bit more detail.
When the control input (the orange pin) is set to zero, the cell will simply output what is on the input if there is only one input. After all, that is the maximum level. So every sample period it will simply output the input sample. This does not seem useful but if you grow the cell to have more than one input then it will be sending out the greatest of the absolute value of the multiple inputs on a sample by sample basis. It will not remember any previous samples. This could be useful.
Then when the control input is a "1". At this point I should mention that the control input just needs to be a non-zero number. So when the control input is NOT zero, then the output will be the maximum of the inputs from the time the control input was changed from zero. If a new sample is greater it will change to this new max value. If all the inputs are less it will hold this last max value.
So back to you resetting the DC cell.
Since you cannot write a new command fast enough, there will be a number of samples where the max value will not be held. So these values will be missed. Yes, it is not very long and the chances of a peak coming and going that fast is unlikely but it could happen.
You can solve this two ways:
1) you can drive the control pin from a GPIO pin. Then your external controller can simply toggle the GPIO pin. It will have to be low for at least one sample period. To be safe I would do at least 1.5 sample periods or two. If you can trigger your controller off of the LRCLK then you can be exact and set it low for one sample period.
2) You can use a different approach. This would be to use a peak envelope generator with the hold time set to your uC polling frequency. If you are polling every 10ms then set the hold time to 10ms and you will read the max peak value over that time period. Then it will decay after that if no new peaks are present in the input signal. This does take more MIPS but you do not have to worry about multiple messages to set it to zero then back to one and possibly miss some peaks.
I hope this helps...
Dave T
Hi Dave,
Thanks for the answer.
If I'm running my SPI at 10MHz and audio at 96kHz then the message will take a litte bit more than 1/2 a sample period so I will have to wait or do something else.
What about my idea of setting the "maxHeld" parameter (of the AbsMax cell) to 0 after I have read it.
I tried it out in SigmaStudio and it appeared to have the desired effect.
I'm thinking that, unlike the DC source method it won't require the DSP to run a sample thru it to clear the peak hold. Am I correct?
Thanks
Alex
Hello Alex,
Setting the cell to zero after reading it will reset the peak, you are correct but you will have to immediately set it back to a non-zero number at least one sample period later. If you do not then it does not hold the max value as I described earlier. What it does is sets the Max peak in memory back to zero and so any sample will now be the max and as long as it stays at zero the memory location to hold the Max will remain at zero. So the result is the value of the current sample.
Setting it to zero will reset it in either the current sample period or the next. It depends on where execution of the program is during the sample period when the parameter is updated. If the code that maintains the ABS/MAX cell has already been executed then it will not pick up the zero and will not reset the memory location that holds the max. So you would have to wait until the next sample period when the code will be executed and the reset will happen. This is why you have to wait at least one sample period and two is not a bad idea.
The program in the DSP is run every sample period. It waits for the new LRCLK edge and then starts running the program . When it is finished it executes NOPs until the next sample period starts. Somewhere in the program is the code that is the ABS/MAX cell. It might be in the early part of the frame or in the later part, but it will act on what it sees at that time.
So read the cell, then write the zero then at least one sample period later you write a non-zero. That will work and if this is done in the span of two or three sample periods you will not miss a peak. Most peaks last for more than three samples so this should work fine for you.
Dave T
Hi Dave,
I think you may have misinterpreted what I'm proposing:
I am leaving the vaule of the DC cell at 1 (or non-zero) permanently.
Then I go to the capture window params tab (in my example here the ADAU1452 is IC3) and press the refresh button to read the heldMax parameter of AbsMax1, at address 24 here.
I reduce the input signal level and press refresh to confirm that the peak value doesn't change
Then I can type in to the heldMax Param field the value 0 and press return.
Then I press the refresh button again and now the heldMax parameter has the new peak value for the smaller signal.
Alex
Hello Alex,
No, I fully understood what you were saying. I was taking it further to explain that while the control input is zero you will not be "remembering" any peaks that were in previous samples that have been processed since you set the control to zero. That was my point.
Now I love that you are using the parameter window! That you are seeing the data and refreshing it. It is a great tool for understanding what is going on in a the DSP. Not that many users take advantage of this feature. But in this case you can experiment with this cell much more easily using a readback cell and some DC cells.
I have attached an example project of how I was testing it. I have the readback set to continuous readback so you can see the output changing in real time.
I could have used a switch on the DC cell feeding the control pin but with a DC cell you can experiment with different numbers into the control port and you will see that it only checks for zero or not zero.
Dave T
ADAU1452 ABS_MAX_Hold test.zip
Hi Dave,
Load your project and open a script window and put this in :
int AbsMax1_heldMax = 20;
ss.ICRegisterWrite("IC 1", AbsMax1_heldMax, 4, 0);
(I'm assuming that AbsMax1_heldMax is at 20 for you as well)
Leave the Control_IN set to 1 and do not change it.
set Data2 to 0.0 and do not change it
set Data1 to 0.5
compile link & download to start it up and set the readback to continuous
The ReadBack should now read 0.5.
set Data1 to 0.2
The ReadBack should still read 0.5.
Run the script
The ReadBack should now read 0.2
set Data1 to 0.01
The ReadBack should still read 0.2.
Run the script
The ReadBack should now read 0.01
set Data1 to 5
The ReadBack should now read 5
This gives me the peak value since the last time I reset it, and resetting it invloves one operation.
Alex
Hello Alex,
I get it.
What you are doing is NOT setting the control input to the cell, you are leaving that alone, what you are doing is writing directly to the variable storage location that holds the max from all the previous samples. So by setting that to zero you have made the old MAX be zero and now any new data is the new max. Since you never changed the control input you will never miss any samples. I like it! This will work well!
It might not change the output during that exact sample period if the code has already run but it does not matter because it will be reset on the next sample period. Plus you would have just read the result and will not be reading again for a long time.
Dave T
Thanks Dave,
The only reservation I have about doing this is that I'm going thru the back door so to speak.
There might be wierd side-effects, or the algorithm might change after a SigmaStudio update.
Any thoughts on that?
Alex
Hello Alex,
Well, besides the obvious of the code compiling to a different address. You can use the indirect parameter table to keep track of the address if that is an issue for you. I do not think there is any risk of the code changing.
This cell has not changed much if any for a long time. It is a pretty simple cell and works fine so I would not expect them to change the code in the future.
BTW, as a side topic. The indirect parameter table does not have to be used exactly like it was intended to do. I think it is too complicated and is not needed for things that are not filters. What you can do is calculate the offset of where the pointer will be stored and then read that address pointer into your controller right after the DSP boots. Then just directly write to the address and do not use the table functionality.
Dave T
Please log in to reply.

