adc dac mirror ... how could be done?

# Thread: adc dac mirror ... how could be done?

1. ## adc dac mirror ... how could be done?

Hello, I have a doubt that while I can not solve ...
As I can do to reflect a pwm and a filter (resistor 1k and capacitor 1uf on the output pin of the pwm), I read the voltage with analog port ...
pwm control with two buttons to get a DAC 1 to 5Vdc is easy; For example:

Code:
```menu:
IF PORTC.6=0 THEN
TIEMPO=TIEMPO+1
IF TIEMPO>10 THEN TIEMPO=10
pause 150
ENDIF

IF PORTC.7=0 THEN
TIEMPO=TIEMPO-1
IF TIEMPO=255 THEN TIEMPO=0
pause 150
ENDIF

SALIDA_PWM:
HIGH PORTC.2
PAUSE TIEMPO
LOW PORTC.2
PAUSE (10 - TIEMPO)
but how could I do to translate the tension that I read in the pwm and generate the same voltage? i have pic only: 16f628...16f876a...16f877a...18f2550

EN ESPAÑOL:
hola, tengo una duda que hace rato no puedo resolver...
Como puedo hacer para reflejar con un pwm y un filtro (resistencia 1k y capacitor 1uf en el pin de salida del pwm), la tension que leo con el puerto analogico...
controlar el pwm con dos pulsadores para obtener un DAC de 1 a 5Vcc es facil; Por ejemplo:

Code:
```menu:
IF PORTC.6=0 THEN
TIEMPO=TIEMPO+1
IF TIEMPO>10 THEN TIEMPO=10
pause 150
ENDIF

IF PORTC.7=0 THEN
TIEMPO=TIEMPO-1
IF TIEMPO=255 THEN TIEMPO=0
pause 150
ENDIF

SALIDA_PWM:
HIGH PORTC.2
PAUSE TIEMPO
LOW PORTC.2
PAUSE (10 - TIEMPO)
pero como podria hacer para traducir la tension que leo en el pwm y generar la misma tension?
solo tengo estos pic: 16f628...16f876a...16f877a...18f2550

2. Did you find this post helpful? |

## Re: adc dac mirror ... how could be done?

Hi,
Use the ADC to read the voltage, use the CCP module (I'm pretty sure all the models you list have at least one) to create the PWM signal. If you set the ADC resolution to 8 bits it'll match the resolution of the CCP module when using the HPWM command. You can get 10bit resolution from the CCP module but you need to set it up manually - plenty of examples around the forum avaiable.

Basic idea:
Code:
```DEFINE ADC_BITS 8

Voltage VAR BYTE
Temp VAR WORD
i VAR BYTE

Main:
' Get a couple of readings and average them to reduce noice.
Voltage = 0
For i = 0 to 15    ' 16 readings
Voltage = Voltage + Temp
Pause 5
Next
Voltage = Voltage >> 4   ' Divide by 16, Voltage now 0 to 255

' Update output only if voltage has changed.
If Voltage <> LastReading THEN
HPWM 1, Voltage, 10000
ENDIF

Goto Main```
/Henrik.

3. Did you find this post helpful? |

## Re: adc dac mirror ... how could be done?

thanks for the help; this is my project hardware (monitor voltage and current output proportional). The idea is to add the 0-5VDC output with pwm controlled to perform a transducer 0-5V / 0-10V / 0-10mA / 4-20mA configurable through jumpers ...

First I start by controlling the input voltage and delivering a value similar to the output from your help ... and I will continue burning after the neurons to attack the current reading.
Try not to make it so complicated, implement a unique port to read analog signals 4-20mA (I saw the topic that the voltage drop is calculated from the resistance of 250 Ohms).
Now as soon as you finish what you offer me, I upload the program the microcontroller. regards

PD: tags that make recommendation me search similar forum topics?...

EN ESPAÑOL:
gracias por la ayuda; este es el hardware de mi proyecto (un monitor de tension y corriente con salida proporcional). La idea es sumar la salida 0-5vcc con el pwm controlado para poder realizar un transductor 0-5v / 0-10v / 0-10mA / 4-20mA configurable por intermedio de los jumper...
primero arranco controlando la tension de entrada y entregando un valor similar a la salida gracias a tu ayuda... y despues seguire quemando las neuronas para atacar la lectura de la corriente.
Quizas para no hacerla tan complicada, implemente un puerto analogico exclusivo para leer señales 4-20mA (vi el topico que se calcula la caida de tension con la resistencia de 250 Ohms).
Ahora ni bien termine lo que me propones, subo el programa del microcontrolador. Saludos

PD: con que tags me recomendas realizar la busqueda de temas similares en el foro?

4. Did you find this post helpful? |

## Re: adc dac mirror ... how could be done?

well, succeed in making a mirror with the help of the LM358.
Basically, what I do is with the first Ampop (12v source) is to convert the 4-20mA 0-5V input voltage ... that, I do mirror the output of a PWM pic and put it in a second Ampop (24v source) which transforms 0-5 in 4-20mA.
While this project could be implemented to build a current source 4-20mA, the initial idea is to add it to a tank level sensor home made. ( The sensor consists of several magnetic sensors with 0 ohm resistors ... with a floating magnet, according to the water level switches enable me )

I think in the future, I will make the display and will try to take a pic 8 pins (just need an analog port and another port for pwm)

sorry for my spanglish!!!!

5. Did you find this post helpful? |

## Re: adc dac mirror ... how could be done?

I leave a part of the program ... basically is the operating principle of the mirror (input voltage for the analog port = output voltage filter pwm)

En español:
les dejo una parte del programa... basicamente es el principio de funcionamiento del espejo (tension de entrada por el puerto analogico = tension de salida en el filtro del pwm)

Code:
```DEFINE OSC 20
'****************************************************************
TRISA = 1
TRISB = %00000000
TRISC = %00000000
'****************************************************************
'****************************************************************
ent420 var word
tiempo var byte
nivel var byte
'****************************************************************
INICIO:
nivel= 1

bucle:
nivel = ent420
PWM PORTC.2,nivel,100  ;nivel PWM = (Vout * 255) / V.Fuente
;gosub grafica
goto bucle

end```

#### Members who have read this thread : 0

You do not have permission to view the list of names.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts