CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

DAC control
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
MCUprogrammer



Joined: 08 Sep 2020
Posts: 221

View user's profile Send private message

DAC control
PostPosted: Thu Mar 23, 2023 6:12 am     Reply with quote

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: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Mar 23, 2023 7:11 am     Reply with quote

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: 303

View user's profile Send private message

PostPosted: Thu Mar 23, 2023 7:17 am     Reply with quote

What is connected to the DAC output? It has a very high impedance.
MCUprogrammer



Joined: 08 Sep 2020
Posts: 221

View user's profile Send private message

PostPosted: Thu Mar 23, 2023 7:22 am     Reply with quote

DAC output is idle. I'm checking with DDM.
_________________
Best Regards...
MCUprogrammer
_______________________________
Work Hard
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Thu Mar 23, 2023 7:40 am     Reply with quote

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: 303

View user's profile Send private message

PostPosted: Thu Mar 23, 2023 7:50 am     Reply with quote

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: 221

View user's profile Send private message

PostPosted: Thu Mar 23, 2023 7:52 am     Reply with quote

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: 19538

View user's profile Send private message

PostPosted: Thu Mar 23, 2023 11:08 am     Reply with quote

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: 221

View user's profile Send private message

PostPosted: Thu Mar 23, 2023 11:24 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Mar 23, 2023 11:33 am     Reply with quote

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: 221

View user's profile Send private message

PostPosted: Thu Mar 23, 2023 12:14 pm     Reply with quote

I want to see 5V when it is 255.
_________________
Best Regards...
MCUprogrammer
_______________________________
Work Hard
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Thu Mar 23, 2023 12:42 pm     Reply with quote

Then you need an int16 counting up to 1023.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 23, 2023 6:55 pm     Reply with quote

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: 19538

View user's profile Send private message

PostPosted: Fri Mar 24, 2023 12:09 am     Reply with quote

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: 221

View user's profile Send private message

PostPosted: Fri Mar 24, 2023 12:28 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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