Jump to content
mikew

Adc Problem

Recommended Posts

After a lot of head-scratching I think I've found the bug that prevents the ADC in the 16F877A from returning the correct value. To cut a very long story short, below is a fragment from the listing file. I notice that in one place ADCON0 is given the address 9F (wrong?) whilst further down it's given 1F (correct?)

I admit that I'm not 100% clear on this matter, but it's the only difference I can find between this code and a previous one using an earlier

version of compiler for a 16F876. Also, it seems unlikely that such a bug would not have been found earlier by others, or have I missed something? I'm using BoostC Vers. 6.85.

Perhaps you could let me know? (BTW, the hex code is as shown in the listing.)

 

0584 30C7 MOVLW 0xC7

0585 059F ANDWF gbl_adcon0, F <-------------here

0586 3007 MOVLW 0x07

0587 0556 ANDWF gbl_channel, W

0588 00FD MOVWF CompTempVar564

0589 0DFD RLF CompTempVar564, F

058A 0DFD RLF CompTempVar564, F

058B 0D7D RLF CompTempVar564, W

058C 39F8 ANDLW 0xF8

058D 00D6 MOVWF gbl_channel

058E 0856 MOVF gbl_channel, W

058F 049F IORWF gbl_adcon0, F <--------------or here

0590 141F BSF gbl_adcon0,0 <-------------and here

0591 3002 MOVLW 0x02

0592 00FD MOVWF delay_ms_00000_arg_del

0593 2015 CALL delay_ms_00000

0594 151F BSF gbl_adcon0,2 <-------------and here

 

Regards

Share this post


Link to post
Share on other sites

mikew,

After a lot of head-scratching I think I've found the bug that prevents the ADC in the 16F877A from returning the correct value. To cut a very long story short, below is a fragment from the listing file. I notice that in one place ADCON0 is given the address 9F (wrong?) whilst further down it's given 1F (correct?)
I think you haven't broken the instruction down correctly. Remember that the instruction only hold a 7 bit register address and that the 2 bank selection bits make the address 9 bits long - 512 byte is total. So bit 7 (the 8th bit of the byte) is holding data or mode or something that is not the register address.

 

So at the moment I don't see a bug.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Thanks for the quick response. Of course you are correct, I have mis-read the data sheet; I was clutching at straws....

...however, whilst on the site I took the opportunity to download Vers. 6.87. The following is the 'same' fragment from the listing file produced by this version from the same C source. The important difference to me is that this now works as expected and I am reluctant to spend any more time looking for problems!

As you can see, there are differences in the object code, and not just to the labels; perhaps you can explain why the previous object always returned the ADC value for channel 0, irrespective of the channel passed to the subroutine.

 

Regards.

 

 

0578 30C7 MOVLW 0xC7

0579 059F ANDWF gbl_adcon0, F

057A 3007 MOVLW 0x07

057B 056B ANDWF ADC_Read_00000_arg_channel, W

057C 00FC MOVWF CompTempVar564

057D 0DFC RLF CompTempVar564, F

057E 0DFC RLF CompTempVar564, F

057F 0D7C RLF CompTempVar564, W

0580 39F8 ANDLW 0xF8

0581 00EB MOVWF ADC_Read_00000_arg_channel

0582 086B MOVF ADC_Read_00000_arg_channel, W

0583 049F IORWF gbl_adcon0, F

0584 141F BSF gbl_adcon0,0

0585 3002 MOVLW 0x02

0586 00FC MOVWF delay_ms_00000_arg_del

0587 2015 CALL delay_ms_00000

0588 151F BSF gbl_adcon0,2

0589 label101

0589 191F BTFSC gbl_adcon0,2

058A 2D89 GOTO label101

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...