MC9S12C64, CW V5.9.0, absolute assembler.
In my program I want to read 5 channels in 8 bit resolution at different points in my program. When I test it on a test program I set an output when the conversion starts, and clear it when the conversion is finished for each channel in succession. Then I record this on my digital signal analyzer to see how long each channel conversion takes. The conversion on Ch0 takes 7.41uS, which is about what I expected. However, each of the next channels take 6uS longer than the previous one.
Ch0 - 7.41uS, Ch1 - 13.42uS, Ch2 - 19.41uS, Ch3 - 25.45uS, ch4 - 31.41uS, Ch5 - 37.41uS.
I'm assuming I have done something wrong in my ADC set up but I can't seem to find it. Any suggestions would be appreciated.
Regards,
Robert
解決済! 解決策の投稿を見る。
Hi Robert,
We don't have any interrupt execution time specification, but you may refer to the reference manual of the core.
https://www.nxp.com/webapp/Download?colCode=S12CPUV2
7.5.3 Interrupt Recognition
Figure 7-1. Exception Processing Flow Diagram
I would recommend that you measure it in your setup.
If you use the interrupts, the core will not be blocked in a loop polling the flags, this is the advantage of it.
It also depends on other interrupt and their priorities.
Regards,
Daniel
Hi Robert,
We don't have any interrupt execution time specification, but you may refer to the reference manual of the core.
https://www.nxp.com/webapp/Download?colCode=S12CPUV2
7.5.3 Interrupt Recognition
Figure 7-1. Exception Processing Flow Diagram
I would recommend that you measure it in your setup.
If you use the interrupts, the core will not be blocked in a loop polling the flags, this is the advantage of it.
It also depends on other interrupt and their priorities.
Regards,
Daniel
Hi @roberthiebert,
I just briefly checked the code, it seems you selected 8 conversions in a sequence.
movb #$00,ATDCTL3 ; %00010000, 1 conversion
ATDCTL3 = 0x00
Hi Daniel,
Thanks so much for your response. Indeed, that was a typo error on my part. I changed to ATDCTL3 = 0x10. Now the program hangs at line 275.
brclr ATDSTAT1,#%00000100*. The conversion complete flag for channel 2 doesn't seem to be setting for some reason.
Regards,
Robert
Hi Robert,
It should be 0x08 for 1 conversion though.
Hi Daniel,
Oh my, another stupid error on my part. I changed ATDCTL3 to 0x08 but now my program just does the conversion for channel 0 then stalls at line 268, waiting for the conversion complete flag. There must be something else involved as well.
Regards,
Robert
I've made some progress, but I still have a problem. With my revised code, (attached) All the ADC channels will work, but the processing time per channel is ~37 uS, which is unacceptable. If I change ATDCTL3 to 0x08, only channel 0 will convert at ~7 uS, but I get nothing on the other channels. I've tried about all the different combinations of settings I can think of to solve this but so far no joy. Any suggestions would be appreciated.
Regards,
Robert
OK. I finally figured out where I was going wrong, (revised code attached), but now I have a question.
Depending on how many conversions I want, the processing time varies like this:
2 conversions ~7.42uS, 4 conversions ~8.41uS, 8 conversions ~10.41uS, 16 conversions ~14.41uS.
I am assuming that the more conversions I do, the better the accuracy, but I have to balance this with speed of conversion.
I am sampling the channels at specific times in the main loop. Every time I sample a channel I have to wait for the conversion to complete. Instead of waiting, I could enable the conversion complete interrupt and read the register and save it to the appropriate variable within the interrupt. So my question is, how much time would it take to service the interrupt and which method would be most efficient, waiting for the conversion completion or servicing conversion complete interrupt?
Regards,
Robert