Autor Tema: Ayuda con codigo para Dimmer  (Leído 4115 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado marvicdigital

  • Colaborador
  • PIC18
  • *****
  • Mensajes: 311
Ayuda con codigo para Dimmer
« en: 07 de Octubre de 2008, 15:24:59 »
 :( llevo buenas horas analizando el código y no veo el error, bueno puede ser el cansancio...la idea es usar un PIC12F508 con GP0 como sensor de cruce por zero, GP1 switch de incremento de intensidad , GP3 disminuye y GP2 como salida hacia el triac que controla una bombilla de 115Vac a 60hz....agradezco enormemente la corrección...ah se emolvidaba, la bombilla prende en un nivel y no pasa nada por más que oprima los pulsadores.

El código es original de Microchip y es para 220Vac y 50hz, le hice la modificación para los 110Vac y 60Hz pero no se si está mal hecha por eso dejo el codigo modificado.

Mil gracias
Código: [Seleccionar]
LIST p=12C508
include p12f508.inc
__config _WDT_ON & _IntRC_OSC & _MCLRE_OFF & _CP_OFF
RAM equ 0x07 ;Begining of RAM
Sync equ 0
Btn1 equ 1
Btn2 equ 3
Out equ 2
cblock RAM

BtnCount1 ;Counters used to delay when buton is pushed
BtnCount2
Phase ;The value got from the Table
Dimmer
Flag
endc

org 0x00
movwf OSCCAL ;calibrating the internal oscillator
goto main
;----------------------------------------------------------
; This table makes the dependence y=sin(x) linear so, if you
; use this program to control dimmers and if you increment x by 1
; up to 63 (0 - 0x3F) and measure the light with luxmeter the dependence
; will be linear
;
Table: andlw .63
addwf PCL,F
retlw .126 ;periodo en 60HZ de 16.6ms medio periodo es de 8,3ms
retlw .124 ; si multiplicamos 126 * 64 (TRMO)= 8064= 8 ms
retlw .122
retlw .118
retlw .114
retlw .111
retlw .109
retlw .107
retlw .105
retlw .103
retlw .101
retlw .99
retlw .97
retlw .95
retlw .93
retlw .91
retlw .89
retlw .88
retlw .87
retlw .85
retlw .84
retlw .82
retlw .81
retlw .80
retlw .79
retlw .78
retlw .77
retlw .76
retlw .75
retlw .74
retlw .73
retlw .72
retlw .71
retlw .70
retlw .69
retlw .68
retlw .67
retlw .65
retlw .63
retlw .62
retlw .60
retlw .58
retlw .56
retlw .54
retlw .52
retlw .50
retlw .48
retlw .46
retlw .44
retlw .42
retlw .39
retlw .37
retlw .34
retlw .32
retlw .29
retlw .26
retlw .23
retlw .20
retlw .17
retlw .15
retlw .12
retlw .10
retlw .5
retlw .0
main
clrf GPIO
movlw B'00111011'
TRIS GPIO
movlw B'01000101' ;clockout/64
OPTION
;---------------------------------------
; When 50Hz net is used the period is 20ms and
; the half period is 10ms. 64us X 156 =9.984ms
; the maximum value that the table gives is 154
movlw .100
movwf BtnCount1 ;Initialize the button counters
movwf BtnCount2 ;there will be about 1 sec delay when you
btfsc GPIO,Sync ;push some button. When you hold the putton
goto $-1 ;the output will change within about 0.1 sec


loop
clrwdt
btfss GPIO,Sync ;loops while Sync=0
goto $-1
clrf TMR0 ; First half period
movf Dimmer,w
call Table ;converts the value in Dimmer to Phase
movwf Phase
La1
movf Phase,w ;compares the Phase with the timer
subwf TMR0,w ;when the time has come swithes the ouput on
btfsc STATUS,C
goto Lb1
bsf GPIO,Out ;output on ******************************//////////*********
;Button 1
Btna1
btfsc GPIO,Btn1 ;skip if button 1 is pushed else
goto Btn1Enda ;inicializes the BtnCount1
decfsz BtnCount1,F ;if the button was held down for about 1 sec
goto BtnEnda ;(when pushed) or 0.1 sec (after the
movlw .10 ;first sec) the value of Dimmer is
movwf BtnCount1 ;incremented
incf Dimmer,F ;if the highest value (0x3F) is reached
btfsc Dimmer,6 ;no more incrementation is done
decf Dimmer,F
goto BtnEnda
Btn1Enda
movlw .100 ;if the button was not pushed BtnCount is
movwf BtnCount1 ;inicialized
goto BtnEnda
;the algorythm downwards is like the above
;Button 2
Btna2
btfsc GPIO,Btn2
goto Btn2Enda
decfsz BtnCount2,F
goto BtnEnda
movlw .10
movwf BtnCount2
decf Dimmer,F
btfsc Dimmer,6
incf Dimmer,F
goto BtnEnda
Btn2Enda
movlw .100
movwf BtnCount2
BtnEnda
clrwdt
bcf GPIO,Out
;Second half period
btfsc GPIO,Sync ;loops while Sync=1
goto $-1
clrf TMR0
movf Dimmer,w
call Table
movwf Phase
Lb1
movf Phase,w
subwf TMR0,w
btfsc STATUS,C
goto Lb1
bsf GPIO,Out
Btnb1
btfsc GPIO,Btn1
goto Btn1Endb
decfsz BtnCount1,F
goto BtnEndb
movlw .10
movwf BtnCount1
incf Dimmer,F
btfsc Dimmer,6
decf Dimmer,F
goto BtnEndb
Btn1Endb
movlw .100
movwf BtnCount1
Btnb2
btfsc GPIO,Btn2
goto Btn2Endb
decfsz BtnCount2,F
goto BtnEndb
movlw .10
movwf BtnCount2
decf Dimmer,F
btfsc Dimmer,6
incf Dimmer,F
goto BtnEndb
Btn2Endb
movlw .100
movwf BtnCount2
BtnEndb
bcf GPIO,Out
goto loop
end

Desconectado migsantiago

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 8257
    • Sitio de MigSantiago
Re: Ayuda con codigo para Dimmer
« Respuesta #1 en: 07 de Octubre de 2008, 16:45:08 »
Hola

Microchip maneja la resistencia de cruce por cero como de 5Mohms y a mi nunca me funcionó con el voltaje que tú estás usando; mejor usa una R de 1Mohm.

Desconectado marvicdigital

  • Colaborador
  • PIC18
  • *****
  • Mensajes: 311
Re: Ayuda con codigo para Dimmer
« Respuesta #2 en: 07 de Octubre de 2008, 17:22:41 »
Hola

Microchip maneja la resistencia de cruce por cero como de 5Mohms y a mi nunca me funcionó con el voltaje que tú estás usando; mejor usa una R de 1Mohm.

Ya lo hice y  nada...no se que hago mal, ya tengo hasta dolor de cabeza  :D...Yo solo quiero ver este código ver que funciona y guiarme con este para hacer el propio, que por cierto es para iluiminar el pecebre en navidad.
Gracias por tu consejo.

Gracias

Desconectado marvicdigital

  • Colaborador
  • PIC18
  • *****
  • Mensajes: 311
Re: Ayuda con codigo para Dimmer
« Respuesta #3 en: 08 de Octubre de 2008, 08:31:08 »
Bueno tengo una duda, en esta parte del código:

Código: [Seleccionar]
loop
clrwdt
btfss GPIO,Sync ;loops while Sync=0
goto $-1
clrf TMR0 ; First half period
movf Dimmer,w
call Table ;converts the value in Dimmer to Phase
movwf Phase
La1
movf Phase,w ;compares the Phase with the timer
subwf TMR0,w ;when the time has come swithes the ouput on
btfsc STATUS,C
goto Lb1
bsf GPIO,Out ;output on
..
..
..
..
..
.
..
Lb1
movf Phase,w
subwf TMR0,w
btfsc STATUS,C
goto Lb1
bsf GPIO,Out

Solo Cuando la resta del registro Phase y el TMRO pase la bandera "C" a cero, solo se enciende el puerto OUT(2) luego si miramos que al no presionar ningun botón vuelve y apaga el triac, osea que solo dura encendido los microsegundos de los ciclos que pasan entre el BSF GPIO,OUT y el BCF GPIO,OUT ?  ...tenía entendido que la teoría del dimmer era dejar pasar la parte de la señal senosoidal desde el cruce de cero(semiciclo positivo) hasta los milisegundos que variavamos antes de llegar al semiciclo negativo ...o estoy equivocado?

Gracias por la ayuda

Saludos

Desconectado Fidel Martins

  • PIC16
  • ***
  • Mensajes: 143
Re: Ayuda con codigo para Dimmer
« Respuesta #4 en: 29 de Octubre de 2008, 20:12:30 »
saludos.
ya nadien te saco la duda....ai va:
el pulso necesario para ligar la senoide (o parte de ella) no debe tener ese ancho que te imaginas. Digamos que va disparar a la mitad de la potencia (un cuarto de ciclo), esto va ocurrir con un pulso de algunos microsegundos, no mas que el resto queda enganchado, pues el triac se queda cebado asta que se acabe la corriente al cruzar por cero.

Desconectado Javicho

  • Colaborador
  • PIC24F
  • *****
  • Mensajes: 570
Re: Ayuda con codigo para Dimmer
« Respuesta #5 en: 29 de Octubre de 2008, 20:23:22 »
Primero debes asegurarte de que tu hardware trabaja bien, para ello tienes que hacer un programa simple como el siguiente: al detectar el cruce por cero temporiza 2mS y a continuación dispara el triac con un pulso 100uS por ejemplo y esperas el siguiente cruce por cero, todo esto en un bucle cerrado, con ello deberias ver una iluminación relativamemte baja en el foco, si eso no funciona es porque tu hardware tiene problemas.

Javicho.


 

anything