| 
	
	|  |  |  
	
		| View previous topic :: View next topic |  
		| Author | Message |  
		| artohautala 
 
 
 Joined: 17 Nov 2011
 Posts: 187
 
 
 
			      
 
 | 
			
				| how to use PIC18F4525 pin A5 analog and pins A0...A4 digital |  
				|  Posted: Wed Oct 17, 2012 2:46 am |   |  
				| 
 |  
				| Hi, I want to use pin A5 as ADC pin and pins A0...A4 digital pins.
 But in header file of PIC18F4525 I can't set it there's only these:
 
  	  | Code: |  	  | // Constants used in SETUP_ADC_PORTS() are:
 #define NO_ANALOGS   0x0F   // None
 #define ALL_ANALOG   0x00   // A0 A1 A2 A3 A5 E0 E1 E2 B2 B3 B1 B4 B0
 #define AN0_TO_AN11  0x03   // A0 A1 A2 A3 A5 E0 E1 E2 B2 B3 B1 B4
 #define AN0_TO_AN10  0x04   // A0 A1 A2 A3 A5 E0 E1 E2 B2 B3 B1
 #define AN0_TO_AN9   0x05   // A0 A1 A2 A3 A5 E0 E1 E2 B2 B3
 #define AN0_TO_AN8   0x06   // A0 A1 A2 A3 A5 E0 E1 E2 B2
 #define AN0_TO_AN7   0x07   // A0 A1 A2 A3 A5 E0 E1 E2
 #define AN0_TO_AN6   0x08   // A0 A1 A2 A3 A5 E0 E1
 #define AN0_TO_AN5   0x09   // A0 A1 A2 A3 A5 E0
 #define AN0_TO_AN4   0x0A   // A0 A1 A2 A3 A5
 #define AN0_TO_AN3   0x0B   // A0 A1 A2 A3
 #define AN0_TO_AN2   0x0C   // A0 A1 A2
 #define AN0_TO_AN1   0x0D   // A0 A1
 #define AN0          0x0E   // A0
 | 
 Is it / how it is  posiible to use only pin A5 for A/D converter ?
 
 best regards
 
 -arto-
 |  |  
		|  |  
		| Ttelmah 
 
 
 Joined: 11 Mar 2010
 Posts: 19966
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed Oct 17, 2012 2:52 am |   |  
				| 
 |  
				| Basically, no. Do a search here.
 _Depending_ on what 'digital I/O' you actually want to do on the other pins, and the timings needed for your analog, you _may_ be able to cheat, by momentarily programming the AN0_TO_AN4 mode, selecting AN4, waiting Tacq, triggering the reading, and immediately switching to NO_ANALOGS, so the pins go back to being digital.
 This has been covered many times in the past here.
 
 Best Wishes
 |  |  
		|  |  
		| artohautala 
 
 
 Joined: 17 Nov 2011
 Posts: 187
 
 
 
			      
 
 | 
			
				|  |  
				|  Posted: Wed Oct 17, 2012 3:08 am |   |  
				| 
 |  
				|  	  | Ttelmah wrote: |  	  | Basically, no. Do a search here.
 _Depending_ on what 'digital I/O' you actually want to do on the other pins, and the timings needed for your analog, you _may_ be able to cheat, by momentarily programming the AN0_TO_AN4 mode, selecting AN4, waiting Tacq, triggering the reading, and immediately switching to NO_ANALOGS, so the pins go back to being digital.
 This has been covered many times in the past here.
 
 Best Wishes
 | 
 
 Thank you for your good and fast answer
   
 One of A0...A4 must be digital output (high state) at a time
 so maybe it's better to exchange A5 to A0 and use
 AN0 for analog converter
 (modifications to hardware are allways very "fun" but now I'm gonna
 use my soldering iron and make this mod.)
 
 brdgs
 
 -arto-
 |  |  
		|  |  
		| Ttelmah 
 
 
 Joined: 11 Mar 2010
 Posts: 19966
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed Oct 17, 2012 3:35 am |   |  
				| 
 |  
				| A pin set as digital output, should happily stay driving high, when analog mode is selected. If you look at table 10.1 in the data sheet, when TRIS is set to '0', it overrides the analog selection. Multiple things apply:
 When the analog pins are setup, the whole 'group' is connected to the input multiplexer. As such digital noise on pins connected here, _will_ increase noise on the signal being read. So if a pin is an output, and you change it while the reading is being done, or inputs and they have rapidly changing signals on them, you may find that you develop noise problems.
 Second problem is if you want to use a separate Vref. Analog pins can't go more than a fraction of a volt above the analog Vrefh, or below the Vrefl. As soon as pins are selected to the multiplexer this limit applies. If they do, they'll actually drive the Vref....
 A real lesson to think about the limits of the chip before laying out the board.
 
 As a comment though, have you considered whether there might be a replacement chip?. Several of the newer chips offer individually selectable analog inputs, and are pin compatible, or can be programmed to be compatible (ones with selectable pins), for your chip.
 
 Best Wishes
 |  |  
		|  |  
		| artohautala 
 
 
 Joined: 17 Nov 2011
 Posts: 187
 
 
 
			      
 
 | 
			
				|  |  
				|  Posted: Wed Oct 17, 2012 3:55 am |   |  
				| 
 |  
				|  	  | Ttelmah wrote: |  	  | A pin set as digital output, should happily stay driving high, when analog mode is selected. If you look at table 10.1 in the data sheet, when TRIS is set to '0', it overrides the analog selection. Multiple things apply:
 When the analog pins are setup, the whole 'group' is connected to the input multiplexer. As such digital noise on pins connected here, _will_ increase noise on the signal being read. So if a pin is an output, and you change it while the reading is being done, or inputs and they have rapidly changing signals on them, you may find that you develop noise problems.
 Second problem is if you want to use a separate Vref. Analog pins can't go more than a fraction of a volt above the analog Vrefh, or below the Vrefl. As soon as pins are selected to the multiplexer this limit applies. If they do, they'll actually drive the Vref....
 A real lesson to think about the limits of the chip before laying out the board.
 
 As a comment though, have you considered whether there might be a replacement chip?. Several of the newer chips offer individually selectable analog inputs, and are pin compatible, or can be programmed to be compatible (ones with selectable pins), for your chip.
 
 Best Wishes
 | 
 
 Hi,
 
 
  	  | Ttelmah wrote: |  	  | A real lesson to think about the limits of the chip before laying out the board. | 
 here you are ABSOLUTELY right
   thks
 |  |  
		|  |  
		|  |  
  
	| 
 
 | You cannot post new topics in this forum You cannot reply to topics in this forum
 You cannot edit your posts in this forum
 You cannot delete your posts in this forum
 You cannot vote in polls in this forum
 
 |  
 Powered by phpBB © 2001, 2005 phpBB Group
 
 |