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
namlosh
Feb 11, 2014

I name this haircut "The Sad Rhino".
I’ve been kind of halfway studying that stuff already via YouTube lol. Anyone have a good learning resource for just enough assembly to be better at C?
I don’t think I’ll ever want to actually program a project in it or anything, but I’ll bet you’re right that it’ll help immensely and I’ve got the interest.

I figure an emulator would be good along with some follow along exercises. I probably need to watch a bunch more of Ben Eaters channel lol

Adbot
ADBOT LOVES YOU

CopperHound
Feb 14, 2012

namlosh posted:

Anyone have a good learning resource for just enough assembly to be better at C?

I wouldn't subject myself to trying to learn assembly. Maybe Check out some mircocontroller data sheets? Amtel puts the equivalent C and Assembly side by side.

Idk if it exists, but a tool that helps you step through and visualize what is happening in a stack and heap would probably be more helpful than just trying to learn assembly.
I'm not sure you exactly need assembly to show "now that you are trying to concat two strings character arrays you need to find another contiguous piece of memory that is big enough."

CopperHound fucked around with this message at 20:51 on Jul 27, 2022

BattleMaster
Aug 14, 2000

I recommend an architecture that has a small instruction set (so you spend more time programming and less time studying the instruction set) and available simulators. I know from my own experience that 8-bit PICs are fairly easy to get into with the official tools and have a very small instruction set.

If you want something more classic, the 6502 has a fairly small instruction set but I don't know the state of its simulators other than obviously having numerous emulators for specific microcomputers and game consoles available. The Z80, which I really love, has adequate free tools available but the instruction set size and number of available registers are daunting if you have no experience. I don't know how AVRs are but I bet they're okay for this too.

Ideally you want a simulator that can step through your code instruction by instruction and show you the contents of CPU registers and RAM. You can do a lot of stuff just by storing the results in a known location in RAM and eyeballing a memory listing to see if the expected result is there. For instance, if you have a loop that increments the contents of a specific RAM location, you can step through the loop one at a time and see if the memory increments as expected.

The simulator in Microchip's MPLAB X IDE can do all that.
http://www.z80.info/z80emu.htm The Zemu program here worked well for me ages ago, and the current version has a lot more features than I remember.
https://www.oshonsoft.com/z80.php is a slick looking z80 simulator from someone who also makes ones for other architectures, but they're commercial.

One suggestion I have for an exercise is to copy a text string of a known length to a known location in RAM. This will be a good introduction to how memory pointers in a loop can be used to traverse through a block of memory.

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
The godbolt compiler is great for testing out small stuff.


Having a working knowledge of how assembly works is super useful, but that kinda just comes down to understanding the five or ten basic op codes that every instruction set includes, along with the 3 or so addressing modes.


"Learning" assembly is a gradient and you'll never get 100% there, but understanding it is easy

Cojawfee
May 31, 2006
I think the US is dumb for not using Celsius
There's a modern version of the 6502 that allows for stopping and stepping the clock so you can easily debug it if you need to.

BattleMaster
Aug 14, 2000

https://www.autometer.de/unix4fun/z80pack/

I just found this and have been playing with it on my Linux machine. The generic z80sim it contains is text mode only but seems pretty full featured. I'm still trying to figure out what I need to do to compile the micro simulators with the front panel GUIs :eyepop:

namlosh
Feb 11, 2014

I name this haircut "The Sad Rhino".
Thx for the input everyone. And yeah just to be clear, I’m in no way trying to really learn assembly in any appreciable way. I just want to know enough that it helps learn C and microcontroller programming better.

Funny enough, a super on topic video came up in my recommendations on YouTube. I’m halfway through and it’s pretty good so far so I thought I’d share:
https://youtu.be/Zt0JfmV7CyI

23 assembly instructions total lol

Shame Boy
Mar 2, 2010

