Hi Experts!
I would love your input if you expect any issues with my approach. I'm also looking for advice if you think there is a better way to structure the code at a high level.
My questions:
1) Do you expect any issues with constantly switching comparator_B channels?
2) At a high level, can you think of a better code structure?
The goal is to measure two separate, independent signals. One signal I call "AC Fault", the other signal "DC Fault". When AC or DC signal pass a threshold, we must quickly trip a relay. LPM is not a priority, but may be implemented once we have something working.
Our connections would look like
P1.0: AC Comparator
P1.1: AC ADC
P1.2: DC Comparator
P1.3: DC ADC
An overview of the code:
A quick explanation:
a. Switch between comparator input channels constantly.
b. If comparator interrupt, trigger ADC reading on channel corresponding to comparator.
c. The comparator tells the MCU if the input signal is an AC or DC fault, then sets the ADC10HI relay trip threshold.
d. If ADC10HI interrupt is entered, trip a relay
Thank you!
// My idea for the while loop while(1){ if (faultMode == NO_FAULT) { // swap between two comparator channels constantly if (index) { CBCTL0 |= CBIPSEL_2; // comp_B input channel CBx <-> IPSEL_x } else { CBCTL0 |= CBIPSEL_0; // comp_B input channel CBx <-> IPSEL_x } // Trigger new ADC read, monitor for fault } else { ADC10CTL0 &= ADC10ENC; ADC10CTL0 |= ADC10ENC + ADC10SC; if (index > FAULT_RESET_DELAY) { index = 0; faultMode = NO_FAULT; } } index++; }
// My idea for the while loop while(1){ if (faultMode == NO_FAULT) { // swap between two comparator channels constantly if (index) { CBCTL0 |= CBIPSEL_2; // comp_B input channel CBx <-> IPSEL_x } else { CBCTL0 |= CBIPSEL_0; // comp_B input channel CBx <-> IPSEL_x } // Trigger new ADC read, monitor for fault } else { ADC10CTL0 &= ADC10ENC; ADC10CTL0 |= ADC10ENC + ADC10SC; if (index > FAULT_RESET_DELAY) { index = 0; faultMode = NO_FAULT; } } index++; }