Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Spatial
Nov 15, 2007

designed my first PCB recently because i wasn't willing to use 120+ jumper wires on a breadboard.

i used Fritzing and it was a painful, buggy and slow experience. but i learned a lot and the end product works! :v:

Adbot
ADBOT LOVES YOU

Spatial
Nov 15, 2007

looks pretty great, i'm checking it out now

Spatial
Nov 15, 2007

the technical manual is a fun read. sometimes prideful, sometimes utterly ashamed of the nightmarish bugs that infest every single aspect of the device

quote:

The tour de force of the Blitter is its ability to generate Gouraud shaded polygons

[...]

None of these work-rounds are very satisfactory, unfortunately.

Spatial
Nov 15, 2007

you can't use this instruction in this memory address range
you can't put this instruction after this other instruction. or this one. or that one. or...
you must put this instruction in front of this instruction, sometimes, but never other times
don't divide and then divide again this way. only the other way
multiply followed by multiply is okay. but not multiply and read the result. obviously
clipping doesn't work properly "in a fairly random manner"
clipping doesn't clip
"may corrupt other data in RAM"
memory access every six cycles. sorry i know i said it was two
hey kids! what's the deal with byte strobes??? you're not strobing bytes!
"This may move the problem [...] which may still cause problems."
don't jump in external memory. don't call in external memory. don't use external memory at all. kill you are self

Spatial
Nov 15, 2007

speaking of DMA, someone tell me if this is normal

i'm doing some graphics stuff on an nxp lpc4357. basically i'm using the dma as a scanline rasteriser using the scatter gather mode.

i made a benchmark to see how much i can wring out of this thing and it's not as good as i hoped:
code:
Test: 32KB transfer

M4 built-in memcpy transfer time: 26689 cycles
Bytes per cycle: 1.23 (61.39% of max)

M4 spatial memcpy transfer time: 18997 cycles
Bytes per cycle: 1.73 (86.25% of max)

DMA transfer time: 20705 cycles
Bytes per cycle: 1.58 (39.56% of max)
it's not bad but not very impressive. the dma has 32-deep FIFOs and 2 bus masters, and there is no other bus activity during the transaction because i put the M4 to sleep

Spatial
Nov 15, 2007

what io module has an accelerometer, gyroscope, rgb led, multitouch pad, 6 potentiometers and 14 buttons, but only needs four wires?



learning how to usb! :v:

Spatial
Nov 15, 2007

got everything working including the rumble and touchpad. feelin pretty good

the touchpad is impressively accurate, about 2000x1000 resolution on a 2x1 inch device.

there's a lot of bad information on the internet about the gyro/accelerometer. but it's easy to see what the values mean by rotating the controller on its axes and looking at the USB data.

Spatial fucked around with this message at 22:24 on Mar 9, 2018

Spatial
Nov 15, 2007

it's an NXP LPCxpresso board with an LPC4367 on it. kind of a cool chip with heterogenous cores, 1x cortex m4f and 2x cortex m0.

i also have a different one with an LCD controller but one less m0 core. i'm going to make a terrible game console out of it for fun.

Spatial
Nov 15, 2007

i spent a while setting up the memory protection unit in my M4. now instead of jumping to NULL and happily executing until it fucks itself up, i'll get an interrupt telling me not only when, but where it happened! i'm approaching 1988 technology here!

Spatial
Nov 15, 2007

this M4 only fires electrons :v:

another nice trick is allocating the stack at the start of memory instead of the end. can't overflow and corrupt memory because the MPU will catch it.

at my workplace the conventional wisdom is to put it at the end. that's not using your noggin fellas

Spatial
Nov 15, 2007

~for my technology~

i work with bare metal where's there's generally only one stack, i guess it's different in an RTOS where there's lots of stacks and their sizes may even be dynamically allocated

you could change the MPU regions during context switch. but there are all sorts of limitations that make it real awkward, like needing power of 2 sized naturally aligned regions, and there are only 8 of them.

Spatial
Nov 15, 2007

actually that reminds me, the newer Cortex M23 and M33 have dedicated registers for detecting stack overflow. it's a good feature.

they can detect stack corruption with a hardware-generated stack canary as well.

Spatial
Nov 15, 2007

speaking of aural fun, i'm working on the audio mixer for my babby console now. i've worked a lot with audio in the past but not at this level of farting around with the individual bits. it's pretty fun.

i'm aiming for 44.1 KHz on 16 channels with independent volume, panning and frequency + linear resampling. real state of the art stuff from before i was born

it's a bit of an optimisation problem because that's 705,600 samples per second with several DSP operations on every sample, and this is a microcontroller with no audio accelerator. that's a lot of cycles. i can always lower the peak channel count but that's no fun

