I am trying to use the MSP430F47187 to read and plot an AC waveform. However, it seems that the SD16A sampling rate is a little less than the 4096 Hz that I expect. It turns out to be something more like 4090 or 4094 Hz. I'm running MCLK with the FLL off of a 32.768 crystal that seems to be stable and accurate when measured off of a buffered output.
My SD16A interrupt is just flipping a bit high, saving the results, and flipping the bit low. The _delay_cycles(x) command I used to make the signal tracewidth a bit wider for measurement purposes but its inclusion does not really alter the results.
Measuring my MCLK directly shows that, while a bit off of 16.777 MHz, it's not nearly enough to account for the discrepancy that I see. FYI if I run the SD16A in single trigger mode and start the capture with Timer A, then the SD16A ISR fires at 4096 on the nose. Thoughts?
#pragma vector=SD16A_VECTOR
__interrupt void SD16ISR(void)
{
P1OUT |= BIT1;
static unsigned int index = 0;
results[index] = SD16MEM0; // Save CH0 results (clears IFG)
results[index] = SD16MEM1;
results[index] = SD16MEM2;
_delay_cycles(100);
P1OUT &= ~BIT1;
}
My SD16A setup should be grouping the 3 channels together and continuously triggering them. The MCLK should be 16.777216 MHz and then divided down to 1.048576MHz. With the 256 oversampling, the interrupt should fire at 4096Hz.
void initSD16A(void)
{
SD16CTL = SD16REFON
| SD16SSEL_0 //_0 = MCLK, _1 = SMCLK, _2 = ACLK
| SD16XDIV_2
| SD16DIV_0
| SD16VMIDON;
SD16CTL &= ~SD16VMIDON;
SD16INCTL0 |= SD16INTDLY_0; // Interrupt on 4th sample
SD16CCTL0 |= SD16GRP | SD16OSR_256 | SD16UNI;
SD16INCTL0 |= SD16GAIN_1;
SD16CCTL1 |= SD16GRP |SD16OSR_256;
SD16INCTL1 |= SD16GAIN_1;
SD16CCTL2 |= SD16OSR_256 | SD16IE;
SD16INCTL2 |= SD16GAIN_1;
volatile unsigned int i;
for (i = 0; i < 0x3600; i++); // Delay for 1.2V ref startup
}
My main function just sets up MCLK and sits in a while loop.
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
FLL_CTL0 |= DCOPLUS + XCAP11PF; // DCO+ set, freq = xtal x D x N+1. XCAP = 11 pF because I removed the capacitors from my test board. Set to 0 on normal pterodactyl - CEL
SCFI0 = FLLD_4+FN_4; // x4 DCO freq muliplier
SCFQCTL = 127; // (SCFQCTL) x 32768 x 4 = MCLK
initSD16A();
_EINT();
SD16CCTL2 |= SD16SC;
while(1); // Loop in place
}