I'm analyzing the firmware that was part of my project (the hardware part is on indefinite hold after I apparently blew up the unit).
One thing that has helped me get a better understanding is rewriting it into a different language (C++ in this case). Also, if I succeed in converting all ~7K of 68HC11 assembly into C, I can perhaps use a Teensy or something similar instead of the antiquated 8-bit era ICs I have / had in my current design.
Part of the interrupt involves continuously polling the output of the receiver stage and assembling the serial data data stream into bytes, and this next step involves comparing the current byte (byteLast) with the previous byte (byteOld) to calculate some values needed further down in the interrupt routine.
So, I did run this through an online C syntax checker / compiler and it seemed to 'take'. What I want to see is - one, to see if others can make sense of this, and two, if there may be a better way to handle the bit compare and loop instructions.
One thing that has helped me get a better understanding is rewriting it into a different language (C++ in this case). Also, if I succeed in converting all ~7K of 68HC11 assembly into C, I can perhaps use a Teensy or something similar instead of the antiquated 8-bit era ICs I have / had in my current design.
Part of the interrupt involves continuously polling the output of the receiver stage and assembling the serial data data stream into bytes, and this next step involves comparing the current byte (byteLast) with the previous byte (byteOld) to calculate some values needed further down in the interrupt routine.
So, I did run this through an online C syntax checker / compiler and it seemed to 'take'. What I want to see is - one, to see if others can make sense of this, and two, if there may be a better way to handle the bit compare and loop instructions.
Code:
#include <stdio.h>
int freq1[10] = {32,23,0,-23,-32,-23,0,23,32,23}; // freq lookup - fundamental
int freq2[9] = {1,0,-1,0,1,0,-1,0,1}; // freq lookup - 2nd harmonic
uint8_t byteLast, byteOld, accA, accB, temp1, valueIi, valueQi, valueI2i, valueQ2i;
int idx;
// Initialize variables
// byteOld = previously processed byte
// byteLast = recently collected byte to be processed
// temp1 = scratchpad byte
int main()
{
nmi05:
accA = byteOld;
temp1 = byteLast;
valueIi = 0;
valueQi = 0;
valueI2i = 0;
valueQ2i = 0;
idx = 8;
// Roll temp1 into position
temp1 = ((temp1 >> 1)|(temp1 << 7)); // ROR
// We are looking for bit state transitions
// If none, we skip and prepare for the next bit compare
nmi07:
temp1 = ((temp1 << 1)|(temp1 >> 7)); // ROL
accB = (accA ^ temp1); // XOR the two bytes
if (accB > 0) {goto nmi10;} // is sign bit (bit 7) = 0?
// Calculate Ii (fundamental, 0 degrees)
accB = freq1[idx];
if (accA < 0) {accB = (-accB);}
valueIi = (valueIi + accB);
// Calculate Qi (fundamental, 90 degrees)
accB = freq1[idx+2];
if (accA < 0) {accB = (-accB);}
valueQi = (valueQi + accB);
// Calculate I2i (2nd harmonic, 0 degrees)
valueI2i = (valueI2i + freq2[idx]);
// Calculate Q2i (2nd harmonic, 90 degrees)
valueQ2i = (valueQ2i + freq2[idx+1]);
nmi10:
accA = temp1;
idx--;
if (idx != 0) {goto nmi07;}
byteOld = accA;
// continue to integrator and vector math
}