i'm outputting over I2S to a Cirrus Logic CS4344 DAC. surprisingly good quality for $1.50!

Spatial
Nov 15, 2007

scopin' dat audio

Spatial
Nov 15, 2007

i got to know the M4's DSP instructions and made the core of the mixer in assembly.

> Channel mixed in 1856 cycles (14.5 cycles/sample).

maybe i can afford reverb after all :mrgw:

Spatial
Nov 15, 2007

Sagebrush posted:

well i started to reprogram the display but i am not sure it's happy about it

https://my.mixtape.moe/euksdx.mp4
this is awesome

Spatial
Nov 15, 2007

lol

have you considered not solving the problem and having even less money than before

Spatial
Nov 15, 2007

i got a PL2303TA usb-uart chip with a supposed max rate of 6 megs. actual max i was able to get: 480k. $1.20 folks

tried an FT232R with a max of 3 megs. works perfectly at the absolute max. $4.50 well spent

Spatial
Nov 15, 2007

lol windows waits 16ms after receiving data on the COM port to tell you about it

not so good when you have a device that responds in 0.003ms.

Spatial
Nov 15, 2007

code:
Running benchmark...

[################################################################]

Transfer:         2048 KB in 7.356 seconds.
Transfer rate:    278.41 KB/s.
Theoretical rate: 292.97 KB/s.
Efficiency:       95.03%
OAT errors:       0
it was 45% :mrgw:

Spatial
Nov 15, 2007

incredibowl

Spatial
Nov 15, 2007

SSE2 can do 16 of those per cycle. it's some variant of PSUB.

that includes the saturation btw

Spatial fucked around with this message at 14:19 on Oct 15, 2018

Spatial
Nov 15, 2007


full motion video, the latest in computer entertainment. it's 24hz 480x272 running on a Cortex M4. i could play the entire movie if i bothered to encode it. not shown but you can seek through the video using the PS4 touchpad

the colour is perfectly accurate in real life but looks extremely blue when recorded on my crappy phone camera. although i did have to colour correct the image for the LCD screen anyway, the blue level of the LCD is more than 200% of normal and looks like rear end otherwise

Spatial
Nov 15, 2007

when you don't know kung fu

Spatial
Nov 15, 2007

a little on how it works, since i like reading about these things maybe you will too!

the movie is dumped to raw pixels using ffmpeg, and then i encode it into a format that's simple enough to practically use on a microcontroller. each 480x272 frame has its own 256 colour palette and each pixel is one byte that indexes into it, a bit like a GIF with no compression. this is then written to an SD card.

the video data is streamed onto off-chip SDRAM via DMA from the SD card controller. the drivers for the DMA and SDC were so bad i had to rewrite them from the barely-documented hardware specs - all SD operations were blocking, which is terribad because there can be hundreds of milliseconds of latency at random intervals. smooth video is impossible under those conditions.

on each vsync interrupt from the lcd controller i start rendering a new frame. the palette is loaded first and then the inner loop loads 96 pixels at a time: the byte sized pixels are loaded into CPU registers, unpacked, their colour is looked up and they're written into the video buffer. the palette is loaded into fast single-cycle on-chip SRAM because SDRAM has very poor random access performance - when you consider that the indirect palette lookup runs 130,000 times per frame it really adds up. once all the pixels are blitted the double buffering pointers are swapped and the cycle repeats.

i wrote the video blitter in assembly and it cranks out a frame in 2ms, leaving lots of time to do other things besides drawing the video. it was an interesting optimisation exercise and is about five times faster than the C equivalent.

Spatial
Nov 15, 2007

does the IronWolf® come with a free t-shirt? :v:

Spatial
Nov 15, 2007

anyone know where i can get a board that converts parallel RGB to something like vga or hdmi?

i want to output a microcontroller's TFT display to a monitor. the opposite of this board on Adafruit pretty much

Spatial
Nov 15, 2007

the last one looks like it's sparkling because of the colour shifts, it's a very lively and cool look. also very demoscene :v:

Spatial
Nov 15, 2007

i was looking into making a circuit to drive a VGA output from my micrcontroller. turns out this is easy in theory because you can use a single component to do it, like the ADV7125.

i thought, hey, computers output 320x200 and that works so i can just pass that through directly. what i didn't realise is that VGA controllers do pixel doubling to do that, and monitors can't understand such a low pixel clock. apparently only the really old 80s style ones can do this. i can drive 640x480 from the MCU and that would work, but it would take too much memory bandwidth and reduce the capabilities of the device too much for what i want to do (a lovely game console).

so now what i'm going to do is something stupid. add another microcontroller that just does the upscaling and nothing else! 320x200 is slow enough (~6MHz) to sample if the GPIOs are hooked up appropriately. then that MCU can output the vga compatible signal.

anything is better than designing an fgpa circuit, at least!

Spatial
Nov 15, 2007

longview posted:

VGA monitors have no way to know what the pixel clock is though, if your sync pulses have valid timings the pixel data can be as slow as you want

you could probably use MCU timers to make the scan timing, and run the video generation at whatever rate you want
i tried this but all the monitors i have (and googling, most monitors period) won't accept anything less than ~31KHz horizontal scan rate. only the oldschool ones like for an Amiga will accept 320x200 in the raw (~15 KHz).

there's no reason a monitor can't accept any old resolution, but it seems like they use simple designs that just try to detect a few known formats from a table.

Spatial
Nov 15, 2007

oh cool, thanks for taking the time to explain it. i didn't quite realise what they were getting at. :)

drat nifty trick if i can pull that off on my MCU!

Spatial
Nov 15, 2007

ah nuts. one thing i can't replicate with my setup is dividing the vertical counter to match up the timing like he does. on mine the video output is generated by a hardware block that doesn't have that degree of flexibility. i can match the horizontal timing but not the vertical.

on the other hand, i can replicate the vertical timing by changing the framebuffer to be double height and duplicating the lines when i'm done drawing. it's a chunk of memory bandwidth but it's more acceptable to double it than to quadruple it like i would've needed to do before

Spatial
Nov 15, 2007

anyone know how tolerant HDMI/DVI are of very low resolutions? kinda curious what happen if i sent 320x200 through a HDMI transmitter

Spatial
Nov 15, 2007

i don't mean the connector but the actual HDMI transmitter IC. some that i've looked at only support a very specific subset of resolutions, most don't specify what they can do at all.

i did find one that does what i want though!

quote:

7.13.1 Pixel repetition
To transmit video formats with pixel rates below 25 megasamples per second or to increase the number of audio sample packets in each frame, TDA19988 allows pixel repetition to increase the transmitted pixel clock. Pixel repetition factor can be adjusted from 1 to 10.

Spatial
Nov 15, 2007

in the meantime i learned kicad and designed the VGA output. last time i made a pcb was with fritzing and it was absolutely terrible. this was much easier, kicad is pretty cool

Spatial
Nov 15, 2007

it sure looks like real HAM, the horizontal smearing is dead on

Spatial
Nov 15, 2007

Spatial posted:

in the meantime i learned kicad and designed the VGA output. last time i made a pcb was with fritzing and it was absolutely terrible. this was much easier, kicad is pretty cool



i had this manufactured! the real deal:


it works too!

Spatial
Nov 15, 2007

Sagebrush posted:

since i can't go flying
nice :)

i've been designing a much more complicated PCB than i've ever done before.

this is a development board / lovely game console based around a Cortex M4 microcontroller. there's a small FPGA to upscale the LCD video output of the MCU and output it to a HDMI transmitter. the front port USB is for a game controller. also like 20 LEDs, you gotta have them lights

i got a bit carried away and added everything i thought would be cool. it's been a hell of a learning experience.



many such layers

Spatial
Nov 15, 2007

while i'm waiting for my last project to get manufactured, i tried making a development board that is very small but still usable and cheap to make. this is the result:



it's based around the stm32g030, a 64mhz cortex M0+ with 8k sram and 64k flash. the pin headers expose 2x I2C, 2x UART, SPI, multiple 2msps 12-bit ADCs and up to 14 gpios. i added an 8-bit DAC and 2 megabytes of spi flash to make it more useful out of the box. also two buttons and leds for tinkering. can be powered over usb or directly from a li-ion battery

costs less than 10 dollars to make even in tiny quantities, which is less than many of the ICs on the boards i typically make :v:

Adbot
ADBOT LOVES YOU

Spatial
Nov 15, 2007

a key factor is that the choice of data encoding is made per row of the image. it's really slow to try all permutations so normal tools often use a heuristic. some just use a fixed encoding choice for all rows, usually paeth since it results in the best average compression rate.

good old DEFLATE is used for compression which has an effort setting of 0-9. saving PNGs is very slow even now so lots of tools compromise on that especially older ones, which is another avenue for improvement.

i've written a parallel PNG encoder before that massively speeds up encoding because i needed to deal with very large images. it compromises compression rate by <1% as a tradeoff because it has to split the data into multiple DEFLATE streams. i don't know how common this is

then there's a bunch of redundant headers tools can add. that probably only matters for tiny images.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply