PDA

View Full Version : adc dac mirror ... how could be done?



martintorres
- 23rd April 2014, 04:53
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:



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)
goto menu

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:


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)
goto menu

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

HenrikOlsson
- 23rd April 2014, 06:28
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:

DEFINE ADC_BITS 8

Voltage VAR BYTE
LastReading 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
ADCIN 0, Temp
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
LastReading = Voltage
ENDIF

Goto Main

/Henrik.

martintorres
- 23rd April 2014, 13:31
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 ...

7317

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?

martintorres
- 30th April 2014, 06:14
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 )

7321

7323

7322
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!!!! :D

martintorres
- 30th April 2014, 16:33
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)



DEFINE OSC 20
'************************************************* ***************
TRISA = 1
ADCON1 = 0
ADCON0 = %11000001
TRISB = %00000000
TRISC = %00000000
'************************************************* ***************
DEFINE ADC_BITS 8
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50
'************************************************* ***************
ent420 var word
tiempo var byte
nivel var byte
'************************************************* ***************
INICIO:
nivel= 1

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

end