View previous topic :: View next topic |
Author |
Message |
rodemer
Joined: 10 Aug 2004 Posts: 1
|
pic 16c781 dac and op amp -- not supported by ccs C? |
Posted: Tue Aug 10, 2004 10:41 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue Aug 10, 2004 1:31 pm |
|
|
If they don't have support for it, then you could always use the registers and set things up "manually". |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Aug 10, 2004 1:34 pm |
|
|
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);
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
Darren Rook
Joined: 06 Sep 2003 Posts: 287 Location: Milwaukee, WI
|
|
Posted: Tue Aug 10, 2004 3:17 pm |
|
|
PCM Programmer, you're too nice of a guy.
We should set up a pizza fund so we can send you pizza deliveries. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Aug 10, 2004 3:30 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Darren Rook
Joined: 06 Sep 2003 Posts: 287 Location: Milwaukee, WI
|
|
Posted: Tue Aug 10, 2004 3:45 pm |
|
|
Maybe you wouldn't work so late if weren't helping so many people here.
Thanks for your time, I don't know if you get enough thanks. |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue Aug 10, 2004 5:37 pm |
|
|
Ought to setup a Paypal account for donations
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. |
|
![](templates/subSilver/images/spacer.gif) |
cavoti
Joined: 29 Jul 2016 Posts: 11
|
DAC |
Posted: Fri Jul 29, 2016 2:25 am |
|
|
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? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19368
|
|
Posted: Fri Jul 29, 2016 7:02 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
|