Hi guys,
I'm facing a very strange behavior with a project of mine based on the MSP430F2274.
The bug shows off once in a while, here are the functions related to it:
// ____________________________________________________________________________ //Reports the actual temperatures and the PWM values. void ReportStatus() { sprintf((char *) printBuffer, "Sens. Temp.: %03.1f\t Estimated Rack Temp.: %03.1f" "\tPWM1: %+4d\r", ((float) isSensTemp) / 10, ((float) SensToRack(isSensTemp)) / 10, PWM1Value); Print((char *) printBuffer); } // ____________________________________________________________________________ // Transmit the given character array over the UART. void Print(char * array) { char * iterator; for (iterator = array; *iterator != '\0'; ++iterator) { while (!(IFG2 & UCA0TXIFG)) ; // Wait until the tx buffer is empty UCA0TXBUF = *iterator; // Put character in the tx buffer } while (!(IFG2 & UCA0TXIFG)) ; // Wait until the tx buffer is empty } // ____________________________________________________________________________ // Converts a sensor temp. value into a rack temp. value int32_t SensToRack(int32_t temperature) { return roomTemp + (temperature - roomTemp) * 1.1963; } int main(void) { ConfigureUART(); ConfigurePeltier(); InitVariables(); ADS_ConfigureADS(); while (1) { if (cmdFlag == CMD_available) { cmdFlag = CMD_empty; ParseCommand(); } if (control == ctrl_loop) { isSensTemp = ADS_FetchTemperature(); CalculatePWM(); ApplyPWM(); if (reportFlag == rep_report) { reportFlag = rep_blank; ReportStatus(); } control = ctrl_running; } } } // UART Rx interrupt routine #pragma vector=USCIAB0RX_VECTOR __interrupt void USCI0RX_ISR(void) { // Add characters if (UCA0RXBUF != '\r') { *rxPtr = UCA0RXBUF; ++rxPtr; if (rxPtr - rxBuffer > 99) rxPtr = rxBuffer; } else { // Command is gathered. *rxPtr = '\0'; rxPtr = rxBuffer; strcpy((char *) cmdBuffer, (char *) rxBuffer); // Set Flag and clear any low power mode. cmdFlag = CMD_available; } } #pragma vector=PORT2_VECTOR __interrupt void PORT2_ISR(void) { if (P2IFG & BIT1) { // DRDY (ADS1246/7/8) interrupt routine P2IFG &= ~BIT1; if (ADS_status == ADS_cont_measuring && control == ctrl_running) control = ctrl_loop; if (ADS_status == ADS_measuring || ADS_status == ADS_calibrating) __bic_SR_register_on_exit( CPUOFF); } }
During operation, I sometimes get such a line.
Sens. Temp.: 6.6 Estimated Rack Temp.: 23.0 PWM1: -424
So, we know that the isSensTemp = 66.
roomTemp = 230 always (const)
But SensToRack(isSensTemp) seems to yield 230
instead of 230 + (66-230) * 1.1963 = 33.
My guess, is maybe the way the return statement is written causes a problem ?
If somehow an interrupt happens at that precise moment where the return statement has to be made ?
Anybody can guess what I'm doing wrong ?
Thanks a lot for your help.
Nessim