Electronics > Microcontrollers
How Fast Could Serial Bits, Read from a Table in SRAM, Be outputted?
KerimF:
Hi all,
Please note that the purpose of this topic is validating the well-known saying: “Necessity is the mother of invention... or innovation”.
I had an ATmega8 and an 8 MHz crystal for it. I needed to output as fast as possible a delta bit stream (its bits are stored as bytes in the MCU SRAM space) whose size could be 96 up to 103 bits.
The outputted serial bits are supposed to generate, after filtering, a sinewave signal.
I ended up, after many months (being not very smart), writing a code (not trivial) that outputs the bits (read from a SRAM table) at a rate of 4 MCU cycles (0.5 us). Therefore, in case of delta Nbits per cycle, the frequency of the generated sinewave is:
F_sine = 1 / (4 * MCU_cycle * Nbits)
Nbits= 96 ==> 20,833 Hz
Nbits= 97 ==> 20,619 Hz
Nbits= 98 ==> 20,408 Hz
Nbits= 99 ==> 20,202 Hz
Nbits= 100 ==> 20,000 Hz
Nbits= 101 ==> 19,802 Hz
Nbits= 102 ==> 19,608 Hz
Nbits= 103 ==> 19,417 kHz
Obviously, the sinewave loop, while running (generating the sinewave), needs to detect the last bit in the SRAM table and restart from the first bit without taking any extra MCU cycle.
For instance, while 96 bits are saved in 12 bytes (12*8-bit), the 97 to 103 bits per cycle have to be saved with an extra byte to include the extra bits, MOD(Nbits,8).
And, in a practical application, if Nbits is odd, the bit stream should be made for 2 sinewave cycles instead of one. For example, if Nbits=97, the size of the bit stream is 194 bits, saved in 24+1 bytes (the extra byte is for the remaining 2 bits).
Sorry, I don’t think any of the readers here has an idea now on how to write such a fast code; not because I am smarter than others but because no one likely ‘needed it’, as I did, in the first place. But, if someone did (needed it), he surely found out how to do it.
For instance, I will be surprised really if someone will be able to find the solution by searching it in the internet.
I will post my work after hearing some serious comments.
Have fun,
Kerim
Added:
Please note that I attached how I did the 4-cycle_per_bit.asm on reply #20
DavidAlfa:
No idea what are you talking about. Where do these "stream bits" go to?
Are you making a sort-of pwm modulation with those bits?
"After many months"... Why? Using a prehistoric atmega in 2023 is totally no sense, you have lots of *much* faster, cheaper devices!
bingo600:
Maybe Jesper's minidds
http://www.radanpro.com/Radan2400/mikrokontroleri/Jesper%27s%20AVR%20pages%20-%20MiniDDS.htm
westfw:
--- Quote ---I will be surprised really if someone will be able to find the solution by searching it in the internet.
--- End quote ---
Also 4 cycles/bit (including clock manipulation): http://nerdralph.blogspot.com/2015/03/fastest-avr-software-spi-in-west.html
(Didn't find it by searching; I remember when Ralph announced it on AVRFreaks)
Using the hardware you can do 2 cycles/bit - people have used the UART (in "SPI Mode") to produce bit-banged video.
KerimF:
--- Quote from: DavidAlfa on September 11, 2023, 04:44:38 pm ---No idea what are you talking about. Where do these "stream bits" go to?
--- End quote ---
They will go to a LPF (acting as a buffer too) as in the case of basic delta modulation/demodulation.
--- Quote from: DavidAlfa on September 11, 2023, 04:44:38 pm ---Are you making a sort-of pwm modulation with those bits?
--- End quote ---
No, I am just making the MCU acts as a conventional delta modulation at a relatively high rate (2 MHz in the presented example),
You surely heard of DDS (Direct Digital Synthesis). What I did could be called DSS (Delta Sinewave Synthesis).
While DDS requires an R-2R ladder, DSS just needs a somehow simple LPF, at one MCU pin, which can cover a relatively wide spectrum.
But there is always a price when the hardware is simplified, the DSS code for generating the delta stream table (satisfying a certain criteria) for every frequency is not simple at all, as it is the case for DDS. This explains why all programmers didn't think about it. Most of them, unlike I, have the privilege to use other advanced alternatives; exactly as you kindly point it out.
Just for knowledge, due to world's regulations made by the World's Elite Group since many decades ago, I don't have the privilege to order any component (I have to rely on the local retailers only) or access any site providing technical services (as advanced compilers for PCs or MCUs) to almost all engineers in the world, for free or paid. So, I have to use the prehistoric C compiler for DOS (of Borland C 3.1, I bought in the 80's) whenever I need to write a program for an in-house application. Naturally, I used to write all my MCU codes (for Z80, C51 then AVR lately) in assembly language only.
So be glad that you can get whatever you may need as tools and devices, for free or not.
On my side, I simply enjoy thinking out of the box every time I design a product for the local consumers while using prehistoric tools and components :)
Navigation
[0] Message Index
[#] Next page
Go to full version