Home    LittleBigPlanet 2 - 3 - Vita - Karting    LittleBigPlanet 2    [LBP2] Help!
#1

latency is killing me

Archive: 23 posts


Ok, all I want to do is take a stored analog value, add another analog value to it, and update the original storage for the next operation. Any ideas how to do this efficiently?

This sounds simple enough, but I just can't seem to get it to work. The latency in the adder/storage on everything I have tried is throwing things off if I try to loop the storage back into it (even with a sampler). Even just attaching a signal meter to an output introduces enough latency to change the behavior of the system depending on the part I attach it to, so I can't get a bead on what I am doing incorrectly.
2011-02-20 02:49:00

Author:
tdarb
Posts: 689


The latency in the adder/storage on everything I have tried is throwing things off if I try to loop the storage back into it (even with a sampler).

I think a sampler will necessarily add a frame of latency - there may not be a solution which entirely eliminates it. FWIW, I have a digital version of the described application which works fine, but I think you already saw it.
2011-02-20 17:17:00

Author:
Aya042
Posts: 2870


you very likely did. I have the memory of a dying fly.

It's amazing how just the tiniest tweak can break the whole thing.
2011-02-21 00:00:00

Author:
tdarb
Posts: 689


How much latency can you tolerate??

The timer-based samplers I put in my blog work by doing the following:
1. Reset the timer
2. Increase the timer's value by 1/30T of the input signal per clock cycle (where T is the target time on the timer)

If you do away with the reset / make the reset explicit then each pulse into the sampler will add onto the previous sample. You will take a single clock cycle to update, but you can immediately add another value into the system (i.e. latency of 0.033s with Max throughput of 30Hz)
2011-02-21 08:56:00

Author:
rtm223
Posts: 6497


You will take a single clock cycle to update, but you can immediately add another value into the system (i.e. latency of 0.033s with Max throughput of 30Hz)

Hmm. Although the timer may take one frame to update, surely the output from the Direction Combiner is instant, so if you're feeding back the timer into the combiner, although the timer will always be one frame off, if you instead take the output from the combiner, you should be able to get a result on the same frame, no?

So, on each frame, the output from the combiner should be whatever the new signal is, added to whatever the timer was at on the previous frame.

Just a thought. Haven't tested, so it might not actually work.

What's the application exactly?
2011-02-21 13:48:00

Author:
Aya042
Posts: 2870


Aya - I have this working if you want to see how I did it. I can take a stored analog value, add another to it and store it in one frame. Of course it's rising edge, so it will incur one frame of cool down before you can do it again.

It's identical to your digital memory-add-store version, except it does analog.
2011-02-21 15:44:00

Author:
Shanghaidilly
Posts: 153


What's the application exactly?

THis is what I was wondering, but as it seems to be a series of += style operations, the simplest solution seems to be to incorporate everything (addition AND storage) inside the timer. There are no combiners in the solution I describe (though you could choose to prefix the timer with an adder to group data from multiple sources into the timer concurrently, assuming your data comes from multiple sources) and there is no loopback.

In case it's not clear what I'm talking about, the timer based samplers already do an addition... it's just that by resetting the timer you are adding onto 0. If you don't reset the timer then you add a value on to the current value.
2011-02-21 16:34:00

Author:
rtm223
Posts: 6497


THis is what I was wondering, but as it seems to be a series of += style operations, the simplest solution seems to be to incorporate everything (addition AND storage) inside the timer. There are no combiners in the solution I describe (though you could choose to prefix the timer with an adder to group data from multiple sources into the timer concurrently, assuming your data comes from multiple sources) and there is no loopback.

In case it's not clear what I'm talking about, the timer based samplers already do an addition... it's just that by resetting the timer you are adding onto 0. If you don't reset the timer then you add a value on to the current value.

I did something similar, but I didn't like the fact I had to initialize the timer with the seed value. Not that it was hard, but somehow I had to guarantee that this was done prior to triggering the addition(s). If your starting value is low, then this is probably not an issue, but I struggled with supporting an entire range of initial values.
2011-02-21 18:05:00

Author:
Shanghaidilly
Posts: 153


I don't know what you mean by initial value TBH, surely the initial value is just another value in the chaining of additions, i.e. a sum of a set of N+1, rather than N? Not entirely sure why the magnitude of the value would matter either, you can record everything from 0-100 in the initial pulse (the same one as you do the reset in).

I'm assuming that you can either deal with the result being scaled, or if not would upscale after the timer to obtain a corrected result.


Again, what is the application that requires an initial value that is somehow different to the other values and can't simply be added in the same manner?
2011-02-21 18:37:00

Author:
rtm223
Posts: 6497


I'm assuming that you can either deal with the result being scaled, or if not would upscale after the timer to obtain a corrected result.

You are correct. I thought of this just after posting my reply and remember not wanting to have to fool with the scaled result (I was being lazy). To me, it was a lot more fun to solve the problem of creating a register for this, versus dealing with timers. Plus, a side benefit of the register was that it stores analog, digital, and player data (not that player data at this point is all that useful, I know). But since I was storing the digital component, creating a signed 7-bit register was easy - not that it's all that useful either.
2011-02-21 18:50:00

Author:
Shanghaidilly
Posts: 153


How much latency can you tolerate??

The timer-based samplers I put in my blog work by doing the following:
1. Reset the timer
2. Increase the timer's value by 1/30T of the input signal per clock cycle (where T is the target time on the timer)

If you do away with the reset / make the reset explicit then each pulse into the sampler will add onto the previous sample. You will take a single clock cycle to update, but you can immediately add another value into the system (i.e. latency of 0.033s with Max throughput of 30Hz)

I have been reading your blog, and it is very helpful. I want to pass in a whole number value rather than a percentage value. Can the timers do that without more manipulation? I already have one frame of latency in my storage. I can live with that.


Hmm. Although the timer may take one frame to update, surely the output from the Direction Combiner is instant, so if you're feeding back the timer into the combiner, although the timer will always be one frame off, if you instead take the output from the combiner, you should be able to get a result on the same frame, no?

So, on each frame, the output from the combiner should be whatever the new signal is, added to whatever the timer was at on the previous frame.

Just a thought. Haven't tested, so it might not actually work.

What's the application exactly?

Basically I am using it to represent a number in a scoreboard of sorts, so every 10% is a new number. 10=1, 20=2, and so on. I want to be able to ultimately add to and subtract from this. I'm sure there's better ways to implement this, so I am open to that too.

I think I found part of my problem. I was using a sequencer set to positional to create a digital signal from the analogue input, and that introduced a frame of latency. By the time the digital signal registered, my analog input signal was gone.

I can't figure out how to get the delay out of my overflow handling now. So if I have 8, and add 4, it changes my value to 100% which outputs 0 for me. Then one frame later the overflow handler completes and sends it the 2. Something in this creates a strange condition that makes my circuit toggle rapidly between two different numbers.

How would I do something along the lines of the following without adding a delay?

if(x != 0){
x=100-x;
}
2011-02-22 08:28:00

Author:
tdarb
Posts: 689


I can't figure out how to get the delay out of my overflow handling now. So if I have 8, and add 4, it changes my value to 100% which outputs 0 for me. Then one frame later the overflow handler completes and sends it the 2. Something in this creates a strange condition that makes my circuit toggle rapidly between two different numbers.

Wouldn't it be easier just to avoid dealing with overflows?

