PDA

View Full Version : Dimmer Circuit



Pesticida
- 21st January 2007, 18:23
Hi,
I make a Dimmer Circuit with Pic16f870,the Zero Detection work,all work fine,but I have a Problem.
I want to Send with my VB Software Data to my Pic to Increase and Decrease my Light Bulb with a Scrollbar.
I do this for example:
Visual Basic Part.

Private Sub Form_Load()
VScroll1.Min = 85
VScroll1.Max = 10
VScroll1.Value = 10
Private Sub VScroll1_Change()
TxtRXLoops.Text = VScroll1.Value
end sub

Private Sub VScroll1_Change()
MSComm1.Output = "!" & Chr(Val(CmbAdresse.Text)) & Chr(VScroll1.Value) _
& Chr(13) & Chr(10)
Sleep 10

End Sub

This is my Pic Part:

DEFINE OSC 4
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_SPBRG 12 ' 19200 Bauds
DEFINE HSER_CLROERR 1
'''''''''''''''''''''''''''''''''''''''''''''''''' ''Communication Variable'''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''
RCIF VAR PIR1.5 ' Receive interrupt flag (1=full , 0=empty)
TXIF VAR PIR1.4 ' Transmit interrupt flag (1=empty, 0=full)
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''
ADCON1 = 7
TRISC=0
TRISA.0=1
DataIn var byte [3]
Adresse var byte
ZeroDetect var PortA.0

low PortC.0
SOUND PORTB.1,[124,100]
low PORTB.0 '''''''''''''''''''''''''''''''''''''''''''''RS485 Input Data Enable'''''''''''''''''''''''''''''''''''''''''''' ''''''''''''
Delay_1 = 8500
MainStart:
Adresse = $1

POS_FLNK:IF ZeroDetect = 0 Then POS_FLNK
NEG_FLNK:IF ZeroDetect = 1 Then NEG_FLNK

PauseUs Delay_1
high PortC.0
PauseUs 100
low PortC.0
hserin [WAIT("!"),STR Datain\5]

goto CheckAdr
Discard:
Delay_1 = Datain[1] * 100
goto MainStart

CheckAdr:

AdresseIn = Datain[0]
if Adresse = AdresseIn then RcvData

GoTo MainStart


RcvData:


IF Datain[2] = 13 Then CheckEnd

Goto MainStart
CheckEnd: ' CheckEnd Routine

IF Datain[3] = 10 Then Discard

Goto MainStart

I Send from VB Values between 10 and 85,in Pic I Multiplicate this with 100 and then I have values between 1000 and 8500.
I think but that my Hserin loop not good is,I try with
hserin 1,mainstart,[WAIT("!"),STR Datain\5]
but I think that 1 millisecond to much is :-(
This dont work !
Please I need Help,thanks.

Regard Pesti.

sayzer
- 21st January 2007, 18:51
What is Delay_1 ?

Byte or WORD?

if Byte, then it can not have any value above 255 as you know.

It must be a WORD to carry a value between 1000 and 8500.


----------------------------------

Pesticida
- 21st January 2007, 19:01
Hi,

Delay_1 is a Word,I try now something more simple:

INCLUDE "modedefs.bas"
DEFINE OSC 4
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_SPBRG 12 ' 19200 Bauds
DEFINE HSER_CLROERR 1
'''''''''''''''''''''''''''''''''''''''''''''''''' ''Communication Variable'''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''
RCIF VAR PIR1.5 ' Receive interrupt flag (1=full , 0=empty)
TXIF VAR PIR1.4 ' Transmit interrupt flag (1=empty, 0=full)
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''
ADCON1 = 7
TRISC=0
TRISA.0=1
DataIn var byte
ZeroDetect var PortA.0
Delay_1 var word
low PortC.0
SOUND PORTB.1,[124,100]

low PORTB.0 '''''''''''''''''''''''''''''''''''''''''''''RS485 Input Data Enable'''''''''''''''''''''''''''''''''''''''''''' ''''''''''''
low PortC.0
Datain = 10
MainStart:
hserin [Datain]
Delay_1 = Datain * 100
POS_FLNK:IF ZeroDetect = 0 Then POS_FLNK
NEG_FLNK:IF ZeroDetect = 1 Then NEG_FLNK
PauseUs Delay_1
high PortC.0
PauseUs 100
low PortC.0
GoTo MainStart


This work the light is now Increase and decrease,but the Bulb dont stay on.

Regard
Pesti

Pesticida
- 21st January 2007, 20:49
Ok Thanks I find the Way.
Maybe someone need this example too:

INCLUDE "modedefs.bas"
DEFINE OSC 4
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_SPBRG 12 ' 19200 Bauds
DEFINE HSER_CLROERR 1
'''''''''''''''''''''''''''''''''''''''''''''''''' ''Communication Variable'''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''
RCIF VAR PIR1.5 ' Receive interrupt flag (1=full , 0=empty)
TXIF VAR PIR1.4 ' Transmit interrupt flag (1=empty, 0=full)
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''
ADCON1 = 7
TRISC=0
TRISA.0=1
DataIn var byte
ZeroDetect var PortA.0
Delay_1 var word
low PortC.0
SOUND PORTB.1,[124,100]

low PORTB.0 '''''''''''''''''''''''''''''''''''''''''''''RS485 Input Data Enable'''''''''''''''''''''''''''''''''''''''''''' ''''''''''''
low PortC.0
Datain = 10
Delay_1 = 9000
MainStart:
'hserin [Datain]


POS_FLNK:IF ZeroDetect = 0 Then POS_FLNK
NEG_FLNK:IF ZeroDetect = 1 Then NEG_FLNK
PauseUs Delay_1
high PortC.0
PauseUs 500
low PortC.0
hserin 0,MainStart,[WAIT("!"),Datain]

Delay_1 = Datain * 100

GoTo MainStart

Regard
Pesti

Pesticida
- 22nd January 2007, 18:10
Hi,:-)

