Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Why this is not working ?

Status
Not open for further replies.
@FvM

I will check.

Here is my Timer interrupt based TRIAC control. Fires triac after 5 ms for 50 Hz AC. buttons are not programmed yet.

- - - Updated - - -

I'm not using Proteus 8 and can't check your simulation setup. But obviously the 4n37 output waveform (about 50 Hz square wave with 50 percent duty cycle) is different from the expectable 100 Hz pulses. It may be something trivial like interchanged pins in the simulation model. You can find out by e.g. reviewing a SPICE netlist of the design.

I have connected the junction where diodes D4 and D3 meets to GND. Is it causing the bridge to function only for half of AC ? I had to use GND because without GND connected to VSINE it doesn't simulate and gives GMIN step error.
 

Attachments

  • Dimmer.rar
    176.8 KB · Views: 135
  • dimmer.png
    dimmer.png
    136.7 KB · Views: 163

I have connected the junction where diodes D4 and D3 meets to GND. Is it causing the bridge to function only for half of AC ? I had to use GND because without GND connected to VSINE it doesn't simulate and gives GMIN step error.
O.K. this explains everything. The picture wasn't visible when I first commented about incorrect waveform. You probably want to correct the circuit in a way that i does not apply the full input voltage to the optocoupler LED.

Apart from this "small problem" you made a halfwave rectifier and got half wave output. Trigger on both edges of the zero crossing signal and everything is fine.
 
Ok. I have ordered the components. I will test in hardware and reply soon. I don't know how to do that in Proteus. In my Proteus if VSINE is not connected to GND it gives GMIN step error and exits simulation.
 

You are working with SPICE simulators for some time as far as I'm aware of. So you should know about some requirements of the simulators, e.g. have no floating nodes. It can be usually overcome by connecting high ohmic resistors, e.g. 100Meg or 1G.

There may be a specific problem with the zero-crossing detector circuit having a too small output pulse, in so far the 50 Hz zero crossing pulse might be a good idea.
 
I have not done AC related simulation much. Here I am attaching bridge rectifier which I made. It simulates fine now but still unable to integrate it in TRIAC simulation. It gives GMIN stepping error and exits. My Proteus file is Proteus 8.1 SP1 format.

Edit 1:

@FvM

When there is only AC or DC things it simulates file but if there is both AC and DC in Proteus then there will be a GND of DC and then Proteus gives error. Maybe you are telling me to have a high value resistance between AC and DC ground. Am I right ? If yes, I will try that.
 

Attachments

  • bridge rectifier.rar
    11.7 KB · Views: 125
  • br.png
    br.png
    100.9 KB · Views: 142
Last edited:

Convergence problem in transient analysis can also occur without floating nodes, by nature of some components and due to unsuitable default SPICE solver parameters. I would suggest in a first a order to read the respective suggestions in the Proteus VSM manual.

The shown circuit however misses a ground connection. Please consider that the oscilloscope measures relative to ground but the circuit has no ground. There are apparently hidden built-in resistors in the Proteus simulation circuit.
 
Ok. I will read the manual.

Here is new circuit. AC negative half wave vanishes. Bridge is working fine and also 4N37 (INT0) and LATD.F0 (Gate trigger). TRIAC signal is strange. I have removed the toggling of INTEGD0 in code. There are now two ZCs per AC wave.
 

Attachments

  • dimmer test4.rar
    22.5 KB · Views: 121
  • dimmer test 4.png
    dimmer test 4.png
    186.2 KB · Views: 149

Both yellow traces are meaningless due to the strange ground situation. In a real world you would need a differential probe to measure voltages in the triac circuit. In the simulation, you can use a voltage controlled voltage source as probe replacement.
 

@ALERTLINKS: "But it does move" (Galilei)

Do you see what has been wrong in the orginal design?
 

7121665000_1424884017.jpg


Ground is wrongly placed. Need only to move like this.

