PDA

View Full Version : Usage of built-in DAC ?



CuriousOne
- 22nd March 2014, 05:18
Hello.

Certain PICs have built-in DAC. Is it possible somehow use it via picbasic?

aratti
- 22nd March 2014, 07:22
Very simple for PIC16C782 you set the register DACON0 to ENABLE the dac and simply set the register DAC with a byte value for the analog output desired.

DAC = 128 will generate an analog output of 2.5 volts if your reference was Vdd (5V)

That's all.

Cheers

Al.

CuriousOne
- 30th March 2014, 20:43
So if I want alternating output, I have to update DAC register in the loop?

which statement will do that write?

Demon
- 30th March 2014, 23:05
Did you try DAC=255 for 100%?

(Or whatever register name is stated in datasheet)

I would stay from 0 to 255 (fits in 1 byte)

Robert

Ruben Pena
- 4th December 2014, 21:11
Hi:
I made this program and I can only get from 0 to 3.77 volts in the DAC output.

'************************************************* ***************
'* Name : EJERCICIO_16F1783.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 11/28/2014 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
'************** CONFIG PARA 16F1782/83/84/86/88 *********************
#CONFIG
__config _CONFIG1, _FOSC_INTOSC & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_ON & _IESO_OFF & _FCMEN_OFF
__config _CONFIG2, _PLLEN_OFF & _LVP_OFF & _BORV_25 & _VCAPEN0_OFF & _VCAPEN1_OFF & _STVREN_OFF
#ENDCONFIG
@ ERRORLEVEL -306 ; turn off crossing page boundary message (dt)
@ ERRORLEVEL -305 ; turn off crossing page boundary message (dt)

'************************************************* ************************
'*********** REGISTER SETUP **********************************************
'************************************************* ************************
ANSELA = 01 'DESHAB ADC _INTRC_OSC_NOCLKOUT RA.0 PIN2
ANSELB = 0 'DESHABILITA ADC
'************* OPCIONES OSCILADOR INTERNO *******************************
OSCCON = $72 '$F8 int osc de 16 mhz $72 PARA 8 MHZ, $6A PARA 4 MHZ.
'************************************************* ************************
CM1CON0 = 0 'DESHAB. COMPARADORES 1
CM2CON0 = 0 ' Y 2
OPA1CON = 0 ' DESHABILITA OP AMPSX
OPA2CON = 0 ' DESHABILITA OP AMP
DACCON0 = $90 '1001 0000 DAC ENABLED,DACOUT2 ENABLED RB.7 PIN 28
CCP1CON = 0 ''NO COMPARE OR PWM
FVRCON = $00 'DISABLED
ADCON0 = $00
ADCON1 = $00
ODCONA = 0
ODCONC = 0
CMOUT = 0
DEFINE OSC 8
DEFINE ADC_BITS 8
DEFINE HSER_RCSTA 90H 'SERIAL INIT
DEFINE HSER_TXSTA 20H
DEFINE HSER_BAUD 1200
TRISA = $01 ' 0000 0001
TRISB = $00
TRISC = $80 '1000 0000
PORTA = 0
PORTB = 0
PORTC = 0
PAUSE 200

LED var porta.7
OUTSER VAR PORTC.6
VALOR VAR WORD
CHAR VAR BYTE
AUX VAR BYTE




START:
FOR AUX = 0 TO 4
LED = 1
PORTA = 255
PORTC = 255
PAUSE 500
LED = 0
PORTA = 0
PORTC = 0
PAUSE 500

NEXT AUX
HSEROUT ["PRUEBA A 8 MHZ",13,10]
FOR AUX = 0 TO $FF
DACCON1 = AUX 'send from 0 to 255 to DAC
HSEROUT ["AUX=",DEC3 AUX,13,10]
PAUSE 300
NEXT AUX
GOTO START
*****************************************
Somebody can tell me what I am doing wrong.?
Thanks in advance...
Ruben de la Pena

Demon
- 4th December 2014, 21:54
Are you checking voltage on pin A.2?

I see nothing, as long as you're checking B.7.

What happens if you move DACCON0 after the other registers, just before DEFINE OSC?

Maybe you are disabling DAC accidentally.

Robert

Ruben Pena
- 4th December 2014, 22:36
Robert: กกก PROBLEM SOLVED กกก
The power supply is 5 V. I am checking Portb.7 because I config the DACCON0 as $90.
This enable the DAC and select Portb.7 as output.
I move the DACCON0 register as you suggest,but the result is the same.
Also I do not why,PORTA.6 remains lit when is making the voltage loop.
It is configured as output and I clear the port at the begginning.
I am using the EASYPIC V7 for development,and I realize I was loading
The portb with the panel Leds. I turnoff the led selection and now all is working OK.

Thanks for your comments...
Ruben de la Pena

Demon
- 4th December 2014, 23:35
Have you tried this?


LED var LATa.7

Demon
- 4th December 2014, 23:40
Why do this?


FOR AUX = 0 TO 4
LED = 1
PORTA = 255
PORTC = 255
PAUSE 500
LED = 0
PORTA = 0
PORTC = 0
PAUSE 500
NEXT AUX

Robert

Ruben Pena
- 4th December 2014, 23:58
Robert:
It works... the problem with Porta.6 was configuration. It was as oscilator output.
Changing & _CLKOUTEN_ON TO & _CLKOUTEN_OFF , in _CONFIG2 ,turn off the porta,6 and then
can be used as normal i/o port.
Thanks again...
Ruben de la Pena

Edited: I was testing the ports as IO.

Greetings...
Ruben de la Pena

metemoine
- 16th December 2014, 05:59
Very simple for PIC16C782 you set the register DACON0 to ENABLE the dac and simply set the register DAC with a byte value for the analog output desired.