So lets look back on what made the temperature application tick from the last post.
I couldn't fit the next bit of code into a screen shot so I'll have to copy paste it :
What it does roughly is create and array : tempMeasured[tempMeasuredPosition++] = ADC10MEM; the purpose of which is to hold previous temperatures that it measured it seems. From there it is just a matter of looping through and getting an average of the temperature change. I'm not too sure what lots of the gritty details do, but overall it simply checks to see if the temperature is more than the TEMP_THRESHOLD or less than it. If it is increasing it lights up the LED.
Its really straight forward but lots of the bit operations hold me up.That and not knowing what every variable and function is, and what they do. Going to have to go over some bit wise operations again pretty soon.
A series of define statements. All of the BIT# definitions come from the included msp430x20x2.h file included. |
What is above is the main while loop. (Hopefully the color selection doesn't make your eyes bleed).while(1)
{
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled
/* Moving average filter out of 8 values to somewhat stabilize sampled ADC */
tempMeasured[tempMeasuredPosition++] = ADC10MEM;
if (tempMeasuredPosition == 8)
tempMeasuredPosition = 0;
tempAverage = 0;
for (i = 0; i < 8; i++)
tempAverage += tempMeasured[i];
tempAverage >>= 3; // Divide by 8 to get average
if ((--uartUpdateTimer == 0) || calibrateUpdate )
{
ConfigureTimerUart();
if (calibrateUpdate)
{
TXByte = 248; // A character with high value, outside of temp range
Transmit();
calibrateUpdate = 0;
}
TXByte = (unsigned char)( ((tempAverage - 630) * 761) / 1024 );
Transmit();
uartUpdateTimer = UART_UPDATE_INTERVAL;
ConfigureTimerPwm();
}
tempDifference = tempAverage - tempCalibrated;
if (tempDifference < -TEMP_THRESHOLD)
{
tempDifference = -tempDifference;
tempPolarity = TEMP_COLD;
LED_OUT &= ~ LED1;
}
else
if (tempDifference > TEMP_THRESHOLD)
{
tempPolarity = TEMP_HOT;
LED_OUT &= ~ LED0;
}
else
{
tempPolarity = TEMP_SAME;
TACCTL0 &= ~CCIE;
TACCTL1 &= ~CCIE;
LED_OUT &= ~(LED0 + LED1);
}
if (tempPolarity != TEMP_SAME)
{
tempDifference <<= 3;
tempDifference += TIMER_PWM_OFFSET;
TACCR1 = ( (tempDifference) < (TIMER_PWM_PERIOD-1) ? (tempDifference) : (TIMER_PWM_PERIOD-1) );
TACCTL0 |= CCIE;
TACCTL1 |= CCIE;
}
}
}
What it does roughly is create and array : tempMeasured[tempMeasuredPosition++] = ADC10MEM; the purpose of which is to hold previous temperatures that it measured it seems. From there it is just a matter of looping through and getting an average of the temperature change. I'm not too sure what lots of the gritty details do, but overall it simply checks to see if the temperature is more than the TEMP_THRESHOLD or less than it. If it is increasing it lights up the LED.
Its really straight forward but lots of the bit operations hold me up.That and not knowing what every variable and function is, and what they do. Going to have to go over some bit wise operations again pretty soon.
Wow too bad i odnt understand it...
ReplyDeleteI'm a bit stupid, is that Python? :P
ReplyDeleteIm an unpracticed programmer, what language is this? C+?
ReplyDeleteu'll get hang on all the variables soon, there arent that many that actually work
ReplyDeleteits C
ReplyDeleteand i understand it perfectly
couldn't understand anything, but interesting post
ReplyDeleteYah, Im with many above me, clueless. But very cool. I remember them trying to teach us some rough code in HS, but that was sooo long ago and likely outdated.
ReplyDeleteTony is right variables are something that you eventually get to hang out of after much trial and error...
ReplyDeletecool. ill check this out
ReplyDeleteA million kids in their parents basement just giggled.
ReplyDeletewouw i feel such a geek that i understand this
ReplyDeletegrrr, code >=|
ReplyDeleteHaving a very, very basic understanding of code sucks sometimes.
seems pretty straight forward on what it does. Nice coding :P
ReplyDeleteNeed a code to make women understandable...
ReplyDeleteah C 1 of 2 reasons I no longer want to program
ReplyDeleteHaha, will look into this, don't really get variables yet.
ReplyDeleteLooks pretty intricate. I know a few languages, but C and C based languages, I've yet to start learning.
ReplyDelete