Hi,
I am trying to use the ADC with the MKW21D512 Processor, I am able to initialize the ADC module and Calibrate the Module, every time I calibrate it, the Plus side gain comes out to be 512 and the minus side gain comes out to be 256.
After I initialize the module and calibrate it, I try and start a conversion by changing the channel in ADC0_SC1A bits 0-4. This doesn't start the conversion though. I tried to check the COCO bit in the ADC0_SC1 register, but that bit never gets set. I also tried to check the ADACT Bit in the ADC0_SC2 Register to see if the conversion is active, and that is never set either.
I am not sure why the ADC will not start after I have initialized it.
I have attached my main and my ADC files and my main header file with the register definitions to the post, my entire project is too large to upload.
Thank you in advance for your help,
Robbie.
Original Attachment has been moved to: main.c.zip
Original Attachment has been moved to: AD1.h.zip
Original Attachment has been moved to: AD1.c.zip
Original Attachment has been moved to: MK21D5.h.zip
Solved! Go to Solution.
Hi, Robert,
In your code, you do not point out the ADC code which can not start ADC conversion.
I suppose that following code has issue:
for(;;)
{
StartTempConversion();
while(ConversionAComplete()==0){
}
.........................................
}
This is my opinion for the StartTempConversion() code:
void StartTempConversion()
{
//need to connect to the A chanel
ADC0_CFG2 = 0x0; //01111
//dissable differential mode
//clear the old reguiseter value and set it to the new value
ADC0_SC1A &= ~0xFFFFFFE0; //Rong:the line will start ADC conversion, pls delete it, because it also write the ADC0_SC1A register
//this shoud start the conversion
ADC0_SC1A |= 0x16 ; //Rong: change it to ADC0_SC1A = 0x16 ; without "|"
//ADC0_SC1(1)= (0<<5) | 0x16 | (1<<6);
//set the first 5 bits equal to the correct location
}
Pls have a try. BTW, pls pay attention the ADC clock frequency, based on data sheet, the ADC clock should be less than 18MHz, you use BUS clock, which can reach up to 60mhz for K21, pls check it yourself. In software triggering mode, the ADTRG bit in ADCx_SC2 should be cleared.
Hope it can help you
BR
Xiangjun Rong
Hi, Robert,
In your code, you do not point out the ADC code which can not start ADC conversion.
I suppose that following code has issue:
for(;;)
{
StartTempConversion();
while(ConversionAComplete()==0){
}
.........................................
}
This is my opinion for the StartTempConversion() code:
void StartTempConversion()
{
//need to connect to the A chanel
ADC0_CFG2 = 0x0; //01111
//dissable differential mode
//clear the old reguiseter value and set it to the new value
ADC0_SC1A &= ~0xFFFFFFE0; //Rong:the line will start ADC conversion, pls delete it, because it also write the ADC0_SC1A register
//this shoud start the conversion
ADC0_SC1A |= 0x16 ; //Rong: change it to ADC0_SC1A = 0x16 ; without "|"
//ADC0_SC1(1)= (0<<5) | 0x16 | (1<<6);
//set the first 5 bits equal to the correct location
}
Pls have a try. BTW, pls pay attention the ADC clock frequency, based on data sheet, the ADC clock should be less than 18MHz, you use BUS clock, which can reach up to 60mhz for K21, pls check it yourself. In software triggering mode, the ADTRG bit in ADCx_SC2 should be cleared.
Hope it can help you
BR
Xiangjun Rong