Forum > Embedded

A circular / ring buffer for embedded

<< < (4/5) > >>

d.ioannidis:
Hi,


--- Quote from: Thaddy on October 12, 2022, 10:30:45 am ---Just let it overflow with {$R-}. Need power of two, of course and the correct bit size.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program ringbuffer;{$R-}var    b:byte = 0;begin  repeat    writeln(b);    inc(b);  until 0=1;// silly, replace with signal hi/lo....end.Audio buffers trick.... That's how I used it in the past... And it is a 256 ringbuffer which is perfect for embedded.

--- End quote ---

 I use the same technique for the ring buffer read/write indices ( i.e. see here for read ) but how the above can be a ring buffer with 256 slots ? Where the values are stored ? What am I missing ?

 Could you please elaborate ?

regards,

alpine:

--- Quote from: d.ioannidis on October 12, 2022, 11:07:31 am ---Hi,


--- Quote from: Thaddy on October 12, 2022, 10:30:45 am ---Just let it overflow with {$R-}. Need power of two, of course and the correct bit size.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program ringbuffer;{$R-}var    b:byte = 0;begin  repeat    writeln(b);    inc(b);  until 0=1;// silly, replace with signal hi/lo....end.Audio buffers trick.... That's how I used it in the past... And it is a 256 ringbuffer which is perfect for embedded.

--- End quote ---

 I use the same technique for the ring buffer read/write indices ( i.e. see here for read ) but how the above can be a ring buffer with 256 slots ? Where the values are stored ? What am I missing ?

 Could you please elaborate ?

regards,

--- End quote ---
IMO this is just an example how the buffer pointer can be incremented and modulo 256 taken, without actually writing it ( b := (b + 1) % 256 ) by using the byte boundaries.

Thaddy:
No, modulo is on most CPU's an expensive operation. Using overflow is NOT an expensive operation.
I will add a simple sine wave later  to demonstrate its use. But it is very easy anyway.

marcov:

--- Quote from: Thaddy on October 12, 2022, 06:11:38 pm ---No, modulo is on most CPU's an expensive operation. Using overflow is NOT an expensive operation.
I will add a simple sine wave later  to demonstrate its use. But it is very easy anyway.

--- End quote ---

Well, assuming of course that this won't fail horribly because the compiler chooses a larger register size for the variable.

Thaddy:
which is not the case.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version