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
Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.

Exitlights posted:

The next step is to figure out how to switch this with a transistor or relay using a microcontroller. I'm concerned about flyback voltage, which looks like it's going to be a problem with my starter.

I think in most cars you'd operate the starter motor via some sort of chunky relay, because it draws incredible current. However, you'd operate that relay with a transistor as per your diagram, if what you're doing is what I think you're doing (I was confused by the placement of the uC in the diagram, where it's powered from, etc.)

I think the location of the diode is fine for handling the inductive load too.

Edit: Oh, and if the signal's coming straight out an MCU/digital logic you'll want a resistor before the base of the transistor so as to not stuff too much current into its gaping maw.

Charles Ford fucked around with this message at 21:16 on Oct 6, 2010

Adbot
ADBOT LOVES YOU

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.

CptAJ posted:

Keep in mind that the other LEDs DO light up (even though they're not in the simplified code version). I think the output_high() function does the setup automatically.

It'd still be worth either investigating the C startup code your compiler is using or looking at the source to the output_* functions, who knows what they're doing. Perhaps before it calls your main it configures your chip with some outputs out and some in for some demo dev board. Do that or try explicitly setting the output anyway before deciding it's a dud chip or anything.

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.

Zo posted:

I recommend getting a USB breakout board for early testing from PC to PIC, like http://www.sparkfun.com/commerce/product_info.php?products_id=718

I'd also recommend the pure simulator in MP-LAB. It freaks out a lot, and doesn't support a lot of complex modules like the PIC USB stuff (which I use regularly) but it does simulate RS232 (reading to/from files) and supports simulated input and logic analyzer display for I/O pins, meaning you can test your bit-banging code entirely in the PC before trying it out in the real world. I've done this a number of times with lots of success, it's extremely handy (most recently to debug some PWM assembler not starting up properly)

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.

CptAJ posted:

This is great. So... how about PWM, can I do that with software too?

That's how I do it. I made a board to make the screen go up and down in my Mazda RX-8's OEM satnav hood - I got it with all the electronics missing, except the buttons and motor. I made a USB interface to these using a PIC, and the PIC uses PWM out of three inputs to control the brightness of the LEDs for each button (independently, so you could have open throb or whatever) as well as the brightness of the LCD backlight LED. The PIC has a PWM module but instead I just used a timer to generate a timebase. When the interrupt appears, I decrement a counter. If it hits 0, I toggle the state, and load the amount of time to keep the new state into the counter (the amount of time 'on' is the opposite of the amount of time 'off'). Works perfectly :)

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.

IsaacNewton posted:

So transistors don't have transisting (??) value, unlike capacitor and such? All I need is a small-ish transistor and pop that in then?

Transistors have a whole set of properties, like maximum voltage across them, switching voltage, gain, maximum current, etc. so you will need to pick the right one for the job. Otherws will be more able to help than I in that regard, though, for this specific situation.

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.

BattleMaster posted:

I figured there'd be overcurrent protection, at the very least to protect from devices that are greedier than the spec allows. Huh.

Sometimes there is, sometimes there isn't. In my experience about half my Apple-made hardware limited to 500mA, half did not. A car stereo with USB MP3 support did, every PC (all Intel chipset-based) did not. So you definitely can't rely on that - it's why when you buy random hardware like an external hard disk or silly USB monitor, it comes with a Ycable to connect to multiple USB ports, and the manual usually says "You may or may not need to connect it to multiple ports".

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.

babyeatingpsychopath posted:

Do I need current-limiting resistors anywhere? fuses? I'm bolting the transistors to an aluminum plate; that should be OK for heat sinking; they're only going to see 12V@1.25A.

Note that the metal tab on your power transistors may be connected internally (such as to base), so if you're bolting them all to the same aluminium plate, it'll short out your circuit.

Edit: You should also have current limiting resistors between the logic outputs and transistor bases.

Do B1-B4 represent the relays? If they're PNP transistors/P channel MOSFETs, I think maybe they should be connected straight to VDD with the load between them and ground (the "switching on" event for the P configuration being a voltage difference from the emitter attached to 12V and the base) although I am hardly the master of transistors/analog electronics.

Charles Ford fucked around with this message at 16:14 on Apr 1, 2011

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.

TacoHavoc posted:

I'm not sure if the 18F has this, but some of the nicer pics have high and low priority interrupts.

The 18F2455 I've been using has "high" and "low" indeed. In my code I left that functionality turned off though, as I didn't need the prioritisation. My code was 50/50, doing RF stuff in interrupts and actual USB/RF buffers in the main loop.

It supports a bunch of modes where the CPU can go to sleep to various amounts, where the peripherals can run off of the main clock, or one of the timer's oscillators, and so on depending on how low power you want it to get.

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.

Hillridge posted:

We actually have a design standard at work where schematics should not be drawn with 4 way intersections because it's too easy to confuse them with one line passing over another on printouts.

This is also what I do, as taught to me by my father, who was an electronics engineer for many years (and still technically is, except his work mostly do software now), and is what was done at many places he worked.

Given that I always found the Forrest Mims style of a little bump from the Radio Shack/Tandy books my dad gave me really weird, although a little amusing, looking. I do love those books though.

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.
I've been using Kicad for a few years. Initially (at least, since my early teens when I played with a DOS PCB app) I used Eagle, but I wanted more layers for a project and didn't want to pay, and their UIs actually feel similar once you figure it out. In that they're both pretty weird and kind of unpleasant from a UX perspective, but once you get used to it it's fine.

I did enjoy the mild association with CERN Kicad has, and being able to tell friends that I used the software CERN used for the LHC to design my PCB, but even that was kind of crashy for a while (e.g. some of their functionality only worked when in OpenGL rendering mode, and enabling that made it crash randomly for me), but it does definitely improve with time as people do seem to be working on it, and I'm pretty happy with it overall (e.g. the OpenGL crash has gone).

I do kind of wonder what I'm missing with the big pay-for applications though, I kind of imagine they must be magical for the price.

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.

ante posted:

They also had a bunch of stupid useless bullshit I never used, like FPGA integration

It's funny you should mention it, the "hobby" project (with a few users) I've been working on for a few years does have an FPGA, and the one thing I keep thinking would be really great would be if Kicad could "know" about that and automatically allow me to just shift around pins that are similarly specced/etc. so I could just make layout simpler instead of having to try some layout, note the way the traces are ending up, then updating that on the FPGA side and then in the schematic side to just get back into the PCB to finish off. The same might be cool of old school TTL chips/etc. of allowing it to just swap out the interchangeable parts of a chip.

Of course, Kicad is open source, so if I really cared I could just add this myself ;)

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.

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.
I started a design myself to use one of the chunkier Linux-capable/PowerVR-included TI chips, I wanted to make a portable with USB-C, PCI-e express, etc. and after all those my stumbling block was actually how to hook up modern DDR RAM. I've never hooked up modern, transactional RAM before (I've only ever really used old school static RAM where it's just parallel buses), and it was very confusing e.g. how to actually hook up the amount of RAM I wanted, like if I wanted to have multiple chips. I assume there's just some standard interface but I couldn't figure out the terms to Google to actually figure it out.

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.