You can generally get gcc (or whatever compiler you're using) to spit out assembly instead of bytecode too with a certain command line flag. I found it pretty helpful to write some simple functions or whatever in C and then see what that became in assembly.

e: This is also real helpful if you think you've come up with a clever optimization and want to see if your optimization actually translates into less poo poo for the processor to do or if gcc's (already pretty darn good) built-in optimizations were doing a better job than you and you just made everything worse. I'd say about 80% of the time it's the latter.

Shame Boy fucked around with this message at 23:23 on Jul 27, 2022

CopperHound
Feb 14, 2012

namlosh posted:

23 assembly instructions total lol
Woah, multiply and divide instructions?! That is getting fancy.

BattleMaster
Aug 14, 2000

There are a few different theoretical one instruction computers out there. They're mostly unusably clunky (like "subtract and branch if not equal to zero" which requires four operands) but I really like the idea where the one instruction is "move the contents of address a to address b" that interacts with the ALU, program counter, memory pointers, and such via memory-mapped registers. Each instruction is the size of two memory addresses so it isn't super svelte but I like its simplicity.

cruft
Oct 25, 2007

Shame Boy posted:

Yeah memory management is especially hard for C++ on microcontrollers because you just kind of have to know the poo poo that's ok and the poo poo that's dangerous (but nothing will tell you is dangerous), and a lot of the dangerous poo poo is stuff that you're supposed to do when you use C++ anywhere else, just to make it worse.

I still think the decision of the Arduino folks to use C++ instead of C was a mistake. new is part of the core language definition, malloc() is just a library you can not include.

BattleMaster
Aug 14, 2000

The Microchip libraries for their 8-bit PICs don't even implement malloc because they felt that there isn't enough RAM for it to be worth it. Though they now have AVR and PICs with 8 and 16 KB of RAM which is in the territory where maybe that will be rethought.

I've also never written anything for an embedded platform that would benefit from the extra features of C++ over C, but I guess that's a me thing.

Foxfire_
Nov 8, 2010

There's a lot of quality-of-life advantages to using C++ over C (but also footguns to avoid). I'd rather have a template class Queue<ItemType, MAX_SIZE> then copy/paste implementation for different types & sizes or try to jury rig some macros.

For assembly stuff, there's a couple of distinct goals, some of which I think are obsolete/only as a curiosity. There isn't really a reason to learn/get experience with patterns for how to structure a large assembly program to be understandable and maintainable. For example in the Apollo 11 guidance computer assembly there's a bunch of baked in knowledge about how to organize the program and generally do things.

Practical modern assembly tasks are things like "Starting from the reset address, do initial clock/memory setup, copy things from flash to RAM, set up the environment C code expects, then jump to main" or "Hand optimize a particularly important region that interfaces with a larger C program"

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS

Shame Boy posted:

You can generally get gcc (or whatever compiler you're using) to spit out assembly instead of bytecode too with a certain command line flag. I found it pretty helpful to write some simple functions or whatever in C and then see what that became in assembly.

e: This is also real helpful if you think you've come up with a clever optimization and want to see if your optimization actually translates into less poo poo for the processor to do or if gcc's (already pretty darn good) built-in optimizations were doing a better job than you and you just made everything worse. I'd say about 80% of the time it's the latter.

Also posting this again in case people missed it the first time

https://godbolt.org/


Even see how compiler versions changed over time!

Edwardly
Jun 28, 2011

I have zero formal EE training. Is there an easier way to design high speed data lines on PCB in kicad than taking EE classes to fully grok differential pairs to solve the impedance problems during routing? (I barely understand half the words I even used there)

I have created a few PCBs now for other use cases but need to handle eDP lanes / USB data lines for a hobby project.

Like is there a guide for idiots I can follow?

Pham Nuwen
Oct 30, 2010



I've got an old portable computer here with a broken power supply. Tried recapping, no luck. Before I make even more digikey orders, I'm wondering if I might just be better off replacing it with something modern. The only caveat is that it needs to supply +15, +12, -12, and +5 volt levels. Anyone know of a smallish module that could give me what I need out of the box?

CopperHound
Feb 14, 2012

Edwardly posted:

Like is there a guide for idiots I can follow?
I'm curious to see what you find. I don't think I've done any circuit board stuff higher speed than usb2, but I have used a TDR enough to see what causes problems in cabling.

Try to keep balanced signals close, parallel, and the same length.
Try to keep unbalanced signals surrounded with ground plane.
Avoid sharp edges and T connections/dead ends.

That's all stuff you probably already read about, but it is worth getting down just in case.


As an example for balanced signals:
For Ethernet, you would want to aim for your traces to be these pin pairs: 1&2,3&6,4&5,7&8
As opposed to 1-8 laid out in a line.

CopperHound fucked around with this message at 20:27 on Jul 28, 2022

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
USB 2 is quite forgiving, keep the lines short and you won't really have a problem.


I would expect eDP to be ambitious, but I've never done it myself.

Spatial
Nov 15, 2007

Edwardly posted:

I have zero formal EE training. Is there an easier way to design high speed data lines on PCB in kicad than taking EE classes to fully grok differential pairs to solve the impedance problems during routing? (I barely understand half the words I even used there)

I have created a few PCBs now for other use cases but need to handle eDP lanes / USB data lines for a hobby project.

Like is there a guide for idiots I can follow?
I have no training either but here's what I've done.

Before I did anything I took a look at various other known good boards and checked out what they did.

For the layout parameters I took the inputs from my PCB manufacturer's layer stackup and plugged them into an impedence calculator where I then fiddled around with the parameters until I got practically applicable width and spacing.

I used a 4-layer PCB, avoided putting breaks in the ground layer under the diff pairs, kept other traces away from them, kept all the pairs on the same layer as the chip, matched the lengths of the pairs closely when there were multiple pairs, and made the distance to route as short as possible to begin with. If the video output pins are practically sitting on the connector pins I doubt it even matters how you route it.

This method has worked fine for USB2 and HDMI so far. I also had no problem using USB2 on a 2 layer PCB when I kept the distance short.

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.

Edwardly posted:

I have zero formal EE training. Is there an easier way to design high speed data lines on PCB in kicad than taking EE classes to fully grok differential pairs to solve the impedance problems during routing? (I barely understand half the words I even used there)

I have created a few PCBs now for other use cases but need to handle eDP lanes / USB data lines for a hobby project.

Like is there a guide for idiots I can follow?

In the KiCad project window, in the list of tools where the schematic editor and pcb editor are, is a button called Calculator Tools. Inside of Calculator Tools is a tab called TransLine that can calculate impedances for a bunch of different geometries, or tell you the geometries that give a specific impedance value.

Knitting Beetles
Feb 4, 2006

Fallen Rib

BattleMaster posted:

I recommend an architecture that has a small instruction set (so you spend more time programming and less time studying the instruction set) and available simulators. I know from my own experience that 8-bit PICs are fairly easy to get into with the official tools and have a very small instruction set.

A small instruction set can make things harder because now goto can be a conditional jump based on flags. You really need to start commenting a lot.

I made a WS2812B RGB led driver for a 32 Mhz 8 bit PIC in assembly as an exercise a while back. Although the result is satisfying (it simply doesn't work in C) the code is unreadable.

Splode
Jun 18, 2013

put some clothes on you little freak

Spatial posted:

I have no training either but here's what I've done.

Before I did anything I took a look at various other known good boards and checked out what they did.

For the layout parameters I took the inputs from my PCB manufacturer's layer stackup and plugged them into an impedence calculator where I then fiddled around with the parameters until I got practically applicable width and spacing.

I used a 4-layer PCB, avoided putting breaks in the ground layer under the diff pairs, kept other traces away from them, kept all the pairs on the same layer as the chip, matched the lengths of the pairs closely when there were multiple pairs, and made the distance to route as short as possible to begin with. If the video output pins are practically sitting on the connector pins I doubt it even matters how you route it.

This method has worked fine for USB2 and HDMI so far. I also had no problem using USB2 on a 2 layer PCB when I kept the distance short.

I'm an EE and I lay out high speed controlled impedance stuff most days. I'm not an absolute authority on it, but I know enough that my designs usually work. I didn't study it at uni (mechatronics didn't go that deep) but I've learnt it on the job. The above advice is all bang on.

You can get pretty detailed rules from the official spec of whatever protocol it is (eg mipi or USB), also many chip manufacturers will write some pretty good application notes. Texas Instruments usually write every clear and straight forward stuff.

The only things not mentioned in the above post is:
Sometimes you need length matching in signal pairs and between pairs. Hope to God your software can work this out for you (Altium does, I'm sure KiCAD does or has a plugin for it). The details on length matching tolerances will be in the spec. If they give it in time, you'll need to calculate it based on the speed of light in copper which is pretty cool, but likely they'll give it to you in distance to save everyone time.

Also no sharp bends in your tracks, avoid changing layers if you can.

Also, tell your pcb manufacturer you want controlled impedance, and if you can (if it's not a pcbway style form) tell them which tracks they are and what impedance you want. It'll cost more but they've got ways to ensure and test to make sure it's the right impedance. Sometimes they'll even tell you the track widths to use. If they do, use this over any of your own calculations: they will adjust stuff to make their widths right.

Next and final piece of advice: don't be afraid! You will get away with some pretty bad stuff, most of the rules are more guidelines. There's always more you can do to get a better signal, bur many modern protocols have ways to unfuck your horrible hardware: USB has very robust lost packet handling, ddr busses for ram often have circuitry that can adjust the termination to correct for non ideal impedances, etc. You have to do a really poo poo job for it to straight up not work. If you need it to work perfectly all the time, that's when you need to follow all the rules.

Also if you post your high speed layouts here I'd be happy to have a look. It's at least more thread relevant than firmware chat (C forever on microcontrollers, all stack no heap easy peasy)

Splode fucked around with this message at 14:15 on Jul 29, 2022

Shame Boy
Mar 2, 2010

Yeah I basically used this thread's recs and a bunch of app notes to design a GPS time standard board a while ago that not only receives GPS shockingly well but outputs a near-perfect 10MHz square wave with no weird glitches or reflections or over/undershoot or anything, and I'm just some random rear end in a top hat with no formal training. Just following the basic rules of thumb that have been posted, using a few calculator tools, and following the datasheet's application notes as close as you can is usually enough to give you a stellar result even if you don't fully understand how :v:

longview
Dec 25, 2006

heh.
Anyone know where I can find actually detailed drawings for making EuroCard PCBs (with DIN41612 plugs)?

I can take a guess based on measuring what it's supposed to fit in (an old TrueTime XL radio clock), but having some actual drawings for a standard card with hole/connector locations would be useful.

A Real Happy Camper
Dec 11, 2007

These children have taught me how to believe.
what are some good resources for learning how to work with a 555? I want to eventually make it do fun things with blinky leds, but for now I just want to make it work.

DC to Daylight
Feb 13, 2012

A Real Happy Camper posted:

what are some good resources for learning how to work with a 555? I want to eventually make it do fun things with blinky leds, but for now I just want to make it work.

For making it work, I'd use the datasheet from TI:

https://www.ti.com/lit/ds/symlink/lm555.pdf

Not too many good app notes though. A google search showed plenty of compilations of circuits, e.g.:

http://www.555-timer-circuits.com/

Also worth noting, a 556 is two 555's in one package.

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
Also pay close attention to frequencies and component values. It's tricky to get the output frequency low enough to be visible without using absurdly large values of resistors and capacitors. Chaining two together makes it easier

Stack Machine
Mar 6, 2016

I can see through time!
Fun Shoe
If you're trying to figure out which circuit to start with, I like this one. I think it's on that website as "simplest 555 oscillator.":



The schematic on the right with the Schmitt trigger inverter is just an equivalent circuit to the one on the left with the 555 (minus the LED). In this application the 555 is just doing the job of detecting when the voltage on the capacitor gets to of 1/3*VCC falling and 2/3*VCC rising. You could make the same circuit with something like a 74HC14, but the frequency would vary so much from chip-to-chip and over temperature that it wouldn't be too useful. Still, if your goal is to make a lot of LEDs flash and you don't care that the speed changes on a hot day, keep in mind that you get 6 oscillators in one 74HC14.

I built it just in case you wanted to see what a very-low-effort assembly of one of these things looks like. Flashes at about 5Hz. In general, the period should be around 2*R*C.

Pollyanna
Mar 5, 2005

Milk's on them.


I’m looking to be a huge loving moron and try my hand at building a voltage-controlled oscillator (VCO). The first thing I thought of was whether there was an IC I could shunt all the hard work off to, and it seems like the CEM3340 and its offshoots (namely the AS3340) were designed for that exact purpose.

Unfortunately, I can’t find either anywhere on Digikey, Jameco, etc. Are these difficult chips to source? Where should I look? Am I better served looking for a different kind of chip? Am I way off base to begin with?

Edit: ended up looking at a different chip - the SSI2131. Also considering whether I’m actually up for doing this in the first place…

Pollyanna fucked around with this message at 19:30 on Aug 4, 2022

CopperHound
Feb 14, 2012

I'm thinking about moving on from attiny85 as my go-to cheap rear end mcu. While figuring out how to bit bang 1wire protocol is a fun exercise to make use of only 8 pins, it does discract from my project goals.

I was looking at the micro pi. The price is right and the .1 pin spacing is good for prototyping, but the dormant power consumption is in the mA instead of uA range. I do lean on MCUs for battery powered data loggers, so I'd prefer an order of magnitude less deep sleep power consumption. The rp2040 chip alone is better about that, but I don't want to wire up external flash and an oscillator for every project.

Do any of you have other go to chips that require minimal support circuitry, have a good powered down standby state, and are well documented?


E: maybe I should just get a micro pi and try cutting traces to the buck-boost regulator and voltage dividers to see how that effects current consumption.

CopperHound fucked around with this message at 19:25 on Aug 4, 2022

BattleMaster
Aug 14, 2000

What about upgrading to an Atmel micro that has more pins and more other stuff in it? Microchip is still developing and manufacturing new Atmel micros so there are a lot to choose from.

Cojawfee
May 31, 2006
I think the US is dumb for not using Celsius
I agree, why not just get an atmel chip with more pins? You're already familiar with them.

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
ESP32 modules


Go big

namlosh
Feb 11, 2014

I name this haircut "The Sad Rhino".

As someone starting out recently, so take it with a grain of salt.
I agree. One of the things that made me want to look at Atmel (after arduino) is the crazy amount of variants they have for different clock, memory, pins and other features.
Are the ATTiny and ATMegas really that different in terms of programming/code?

e:

^^^^^^^^^^ that though lol
ESP32 is awesome. So many more fun things to do with WiFi built-in.

namlosh fucked around with this message at 19:43 on Aug 4, 2022

CopperHound
Feb 14, 2012

I guess I am just seeing stuff like ARM and ESP being super powerful for the price, and was wondering if there was something like that but as easy as amtel to integrate.

Last I looked at ESP the documentation was not great, but I might give it another look.

namlosh posted:

Are the ATTiny and ATMegas really that different in terms of programming/code?
Pretty much the same aside from some different special registers depending on features supported by chip.

CopperHound fucked around with this message at 20:03 on Aug 4, 2022

Foxfire_
Nov 8, 2010

Now is weird because highly useful/cheap/easy/well-documented/widely used microcontrollers are also in indefinite supply chain hell. You kind of want to get something exotic for hobby stuff just so you can actually get parts.

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.
I've been waiting for the Microsemi SmartFusion2 chips to come back in stock for ages, and they're a wee bit exotic.

Marsupial Ape
Dec 15, 2020
the mod team violated the sancity of my avatar
https://www.goldmine-elec-products.com/ is a good place to find odd parts.

Splode
Jun 18, 2013

put some clothes on you little freak

Foxfire_ posted:

Now is weird because highly useful/cheap/easy/well-documented/widely used microcontrollers are also in indefinite supply chain hell. You kind of want to get something exotic for hobby stuff just so you can actually get parts.

Yeah normally I'd recommend ST for 32 bit microcontrollers, because they're cheap and have a pretty good tool chain. But pretty much their whole range is out of stock at the moment and has been for over a year. My other favourite, the ATMEGA32U4 is also out of stock at this point.

Adbot
ADBOT LOVES YOU

CopperHound
Feb 14, 2012

Wow, I haven't actually gone shopping for this stuff in a few years. It is wild to see a 0 next to the stock for all these mainstream MCUs. Is this the large process crunch I've been hearing so much about?

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