The shown circuit however misses a ground connection. Please consider that the oscilloscope measures relative to ground but the circuit has no ground.
 
@FvM

Yes.

Thank you ALETLINKS. Now I can finalize the code using Timer interrupts.
 

Attachments

  • Dimmer fixed rev1.rar
    54.6 KB · Views: 112

It was OK in post #12. After that added ground on optocoupler in post#15. In post#27, the ground for scope removed. Now you see, there is nothing new. It is same as in post#12 except the improvement in code.
 
My circuits never contained the two resistors that you added between VSINE and bridge.
 

That is just another way to connect. Try to correct ground connection in attachment in post#27 according to as described in post#31. What went wrong in post#12?
 

Earlier I had tried what you have mentioned in post #31 but it was giving GMIN stepping error but now it works fine.


I really don't know what was wrong in circuit of post #12 but I am sure that the code was fine. Maybe it was a bug of Proteus or deficiency of resources needed for simulation.
 

Attachments

  • dimmer test 5.png
    dimmer test 5.png
    119.7 KB · Views: 133
  • Dimmer Timer Interrupt with buttons.rar
    22.4 KB · Views: 109
Last edited:

Be careful!! You missed current limiting resistor for optocoupler.
 

Post #12 circuit contains a 22k for optocoupler input circuit (current limiting).
 

My project is 4 Triac control. I have 8 buttons to increment or decrement the firing angle of 4 Triacs. The timer interrupt is for 1 ms. Between two ZCs there is 10 ms duration. The triac can fire at 9th ms and conduct till 10th ms after which it turns OFF hence the milliSec[x] counter values can have a max value of 9. The milliSec[x] can have a value of 0. So, when it is 0 the TRIACs whose milliSec[x] value is 0 have to be fired at ZC. So, When timer is started after ZC the initial value loaded to Timer is 0xFFFF so that when timer starts it immediately interrupts and fires the TRIACs whose millisec[x] values are 0.

Now, what is wrong in the code ? Why buttons are not working ? mikroC PRO PIC Compiler is used for coding and Proteus 8.1 SP1 format file is attached.

- - - Updated - - -

Edit:

Modified the code a little (rev1). Still it is not working.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
char milliSec[4] = {0, 0, 0, 0}, i = 0, max_ = 0, initial = 0, readKeys = 0;
 
sbit Gate1_Trigger at LATD0_bit;
sbit Gate1_Trigger_Direction at TRISD0_bit;
 
sbit Gate2_Trigger at LATD1_bit;
sbit Gate2_Trigger_Direction at TRISD1_bit;
 
sbit Gate3_Trigger at LATD2_bit;
sbit Gate3_Trigger_Direction at TRISD2_bit;
 
sbit Gate4_Trigger at LATD3_bit;
sbit Gate4_Trigger_Direction at TRISD3_bit;
 
//Timer1
//Prescaler 1:1; TMR1 Preload = 63536; Actual Interrupt Time : 1 ms
 
//Place/Copy this part in declaration section
void InitTimer1() {
    T1CON = 0x01;
    TMR1IF_bit = 0;
    TMR1H = 0xF8;
    TMR1L = 0x30;
    TMR1IE_bit = 1;
}
 
void InitTimer1Initial() {
    T1CON = 0x01;
    TMR1IF_bit = 0;
    TMR1H = 0xFE;
    TMR1L = 0xFF;
    TMR1IE_bit = 1;
}
 
void interrupt() {
 
     if(INT0IF_bit) {
        i = 0;
        if(initial == 0){InitTimer1Initial(); initial = 1;}
        else InitTimer1();
        INT0IF_bit = 0;
     }
     
     if(TMR1IF_bit) {
     
          if(i == (milliSec[0]))
              Gate1_Trigger = 1;
 
          if(i == (milliSec[1]))
              Gate2_Trigger = 1;
 
          if(i == (milliSec[2]))
              Gate3_Trigger = 1;
 
          if(i == (milliSec[3]))
              Gate4_Trigger = 1;
 
          Delay_us(100);
          Gate1_Trigger = 0;
          Gate2_Trigger = 0;
          Gate3_Trigger = 0;
          Gate4_Trigger = 0;
          
          if(i == max_)TMR1ON_bit = 0;
          
          ++i;
          
          TMR1IF_bit = 0;        // 1ms Timer interrupt
          TMR1H = 0xF8;
          TMR1L = 0x30;
     }
     
     if(INT1IF_bit) {
          readKeys = 1;
          INT1IF_bit = 0;
     }
}
 
