Autor: dvalin Data: Dla: dng Temat: Re: [DNG] C vs ADA : advice sought
On 01.10.24 22:24, Joel Roth via Dng wrote:
> Erik Christiansen via Dng wrote: > > On 8-bit microcontrollers, the KISS principle is key to survival. There > > is no fat for surplus fancy stuff. But go to an ARM chip with reams of RAM > > and program memory, and you can pack the piano in your luggage for the > > trip. So, is the aim an ocean liner cruise, or wilderness canoeing? > > Hi Erik, > > Tho I don't program for microcontrollers, reading your text > I find great introduction to the issues involved, and > helpful in thinking about programming in general. > > I live almost entirely in the world of "cotton wool" and it > helps to know how to think about things when some or other > thorn pokes through.
It seems to me a bit like being in the infantry, rather than in the
navy, on an aircraft carrier with AWACS overhead and a swarm of F35s in
three rings screening out to 300 km. Both the reconnaissance and the
actions are distinctly more immediate.
On the current project, a 230 Vac "excess solar only" power diverter for
my HWS (Hot Water Service, probably called a "Boiler"? in USA), I
connected a simple zero-crossing detector to the ATmega16's INT0
external interrupt pin, for AC frequency measurement and minimum
interference Triac (power switch) firing. But on turning from hardware
design to software, while the PCB was being made, I found it would have
been better to use another input (ICP) which can trigger an
instantaneous snapshot of on-board hardware Timer1, into a 16 bit
capture register pair, for software reading at a slower pace. (I'm
running Timer1 at 4 uS ticks to count the nominal 50 Hz half-cycle
duration. If it has shifted significantly toward 53 Hz (possible only
off-grid) then the battery inverters are throttling back the AC
inverters due to an excess of solar generation over consumption. That
throttling method is an industry norm, here down under. Dunno what's
done where you don't have to dodge kangaroos on country roads at night.)
But closer reading of the 323 page microcontroller datasheet revealed
that even while pin6 on I/O port D was configured to the alternate
function of ICP (timer capture), it could *simultaneously* be configured
as an output pin. That should allow me to software set the pin in the
INT0 ISR, synthesising the desired ICP response despite a missing
physical connection, so the hardware convenience is utilised, without
having to chop PCB tracks and run ugly little wires in fiddly fashion.
If that vaguely resembles rebuilding an aircraft after take-off, then it
shouldn't surprise that working pointers hard is not even slightly
scary.
Why not just buy one? Well, the commercial diverters assume a grid
connection, and use power export to the grid as a measure of solar
surplus. That's not much use when there's no grid. Until my unit is up
and running, it's a matter of switching the HWS off before sunset to
avoid flattening the house battery unnecessarily, though at 46 kWh, it'd