Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
analog.c BUFS bit
23-01-2012, 03:46 PM,
#1
analog.c BUFS bit
I understand the BUFS bit, such as used in analog.c with AD1CON2bits.BUFS, is intended when double-buffered A/D conversions are being done.

The actual code in analog.c look harmless, though pointless, so long as double-buffering is NOT being done. I think it needs an inversion if double-buffering is done.

Please check and if I'm right please either simplify the code or make it robust (i.e. so it works whether double-buffering is done or not). Some comments about this in the code would be useful.

John
Reply
30-01-2012, 03:04 PM,
#2
RE: analog.c BUFS bit
Hi John,
Can you update the analog.c and send it to me ?
Thank you.
Régis

(23-01-2012, 03:46 PM)pingotg Wrote: I understand the BUFS bit, such as used in analog.c with AD1CON2bits.BUFS, is intended when double-buffered A/D conversions are being done.

The actual code in analog.c look harmless, though pointless, so long as double-buffering is NOT being done. I think it needs an inversion if double-buffering is done.

Please check and if I'm right please either simplify the code or make it robust (i.e. so it works whether double-buffering is done or not). Some comments about this in the code would be useful.

John

It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply
31-01-2012, 06:06 PM,
#3
RE: analog.c BUFS bit
The Microchip doc actually say it's not legal to do what the code now does.

The last line in analog.c's analogRead:

return(ADC1BUF0+(8*(AD1CON2bits.BUFS&0x01))); // return result

is using BUFS, but dual-buffer mode (with BUFM set to 1) is not being used.

Change the line above to just:

return ADC1BUF0;

BTW, I think the current habit of disabling the ADC then re-enabling it will be quite slow as it forces ADC setup & settle on every read. I'm not sure if it affects accuracy.

John
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)