3rd Nov 2021 - Having decided on the new ATtiny 1604/1616, with the avrxmega3 core, for the spitfire instruments it was time to update the Arduino IDE and work out how to physically connect and program using the new UPDI interface.
I found an excellent primer on bitlunis channel on youtube https://www.youtube.com/watch?v=AL9vK_xMt4E this provide a link to Spence Kondes github site which has guides for building one of 2 programmers.
WARNING 16 Nov 21 - I have just lost 2 days debugging the motor board because Google Images serves up out of date Arduino PINOUT charts, the initial proposal and not the final accepted version; which has renumbered all the digital Pins with the exception of 0 to 3. So motor channel 1 worked out the box but motor channel 2 was was not working and it took a long time debugging the wrong pins before finding the output 2 pins over !
I originally built the older Arduino nano based programmer which has since been superseded. This is basically a Nano, plus sketch, plus a 4K7 resistor (WRONG ! Buried deep in the notes is an update saying reduce this to 470R ). This programmer worked a few times, so I built it onto a board soldered it up and it worked a few more times then started giving me errors. Some of which were my stupidity (more below about that) but others I was not so sure about. This design is known to have problems syncing with the ATtiny and most of my problems were sync errors.
So this evening I read up on the newer serial adapter method. Yesterday I had ordered the recommended CH340G adapter from China with the intention of building one in a few weeks/months time when it eventually arrives. But with the unreliability of the Nano I decided to repurpose another adapter from stock.
Following a long search of all my organizers I found I owned 3 serial adapters
CH340G ESP01 programmer that I could just not work out the wiring of, so dropped that one
An "FTDI" 6 pin adapter with a sanded down 28pin chip (this shows up as a PL2303 in my System Report)
A D-SUN 5 pin adapter with a PL2303 chip
Unfortunately there are no instructions for the PL2303 in Spences guide
https://github.com/SpenceKonde/AVR-Guidance/blob/master/UPDI/jtag2updi.md
However his notes do say that most adapters should work. So I decided to give the D-SUN a go. After metering the TX and RX lines I determined that this was one of those rare boards which do not have a current limiting resistor on the TX line.
So I wired up a scrap of board with a 1N4148 diode and a 470R resistor used the 5V0 rail rather than the 3V3 rail and connected it up to a 1604. I changed the Arduino IDE programmer option from jtag2updi to SerialUPDI with 4.7K resistor or diode.
Initially I rather optimistically tried the (230400 baud) option which did not work. So I switched to the SLOW (57600 baud) option and that worked. I suspect that the PL2303 chip (which may well be a fake/clone) is not that fast, but it does work !
But when I switched the Arduino IDE configuration over to the 1616 I made a couple of mistakes..
First I changed the board to the correct family but left the default chip as 3216. When I tried to write the compiled the code checked the chip id found a mismatch and refused to burn, returning an error. Nothing new, I had made the same mistake on the old jtag2updi when I tried to burn the blink sketch.
The second mistake that caught me out was that there are actually two Board entries that support each chip type, depending on if you have burnt optiboot on to the chip or not. Of course I had been using the wrong one all afternoon. I wonder if I had removed optiboot when I burnt the blink sketch....
I have since added some socket headers to the board replacing the 3 wire connection making programming a lot simpler and quicker.
4th Nov 2021 - Next up is to check out the serial output, for debug prints, theoretically I only need to wire PB3 (RXD) & PB2 (TXD) to the PL2303 board's RXD and TXD. At some point in the future I will have to investigate the onboard debug provided on the UPDI/Debug pin.
But watch out! Unlike PA0 to 7 which remain in the same relative pinout positions at the top of both chips, PB2 and PB3 move pins between chip packages.
Looking at Spence's breakout boards he has the ATtiny TX connected to FTDI TX not swapped with RX so that is what I will try first...
3 hours later. Oh boy that was fun, not.... When I soldered the two ATtiny's onto their SOP-to-DIP carriers (for use on my plug boards) I managed to miss pin 7 on the 1604 and pins 9 and 10 on the 1616 - so both test boards were missing their TXD pins. But because the pins were directly above the pads the TXD data was coupling capacitively at around 100mV's, making me think I had blown the output drivers. It was only when I 'scoped the chip pins directly that I realised my error.
Both my PL2303 board's work happily TX connected to TXD.
11th Nov 2021 - I have been having fun with the RXD connection on the PL2303 stopping the boot sequence on the 1604. For some time I was puzzled by this, but facebook (many thanks Gray Mack) came to the rescue. The PL2303 RXD line is held high (5V) and was providing some some parasitic power to the ATtiny when I pulled the 5V to reset it, resulting in a hung ATtiny. I have found a workaround by putting a 1K5 resistor in series with the RXD line. Again this was purely my own stupidity, but as the Serial is for debug and configuration only it will not be an issue in the final project.
The ATtiny Serial works just like any other Arduino's hardware Serial, so coding is cut and paste.
Given that the other PL2303 (on the UPDI line) seems limited to 57,600 baud I have stuck to that for Serial Comms.
4th Nov 2021 - Both the 1604 and 1616 have 256 Bytes of EEPROM guaranteed for 100K writes only. If this was to be changed frequently then we would need to write some code to move the configuration around the EEPROM to lifetime load level it. But in our case we only need to set a few parameters when installing each gauge -
the device address
the zero offset
engine off position (voltage, brake gauges & fuel )
gauge 100% offset (temperatures, pressure, fuel)
some kind of acceleration factors (to stop the gauge jolting between steps) .
The rest can hopefully be in the 16K of program flash memory.
? Choose - Send configuration instructions via serial or I2C ?
For now just #include <EEPROM.h> and the standard EEPROM.read() etc.. work flawlessly.
Note: AT some point we also need to change compile settings to burn the EESAVE fuse to avoid the EEPROM data being overwritten with every code update.
8th Nov 2021 - I had great difficulty getting this working mainly due to some poor wiring connections and the serial RXD hanging the boot sequence. But once I sorted those this was effectively a simple digital 3 wire connection Reset, Direction, Step. There are some simple timing constraints that need to be coded and the VID6606 needs a pair of capacitors to avoid lockups 10uf per motor and 100nF per chip.
16th Nov 2021 - Getting the second motor working was just as difficult as I was using the wrong Arduino Pin definitions, thank you Google Images for giving me proposal level Arduino pinout definitions and not the final drawings.
25th Nov 2021 - The same code and wiring also works for the X12011728SG 4-way motor driver chip. This chip seems to run the X.27 motors more quietly - but at the cost of real estate - the chip is a 20 pin wide SOP-8
This image, which I was working from, comes from Issue 24 on Spence Kondes Githib site and I now know is the original proposal artwork which was subsequently modified
This image comes from Spence's Drazzy shop on Tindie.com and shows the updated Pinout Number's for the Analogue/Digital Pins
So that leaves testing
the I2C (or possibly the SPI) interface for receiving the target needle positions from the Teensy USB listener board. However Spenecs Github site states that there may be issues with the Wire Library - we will have to see...