Jump to content
43oh

Convert 2 analog signals into 1 with the msp430


Recommended Posts

Hi guys,

 

Thanks for your last replies. One more question about feasibility.

How long don't you think it should take to do this for:

- someone who knows the msp430 really well ?

- A senor in undergrad study of computing ?

- A graduate student with average knowledge in computing ?

 

I need to know how long this is going to take me or I will try to get someone to do this.

 

Thomas

Link to post
Share on other sites

Someone who has experience with the MSP430 and the protocols involved (SPI or I2C for the DAC) can whip something up in a few hours. Rock solid code in a day or two.

 

I don't really know what level of experience an undergrad or graduate student would have (honestly, I'm not really sure what exactly those are... ;) ), but someone who is an somewhat experienced MCU programmer can get comfortable with the MSP in a few days. If someone has never done real embedded work and is "just" a computer science student, it could be weeks before something useful emerges...

 

Disclaimer: All of the above is of course personal opinion with no real data to back it up, except some experience from my own transition from studying computer science, to focusing on embedded and MCUs, to being a professional embedded programmer :D

Link to post
Share on other sites

This project is pretty easy and straight forward, give it a try and we will help you finish it :)

 

1. Get MCP4822/4821

2. Use 1 channel ADC code example to create a project and change it to alternate between two channels.

3. You can also use example with sequence.

4. Find MCP4822 example on 43oh to help you implement SPI and DAC functions.

5. Add function to convert 2 ADC values into a single value.

6. Voil

Link to post
Share on other sites
  • 2 weeks later...

Here's the basic code that you can use to do 2 ADC -> 1 DAC.

 

The only thing left is the actual conversion.

 

#include 

#define DAC_CLK_PIN BIT5
#define DAC_SIMO_PIN BIT7
#define DAC_CS_PIN BIT3	// P1
#define DAC_LDAC_PIN BIT6 // P2
#define CONFIG_A 0x3000

unsigned int adcValues[2] = { 0, 0 }; // ADC buffer

unsigned int getPosition();
void sendPositionToDAC(unsigned int position);
void sendByte(unsigned char byte);

void main(void) {
WDTCTL = WDTPW + WDTHOLD; // Stop WDT

BCSCTL1 = CALBC1_1MHZ; // 1MHz clock
DCOCTL = CALDCO_1MHZ;

P1OUT |= DAC_CS_PIN;
P1DIR |= DAC_CS_PIN + DAC_CLK_PIN + DAC_SIMO_PIN;

   P2SEL &= ~(BIT6|BIT7);
   P2DIR &= DAC_LDAC_PIN;
   P2OUT |= DAC_LDAC_PIN;

ADC10CTL1 = INCH_1 + CONSEQ_1;
ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE;
ADC10DTC1 = 0x02;
ADC10AE0 |= 0x03;

ADC10SA = (unsigned int) adcValues;
ADC10CTL0 |= ENC + ADC10SC;

_bis_SR_register(GIE);
}

// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void) {
unsigned int position = getPosition();
sendPositionToDAC(position);
ADC10SA = (unsigned int) adcValues;
ADC10CTL0 |= ENC + ADC10SC;
}

unsigned int getPosition() {
// do calculations
return adcValues[0] + adcValues[1]; // for testing, just add both values
}

void sendPositionToDAC(unsigned int position) {
unsigned int daca = CONFIG_A | position;
P1OUT &= ~DAC_CS_PIN;
sendByte(daca >> 8);
sendByte(daca);
P1OUT |= DAC_CS_PIN;
P2OUT &= ~DAC_LDAC_PIN;
P2OUT |= DAC_LDAC_PIN;
}

void sendByte(unsigned char byte) {
char c = 0;
while (c < 8) {
	(byte & BIT7) ? (P1OUT |= DAC_SIMO_PIN) : (P1OUT &= ~DAC_SIMO_PIN);
	P1OUT |= DAC_CLK_PIN;
	P1OUT &= ~DAC_CLK_PIN;
	byte <<= 1;
	c++;
}
}

 

You can also add averaging

 

//add right after adcValues
unsigned int adcAvg[2][8] = { { 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0 } }; // ADC average
char adcCounter = 0;

//replace function
unsigned int getPosition() {
// average
adcAvg[0][adcCounter] = adcValues[0];
adcAvg[1][adcCounter] = adcValues[1];
adcCounter = ++adcCounter & 0x07;
char c = 0;
long a0 = 0;
long a1 = 0;
while (c < 8) {
	a0 += adcAvg[0][c];
	a1 += adcAvg[1][c];
	a0 >>= 3;
	a1 >>= 3;
	c++;
}
// do calculations
return adcValues[0] + adcValues[1]; // for testing, just add both values
}

Link to post
Share on other sites

As a thought since the signal is slow moving electronics wise, you could take tge 2 adc inputs into the msp430, then make an analog output with taking a msp430 digital output and doing a PWM driving a capacitor with a fixed drain rate. I am on my phone so i cant draw the diagram, but you guys should be able to picture

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...