Bear in mind that analog signals are (I believe) floating point values between -n and +n - not sure what 'n' is exactly, but in order to take advantage of their full resolution, you need to be working with much smaller values. Using a battery set at 10% as your smallest value only gives 10 discrete positive values, whereas using a timer set to max=1000, value=0.1 gives you 10,000. Check out this thread (https://lbpcentral.lbp-hub.com/index.php?t=48523-Analog-Signal-Display) for a useful gadget to show analog signals at that resolution.

So just do all your math at that kinda resolution, then multiply it up at the end into a range which is useful for display. If 10,000 isn't enough, you can potentially squeeze a bit more out of it by bumping the max value, but you might find it difficult to determine what signals you're actually dealing with (and you'll eventually hit the resolution limit of a single-precision floating point), so if you need to distiguish between millions or billions of discrete values, then I'd recommend switching to a digital solution.
2011-02-22 11:19:00

Author:
Aya042
Posts: 2870


The overflow system I propose for my analogue adders shouldn't add latency... Though I don't wanna claim that too hastily as they haven't been tested by me this side of the Beta.


Overall, what Aya said is about right IMO - a downscaling timer is generally going to be simpler to use than multiple signals handling overflow. The timer also allows for an adder / subtractor implementation with ease as well.
2011-02-22 11:28:00

Author:
rtm223
Posts: 6497


Overall, what Aya said is about right IMO - a downscaling timer is generally going to be simpler to use than multiple signals handling overflow. The timer also allows for an adder / subtractor implementation with ease as well.

In retrospect, I think I know why he's chosen the "resolution of 10" option, which is so that each digit in the score is represented by a different timer, and if he can get the overflow working in real time, the solution can be scaled by an arbitrary amount just by adding additional timers.

Could work, I guess, but could get kinda funky if you need to add values greater than 10, since they can't be represented as a single analog signal. Maybe not tho' - haven't really played much with this sorta thing.
2011-02-22 12:19:00

Author:
Aya042
Posts: 2870


if(x != 0){
x=100-x;
}


x = 100 - x is done using a combiner, which has no frame latency, so the only issue there is checking x!=0 without latency.
I can't test this right now, and I may be wrong completely, but could you have X activate a microchip (to see if its !0), then inside that microchip have the combiner?

The problems I forsee with that are; do microchips activate and process their contents immediately, or next frame? Do they activate with anything more than 0%, or only when it reaches a higher %?
2011-02-22 14:44:00

Author:
merkaba48
Posts: 79


if(x != 0){
x=100-x;
}


x = 100 - x is done using a combiner, which has no frame latency, so the only issue there is checking x!=0 without latency.
I can't test this right now, and I may be wrong completely, but could you have X activate a microchip (to see if its !0), then inside that microchip have the combiner?

The problems I forsee with that are; do microchips activate and process their contents immediately, or next frame? Do they activate with anything more than 0%, or only when it reaches a higher %?

Analog signals won't activate a microchip. Therein lies the issue. The analog/digital duality of LBP2 is what trips up most people. *shang stumbles and does a faceplant*
2011-02-22 14:50:00

Author:
Shanghaidilly
Posts: 153


In retrospect, I think I know why he's chosen the "resolution of 10" option, which is so that each digit in the score is represented by a different timer, and if he can get the overflow working in real time, the solution can be scaled by an arbitrary amount just by adding additional timers.

Could work, I guess, but could get kinda funky if you need to add values greater than 10, since they can't be represented as a single analog signal. Maybe not tho' - haven't really played much with this sorta thing.

That's more or less what I am doing. each of these adders represents a single digit. All of my values to be added are known values so I can add them to the proper digit. The input for this system will be tag sensors set to signal strength with each digit having a differently labeled tag. That is also why i need the overflow working.

If i add 40 to 80, then I need to maintain that two so that my readout is correct.


Analog signals won't activate a microchip. Therein lies the issue. The analog/digital duality of LBP2 is what trips up most people. *shang stumbles and does a faceplant*

yep, that's the part that's kicking my butt at the moment.

Well, that and trying to wrap my head around this timer solution rtm and aya are talking about. I can't figure out how to use the timers without dealing with percents.
2011-02-22 17:59:00

Author:
tdarb
Posts: 689


Analog signals won't activate a microchip. Therein lies the issue. The analog/digital duality of LBP2 is what trips up most people. *shang stumbles and does a faceplant*

Aw that's nuts. A battery of 1% will trigger one, but you're right analogue signal from the joystick wont.

HOWEVER, here's a crazy thing: A joystick connected to a key, which is picked up by a strength-scale key sensor will activate a microchip even at 1%. I don't know if there's a frame latency there or not though
*edit*

Yeah I think there is a frames latency; the sensor only triggers once the key is on for 1 frame. I tested this using an emitter on a very fast rotating object attached directly to the speed signal, to see if it would emit at its start position or offset - it was offset.
2011-02-22 21:26:00

Author:
merkaba48
Posts: 79


You could feed the analogy signal into a sequencer with a 100% battery that covers it's entire length, and have that activate the microchip2011-02-23 00:58:00

Author:
Speed Racer
Posts: 156


You could feed the analogy signal into a sequencer with a 100% battery that covers it's entire length, and have that activate the microchip

That ends up adding a frame of latency though.

But I did have another thought; do as others have suggested and just use a single timer for the score tracking in very small increments. It severely simplifies the logic there.

Then just take the resulting analog signal and run it through a series of analog to decimal decoders. Each decoder will introduce a frame of latency, but it will never effect the score calculations, only how long it takes for the display to catch up. And that can be mitigated with some extra logic.

For the analog to decimal decoder, I already have such a circuit constructed; it takes as input an analog signal, then outputs the 7 segment display segments and a new analog signal. The new signal subtracts the displayed value (IE if it displays 5 it subtracts 50%) then scales it up 10x. In this way, you can chain these to any level of precision you desire, though after 7 you run into the limitation of single precision floating point.

When I get a chance later today I'll post a picture of the circuit if you desire.
2011-02-23 02:23:00

Author:
Tygers
Posts: 114


That would be awesome. I may end up going with a binary setup, but i would probably only use 4 bit since I just need the numbers 0 through 9.

I have the storage squared away so that it is persistent, but easily set.

Basically it is a row of sequencers set from 0-9 that pulse into a selector which activates a corresponding microchip containing a battery set to the proper capacity. The batteries output into an OR gate. The pulser I have used is a selector looped back into itself as it provides a one shot ability with 0 latency.

It works with the same latency as working with a timer(1 frame), and can keep a persistent value without any new inputs. Unlike a timer, it can be set directly by receiving any analogue value, and I can determine my own scaling and rounding directly...and it doesn't have that pesky extra frame hidden in it that can cause rounding errors.

The latency issue is with the overflow handling. When my number goes over 10, the positive addition finishes one frame before my overflow can. Since the output is now essentially 0, that is fed back in resetting my overflow to 0. Under certain conditions, it creates a condition where the value toggles between 0 and whatever my overflow is trying to set it to.

The main purpose of this is to be a currency system, so a binary setup may be better anyway. I look forward to seeing what you have.
2011-02-23 03:23:00

Author:
tdarb
Posts: 689


So I tried setting up an analog circuit which used a single counter to add/subtract value, and I couldn't tune it to be as precise as I liked. If I can come up with something better I'll let you know, but in the mean time, you're probably better off doing the digital circuit instead.2011-02-23 10:03:00

Author:
Tygers
Posts: 114


That would be awesome. I may end up going with a binary setup, but i would probably only use 4 bit since I just need the numbers 0 through 9.

Certainly sounds a lot easier, and unless you need a huge number of registers, the thermo overhead is marginal. Choices are to either go with BCD as you suggest, and use a BCD adder (https://lbpcentral.lbp-hub.com/index.php?t=35151-How-to-make-your-own-addtion-calculator-useing-BCD-calculator-basics-of-numeral-logic), or work in binary, and just convert to to BCD (https://lbpcentral.lbp-hub.com/index.php?t=48803-8-bit-Digital-Readout) for display.
2011-02-23 10:22:00

Author:
Aya042
Posts: 2870


LBPCentral Archive Statistics
Posts: 1077139    Threads: 69970    Members: 9661    Archive-Date: 2019-01-19

Datenschutz
Aus dem Archiv wurden alle persönlichen Daten wie Name, Anschrift, Email etc. - aber auch sämtliche Inhalte wie z.B. persönliche Nachrichten - entfernt.
Die Nutzung dieser Webseite erfolgt ohne Speicherung personenbezogener Daten. Es werden keinerlei Cookies, Logs, 3rd-Party-Plugins etc. verwendet.