Hello,
Can someone help me out with the problem facing with this code
Original code and description by old_cow_yellow
Description:The buffer size of 1000. Thus when you stop it anytime after 2 seconds of running, there are 1000 most resent results in the array results[0...999] for you to inspect. Do not use debug single-step or break-point.
I do not have CC430F5137. It is suppose to read the internal temperature sensor every 2 msec. If you heat up or cool down the chip a few degrees, and repeat the test, you should be able to see the difference between the two sets of data. You should be able to see the slight variation within each set too or even the difference between the beginning and the ending the 2 seconds.
#include <msp430.h>
#define Smclk 1048576u /* default frequency */
#define Size 1000 /* size of result buffer */
__no_init volatile unsigned results[Size];
volatile int oldest = 0;
volatile int filled = 0;
void main( void )
{
WDTCTL = WDTPW + WDTHOLD;
// Initialize ADC12_A to sample internal-temperature-sensor
REFCTL0 = REFMSTR + REFON;
ADC12CTL0 = ADC12SHT0_4 + ADC12REFON + ADC12ON;
ADC12CTL1 = ADC12SHS_1 + ADC12SHP + ADC12CONSEQ_2;
ADC12CTL2 = ADC12PDIV + ADC12RES_2;
ADC12MCTL0 = ADC12SREF_1 + ADC12INCH_10;
P2SEL = BIT2;
ADC12IE = ADC12IE0;
ADC12CTL0 |= ADC12ENC;
// Set up TA0CC1 to generate a 500 Hz square wave to start ADC12 conversion
TA0CCR0 = Smclk/(500) - 1;
TA0CCR1 = TA0CCR0 - 20;
TA0CCTL1 = OUTMOD_3;
TA0CTL = TASSEL_2 + MC_1;
while (1)
{
__bis_SR_register(CPUOFF + GIE);
// Do data processing here
// The oldest result is in results[oldest]
// ... ... ... ...
// ... ... ... ...
// ... ... ... ...
// This must be accomplished well within 2 msec.
// You may need to increase the core voltage and speed up MCLK
}
}
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR(void)
{
ADC12IV;
results[oldest++] = ADC12MEM0;
if (oldest >= Size)
{
oldest = 0;
filled = 1;
}
if (filled)
{
__bic_SR_register_on_exit(CPUOFF);
}
}
old_cow_yellow :I don't have CCS so I don't know what is the problem.
Can someone inspect this in sloving the below
when I tried to look into the ADC register section in the debug window by running this programme by changing ADC12INCH_2; P2SEL = BIT2; it was showing "error:unable to read".
Here in the programme it says "Do data processing here" means that displaying the last sampled ADC value i.e, results[oldest] .
Actual programme should read ADC values continuoulsy with a sample rate of 500Hz as mentioned in the programme with a timer.
Thanks.


