Wednesday, March 16, 2011

Mid Term Hell

So I've been working on projects leading into mid terms as well as studying for mid terms. As such I haven't gotten a thing done with this board in a while. Working on getting some stuff up but things might be moving slowing for a bit. Keep checking back for updates.

Saturday, March 5, 2011

Temperature application code

So lets look back on what made the temperature application tick from the last post.

A series of define statements. All of the BIT# definitions come from the included msp430x20x2.h file included.
I couldn't fit the next bit of code into a screen shot so I'll have to copy paste it :
    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 )
      if (calibrateUpdate)
        TXByte = 248;                       // A character with high value, outside of temp range
        calibrateUpdate = 0;
      TXByte = (unsigned char)( ((tempAverage - 630) * 761) / 1024 );     
      uartUpdateTimer = UART_UPDATE_INTERVAL;
    tempDifference = tempAverage - tempCalibrated;
    if (tempDifference < -TEMP_THRESHOLD)
      tempDifference = -tempDifference;
      tempPolarity = TEMP_COLD;
      LED_OUT &= ~ LED1;
    if (tempDifference > TEMP_THRESHOLD)
      tempPolarity = TEMP_HOT;
      LED_OUT &= ~ LED0;
      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 is above is the main while loop. (Hopefully the color selection doesn't make your eyes bleed).
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.

Tuesday, March 1, 2011

Temperature Application pt. II

A few days ago I posted the temperature appliction which comes pre-programmed on the board. Temperature app basically consists of a Hello World application (flashing LEDs) as well as showing off the temperature sensor.

What I didn't know at the time was that there was a GUI app for windows as well. Watch as the numbers rise and fall. Excitement!