- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am using ADCINVR to measure to two different voltage and use DAC to supply to voltage, i am using mux to select pin01 and pin03 for measuring. There is problem. the first measurement always give me deviation. say i use pin01 to measure the voltage first, use pin03 to measure voltage then.
If i switch pins, then the pin03 measure the voltage first, the deviation is on pin03
if i do not use mux and use each seperately, i work properly . I thought i need a delay before DAC. but it does not work after i put delay before DAC.
DAC supply voltage at pin05
the code is below
void main(void)
{
LCD_Start();
PGA_Start(PGA_HIGHPOWER);
ADCINCVR_Start(ADCINCVR_HIGHPOWER );
ADCINCVR_GetSamples(0);
DAC8_Start(DAC8_HIGHPOWER);
M8C_EnableGInt;
fScaleFactor =(double)2.6/(double)8192;
while(1)
{
DAC8_WriteStall(150);
AMUX4_InputSelect(AMUX4_PORT0_1);
while(ADCINCVR_fIsDataAvailable()==0);
iData1=(double)ADCINCVR_iGetDataClearFlag();
voltage1 = fScaleFactor*iData1;
AMUX4_InputSelect(AMUX4_PORT0_3);
while(ADCINCVR_fIsDataAvailable()==0);
iData2=(double)ADCINCVR_iGetDataClearFlag();
voltage2 = fScaleFactor*iData2;
//iData=(double)ADCINCVR_iGetDataClearFlag();
//voltage2 = fScaleFactor*iData;
//iData=(double)ADCINCVR_iGetDataClearFlag();
//voltage3 = fScaleFactor*iData;
average=voltage1;
LCD_Position(0,0);
LCD_PrCString("Low");
LCD_Position(0,4);
LCD_Display(voltage1);
LCD_Position(0,10);
LCD_PrCString("volts");
LCD_Position(1,0);
LCD_PrCString("high");
LCD_Position(1,5);
LCD_Display(voltage2);
LCD_Position(1,9);
LCD_PrCString(" volts");
}
}
void LCD_Display(double data)
{
char * value;
int * status =0;
value = ftoa(data,status);
LCD_PrString(value);
}
- Labels:
-
PSoC 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi!
As I just posted on a similar thread:
The datasheet of the ADC states that if you use a MUX to switch inputs, you have to discart one measurement after switching the inputs or the result will not be correct!
Have fun
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ADCINCVR_GetSamples(0);
That means you've asked for continuous samples. As the previous respondent said, you need to discard the first conversion after a mux change -- because the next conversion started before you changed the mux, so the conversion got part of one input and part of another.
Discarding one sample is one way to do it. I prefer to request one sample at a time, myself.
ADCINCVR_Start(ADCINCVR_HIGHPOWER );
DAC8_Start(DAC8_HIGHPOWER);
...
DAC8_WriteStall(150);
AMUX4_InputSelect(AMUX4_PORT0_1);
ADCINCVR_GetSamples(1);
while(ADCINCVR_fIsDataAvailable()==0);
iData1=(double)ADCINCVR_iGetDataClearFlag();
voltage1 = fScaleFactor*iData1;
AMUX4_InputSelect(AMUX4_PORT0_3);
ADCINCVR_GetSamples(1);
while(ADCINCVR_fIsDataAvailable()==0);
iData2=(double)ADCINCVR_iGetDataClearFlag();
voltage2 = fScaleFactor*iData2;
In my case I have state machines, time constraints and minimum sample rates, with conversions running in the background while I read buttons and send messages and so on, so I need better control. In your case you probably don't care, so just calling "while(ADCINCVR_fIsDataAvailable()==0);" twice in a row (with a "clear flag" between) is probably good enough. But I wanted to make the point. Because I'm a pedant. 🙂