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.
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.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.
The shown circuit however misses a ground connection. Please consider that the oscilloscope measures relative to ground but the circuit has no ground.
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; } } }
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?