Hi,
i am trying to code adc in MC56F8367, since trying with the sample code provided in codewarrior we were able to find some values in result register after initializing without providing any sample voltage.
since we tried to check the varience from (0-20)v we are not able to find any major difference upto 8v, after 9v is applied as sample input we are not able to get the desired output whereas could find some nearest value with the difference value of 9%
kindly find the attachment for the sample code
Thanks
Sasikumar E
Hi, Sasi,
As Kamil said the ADC analog pins are input pins, it does not make sense to test the ADC analog pin voltage when the ADC analog pins are float.If you use ADC to test the analog ADC channel voltage, the ADC analog channel must be driven by low impedance source.
BR
Xiangjun Rong
Hi, Sasi,
Pls refer to the attached example of ADC, but it is based on MC56F8323.
If you still have issue, pls attach your project so that I can help to have a debug.
The example uses software triggering mode. In the events.c,
#pragma interrupt called
void AD1_OnEnd(void)
{
AD1_GetValue16(sample);
adcresult0 = getReg(ADCA_ADRSLT0); //connect AN0 pin to 3.3V,adcresult0=32760 after I tested
asm(nop);
adcresult1 = getReg(ADCA_ADRSLT1);
asm(nop);
//the array sample[] save the ADC result
asm(nop);
AD1_Measure(FALSE);
// setRegBit(ADCA_ADSTAT,EOSI); //ADCA_ADSTAT_EOSI_MASK);
/* Write your code here ... */
}
BR
Xiangjun Rong
Hi, Sasi
Can you tell me the tools you are using for example CodeWarrior for DSP56800E or CodeWarrior for mcu verxx? I think the tools can generate the example code based on PE, pls use the example code.
BR
Xiangjun Rong
Hi xiangjun,
as for the above comment while trying to initialise ADC i m getting an 1.7V in the respective ADC pin but this voltage is produced only in loop simultaneous mode or loop sequential mode, while in the once sequential, once simultaneous, triggered sequential, triggered simultaneous unable to find that voltage
Hello Sasi,
voltage at ADC pin should be from external circuit, MCU doesn't create any voltage at its ADC pin irrespective of its configuration. As it is input pins and not output pins. Hence, please verify your schematic around MCU to make sure voltages are correct. and if possible please share schematic around MCU.
Kamil
Hi xiangjun,
while trying to initialize adc the respective pin provides 1.7V such as when any pin is initialized we get 1.7V at the respective pin
Hi xiangjun,
i am using code warrior for mcu version 11.1 i am getting error with the available sample code
Hi all,
Thanks, I forgot to mention we have a divider which scales down the 20v voltage supply to 3v as for the adc input supply,
this is one of my reference values provided for the desired output voltage
Divider voltage ADC register value
No input 3898
0V 3a50
0.75V 3b70
1V 4c88
1.5V 5768
3V 6988
in most cases there is only a little variance in register value
Thanks
Sasikumar E
Hi Sasi
What are the resistor sizes in your divider.
If you have too high of an impedance you will not get a good reading. I had that problem in the past.
Also you should add a small capacitor at the ADC input to help.
Pete
what is the value of VrefH and VrefL is selected? and how ADC is configured?
AD1_EnUser = TRUE; /* Enable device */
EnEvent = TRUE; /* Enable events */
OutFlg = FALSE; /* No measured value */
AD1_ModeFlg = IDLE; /* Device isn't running */
setReg(ADCA_ADCR1,16386); /* Set control register 1 */
setReg(ADCB_ADCR1,16386); /* Set control register 1 */
setReg(ADCA_ADOFS0,0); /* Set offset reg. 0 */
setReg(ADCB_ADOFS0,0); /* Set offset reg. 0 */
setReg(ADCA_ADHLMT0,32760); /* Set high limit reg. 0 */
setReg(ADCB_ADHLMT0,32760); /* Set high limit reg. 0 */
setReg(ADCA_ADLLMT0,0); /* Set low limit reg. 0 */
setReg(ADCB_ADLLMT0,0); /* Set low limit reg. 0 */
setReg(ADCA_ADZCSTAT,65535); /* Clear zero crossing status flags */
setReg(ADCB_ADZCSTAT,65535); /* Clear zero crossing status flags */
setReg(ADCA_ADLSTAT,65535); /* Clear high and low limit status */
setReg(ADCB_ADLSTAT,65535); /* Clear high and low limit status */
//setReg(ADCA_ADSTAT,2048);
setReg(ADCA_ADSTAT,0); /* Clear EOSI flag */
setReg(ADCB_ADSTAT,0); /* Clear EOSI flag */
setReg(ADCA_ADSDIS,0); /* Enable all samples */
setReg(ADCB_ADSDIS,0); /* Enable all samples */
setReg(ADCA_ADLST1,12816); /* in sample 0 select channel 0 , in sample 1 select channel 1..... */
setReg(ADCB_ADLST1,12816); /* in sample 0 select channel 0 , in sample 1 select channel 1..... */
setReg(ADCA_ADLST1,30292); /* in sample 4 select channel 4 , in sample 5 select channel 5......*/
setReg(ADCB_ADLST1,30292); /* in sample 4 select channel 4 , in sample 5 select channel 5......*/
setReg(ADCA_ADZCC,0); /* Set zero crossing control reg. */
setReg(ADCB_ADZCC,0); /* Set zero crossing control reg. */
setReg(ADCA_ADCR2,30); /* Set prescaler */
setReg(ADCB_ADCR2,30); /* Set prescaler */
HWEnDi(); /* Enable/disable device according to the status flags */
Hello sasi kumar, hope you are not connecting more then 3.3V directly to MCU pins. voltage higher then 3.3V must be scale down by resistor divider or by any other means to bring it to VrefH V range then only connect to MCU pins. Hence please share the hardware gain of your signal to check what voltage ADC pin is connected to, As well as can you please also share your ADC result register (digital) value.
Kamil
Hi, Sasi,
Regarding your question, from the following table 10-1, we know that the input analog voltage ranges from -0.4V to +4.0V, the operating analog input voltage is from GND to Vrefh(it is 3.3V generally).
So you can not connect the 20V voltage to the analog pin directly, otherwise, the ADC may be damaged. If you want to test the 20V voltage, you can use a resistor divider and guarantee that the voltage to the analog ADC pin is in the range from GND to 3.3V.
BR
Xiangjun Rong