Pollyanna posted:

Whoever came up with the idea of surface mount is a complete shithead. I hate this finicky bullshit.

My dad worked for Philips back when they were first making the push to surface mount (which I think as a company they were very invested in). He designed a PCB using the parts he was required to use, sent it off for layout and assembly, and when it came back, it didn't work at all...unless you pushed down on the chips. The assembly department were apparently still hand-soldering it as they either hadn't figured out or received the equipment to do it the "right" way. My dad still has a mistrust of surface mount due to all that business.

I've never had much bother removing surface mount chips, I just use a hot air gun to get it nice and loose (problem is sometimes small nearby components can also fly away, though it's fairly easy to control). Actually soldering the stuff down is a nightmare.

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.
I grew up with stripboard (it seemed very common in the UK, everyone used it, when I came to the US it seemed like everyone used perfboard and I had no idea why. It seemed even worse than wirewrapping, which at least has a little tool and doesn't involve soldering onto a tiny pad).

I've definitely started just ordering $3 runs of 10 PCBs from China or whatever if it's something with a bunch of wiring up to do (like recently I made a breakout board to plug the pod cables from an early '90s HP logic analyser, which were meant to plug straight into your 486 motherboard or whatever you were trying to analyse that would have the actual probe circuits built in, so I could just turn them into individual probes. 96 of them, in fact, via 12 separate PCBs).

I do still occasionally use stripboard for super simple things (like a traic to operate a contactor, or just hook up a 5V regulator and springed connector to a thing I 3D printed for my ebike to get power out of the "proprietary lighting system"). I don't really "plan" it though, I just kind of imagine how it should all work out perfectly, cut it out to be just the right size, make a couple of annoying mistakes, then it mostly works.

I did once try something a little more ambitious, when I was around 12 years old:



It's an attempt to build a Z80 computer, entirely on stripboard. There's buses and things in there, in the mess of wires. It had a separate I/O board meant to drive the keyboard recovered from an old trashed BBC Micro. It didn't work at all, but I borrowed an ICE from my dad's work (an old one - it was a long, narrow box filled with PCBs that ran the full length of it, with a pile of ribbon cables that ran out to a "pod". You could swap out the pod and its interface board inside the box for different CPUs, and it had an extremely delicate connector on a ribbon cable that came out of the pod that would plug into the CPU socket on your system. You then controlled it via a command line interface on an RS232 port on the back of the box). It told me multiple lines on all of my buses were tied together, after which I was filled with a kind of despair and never tried it again.

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.

Shame Boy posted:

I still etch my own boards sometimes because I'm a weirdo who likes fiddling around with things and also instant gratification.

Never been able to get that film photoresist to apply to copper clad properly though so I gotta buy the more expensive presensitized stuff. At least it works really well.

I tried making my own PCBs a few times in the 2000s, as I had much less money and Chinese cheapo PCBs were less of a thing (or at least, less obviously a thing I had access to). I tried the photoresist once or twice but ended up just using a laser printer on photo paper (there's also a dedicated product meant for this but plain photo paper worked better), using a clothes iron to transfer the toner. I even managed to do double sided a couple of times this way, though it took a few attempts to get the toner nicely aligned (I'd predrill a couple of alignment holes that had matching holes on the PCB image, so once it was transferred I could visually confirm. If you made a mistake you could just wash the toner off with acetone, re-clean the copper and try again).

I also used ammonium persulphate as it remained nice and transparent throughout the process. It also turns a lovely blue as it absorbs the copper.

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.

Splode posted:

The biggest gotcha when doing footprints yourself is some rear end in a top hat at the manufacturer putting a bottom view pinout on the sheet.

My favourite is when there's a diagram of the footprint, and it's got some weird shape, and they give you all the dimensions...but you need to keep doing mental arithmetic o get to the values you'd need to actually put it into a footprint editor.

That or the ones where they specifically omit whether it's top or bottom view of a non-symmetrical part, or it's a weirdly shaped part and they don't bother noting which pins are which.

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.

Rescue Toaster posted:

There are definitely 8 bit flash ADCs that have a full 256 comparators. But they still have a clock on the decoders and output because as you say, you have to know when to sample otherwise the output bits could be mid-transition and you'd have to worry about metastability poo poo on your inputs.

Obviously this is why you want your asynchronous ADC to use a Gray code! It's perfect!

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.
I tried OpenSCAD for a while but found it a little obtuse in making “nice” objects, though if you just want shapes arranged relative to each other it was fine. I was trying to make little gearboxes so I was also trying to use various open source gear libraries for it with varying success, but I did also find it was pretty easy to write programs for it that would cause it to just crash, usually if they involved curves as it has to generate a lot of triangles to make them look smooth.

I then tried Fusion 360 back when they had the startup license, and it was pretty good, but I didn’t want to continue with the “everything public/no commercial use/some features removed” hobbyist edition and switched to Solidworks, for which educational licenses could be had via various club memberships. After that was also promptly cancelled I tried FreeCAD but I’ve never really been able to figure it out compared to eg Fusion 360 so I’m kind of back to OpenSCAD again.

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.

Cojawfee posted:

You just have to change the alarm sound from "Warning: Bear detected!" to "Warning: Bear or an animal with similar food stealing tendencies detected!"

Still seems too specific, what if it’s a curious Bigfoot? Or murderous Wendigo? The message needs to cover all possibilities.

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.
When I was young and got some money from Christmas/my birthday I'd get my dad to take me to Maplin to pick up some Velleman kits.

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.
All the same board except the last one, a four layer PCB with components (including large ICs) on both sides, and a couple of throughhole connectors.

In the US I've tried:
- PCB.NG - won't assemble throughhole (at least when I tried) though that's fine as it's not fiddly. Had warnings about BGA but everything worked fine. I got the impression this is just like a one man operation, like he wanted to buy some PCB equipment for himself and running a business from it is just so he can.
- Macrofab - had good prices, but they've gone up a lot and so I'm not sure. Will do throughhole if requested and are pretty prompt once the components arrive.

In both cases, I believe the actual PCBs themselves were fabricated in China, but I don't know the factory.

In China I tried (and suspect are the same factory):
- PCBWay - the PCB was fine, and the assembly (including throughhole) was entirely acceptable, but they used the wrong parts in a couple of places (there were two types of IC involved, 74244 class, but different types for different bus voltages) and they just had all of the same type so they'd work for a few minutes before burning out. They gave me a store credit I never used. I used them on a second PCB of similar complexity but singlesided and it was fine.
- PCBGogo - same website design and identical quality to above. In this case I used them to make a giant keyboard PCB for a DIY hardware keyboard (there's a picture in the aliexpress GBS thread). They contacted me to say the PCBs were so long they were warping (which was very slight, when I actually received them) but I told them it was fine (and it was), so overall I assume they're acceptable.

For both the US ones they had a fancy web interface where you see your gerbers, can confirm the position of the parts, and other such stuff, and in both cases I found them pretty buggy. Generally fine, but sometimes incredibly problemmatic, so really you're still relying on contacting support.

For the Chinese one(s) there is no real "UI", just a webform you fill in and it sends some person your files, which they review. They send e-mails asking for details/clarification/substitution of components and generally I actually find it a bit better than the way the US ones work. They seem to be able to get parts from interesting sources - one of my PCBs was assembled in 2020 or so and had the correct FPGAs, but datecoded to ~2010, with the pre-buyout manufacturer's logo on them, so I wonder if they were just in some box in China at some component broker's warehouse or something. The US companies seem to primarily just use Mouser and Digikey.

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.
I've just got:
- Gould OS3000, an old analog scope (only does 40MHz)
- HP 16500C, an old logic analyser (CRT touchscreen with 192 digital inputs and two oscilloscope inputs as well as a timing card - worth 5 digits when it was new in like 1990, it's still very good if you need to capture an entire 16 bit databus, address bus and control signals. Can do "reverse assembly" (by which they mean disassembly) where you feed it datafiles you make with a DOS app still on the Agilent site, and has support for I think ELF symbol files, though I haven't used any of that, just a punch of signals for computer expansion ports and such and looking at the signals raw. The oscillloscope screen is laughably low refresh rate, but I'm not sad I have it or anything. I would like to get the ethernet card for this so I can use it as an X server and control it remotely)
- HP/Agilent 54622D digital oscilloscope (100MHz, but it's neat, as well as two analog inputs it has 16 digital inputs, and is way more responsive to signals than the logic analyser. Also has an asteroids game easter egg).

The one Tektronix thing I really want though isn't test equipment, it's a '70s computer, a 4050-series. Made famous in things like Battlestar Galactica with the storage CRT, the model with built in BASIC and a tape drive. They appear sometimes on eBay for thousands but I'm hoping I can get a more reasonable one if I just wait for a local surplus or something, though not really hopeful. I wouldn't mind a broken one (assuming the CRT is fine) to just fix.

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.

Shame Boy posted:

He also showed me his collection of TI part catalogues from the 80's and 90's but apparently some TI fanboy group online wanted those real bad so they can have them.

I have "The TTL Data Book for Design Engineers" that my dad gave me when I was little, it's like 1.5" thick yellow-covered collection of a bunch of things including datasheets for every TTL logic IC they sold at the time. It was very handy in my youth trying to understand digital electronics and use chips I'd recovered from old equipment (or my dad's collection of previously recovered chips) but it was also just kind of fun to look at and spark the imagination. As well as pinouts and descriptions, it had equivalent circuits and explanations for why things were the way they were, quite educational!

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.
I was looking at USB-C for a project I had where I want to make my own PDA. The chip (one of the TI ones with PowerVR) had SS support, but the amount of auxiliary junk you need is amazing - the chip for deciding which "side" of the USB-C cable to use (which talks to the other end and the cable, and also has I2C for your app CPU's USB drivers), the power chip (which also has to do your battery if you want a battery, and also has I2C for your app CPU's power drivers), the SS switcher chip (controlled by the decider chip), still have USB2 there for a laugh. I think I'm missing one or two.

I think I got it all wired up right but wasn't sure, but SS is supposedly too fast to just have jumpers to be able to rewire if I made a mistake. Doesn't matter anyway, after getting that, PCI-e and USB all finished I got a bit confused by DDR RAM and haven't yet returned to the project.

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.
The best thing I ever found with a thermal camera was a tiny 50Mhz oscillator IC which the assembly place had installed in the wrong orientation, so +3.3V was being fed into its output and its power input was ground. It was running at 120C or so.

I just desoldered it and for a laugh resoldered it in the correct orientation. It worked perfectly.

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.
I agree the labelling of nets/etc. is a nightmare, but i quite like the idea behind the nesting schematics to provide some kind of structure. Where I feel it fails is that it'd be good to have multiple instances of the literal same schematic so I could create a reusable circuit and keep copying it for things involving repetitive hardware. This obviously has many problems with at the very least annotation (and also PCBs - but it'd be good if the same modules could become blobs of PCB too, since they might all want the same layout, too), though they're solvable, but would require a lot of work so it'll never happen.

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.

ante posted:

Have you tried? I do exactly that, frequently. And then the Replicate Layout plugin to tile my PCB portion.


Anyway, the property editor was basically the last quality of life change to make KiCad on par with regular usage of Altium, from my memory of doing it professionally.

Now hopefully they move onto the RF and flex stuff, and so on.

I tried and was able to duplicate them, so each became a new sheet, but that means if I find a mistake I'd need to correct each separately. I'd like them to genuinely be the same, but I don't think it'd handle that?

Speaking of RF, I've only ever done digital and very basic interfacing stuff (so maybe a MOSFET to make a motor go, or a triac to turn on a bigger triac to turn on an incredibly scary contactor). My work apparently just added Coursera as a benefit and I saw a couple of courses like "RF electronics" and "power electronics" (I thought the latter might be interesting in terms of solar inverters and EVs), does anyone know if such things are actually any good?

Of course, for RF, my dad specifically put me off doing electronics as a career because of the intense maths, but still, I am interested.

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.

ante posted:

No, make sure each sheet is associated with the same schematic file on your filesystem. All changes will propagate through to all them.

Well, that's interesting, I'm not sure why it didn't work last time I tried it but I'll give it a go next time I need a bunch of something!

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.
I found the interface for Fusion360 relatively intuitive, and then when Autodesk dumped all the "startup licenses" and such, I tried Solidworks for a while as there was a brief window you could get a student license for that by membership in an organisation they had a deal with (such as the EAA), and its interface was understandable and somewhat similar, but then that deal abruptly ended too.

Every time, also before and during, I've tried to use FreeCAD, but the UI just seems unusable. I've done tutorials and all but it just feels like drawing teeth, it's shockingly bad. It's a shame as I do use KiCad and even before the recent improvements it was entirely usable.

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.
Well, I decided to try Kicad 7 on a fairly complex PCB I hadn't fiddled with much since 5 (mostly due to the chip shortage) and it certainly has changed a bit, mostly at random (menu items shuffling around, that sort of thing).

Main irritation is all the symbol names changed so I had to fix that, but I can't get it to stop saying "Footprint <x> does not match copy in library <y>" however much I try to re-set it. Googling that reveals people trying some 6.x beta and being told "it's a beta, don't worry about it". There was also a dialog open, full of changes, and pressing some other button in the main schematic window just lost all the changes without warning, so it's still got the usual niggles.

Other main irritation is that if I switch back and forth between my schematic and PCB layout in a certain way I haven't been able to pin down yet it just crashes, it's happened about four times now, so got to keep hitting that save button (though it does detect it crashed and apologises).

On the plus side I was looking to encheapen my PCB by making vias bigger/tracks more spaced/etc. and the DRC seems to have found over a thousand new things to complain about.

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.

Shame Boy posted:

Honestly the speaker idea makes a lot more sense and would prolly be easier to do, but I really love the idea of a big grid of relays ch-chunking like it's some 1940's telephone exchange sooo

Saw a guy at the Vintage Computer Fair one year that had built his own relay-based computer, and had one clacking away at his little stall. It sounded great, even if it was impractical for all but the most basic of computations. Looked great too as it had lots of LEDs to show state/etc.

He said he'd actually built a bunch of them to try different relays to get the best sound, and his favourite were a specific Eastern European brand that was quite a bit louder than the rest.

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.
The standard is definitely Lwip - it's not overly efficient and it has the occasional security vulnerability but implementing a TCP/IP stack itself is a big task (see the osdev.org forums for people who do that kind of thing as a hobby) and fraught with peril for the same reasons. Lwip can run in multithreaded or singlethreaded modes (and you can e.g. do your own multithreading on top of it in singlethreaded mode) and you just kind of plumb in a driver for the MAC/PHY in a single file, it's pretty convenient. I've seen many products use Lwip, including my Chamberlain "MyQ" garage door opener (the web server it briefly ran after setup revealed Lwip as its user agent), and I've used it at work and for hobby stuff too.

In my case I actually wanted to put a USB host-enabled project I had online so I connected an Amazon Basics USB2 (e.g. very slow) ethernet adapter to my PCB and wrote a USB driver for Lwip on my microcontroller. The hardest bit was NXP's crappy USB stack (licensed from some guy who made an Arduino USB stack, it had many bugs to find and a few broken assumptions about how USB works, at least in real world terms).

There's definitely books on "implementing TCP/IP from an Operating System Development" front, which seems to be what you're asking for, but as I mention, that's more rare than just using an existing solution (Lwip or something proprietary). However, if you *actually* just want to know how to do a network once you have Lwip fired up, it works almost exactly the same as on desktop except it's slightly less confusing (it's pretty much just "open a socket, do a thing", and Lwip actually has examples to do simple stuff as well as things like web servers (the web server example in Lwip is terrible and you can make it much better with some programming, too). Once place I worked I added all sorts of dynamic JSON generation and parsing to the Lwip server by using JSON templates that were precomputed into header files by Python scripts at build time that could then be run on the microcontroller in the field, which was a good laugh.

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.
I almost started implementing my own USB stack to replace that NXP one for host, the actual USB hardware on that range of microcontrollers (LPC1857-type range) just implements an almost completely standard EHCI interface (and the places it deviates are often improvements like using a speed translator instead of requiring a companion OHCI or UHCI controller to support USB1.1 devices), so it wouldn't be *totally* wasted work if I ever moved to another (standards-compliant) microcontroller or add USB to my homebrew OS. Weirdly, the various open source alternative stacks didn't (at the time, at least) seem to support the chip.

Sadly, I did then move to a microcontroller that seems to do its own thing for USB and isn't standard, but its provided stack also seems to work much better anyway.

But agree re: Lwip, do you really want to remove the code you disabled? On multiple different projects I've definitely had to go back and turn something on that I or someone else initially didn't think we needed!

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.
There's definitely been occasions where search catching the greyed-out-by-the-IDE code has helped me, like in figuring out bugs like a manager complaining he can't ping the board from his Windows machine and eventually hunting out that LwIP just has "support being pinged from Windows machines turned off by default" via macro.

But either way, I don't think there's any right or wrong answer here, it really is just preference, and the compilers hardly help. Recently on one microcontroller (I forget which) I found 40K of flash in Release mode (when the chip only had like 64K flash) was being used by the provided "configure system oscillators" function, which just took a few parameters deciding options. I was able to reduce that flash usage to 500 bytes or so in a way that made me feel a little dirty - copy and paste the source for the function into my file containing main. The compiler was then able to optimise for the actual parameters and get rid of the millions and millions of ifs it contained.

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.

PDP-1 posted:

I guess really I'm looking for the ARP/IP/UDP/TCP part. When you plug an Ethernet cable into the port what is the sequence of messages that go back and forth to establish the link, then reach out to a DHCP server to get an IP address, etc. Basically I want to understand the protocols well enough that I can look at a Wireshark screen and know if what's going on is correct or not.

For the Wireshark side you can run Lwip on Linux in userspace and see what it does (there's projects to do this on Github, via things like TUN/TAP). Wireshark will obviously tell you if you get your frames wrong too, since it'll highlight bad ones in red, so you can even hack it up and see if you can break the packets/etc. if that's what you want to try.

Basically in terms of Lwip, once the MAC RX/TX DMA is working, you just feed Lwip everything that appears in RX, and when Lwip calls you back to say it has something to send, you stuff it into TX without any thought. So this is still in the realm of "writing a TCP/IP stack", not that there's anything wrong with writing a TCP/IP stack of course (as a hobby - places I've worked would definitely balk at the suggestion for actual products both from a time and a security perspective), and I feel you should at least consider going and hanging out on the osdev.org forums where people love this kind of thing (do we have an osdev thread here? It seems like something some goons must have done).

As pointed out, there's RFCs for everything that happens beyond "I got a packet in from my MAC" and "I want to construct a packet I can send out via my MAC", which sounds like the stage you're at, so you can basically just send whatever you want now.

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.
Just don't, like, somehow attach them direct to the compressor or something until this ends up like some kind of old lady who swallowed a fly-type fridge situation.

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.
For Windows CE one of the tools Microsoft provided (which was required to actually ship e.g. a Windows Mobile device) was just a tool that'd click the screen at random and open/select menus (which it had special knowledge of, beyond just clicking the screen, to ensure it'd reliably trigger menu-based functionality). The longer it'd run (on the scale of like 24 hours or more) with multiple seeds, the more Microsoft were happy for you to ship your device. It would stop the moment it hit any crash.

I worked at a company that had a multiplatform product including Windows CE, and occasionally OEMs wanting to integrate our stuff would send these crash reports consisting of the tool, the seed they'd used, and the report that it'd crash in 7 hours. They were right, it did, but normally it was much easier to produce than their suggested "wait 7 hours" (though if they didn't happen to have any further info, we'd need to do that at least the first time).

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.

ante posted:

I've done it on an FPGA, but it requires a PLL - The smallest and cheapest solution is about $8 a chip for one of the Ice40s, and also needs 2(!) external clocks and flash memory and like, three different power domains, and it's huge. I've been able to get 16-bit control at 30kHz, however, which is phenomenal. But the rest of the cons are verging on dealbreaker.

The ICE40 chips I looked at have PROM, so if you're really sure you got it right you can blow one away and it'll forever contain your shame (they claim it can't be read by electron microscope, either) so you could do away with your flash memory. You can also run VPP_2V5 at 3.3V unless you're actually *writing* the PROM (when not writing, it has the same max rating as the 3.3V VCCIO inputs). Still two power domains though, as the core runs at 1.2V and the lowest I/O it can do is 1.8V.

When I used one I just had it driven by a microcontroller though, it stuffed the bitmap in via SPI each boot so I could change it later (and since it was baked into the firmware and not some random flash chip, it was also just one thing to update the whole board). I know people who've made tiny processors in those things, though, they're good fun.

You could also look at the Cypress PSoC ARM microcontrollers that have toy FPGAs in them (tiny "fabric" that's more like a really fancy I/O matrix, but enough to do PWM. Also Verilog only and the IDE will fight you if you try to use C++), or the chunkier Microsemi SmartFusion2 (which also has a handy self destruct mechanism), and are both surprisingly reasonably priced (though not as cheap as the ICE40s). The small SF2s (e.g. M2S005) contain PLLs too, I think, unlike the smallest ICE40s.

Edit: On the subject of doing it analogly I've seen it done with 555 timers, but I don't think that was attempting any kind of accuracy.

Charles Ford fucked around with this message at 05:56 on May 10, 2023

Adbot
ADBOT LOVES YOU

Charles Ford
Nov 27, 2004

The Earth is a farm. We are someone else’s Ford Focus.
I did that MITx free online "electronics intro" course that had all the stuff my dad (an actual electronics engineer) would have done at college like figuring out the sum at every node in the circuit to work out exactly how everything works and everything.

I forgot all of it, but I understood it at the time, so I still feel like I accomplished something and I feel like it did slightly improve my understanding of general electronics even if I'm still just doing digital stuff. Also it had a lot of homework and it was surprisingly hard.

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