One last thought for TIMERA, before moving on to B2.
This is my clock pipeline for the timer:
Attachment:
timer2_clockpipeline_annotated.png [ 51.27 KiB | Viewed 1763 times ]
These are the sections of the pipeline :
Timer Input. It switches counting between CNT to PHI2, depending on the TAINMODE input from the Control Register. When TAINMODE=0, timer input always outputs 1. When it's 1, it emits a pulse after each CNT rising edge. As the CNT input is not syncronized to the system clock, these DFF convert the rising edge to a single clock pulse.
Start. If TASTART is 1, it equals the Timer Input value, allowing the timer to count. If TASTART is 0, nothing happens after this point
Underflow & Reload. This section handles the timers reload from the latches whenever needed. It isn't relevant to my issue.
Timer Clock. This section mixes the output of Timer input, whenever START=1, with PHI2, to generate a pulse each time the timer needs to count down. It's, I'd say, very convoluted, and it is so it can replicate the behaviour of MOS6526.
When counting down on PHI2, the moment we reach 0000 in the timer, it resets and reloads the original value from the latches. At this moment, U118B is reset, so during a PHI2 cycle, there's no clock to the timers, and the reloaded value is repeated for a cycle, with no 0 appearing at any time (3-2-1-3-3-2)
This is different when counting CNT pulses (Or TAPULSES for TIMER). Here we get 3-2-1-0-3-2-1....
I've made the following time diagram, when counting PHI2.
Attachment:
timeline.png [ 16.92 KiB | Viewed 1763 times ]
The issue is, the second FF (U119A) delays the clock by 1 cycle, so the timer starts counting 1 cycle late. Removing this FF fixes this, but then I'm not able to skip a clock after underflow. I've been scratching my head for a week, trying different solutions, but doesn't feel I'm getting any closer.
As I said before, this pipeline feels... delicate. Changing anything affects everything, and I'm actually amazed it works the way it does. So, for now, I'm moving into B2. Schematic is complete, and routing of the PCB is almost there. It's pretty much a reuse of B1, so it's been an easy one.
Oh, BTW, If the pipeline is complex, keep in mind that, when TIMERB is counting TA underflows, I'll have two of them chained.
Let's just hope a cycle offset it's not harmful