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 support@ccsinfo.com

pic 16c781 dac and op amp -- not supported by ccs C?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rodemer



Joined: 10 Aug 2004
Posts: 1

View user's profile Send private message

pic 16c781 dac and op amp -- not supported by ccs C?
PostPosted: Tue Aug 10, 2004 10:41 am     Reply with quote

I'm looking to use the digital-to-analog converter built into the 16c781 to output a sine wave, which I plan to amplify with the built-in op-amp also in that chip, to run some kinetic sculptures.

Scouring the ccs .h file for this chip, I can't see where there is any library function that would allow control of these features. Is it just called something else, or is there really no support for these features?

Thanks.

Michael Rodemer
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Aug 10, 2004 1:31 pm     Reply with quote

If they don't have support for it, then you could always use the registers and set things up "manually".
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 10, 2004 1:34 pm     Reply with quote

I don't think CCS has support for it. I haven't used that chip,
but by reading the data sheet, and following standard CCS methods,
I was able to write the following driver and demo program for you.
I don't have a 16C781 chip to test this file, but it will probably work,
and should at least get you started. Note that you need to supply
a DAC reference voltage to the Avdd pin on the 16C781 to use this
program.

Code:
#include <16C781.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT 
#use delay(clock = 4000000)

// Define the addresses of the DAC registers and
// the Analog Select register.
#byte DAC = 0x11E
#byte DACON0 = 0x11F
#byte ANSEL = 0x9D 

//-----------------------------------------------------
// setup_dac()
// This function allows configuration of the DAC module.
// The code inside the function follows the assembly lanuage
// example shown in the 16C781 data sheet in section 10-3.
// Note that their sample code appears to have one error.
// It has "BSF ANSEL,1"  and it should be "BSF ANSEL,5"
// because pin B1 is the AN5 pin.   Also note that if you
// use the CCS function setup_adc_ports(), it over-writes
// the ANSEL register (which we use below), so you must
// include sAN5 in the parameter list, if you call setup_adc_ports().
//
// Example of use:  setup_dac(DAC_ON | DAC_OE | DAC_REF_AVDD);
//
void setup_dac(char config)
{
output_float(PIN_B1);    // Make Pin B1 be an input.
ANSEL |= sAN5;           // Make Pin B1 (AN5) be an analog pin.
DAC = 0;                 // Zero the DAC register.
DACON0 = config;         // Set DAC config.
}

// These constants ared used with the setup_dac() function, above.
// These can be OR'ed together.  See the data sheet for details.
#define DAC_ON        0x80   // Turn on the DAC module
#define DAC_OFF       0x00   // Turn off the DAC module
#define DAC_OE        0x40   // Enable output on the Vdac pin
#define DAC_REF_AVDD  0x00   // Use the AVdd pin for DAC reference voltage
#define DAC_REF_VREF1 0x01   // Use the Vref1 pin for DAC reference voltage
#define DAC_REV_VR    0x02   // Use the VR module for DAC reference voltage
//-----------------------------------------------
// This macro allows writing to the DAC register.
// A macro is used instead of a function, because it
// generates more compact code when compiled.
//
// Example of use:  write_dac(0x55);
//
#define write_dac(value)  DAC = value


//====================================
main()
{
char i;


// Turn on the DAC, enable output on the Vdac pin, and use
// the AVdd pin as the Voltage Reference for the DAC.
setup_dac(DAC_ON | DAC_OE | DAC_REF_AVDD);

// Create a sawtooth waveform by ramping up the DAC
// from 0 to 0xFF, one step at a time, continuously.
i = 0;
while(1)
  {
   write_dac(i);
   i++;
   delay_us(10);
  }

}
Darren Rook



Joined: 06 Sep 2003
Posts: 287
Location: Milwaukee, WI

View user's profile Send private message Send e-mail

PostPosted: Tue Aug 10, 2004 3:17 pm     Reply with quote

PCM Programmer, you're too nice of a guy.

We should set up a pizza fund so we can send you pizza deliveries.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 10, 2004 3:30 pm     Reply with quote

I do get a pizza occasionally here. If we work past 7pm, the company
owner buys a large pepperoni and cheese, and a liter of Coke. Then
I don't mind working late.
Darren Rook



Joined: 06 Sep 2003
Posts: 287
Location: Milwaukee, WI

View user's profile Send private message Send e-mail

PostPosted: Tue Aug 10, 2004 3:45 pm     Reply with quote

Maybe you wouldn't work so late if weren't helping so many people here. Laughing

Thanks for your time, I don't know if you get enough thanks.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Aug 10, 2004 5:37 pm     Reply with quote

Ought to setup a Paypal account for donations Very Happy

Now don't say you are not in it for the money, I already know that. But hey, beer, pizza, demo boards, compilers, cash, it's all good.
cavoti



Joined: 29 Jul 2016
Posts: 11

View user's profile Send private message

DAC
PostPosted: Fri Jul 29, 2016 2:25 am     Reply with quote

Hello I am using a PIC16F1709 and also tried to use the DAC. I wrote the same program code to activate the DAC but with the Addresses of my PIC. The DAC does something but I have a strange problem. When I write to the DAC the highest value the output is 0.3V and when I write the lowest value the output is 0.9V but my Reference is 3.3V(VDD). I've done all the necessary steps but it still doesn't work. Could someone help me?
Ttelmah



Joined: 11 Mar 2010
Posts: 19260

View user's profile Send private message

PostPosted: Fri Jul 29, 2016 7:02 am     Reply with quote

Old question - what compiler version?.

The modern compilers have code for these DAC's now, so you will be on an old compiler. The version may affect whether the code works.

However, the output enables are different on your chip (0x20, for output1, and 0x10 for output2).

Obviously you are also aware that this source has quite a high output impedance?. A buffer op-amp is needed if you are going to drive anything other than a very high impedance.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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