void main() {
 
     CM1CON0 = 0x00;
     CM2CON0 = 0x00;
     
     ANSELA = 0x00;
     ANSELB = 0x00;
     ANSELC = 0x00;
     ANSELD = 0x00;
     ANSELE = 0x00;
 
     TRISA = 0xC0;
     TRISB = 0x03;
     TRISC = 0xFF;
     TRISD = 0x00;
     TRISE = 0x08;
 
     PORTA = 0x00;
     PORTB = 0x00;
     PORTC = 0x00;
     PORTD = 0x00;
     PORTE = 0x08;
 
     LATA = 0x00;
     LATB = 0x00;
     LATC = 0xFF;
     LATD = 0x00;
     LATE = 0x00;
 
     Gate1_Trigger_Direction = 0;
     Gate2_Trigger_Direction = 0;
     Gate3_Trigger_Direction = 0;
     Gate4_Trigger_Direction = 0;
 
     Gate1_Trigger = 0;
     Gate2_Trigger = 0;
     Gate3_Trigger = 0;
     Gate4_Trigger = 0;
 
     INTEDG0_bit = 0;
     INT0IF_bit = 0;
     INT0IE_bit = 1;
     
     INTEDG1_bit = 1;
     INT1IF_bit = 0;
     INT1IE_bit = 1;
     
     PEIE_bit = 1;
     GIE_bit = 1;
 
     while (1) {
 
            if(milliSec[0] > milliSec[1])max_ = milliSec[0];
            else max_ = milliSec[1];
            
            if(milliSec[1] > milliSec[2])max_ = milliSec[1];
            else max_ = milliSec[2];
            
            if(milliSec[2] > milliSec[3])max_ = milliSec[2];
            else max_ = milliSec[3];
            
            if(milliSec[3] > milliSec[4])max_ = milliSec[3];
            else max_ = milliSec[4];
            
            if(readKeys) {
                 Delay_ms(50);
                 
                 if(PORTC == 0x01)
                        if(milliSec[0] < 9)++milliSec[0];
                 else if(PORTC == 0x02)
                        if(milliSec[0] > 0)--milliSec[0];
                 else if(PORTC == 0x04)
                        if(milliSec[1] < 9)++milliSec[1];
                 else if(PORTC == 0x08)
                        if(milliSec[1] > 0)--milliSec[1];
                 else if(PORTC == 0x10)
                        if(milliSec[2] < 9)++milliSec[2];
                 else if(PORTC == 0x20)
                        if(milliSec[2] > 0)--milliSec[2];
                 else if(PORTC == 0x40)
                        if(milliSec[3] < 9)++milliSec[3];
                 else if(PORTC == 0x80)
                        if(milliSec[3] > 0)--milliSec[3];
                        
                 readKeys = 0;
            }
     }
}

 

Attachments

  • 4 Dimmer Timer Interrupt with buttons.rar
    71.1 KB · Views: 119
  • 4 dimmer.png
    4 dimmer.png
    126.3 KB · Views: 133
  • 4 Dimmer Timer Interrupt with buttons rev1.rar
    63.5 KB · Views: 113
  • dimmer.png
    dimmer.png
    40.4 KB · Views: 127
I understand that your focus is on software not hardware design.

But why are you repeatedly posting circuits that will immediately explode into smoke when build in real hardware, although the fault has been mentioned by others?

8497872000_1424937156.gif
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top