| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| MCUprogrammer 
 
 
 Joined: 08 Sep 2020
 Posts: 233
 
 
 
			    
 
 | 
			
				| DAC control |  
				|  Posted: Thu Mar 23, 2023 6:12 am |   |  
				| 
 |  
				| Hello With 8 Bit input, I want to send 8 bit information to 3 different DAC outputs according to Position information. But I'm having trouble testing 1 more. Where is the mistake?
 So in the first place I simply want to send 8 bits to the DAC output.
  	  | Code: |  	  | #include <16F1779.h>
 #use delay(internal = 32MHZ)
 
 
 
 
 void main(void)
 {
 setup_dac( DAC_VSS_VDD | DAC_OUTPUT1 | DAC_LEFT_JUSTIFIED);
 
 while(TRUE)
 {
 for(int8 i=0; i<255; i++)
 {
 DAC_WRITE(i);
 delay_ms(250);
 }
 }
 
 }
 | 
 _________________
 Best Regards...
 MCUprogrammer
 _______________________________
 Work Hard
 
 Last edited by MCUprogrammer on Thu Mar 23, 2023 8:02 am; edited 2 times in total
 |  | 
	
		|  | 
	
		| temtronic 
 
 
 Joined: 01 Jul 2010
 Posts: 9589
 Location: Greensville,Ontario
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Mar 23, 2023 7:11 am |   |  
				| 
 |  
				| quick check of datasheet says PPS... 
 hmm, that PIC has PPS so you probably need to configure PPS before you setup the DAC ??
 |  | 
	
		|  | 
	
		| gaugeguy 
 
 
 Joined: 05 Apr 2011
 Posts: 350
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Mar 23, 2023 7:17 am |   |  
				| 
 |  
				| What is connected to the DAC output?  It has a very high impedance. |  | 
	
		|  | 
	
		| MCUprogrammer 
 
 
 Joined: 08 Sep 2020
 Posts: 233
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Mar 23, 2023 7:22 am |   |  
				| 
 |  
				| DAC output is idle. I'm checking with DDM. _________________
 Best Regards...
 MCUprogrammer
 _______________________________
 Work Hard
 |  | 
	
		|  | 
	
		| Ttelmah 
 
 
 Joined: 11 Mar 2010
 Posts: 19966
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Mar 23, 2023 7:40 am |   |  
				| 
 |  
				| Analog functions don't support PPS. The output will be pin RA2. However as GaugeGuy says it will be quite a high impedance source. It'll only
 swing 1/4 the supply (10bit DAC), unless you specify to left justify.
 Really to use this output for anything that offers any load, you need to
 send the DAC output to the non inverted input of an op-amp (internal
 or external), and use the output of this.
 The main mistake is much simpler though.
 Look at this line:
 
 for(int8 i=0; i<255; i)
 
 i is never incremented. Result output will always be 0.....
 |  | 
	
		|  | 
	
		| gaugeguy 
 
 
 Joined: 05 Apr 2011
 Posts: 350
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Mar 23, 2023 7:50 am |   |  
				| 
 |  
				| What are you getting at the output?  That is a 10 bit DAC so sending 0-255 should give you up to 1/4 of VDD max as long as the output is not loaded. |  | 
	
		|  | 
	
		| MCUprogrammer 
 
 
 Joined: 08 Sep 2020
 Posts: 233
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Mar 23, 2023 7:52 am |   |  
				| 
 |  
				| I noticed it while typing. I have the value "++i" in my code. But the result is still 0. _________________
 Best Regards...
 MCUprogrammer
 _______________________________
 Work Hard
 |  | 
	
		|  | 
	
		| Ttelmah 
 
 
 Joined: 11 Mar 2010
 Posts: 19966
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Mar 23, 2023 11:08 am |   |  
				| 
 |  
				| You have got Avss/Vdd connected. The DAC requires the analog supply pins connected or it will not be driven.
 
 What compiler version are you using?. I've just checked on the current
 compiler and the code works correctly, with i++.
 |  | 
	
		|  | 
	
		| MCUprogrammer 
 
 
 Joined: 08 Sep 2020
 Posts: 233
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Mar 23, 2023 11:24 am |   |  
				| 
 |  
				| 5.115 how? Does the code I added now give you an output?
 Pins 11-12 AND 31-32 are already connected. Since it is a development board, the supply line is already connected. I want to read voltage from DAC output pins.
 _________________
 Best Regards...
 MCUprogrammer
 _______________________________
 Work Hard
 
 Last edited by MCUprogrammer on Thu Mar 23, 2023 12:12 pm; edited 1 time in total
 |  | 
	
		|  | 
	
		| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Mar 23, 2023 11:33 am |   |  
				| 
 |  
				| 1. You have setup the DAC to use left justified data, but you are not giving it left justified data.  You are giving it right-justified data.  Change it to this:
 
  	  | Code: |  	  | setup_dac( DAC_VSS_VDD | DAC_OUTPUT1);
 
 | 
 
 2. Wiith a 250 ms loop delay, it will take 255 x .25 second = 63.75 seconds
 to ramp up.  That's too long.  Change it to 25 ms.  Then it will ramp up in
 about 6 seconds.
 
 3. You are using DAC1, which is a 10-bit DAC.  Since your highest data
 value is 254, your voltage ramp on the output pin will be from 0v to 1.24v.
 |  | 
	
		|  | 
	
		| MCUprogrammer 
 
 
 Joined: 08 Sep 2020
 Posts: 233
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Mar 23, 2023 12:14 pm |   |  
				| 
 |  
				| I want to see 5V when it is 255. _________________
 Best Regards...
 MCUprogrammer
 _______________________________
 Work Hard
 |  | 
	
		|  | 
	
		| Ttelmah 
 
 
 Joined: 11 Mar 2010
 Posts: 19966
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Mar 23, 2023 12:42 pm |   |  
				| 
 |  
				| Then you need an int16 counting up to 1023. |  | 
	
		|  | 
	
		| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Mar 23, 2023 6:55 pm |   |  
				| 
 |  
				|  	  | MCUprogrammer wrote: |  	  | I want to see 5V when it is 255. | 
 You could let us know if it's now working, or not.
 |  | 
	
		|  | 
	
		| Ttelmah 
 
 
 Joined: 11 Mar 2010
 Posts: 19966
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Fri Mar 24, 2023 12:09 am |   |  
				| 
 |  
				| It'll do that, if you use the left justification, and put the value into an int16. The left justification justifies the _10 bit_ value left in the output
 register. The value still needs to be 10bit though, However it won't quite
 give 5v, The value generated will be 1020, so the output will be 4.98v.
 |  | 
	
		|  | 
	
		| MCUprogrammer 
 
 
 Joined: 08 Sep 2020
 Posts: 233
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Fri Mar 24, 2023 12:28 am |   |  
				| 
 |  
				| I have a PIC18F57Q43. I tried. It is working. But  When I do with PIC16F1779 not working. I made variable type int16. The value count to 1023. The result same. _________________
 Best Regards...
 MCUprogrammer
 _______________________________
 Work Hard
 |  | 
	
		|  | 
	
		|  |