Another question have I,did I have a chance to dimming two or more bulb on one PIC.
While I find that is a little problem with the Delay method.

POS_FLNK:IF ZeroDetect = 0 Then POS_FLNK
NEG_FLNK:IF ZeroDetect = 1 Then NEG_FLNK
PauseUs Delay_1
high PortC.0
PauseUs Delay_2
high PortC.1
PauseUs 500
low PortC.0
low PortC.1
hserin 0,MainStart,[WAIT("!"),STR Datain\3]
goto CheckAdr
Initialize:
Delay_1 = Datain[1] * 100
Delay_2 = Datain[2] * 100

GoTo MainStart

Can not work with two delays !?

Regard
Pesti

Pesticida
- 23rd January 2007, 12:55
Hello,

Did someone had the same Problem like Me.

I try all methods but I can not Dimm two Outputs.

Please I need Help or just a answer if this can work with two Channels.

Thanks.

Regard
Pesti

sayzer
- 23rd January 2007, 13:55
Are you trying to control two outputs with two different dimmer settings?

In your code, you seem to be having the same setting for both delays.

Pesticida
- 23rd January 2007, 15:20
Hi,

Yes I send trough RS485 data to my Pic,for channel one and channel two.

But when I receive the delay data for the first Channel for example 30*100=3000 us and 40 *100 =4000 us for the second Channel,then I think that this can not work while the first channel must wait 3000 us + 4000 us and then go low.

Did you understand what I mean,wehn I modify the data for Channel one then i go modify the data for the Channel two too.

regard
Pesti

Pesticida
- 23rd January 2007, 16:41
Ok Im A Idiot :-),Ifind the way I must just for every Channel put a New Zero Cross Detection like here:

POS_FLNK:IF ZeroDetect = 0 Then POS_FLNK
NEG_FLNK:IF ZeroDetect = 1 Then NEG_FLNK
PauseUs Delay_1
high PortC.0
pauseUs 100
low PortC.0
POS2_FLNK:IF ZeroDetect = 0 Then POS2_FLNK
NEG2_FLNK:IF ZeroDetect = 1 Then NEG2_FLNK
PauseUs Delay_2
high PortC.1
pauseUs 100
low PortC.1
hserin 1,MainStart,[WAIT("!"),DataIn[0],DataIn[1]]
Delay_1 = Datain[0] * 100
Delay_2 = Datain[1] * 100
GoTo MainStart

Regard Pesti

Pesticida
- 25th January 2007, 14:37
Hallo,

My Code is Working ,but :-) I dont have the full Brightness on all the light bulbs.

Did some one know what I can change in my Code,
I use now a 20 Mhz Osc.

Thanks.

Regard
Pesti