PDA

View Full Version : Two hopefully easy questions?



Ramius
- 3rd April 2012, 03:18
Hi All!

1. To change the results from a 12 bit A/D from 12 bit to 8 bit, would you simply change SHIFTIN DOUT, CK, MSBPRE, [RESULT\12] to SHIFTIN DOUT, CK, MSBPRE, [RESULT\8] ?

2. When compiling a program where you are not allowed to use CMCON=7 to make all inputs digital and not analog, is this where you would use something like the TRIS command auch as TRISA for the A A/D AND TRISHB for the B A/D and so on?

Thanks, Ed

HenrikOlsson
- 3rd April 2012, 06:15
Hi Ed,
1) Since you're using MSBPRE it might work to just shift in 8 bits (try it) since that will give you the eight high bits of the result but I don't know what the ADC thinks about having the transfer interrupted in the middle. Personally I'd read the 12bit result and then shift it, EightBit = TwelveBit >> 4.

2) If you're not "allowed" to set CMCON it's because the chip you're using doesn't HAVE that register (likely because it doesn't have comparators) so there's no need to set CMCON. By the way, CMCON is configured differently on different PIC's so just because CMCON=7 turns off the comparators on one PIC doesn't mean it necccesarily does so on another, make sure you read the datasheet.

The TRIS registers are used to select if a particular pin/port should be an input (TRIS.x=1) or an output (TRIS.x=0) it has nothing to with the analog functions per se. The ADC is usually controlled thru the ADCON register but it depends on the particullar PIC you're using, make sure you read the datasheet.

Finally, neither CMCON, TRIS or ADCON are commands - they are registers in the PIC which you assign values to in order to make the chip operate the way you want.

/Henrik.

Ramius
- 3rd April 2012, 12:39
Thanks Henrik.
So if you have a PIC 18F1320 and you wish to make it all digital inputs is there one command to do this or do you have to do an ADCON0=1, and so on for all the A/D's (I think there are 7)?

Thanks, Ed

Acetronics2
- 3rd April 2012, 12:56
Hi, Ed

There are no genuine " all digital " command in PBP ... Buuutttt ... Darrel wrote one !!!

http://www.picbasic.co.uk/forum/showthread.php?t=11100

Alain

HenrikOlsson
- 3rd April 2012, 13:45
Hi Ed,
If you look at the datasheet (http://ww1.microchip.com/downloads/en/devicedoc/39605f.pdf) you'll find that on the 18F1320 you select if a pin should be analog or digital thru ADCON1 (see section 17.2), so to set all pins as digital you can simply do ADCON1 = 255. That's one command.

It's also a good idea to look at the initialization conditions (Table 4.3), there you'll see that ADCON1 defaults to a value of 0 on power on and reset which means that all analog pins starts up in analog mode so you need to switch them to digital.

You can use Darrels AllDigital but it's always nice to be able to do it "manually" in case AllDigital isn't kept up to date or doesn't work for whatever reason.

/Henrik.

Ramius
- 4th April 2012, 00:21
Thank you both very much! It is pleasure learning from you!

Best, Ed