ADC problem

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

ADC problem

跳至解决方案
2,529 次查看
dgipling
Contributor I

Hi, I am pretty new to ColdFire CPU and have just started to work with it.  I want to use the ADC converter to do some simple measurments.  I have tried the following code but all that is printed is 0 for all channels.

 

           MCF_ADC_CTRL2 = 0x1F; //slowest possible clock
          
           MCF_ADC_POWER &= ( MCF_ADC_POWER_PD0 |   //power up ADC
                  MCF_ADC_POWER_PD1 |
                  MCF_ADC_POWER_PD2 );
          
           MCF_GPIO_PANPAR = 0xff;   //use adc on AN0-7
          
           MCF_ADC_CTRL1 = 0x2000;  //start convertion single ended once seqential
          
           while ( MCF_ADC_ADSTAT & 0xc000 ); //wait till convertions ready
          
           for ( i = 0; i < 8; i++ )
            printf ( "ADC%d: %x\n", i, MCF_ADC_ADRSLT(i));

 

The CPU is a 52233 using a 25MHz Xtal multipledied with 2 by the PLL to be able to use fast ethernet.   

标签 (1)
0 项奖励
回复
1 解答
1,412 次查看
mjbcswitzerland
Specialist V

Hi

 

Check the following line:

 

MCF_ADC_POWER &= ( MCF_ADC_POWER_PD0 | MCF_ADC_POWER_PD1 | MCF_ADC_POWER_PD2 );

 

These bits are '1' as default (powered down) so to power them up you need to set them to '0'. That is you need to use &= ~(...)

 

If you need complete ADC support, check out the following: http://www.utasker.com/forum/index.php?topic=280.0. The utasker simulator supports the ADC module and can be used to test threshold triggering interrupts etc...It also automatically optimises the power consumption of the module depending on its exact usage.

 

Regards

 

Mark

 

 

www.uTasker.com
- OS, TCP/IP stack, USB, device drivers and simulator for M521X, M521XX, M5221X, M5222X, M5223X, M5225X. One package does them all - "Embedding it better..."

 

 

在原帖中查看解决方案

0 项奖励
回复
4 回复数
1,413 次查看
mjbcswitzerland
Specialist V

Hi

 

Check the following line:

 

MCF_ADC_POWER &= ( MCF_ADC_POWER_PD0 | MCF_ADC_POWER_PD1 | MCF_ADC_POWER_PD2 );

 

These bits are '1' as default (powered down) so to power them up you need to set them to '0'. That is you need to use &= ~(...)

 

If you need complete ADC support, check out the following: http://www.utasker.com/forum/index.php?topic=280.0. The utasker simulator supports the ADC module and can be used to test threshold triggering interrupts etc...It also automatically optimises the power consumption of the module depending on its exact usage.

 

Regards

 

Mark

 

 

www.uTasker.com
- OS, TCP/IP stack, USB, device drivers and simulator for M521X, M521XX, M5221X, M5222X, M5223X, M5225X. One package does them all - "Embedding it better..."

 

 

0 项奖励
回复
1,412 次查看
dgipling
Contributor I

Thanks a lot Mark,  I have to read the data sheet more detailed I understand.  I had to add another line of code after I had powered up the ADC by addin the code

 

while (MCF_ADC_POWER & (MCF_ADC_POWER_PSTS0 |

MCF_ADC_POWER_PSTS1 | MCF_ADC_POWER_PSTS2))
           {};

0 项奖励
回复
1,412 次查看
mjbcswitzerland
Specialist V

Hi

 

Yes, this is also true.

 

Regards

 

Mark

0 项奖励
回复
1,412 次查看
TVNAIDU
Contributor III

I am using only AN7 bit for ADC, before checking ADSTAT, I need to start sampling once voltage available on AN7, how can I start sampling?. what register I need to set to start sampling?.

0 项奖励
回复