SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions on how to get your MSP JTAG programmer up and running.
By marlene
#81517
Im quite new to this tool. My proj is to connect EKG board to eZ430-RF2500 target board. 1st of all, I tried to input a direct voltage to eZ430-RF2500 target board to fake as EKG signal.

I chose P2.0 (Pin 3 on the board) as input pin. Basically i juz follow the sample code "Temperature mearsure" and "Voltage measure" parts to add in code. Here is my code(simplified):

//Declaration (Only show the msg[] and result[] )
uint8_t msg[8];
int results[3];
int aNewVolt;

//Ports
P2DIR = 0x2E;

//This part is for temperature measurment (Omitted)

// I/p the voltage. I/p pin is P2.0 (pin 3, A0)
ADC10CTL1 = INCH_0; // A0
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE + ADC10SR;
__delay_cycles(350); // delay to allow reference to settle
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(LPM0_bits + GIE); // LPM0 with interrupts enabled
results[2] = ADC10MEM;
ADC10CTL0 &= ~ENC;

//This part is for voltage measurment (Omitted)

//Passing value
aNewVolt=results[2];
msg[8]=aNewVolt;

I plug in the target board (without apply external voltage) and open the hyper terminal, the value of aNewVolt is 33 or 32.
Then i searched this forum. I saw some ppl also did similar thing as i did. I copied their code and aNewVolt value is still 32 or 33 when no input voltage is applied:

ADC10AE0 |= 0x01 ; // analog input enable for A0
ADC10CTL1 = INCH_0; // A0
ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE + ADC10SR;
__delay_cycles(350); // delay to allow reference to settle
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled
result[2] = ADC10MEM;
ADC10CTL0 &= ~ENC;

This code is from
viewtopic.php?t=14528&highlight=ez430rf2500
I changed it slightly.

It is supposed to be 0 if i dont apply voltage, rite? Anybody plzzzz help me wiv the code?????
Plus, the ground from power generator must connect to ground pin rite? Tks!!!
User avatar
By leon_heller
#81528
Try the TI forums.

Leon
By marlene
#81577
I did.......there is no reply so far.

Last nite i changed my code to:

//P2REN |= 0x01; // Disable this one in the pins setting(I dont know what this instruction is used for)

The rest are the same. What i get is if i apply a variable external voltage to the target board, I always get a same number(55).
If i take away the voltage, the value is jumping.

Anyone can help me???? Tks a lot
By TheDirty
#81582
Have you read the 2xxx series datasheet at all?

Really, I haven't had much experience with the ADC so I'm not going over the code in detail, but what variable voltage are you using to test? The code has set the internal reference on, and is not setting REF2_5, so the reference voltage is 1.5V. That means it's going to max out at anything over 1.5V.
By marlene
#81657
Tks for the reply....

Here is what i did last nite:

P2DIR = 0x2E;
//P2REN |= 0x01;
P2OUT = 0x00;
// Configure P2.0 as analog pins
P2SEL |= 0x01;
// Configure P2.0 as inputs
P2DIR &= ~0x01;

// Measure Temperature(Omitted)

// Measure Battery Voltage(Omitted)

// i/p voltage
ADC10AE0 |= 0x01 ; // analog input enable for A0
ADC10CTL1 = INCH_0; // A0
ADC10CTL0 = ADC10SHT_3 + ADC10ON + ADC10IE + ADC10SR;
__delay_cycles(350); // delay to allow reference to settle
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(LPM0_bits + GIE); // LPM0 with interrupts enabled
results[2] = ADC10MEM;
ADC10CTL0 &= ~ENC;
ADC10CTL0 &= ~(REFON + ADC10ON); // turn off A/D to save power
//

aNumber= results[2];

I thought Vref is for sampling...So i juz turn it off. Same result. I apply variable voltage, the aNumber value show 49. I also use my both hands to touch it (each on P2.0 and ground), the value is also 49.

Then I added breakpoints to check. After running

results[2] = ADC10MEM;

The console window shows:

MSP430: Can't Run Target CPU: No error

What is this suppose to mean??????

Plus i found the aNumber value is the same as the volt value (to measure the battery voltage), 49.

What is going on????
By ThanhTran
#81673
It's been a long time since I played with the F2274 ADC. I had ADC working on 2 channels of the 2500RF board a while ago for a home made high voltage boost charger.

It looks like you use interrupt for ADC, but I don't see you have a handler for the ADC interrupt. When the conversion is done, the interrupt is handled, and that's when you read the ADC10MEM to get the value. After reading the value here, I then switch the ADC channel (setting correct value for ADC10CTL1). I would try to make the code work with one channel first before going to multiple channels.

I don't know if the ADC10MEM is valid when when the CPU wakes up after the instruction __bis_SR_register(LPM0_bits + GIE); Does it wake up because the ADC is done or because of something else (like timer for example)

I noticed that if I set up a break point before I run the code, some how it won't run properly. I normally run the code first then set break point later while the code is running.

Hope that shed some lights

-Thanh
By TheDirty
#81708
Have you tried looking at the sample code from TI. I always find their little sample programs that use each hardware block to be useful.

http://focus.ti.com/mcu/docs/mcuprodcod ... tabId=1468

They have both C and assembler examples and there's a bunch of ADC code that's pretty basic.
By marlene
#81713
To ThanhTran: Tks a lot...My supervisor juz came back yesterday. He indicated that my direction was wrong. So i juz stopped what i hav done :cry:

To The Dirty: Tks. I am now reading and trying to modify some of the c code.