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.
已解决! 转到解答。
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..."
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..."
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))
{};