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.

[PIC] Having Issues With Full-Bridge Signals [ Code MPLAB-X XC8 ]

Status
Not open for further replies.

Quantum.Dot

Newbie level 6
Joined
Apr 3, 2022
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
260
Having Issues With Full-Bridge Signals [ Code MPLAB-X XC8 ]

This is my code.

Code:
/*
 * File:   main.c
 * Author: Quantum.Dot
 *
 * Created on 2 April, 2022, 11:48 PM
 */

#define _XTAL_FREQ 16000000UL


// PIC18F45K22 Configuration Bit Settings

// 'C' source line config statements

// CONFIG1H
#pragma config FOSC = INTIO67   // Oscillator Selection bits (Internal oscillator block)
#pragma config PLLCFG = ON     // 4X PLL Enable (Oscillator used directly)
#pragma config PRICLKEN = ON    // Primary clock enable bit (Primary clock is always enabled)
#pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor enabled)
#pragma config IESO = ON        // Internal/External Oscillator Switchover bit (Oscillator Switchover mode enabled)

// CONFIG2L
#pragma config PWRTEN = ON      // Power-up Timer Enable bit (Power up timer enabled)
#pragma config BOREN = ON       // Brown-out Reset Enable bits (Brown-out Reset enabled and controlled by software (SBOREN is enabled))
#pragma config BORV = 285       // Brown Out Reset Voltage bits (VBOR set to 2.85 V nominal)

// CONFIG2H
#pragma config WDTEN = ON      // Watchdog Timer Enable bits (Watch dog timer is always disabled. SWDTEN has no effect.)
#pragma config WDTPS = 1024     // Watchdog Timer Postscale Select bits (1:1024)

// CONFIG3H
#pragma config CCP2MX = PORTC1  // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
#pragma config PBADEN = OFF     // PORTB A/D Enable bit (PORTB<5:0> pins are configured as digital I/O on Reset)
#pragma config CCP3MX = PORTB5  // P3A/CCP3 Mux bit (P3A/CCP3 input/output is multiplexed with RB5)
#pragma config HFOFST = ON      // HFINTOSC Fast Start-up (HFINTOSC output and ready status are not delayed by the oscillator stable status)
#pragma config T3CMX = PORTC0   // Timer3 Clock input mux bit (T3CKI is on RC0)
#pragma config P2BMX = PORTD2   // ECCP2 B output mux bit (P2B is on RD2)
#pragma config MCLRE = INTMCLR  // MCLR Pin Enable bit (RE3 input pin enabled; MCLR disabled)

// CONFIG4L
#pragma config STVREN = ON      // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
#pragma config LVP = OFF        // Single-Supply ICSP Enable bit (Single-Supply ICSP disabled)
#pragma config XINST = OFF      // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))

// CONFIG5L
#pragma config CP0 = OFF        // Code Protection Block 0 (Block 0 (000800-001FFFh) not code-protected)
#pragma config CP1 = OFF        // Code Protection Block 1 (Block 1 (002000-003FFFh) not code-protected)
#pragma config CP2 = OFF        // Code Protection Block 2 (Block 2 (004000-005FFFh) not code-protected)
#pragma config CP3 = OFF        // Code Protection Block 3 (Block 3 (006000-007FFFh) not code-protected)

// CONFIG5H
#pragma config CPB = OFF        // Boot Block Code Protection bit (Boot block (000000-0007FFh) not code-protected)
#pragma config CPD = OFF        // Data EEPROM Code Protection bit (Data EEPROM not code-protected)

// CONFIG6L
#pragma config WRT0 = OFF       // Write Protection Block 0 (Block 0 (000800-001FFFh) not write-protected)
#pragma config WRT1 = OFF       // Write Protection Block 1 (Block 1 (002000-003FFFh) not write-protected)
#pragma config WRT2 = OFF       // Write Protection Block 2 (Block 2 (004000-005FFFh) not write-protected)
#pragma config WRT3 = OFF       // Write Protection Block 3 (Block 3 (006000-007FFFh) not write-protected)

// CONFIG6H
#pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write-protected)
#pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot Block (000000-0007FFh) not write-protected)
#pragma config WRTD = OFF       // Data EEPROM Write Protection bit (Data EEPROM not write-protected)

// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protection Block 0 (Block 0 (000800-001FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF      // Table Read Protection Block 1 (Block 1 (002000-003FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR2 = OFF      // Table Read Protection Block 2 (Block 2 (004000-005FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR3 = OFF      // Table Read Protection Block 3 (Block 3 (006000-007FFFh) not protected from table reads executed in other blocks)

// CONFIG7H
#pragma config EBTRB = OFF      // Boot Block Table Read Protection bit (Boot Block (000000-0007FFh) not protected from table reads executed in other blocks)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>

#define scrGateTriggerPin LATD0
#define outputFullBridgeGateTriggerPin LATD1
#define LedPin  LATD2
#define zcdMimicPin LATB1

unsigned int state = 0;
unsigned int zcdCount = 0;
unsigned int timer2InterruptCount = 0;

unsigned int voltage = 0;
unsigned int frequency = 0;
unsigned int loadCurrent = 0;

unsigned sinewaveLutIndex = 0;

unsigned int sinewaveLUT[32] = {0,10,39,86,149,226,314,410,509,608,704,792,869,932,979,1008,1018,1008,979,932,869,792,704,608,
509,410,314,226,149,86,39,10};

/*
unsigned int sinewaveLUT[32] = {509,608,704,792,869,932,979,1008,1018,1008,979,932,869,792,704,608,
509,410,314,226,149,86,39,10,0,10,39,86,149,226,314,410};
*/

//Timer1
//Prescaler 1:4; TMR1 Preload = 25536; Actual Interrupt Time : 10 ms

//Place/Copy this part in declaration section
void InitTimer1() {
    T1CON = 0x21;
    TMR1IF = 0;
    TMR1H = 0x63;
    TMR1L = 0xC0;
    TMR1IE = 1;
}

//Timer2
//Prescaler 1:1; Postscaler 1:4; TMR2 Preload = 249; Actual Interrupt Time : 62.5 us
void InitTimer2(){
    T2CON = 0x1C;
    TMR2IE = 1;
    PR2 = 249;
    TMR2ON = 0;
}

void __interrupt () my_isr_routine (void) {
    if((TMR2IE) && (TMR2IF)) {
        TMR2IF = 0;
        scrGateTriggerPin = 0;
        //Enter your code here
        if(timer2InterruptCount++ == 5) {
            timer2InterruptCount = 0;
            if(++sinewaveLutIndex == 32) {
               sinewaveLutIndex = 0;
               P1M1 = ~P1M1;
            }
        }
     
        CCPR1L = (unsigned char)sinewaveLUT[sinewaveLutIndex];
        DC1B1 = ((sinewaveLUT[sinewaveLutIndex] >> 9) & 0x01);
        DC1B0 = ((sinewaveLUT[sinewaveLutIndex] >> 8) & 0x01);
    }
 
    if((TMR1IE) && (TMR1IF)) {
        TMR1IF = 0;
        TMR1H = 0x63;
        TMR1L = 0xC0;
        //Enter your code here
        zcdMimicPin = ~zcdMimicPin;
    }
 
    if((INT0IE) && (INT0IF)) {
        INT0IF = 0;
        INTEDG0 = ~INTEDG0;
        scrGateTriggerPin = 1;
        //Enter your code here
        if((zcdCount++ % 50) == 0)LedPin = ~LedPin;
     
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
     
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
     
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
     
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
     
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
     
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
     
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
     
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
     
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
     
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
     
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
     
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
     
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
     
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
     
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
     
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        __asm ("nop");
        //...
             
        scrGateTriggerPin = 0;
        if(!TMR2ON)TMR2ON = 1;
    }
}

void main(void) {
    OSCCON = 0b01110000;
    OSCCON2 = 0b00000111;
    OSCTUNE = 0b01000000;
 
    CM1CON0 = 0b00000000;
    CM2CON0 = 0b00000000;

    SLRCON = 0b00000000;

    ADCON1 = 0b00000000;
    ADCON2 = 0b10110101;

    ANSELA = 0b00000000;
    ANSELB = 0b00000000;
    ANSELC = 0b00000000;
    ANSELD = 0b00000000;
    ANSELE = 0b00000000;

    TRISA = 0b00000000;
    TRISB = 0b00000001;
    TRISC = 0b00000000;
    TRISD = 0b11111111;
    TRISE = 0b00000000;

    PORTA = 0b00000000;
    PORTB = 0b00000000;
    PORTC = 0b00000000;
    PORTD = 0b00000000;
    PORTE = 0b00000000;

    LATA = 0b00000000;
    LATB = 0b00000000;
    LATC = 0b00000000;
    LATD = 0b00000000;
    LATE = 0b00000000;

    P1M0 = 1;
    P1M1 = 0;

    INTEDG0 = 1;
    INT0IF = 0;
    INT0IE = 1;
 
    CCP1M0 = 1;
    CCP1M1 = 0;
    CCP1M2 = 1;
    CCP1M3 = 1;
 
    CCPR1L = 0;
    DC1B0 = 0;
    DC1B1 = 0;
 
    InitTimer2();
    TRISD = 0b00000000;
 
    InitTimer1();
 
    PEIE = 1;
    GIE = 1;
 
    while(1) {
        __asm("clrwdt");
    }
 
    return;
}
 

Attachments

  • ups-htr-ss002.png
    ups-htr-ss002.png
    142.7 KB · Views: 116
Last edited by a moderator:

Hi,

400 lines of uncommented code,
a scope picture...

No schematic, no information what "issue" you talk about.

This looks more like a big riddle than asking for help.

Klaus
 

Leave the nops() and the code becomes few lines.

The code is for a UPS based on PIC18F45K22.

The ZCD input to INT0/RB0 pin is mimiked by RB1 pin which toggles once every 10ms and is fed into RB0.

Timer1 and 2 are configured properly and also Oscillator. WDT check has been performed and there is no reset of PIC due to WDT.

The issue is only related to timings of the full-bridge signals and modulated (SPWM) signals look strange with breaks.

I guess schematic is not necessary to analyze the issue. The only signals from PIC18F45K22 are INT0/RB0 and RB1 as ZCD and PORTC2 = P1A, PORTD5,6,7 as P1B,P1C,P1D.

The circuit is this as of now.
 

Attachments

  • UPS-V1-REV1.PDF
    67.4 KB · Views: 153
  • UPS-V1-REV2.PDF
    67.4 KB · Views: 141
Last edited:

Hi,

I still don't know what you expect and what exactly you consider to be wrong.

Generally speaking about your code:
An ISR should be as short as possible. Busy "waits" should be avoided.
Still don't know what all the NOPs are good for.
Especially it seems they have something to do with an SCR .. but there is no SCR in your schematic.

I don't want to guess anymore.

Klaus
 

Hi,

I still don't know what you expect and what exactly you consider to be wrong.

Generally speaking about your code:
An ISR should be as short as possible. Busy "waits" should be avoided.
Still don't know what all the NOPs are good for.
Especially it seems they have something to do with an SCR .. but there is no SCR in your schematic.

I don't want to guess anymore.

Klaus


The SCR is for AC to DC Conversion part. Leave that. That signal is perfect and around 209us. It uses 4 SCRs as the controlled bridge rectifier for AC to DC conversion and 1-pair of diagonally opposite SCRs fire at a time and one SCR_GT_TRIG signal of width 209us is used and a 800V, 80A, Igt 40mA SCRs are used. One 74HC04 is used of which one NOT gate controls the GT of 1nd pair of diagonally opposite SCRs in the bridge.

The issues are with timings of P1A, P1B, P1C, and P1D signals and P1C and P1D modulated signals which are for the output N MOSFET full-bridge. The modulated signals look strange with breaks due to 0 value of the sinewave LUT.

The Timer2 is for 62.5us and so the SPWM frequency is 16kHz. It is a 32-point sinewave (32-points for 180 degrees) and each point is applied 5 times and so 62.5us * 5 * 32 = 10ms that is half of 20ms T which is the period of 220V 50Hz AC signal.

View attachment UPS-V1.png
--- Updated ---

This is the SCR-Bridge.


View attachment UPS-V1-REV2-SS01.png

View attachment UPS-V1-REV2-SS02.png
 
Last edited:

160 'nops' is possibly delaying the ISR return so it periodically misses a timer tick.
If I read the code and the problem correctly, the delay they create is only to set the duration of the SCR trigger pulse so why not set a flag in the ISR then use a simple timing loop in the main() section to make the delay. It would at least ensure the ISR exit was reached as quickly as possible.

Brian.
 

Thanks for replying Brian.

Tried that change with few other changes but there is no improvement in the P1A...P1D signals.

The SCR_GT_TRIG signal became better.


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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
 * File:   main.c
 * Author: Quantum.Dot
 *
 * Created on 2 April, 2022, 11:48 PM
 */
 
#define _XTAL_FREQ 16000000UL
 
 
 
// PIC18F45K22 Configuration Bit Settings
 
// 'C' source line config statements
 
// CONFIG1H
#pragma config FOSC = INTIO67   // Oscillator Selection bits (Internal oscillator block)
#pragma config PLLCFG = ON      // 4X PLL Enable (Oscillator multiplied by 4)
#pragma config PRICLKEN = ON    // Primary clock enable bit (Primary clock is always enabled)
#pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor enabled)
#pragma config IESO = ON        // Internal/External Oscillator Switchover bit (Oscillator Switchover mode enabled)
 
// CONFIG2L
#pragma config PWRTEN = ON      // Power-up Timer Enable bit (Power up timer enabled)
#pragma config BOREN = ON       // Brown-out Reset Enable bits (Brown-out Reset enabled and controlled by software (SBOREN is enabled))
#pragma config BORV = 285       // Brown Out Reset Voltage bits (VBOR set to 2.85 V nominal)
 
// CONFIG2H
#pragma config WDTEN = ON       // Watchdog Timer Enable bits (WDT is always enabled. SWDTEN bit has no effect)
#pragma config WDTPS = 1024     // Watchdog Timer Postscale Select bits (1:1024)
 
// CONFIG3H
#pragma config CCP2MX = PORTC1  // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
#pragma config PBADEN = OFF     // PORTB A/D Enable bit (PORTB<5:0> pins are configured as digital I/O on Reset)
#pragma config CCP3MX = PORTB5  // P3A/CCP3 Mux bit (P3A/CCP3 input/output is multiplexed with RB5)
#pragma config HFOFST = ON      // HFINTOSC Fast Start-up (HFINTOSC output and ready status are not delayed by the oscillator stable status)
#pragma config T3CMX = PORTC0   // Timer3 Clock input mux bit (T3CKI is on RC0)
#pragma config P2BMX = PORTD2   // ECCP2 B output mux bit (P2B is on RD2)
#pragma config MCLRE = INTMCLR  // MCLR Pin Enable bit (RE3 input pin enabled; MCLR disabled)
 
// CONFIG4L
#pragma config STVREN = ON      // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
#pragma config LVP = OFF        // Single-Supply ICSP Enable bit (Single-Supply ICSP disabled)
#pragma config XINST = OFF      // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))
 
// CONFIG5L
#pragma config CP0 = OFF        // Code Protection Block 0 (Block 0 (000800-001FFFh) not code-protected)
#pragma config CP1 = OFF        // Code Protection Block 1 (Block 1 (002000-003FFFh) not code-protected)
#pragma config CP2 = OFF        // Code Protection Block 2 (Block 2 (004000-005FFFh) not code-protected)
#pragma config CP3 = OFF        // Code Protection Block 3 (Block 3 (006000-007FFFh) not code-protected)
 
// CONFIG5H
#pragma config CPB = OFF        // Boot Block Code Protection bit (Boot block (000000-0007FFh) not code-protected)
#pragma config CPD = OFF        // Data EEPROM Code Protection bit (Data EEPROM not code-protected)
 
// CONFIG6L
#pragma config WRT0 = OFF       // Write Protection Block 0 (Block 0 (000800-001FFFh) not write-protected)
#pragma config WRT1 = OFF       // Write Protection Block 1 (Block 1 (002000-003FFFh) not write-protected)
#pragma config WRT2 = OFF       // Write Protection Block 2 (Block 2 (004000-005FFFh) not write-protected)
#pragma config WRT3 = OFF       // Write Protection Block 3 (Block 3 (006000-007FFFh) not write-protected)
 
// CONFIG6H
#pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write-protected)
#pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot Block (000000-0007FFh) not write-protected)
#pragma config WRTD = OFF       // Data EEPROM Write Protection bit (Data EEPROM not write-protected)
 
// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protection Block 0 (Block 0 (000800-001FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF      // Table Read Protection Block 1 (Block 1 (002000-003FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR2 = OFF      // Table Read Protection Block 2 (Block 2 (004000-005FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR3 = OFF      // Table Read Protection Block 3 (Block 3 (006000-007FFFh) not protected from table reads executed in other blocks)
 
// CONFIG7H
#pragma config EBTRB = OFF      // Boot Block Table Read Protection bit (Boot Block (000000-0007FFh) not protected from table reads executed in other blocks)
 
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
 
#include <xc.h>
 
#define scrGateTriggerPin LATD0
#define LedPin  LATD2
#define zcdMimicPin LATB1
 
unsigned int state = 0;
unsigned int zcdCount = 0;
unsigned int timer2InterruptCount = 0;
unsigned int voltage = 0;
unsigned int frequency = 0;
unsigned int loadCurrent = 0;
unsigned sinewaveLutIndex = 0;
 
unsigned int sinewaveLUT[32] = {0,10,39,86,149,226,314,410,509,608,704,792,869,932,979,1008,1018,1008,979,932,869,792,704,608,
509,410,314,226,149,86,39,10};
 
//Timer1
//Prescaler 1:4; TMR1 Preload = 25536; Actual Interrupt Time : 10 ms
 
//Place/Copy this part in declaration section
void InitTimer1() {
    T1CON = 0x21;
    TMR1IF = 0;
    TMR1H = 0x63;
    TMR1L = 0xC0;
    TMR1IE = 1;
}
 
//Timer2
//Prescaler 1:1; Postscaler 1:4; TMR2 Preload = 249; Actual Interrupt Time : 62.5 us
void InitTimer2(){
    T2CON = 0x1C;
    TMR2IE = 1;
    PR2 = 249;
    TMR2ON = 0;
}
 
void __interrupt () my_isr_routine (void) {
    if((TMR2IE) && (TMR2IF)) {
        TMR2IF = 0;
        //Enter your code here
        if(timer2InterruptCount++ == 5) {
            timer2InterruptCount = 0;
            scrGateTriggerPin = 0;
     
            if(++sinewaveLutIndex == 32) {
               sinewaveLutIndex = 0;        
               P1M1 = ~P1M1;
            }
     
            DC1B1 = ((sinewaveLUT[sinewaveLutIndex] >> 9) & 0x01);
            DC1B0 = ((sinewaveLUT[sinewaveLutIndex] >> 8) & 0x01);
            CCPR1L = (unsigned char)sinewaveLUT[sinewaveLutIndex];
        }        
    }
 
    if((TMR1IE) && (TMR1IF)) {
        TMR1IF = 0;
        TMR1H = 0x63;
        TMR1L = 0xC0;
        //Enter your code here
        zcdMimicPin = ~zcdMimicPin;
    }
 
    if((INT0IE) && (INT0IF)) {
        INT0IF = 0;
        INTEDG0 = ~INTEDG0;
        scrGateTriggerPin = 1;
        timer2InterruptCount = 0;
        //Enter your code here
        if((zcdCount++ % 50) == 0)LedPin = ~LedPin;
        if(!TMR2ON)TMR2ON = 1;
    }
}
 
void main(void) {
    OSCCON = 0b01110000;
    OSCCON2 = 0b00000111;
    OSCTUNE = 0b01000000;
 
    CM1CON0 = 0b00000000;
    CM2CON0 = 0b00000000;
 
    SLRCON = 0b00000000;
 
    ADCON1 = 0b00000000;
    ADCON2 = 0b10110101;
 
    ANSELA = 0b00000000;
    ANSELB = 0b00000000;
    ANSELC = 0b00000000;
    ANSELD = 0b00000000;
    ANSELE = 0b00000000;
 
    TRISA = 0b00000000;
    TRISB = 0b00000001;
    TRISC = 0b00000000;
    TRISD = 0b11111111;
    TRISE = 0b00000000;
 
    PORTA = 0b00000000;
    PORTB = 0b00000000;
    PORTC = 0b00000000;
    PORTD = 0b00000000;
    PORTE = 0b00000000;
 
    LATA = 0b00000000;
    LATB = 0b00000000;
    LATC = 0b00000000;
    LATD = 0b00000000;
    LATE = 0b00000000;
 
    P1M0 = 1;
    P1M1 = 0;
 
    INTEDG0 = 1;
    INT0IF = 0;
    INT0IE = 1;
 
    CCP1M0 = 1;
    CCP1M1 = 0;
    CCP1M2 = 1;
    CCP1M3 = 1;
 
    CCPR1L = 0;
    DC1B0 = 0;
    DC1B1 = 0;
 
    InitTimer2();
    TRISD = 0b00000000;
 
    InitTimer1();
 
    PEIE = 1;
    GIE = 1;
 
    while(1) {
        __asm("clrwdt");
    }
 
    return;
}



The only changes done are to the Tiimer2 and INT0 interrupt service routines.


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
void __interrupt () my_isr_routine (void) {
    if((TMR2IE) && (TMR2IF)) {
        TMR2IF = 0;
        //Enter your code here
        if(timer2InterruptCount++ == 5) {
            timer2InterruptCount = 0;
            scrGateTriggerPin = 0;
     
            if(++sinewaveLutIndex == 32) {
               sinewaveLutIndex = 0;        
               P1M1 = ~P1M1;
            }
     
            DC1B1 = ((sinewaveLUT[sinewaveLutIndex] >> 9) & 0x01);
            DC1B0 = ((sinewaveLUT[sinewaveLutIndex] >> 8) & 0x01);
            CCPR1L = (unsigned char)sinewaveLUT[sinewaveLutIndex];
        }        
    }
 
    if((TMR1IE) && (TMR1IF)) {
        TMR1IF = 0;
        TMR1H = 0x63;
        TMR1L = 0xC0;
        //Enter your code here
        zcdMimicPin = ~zcdMimicPin;
    }
 
    if((INT0IE) && (INT0IF)) {
        INT0IF = 0;
        INTEDG0 = ~INTEDG0;
        scrGateTriggerPin = 1;
        timer2InterruptCount = 0;
        //Enter your code here
        if((zcdCount++ % 50) == 0)LedPin = ~LedPin;
        if(!TMR2ON)TMR2ON = 1;
    }
}




The nop()'s were the main culprits.

Tried this modification and timings are correct but still the P1A and P1C modulated signals are not good that is SPWM signals are not good I guess. Timings are okay.


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
void __interrupt () my_isr_routine (void) {
    if((TMR2IE) && (TMR2IF)) {
        TMR2IF = 0;
        //Enter your code here
        timer2InterruptCount = timer2InterruptCount + 1;
        switch(timer2InterruptCount) {
            case 5:
                timer2InterruptCount = 0;
                scrGateTriggerPin = 0;
                sinewaveLutIndex = sinewaveLutIndex + 1;
                break;
        };
  
        switch(sinewaveLutIndex) {
            case 32:
                P1M1 = ~P1M1;
                timer2InterruptCount = 0;
                sinewaveLutIndex = 0;
                break;
        };
  
        DC1B1 = ((sinewaveLUT[sinewaveLutIndex] >> 9) & 0x01);
        DC1B0 = ((sinewaveLUT[sinewaveLutIndex] >> 8) & 0x01);
        CCPR1L = (unsigned char)sinewaveLUT[sinewaveLutIndex];
    }
 
    if((TMR1IE) && (TMR1IF)) {
        TMR1IF = 0;
        TMR1H = 0x63;
        TMR1L = 0xC0;
        //Enter your code here
        zcdMimicPin = ~zcdMimicPin;
    }
 
    if((INT0IE) && (INT0IF)) {
        INT0IF = 0;
        INTEDG0 = ~INTEDG0;
        scrGateTriggerPin = 1;
        timer2InterruptCount = 0;
        //Enter your code here
        if((zcdCount++ % 50) == 0)LedPin = ~LedPin; 
        if(!TMR2ON)TMR2ON = 1;
    }
}



ups-htr-ss003.png



View attachment UPS-V1-REV2-SS04.png
 
Last edited by a moderator:

Hi,

I'm not familiar with PIC..
And you don't spend time to improve your informations (like comments in your code).
Thus I don't spend much time, too.

I guess you don't understand
* the timer
* the PWM
* and interrupt concepts.

Thus you need to relate to existing tutorials, application notes, examples. (There are many, many in the internet)
Which one(s) did you use? (Links)
What do you understand so far?
And what information do you miss?

I guess there are a couple of problems:
* not synchronizing PWM value update to PWM phase
* confusing the PWM with manipulating counter value
* expecting wrong things

Examples:
* One time it sounds you are complaining about the "gap" in the PWM ... but next time you give the explanation for the gap.
* We don't know what the 50Hz signal, the ZCD is for, since it is not used for sine generation at all.
* we don't know on what exact item you are focussed. You say timing ... but don't show which exact timing you mean.
* we can not verify PWM frequency, because your scope pictures don't show. Is it close to 16kHz? (Can it be that it is way off?)

Klaus
 

Hi,

I'm not familiar with PIC..
And you don't spend time to improve your informations (like comments in your code).
Thus I don't spend much time, too.

I guess you don't understand
* the timer
* the PWM
* and interrupt concepts.

Thus you need to relate to existing tutorials, application notes, examples. (There are many, many in the internet)
Which one(s) did you use? (Links)
What do you understand so far?
And what information do you miss?

I guess there are a couple of problems:
* not synchronizing PWM value update to PWM phase
* confusing the PWM with manipulating counter value
* expecting wrong things

Examples:
* One time it sounds you are complaining about the "gap" in the PWM ... but next time you give the explanation for the gap.
* We don't know what the 50Hz signal, the ZCD is for, since it is not used for sine generation at all.
* we don't know on what exact item you are focussed. You say timing ... but don't show which exact timing you mean.
* we can not verify PWM frequency, because your scope pictures don't show. Is it close to 16kHz? (Can it be that it is way off?)

Klaus


I understand timer and pwm very well.

In PICs Timer2 is related to PWM module. The AC is 220V 50Hz. So, T is 20ms and T/2 is 10ms.

This is for a Stabilizer cum UPS where the mains 220V 50Hz 1-Phase AC is converted to DC with SCR bridge and directly applied to the load as 325V VBUS. Adding +/- up to 30V is done with additional circuit so that whatever be the load the VBUS is adjusted such that the load voltage is always 220V 50Hz AC. The UPS part will either have one or two 12V 20Ah batteries with output transformer or it will have only batteries and no soutput transformer. When there is mains which is sensed by ZCD circuit and frequency is found out in 30ms steps. If frequency is 50Hz then it is assumed that the system is 220V 50Hz AC system and if frequency detected is 60Hz then it is taken as 110V AC 60Hz system.

When there is mains supply then it is a stabilizer and when there is no mains it is a stabilizer cum UPS.

So, whenever load is connected in stabilizer mode and when load is reconnected to mains in stabilizer mode (through full-bridge circuit) the SPWM and non-modulated signals that is P1A,P1B,P1C, and P1D must be in sync with mains AC.

I will be modifying only the VBUS voltage to keep output constant in both stabilizer and UPS modes.


Code C - [expand]
1
2
3
4
P1M0 = 1;
P1M1 = 0;
 
//P1M1 = 0; //this one toggles



The above toggles the full-bridge direction and it must be once every 10ms.


Code C - [expand]
1
2
3
INTEDG0 = 1;
INT0IF = 0;
INT0IE = 1;



The above configures the external interrupt INT0 to detect positive going transition of the ZC signal.
In ISR the INTEDG0 bit is toggles to alternately detect H-to-L and L-to-H of the ZC signals.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
CCP1M0 = 1;
CCP1M1 = 0;
CCP1M2 = 1;
CCP1M3 = 1;
[syntax=c]
 
These configure the Capture Compare PWM module ECCP1 for full-bridge mode with P1A,P1C active and P1B,P1D inactive and P1A and P1C are non modulated and P1B and P1C are modulated signals.
 
[syntax=c]
CCPR1L = 0;
DC1B0 = 0;
DC1B1 = 0;



CCPR1L is an 8-bit duty register and the duty used is 10-bit one and the higher two bits of the duty from the sine LUT goes into the DC1Bx bits.
 
Last edited:

Hi,

How is post#9 focussed on the problem you see?
It gives me not the informations I asked for.

I guess I'm not of help anymore.

Klaus
 

Hi,

I'm not familiar with PIC..
And you don't spend time to improve your informations (like comments in your code).
Thus I don't spend much time, too.

I guess you don't understand
* the timer
* the PWM
* and interrupt concepts.

Thus you need to relate to existing tutorials, application notes, examples. (There are many, many in the internet)
Which one(s) did you use? (Links)
What do you understand so far?
And what information do you miss?

I guess there are a couple of problems:
* not synchronizing PWM value update to PWM phase
* confusing the PWM with manipulating counter value
* expecting wrong things

Examples:
* One time it sounds you are complaining about the "gap" in the PWM ... but next time you give the explanation for the gap.
* We don't know what the 50Hz signal, the ZCD is for, since it is not used for sine generation at all.
* we don't know on what exact item you are focussed. You say timing ... but don't show which exact timing you mean.
* we can not verify PWM frequency, because your scope pictures don't show. Is it close to 16kHz? (Can it be that it is way off?)

Klaus


I have not used any internet tutorials or links.

PIC18F has PWM module which can generate Half and Full bridge signals.

I am using the Full-Bridge mode for the output.

SPWM signals have to be generated by applying correct sequence of sinewave duties (which in turn are PWM duties) to the CCPR1L and DC1B0 and DC1B1 bits to get the 10-bit PWM based SPWM signals.

32 points are used in the 180 degree of the sine signal. The full-bridge toggles once every 10ms in my system to get a 50Hz signal and so the Timer2 related to ECCP1 is configured for 62.5us T. F = 16kHz.

Timer2 ISR loads the PWM duties on every interrupt but duty changes once every 5 interrupts and so 5 * 32 * 62.5us = 10ms. Then P1M1 bit toggles and the full-bridge is reversed and so the direction of the resultant AC signal of the bridge obtained with or without the LC filter produces alternating square wave of 325V DC or sinewave voltage signal of 220V 50Hz with LC filter.

Let me know if you need more information.
 

I'm not sure but shouldn't TMR2 be configured for the PWM frequency then left alone. You turn it off during the duty cycle calculation then turn it on again. Cant you just reprogram the duty cycle as needed but leave the timer running and without its interrupts enabled. I would have used a timer to step through the sine table but not actually stopped the PWM while doing it.

Brian.
 

I'm not sure but shouldn't TMR2 be configured for the PWM frequency then left alone. You turn it off during the duty cycle calculation then turn it on again. Cant you just reprogram the duty cycle as needed but leave the timer running and without its interrupts enabled. I would have used a timer to step through the sine table but not actually stopped the PWM while doing it.

Brian.

I modified the code and cleaned it up.

Now the PWM frequency as set by Timer2 is 16khz and T is 62.5us. Instead of 32 points I have chosen 32 * 5 = 160 points. Nearly 10-bit PWM duty according to device datasheet PWM section formula and so max 1018 as the PWM duty.

Signals have improved and timings are perfect but still the two modulated signals doesn't look good.

Is there any issue with Oscillator configuration?

I am using Internal HFOSCINT 16mhz will x4 PLL.

I doubt that OSCCON, OSCCON2, OSCTUNE settings might be incorrect.

Can you please check them for me?


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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
 * File:   main.c
 * Author: Quantum.Dot
 *
 * Created on 3 April, 2022, 6:47 PM
 */
 
#define _XTAL_FREQ 16000000UL
 
// PIC18F45K22 Configuration Bit Settings
// 'C' source line config statements
 
// CONFIG1H
#pragma config FOSC = INTIO67   // Oscillator Selection bits (Internal oscillator block)
#pragma config PLLCFG = ON      // 4X PLL Enable (Oscillator multiplied by 4)
#pragma config PRICLKEN = ON    // Primary clock enable bit (Primary clock is always enabled)
#pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor enabled)
#pragma config IESO = ON        // Internal/External Oscillator Switchover bit (Oscillator Switchover mode enabled)
 
// CONFIG2L
#pragma config PWRTEN = ON      // Power-up Timer Enable bit (Power up timer enabled)
#pragma config BOREN = ON       // Brown-out Reset Enable bits (Brown-out Reset enabled and controlled by software (SBOREN is enabled))
#pragma config BORV = 285       // Brown Out Reset Voltage bits (VBOR set to 2.85 V nominal)
 
// CONFIG2H
#pragma config WDTEN = ON       // Watchdog Timer Enable bits (WDT is always enabled. SWDTEN bit has no effect)
#pragma config WDTPS = 1024     // Watchdog Timer Postscale Select bits (1:1024)
 
// CONFIG3H
#pragma config CCP2MX = PORTC1  // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
#pragma config PBADEN = OFF     // PORTB A/D Enable bit (PORTB<5:0> pins are configured as digital I/O on Reset)
#pragma config CCP3MX = PORTB5  // P3A/CCP3 Mux bit (P3A/CCP3 input/output is multiplexed with RB5)
#pragma config HFOFST = ON      // HFINTOSC Fast Start-up (HFINTOSC output and ready status are not delayed by the oscillator stable status)
#pragma config T3CMX = PORTC0   // Timer3 Clock input mux bit (T3CKI is on RC0)
#pragma config P2BMX = PORTD2   // ECCP2 B output mux bit (P2B is on RD2)
#pragma config MCLRE = INTMCLR  // MCLR Pin Enable bit (RE3 input pin enabled; MCLR disabled)
 
// CONFIG4L
#pragma config STVREN = ON      // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
#pragma config LVP = OFF        // Single-Supply ICSP Enable bit (Single-Supply ICSP disabled)
#pragma config XINST = OFF      // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))
 
// CONFIG5L
#pragma config CP0 = OFF        // Code Protection Block 0 (Block 0 (000800-001FFFh) not code-protected)
#pragma config CP1 = OFF        // Code Protection Block 1 (Block 1 (002000-003FFFh) not code-protected)
#pragma config CP2 = OFF        // Code Protection Block 2 (Block 2 (004000-005FFFh) not code-protected)
#pragma config CP3 = OFF        // Code Protection Block 3 (Block 3 (006000-007FFFh) not code-protected)
 
// CONFIG5H
#pragma config CPB = OFF        // Boot Block Code Protection bit (Boot block (000000-0007FFh) not code-protected)
#pragma config CPD = OFF        // Data EEPROM Code Protection bit (Data EEPROM not code-protected)
 
// CONFIG6L
#pragma config WRT0 = OFF       // Write Protection Block 0 (Block 0 (000800-001FFFh) not write-protected)
#pragma config WRT1 = OFF       // Write Protection Block 1 (Block 1 (002000-003FFFh) not write-protected)
#pragma config WRT2 = OFF       // Write Protection Block 2 (Block 2 (004000-005FFFh) not write-protected)
#pragma config WRT3 = OFF       // Write Protection Block 3 (Block 3 (006000-007FFFh) not write-protected)
 
// CONFIG6H
#pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write-protected)
#pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot Block (000000-0007FFh) not write-protected)
#pragma config WRTD = OFF       // Data EEPROM Write Protection bit (Data EEPROM not write-protected)
 
// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protection Block 0 (Block 0 (000800-001FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF      // Table Read Protection Block 1 (Block 1 (002000-003FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR2 = OFF      // Table Read Protection Block 2 (Block 2 (004000-005FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR3 = OFF      // Table Read Protection Block 3 (Block 3 (006000-007FFFh) not protected from table reads executed in other blocks)
 
// CONFIG7H
#pragma config EBTRB = OFF      // Boot Block Table Read Protection bit (Boot Block (000000-0007FFh) not protected from table reads executed in other blocks)
 
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
 
#include <xc.h>
 
#define zcdMimicPin LATB1
#define scrGateTriggerPin LATD0
#define LedPin  LATD2
#define enableLoad LATD3
 
unsigned int zcdCount = 0;
unsigned int SPWMdutyLUTIndex = 0;
 
unsigned int SPWMdutyLUT[160] = {
0,0,2,4,6,10,14,19,25,31,39,47,55,65,75,86,97,109,122,135,149,163,178,194,
210,226,243,260,278,296,314,333,352,371,390,410,429,449,469,489,509,529,
549,569,589,608,628,647,666,685,704,722,740,758,775,792,808,824,840,855,
869,883,896,909,921,932,943,953,963,971,979,987,993,999,1004,1008,1012,
1014,1016,1018,1018,1018,1016,1014,1012,1008,1004,999,993,987,979,971,
963,953,943,932,921,909,896,883,869,855,840,824,808,792,775,758,740,722,
704,685,666,647,628,608,589,569,549,529,509,489,469,449,429,410,390,371,
352,333,314,296,278,260,243,226,210,194,178,163,149,135,122,109,97,86,75,
65,55,47,39,31,25,19,14,10,6,4,2,0};
 
//Timer1
//Prescaler 1:4; TMR1 Preload = 25536; Actual Interrupt Time : 10 ms
 
//Place/Copy this part in declaration section
void InitTimer1() {
    T1CON = 0x21;
    TMR1IF = 0;
    TMR1H = 0x63;
    TMR1L = 0xC0;
    TMR1IE = 1;
}
 
//Timer2
//Prescaler 1:1; Postscaler 1:4; TMR2 Preload = 249; Actual Interrupt Time : 62.5 us
void InitTimer2(){
    T2CON = 0x1C;
    TMR2IE = 1;
    PR2 = 249;  
}
 
void __interrupt () my_isr_routine (void) {
    if((TMR2IE) && (TMR2IF)) {
        TMR2IF = 0;
        switch(SPWMdutyLUTIndex) {
            case 2:
                scrGateTriggerPin = 0;              
                break;
            case 0:
                P1M1 = ~P1M1;                      
                break;   
        };
      
        DC1B1 = ((SPWMdutyLUT[SPWMdutyLUTIndex] >> 9) & 0x01);
        DC1B0 = ((SPWMdutyLUT[SPWMdutyLUTIndex] >> 8) & 0x01);
        CCPR1L = (unsigned char)SPWMdutyLUT[SPWMdutyLUTIndex];
        SPWMdutyLUTIndex = SPWMdutyLUTIndex + 1;
        if(SPWMdutyLUTIndex == 160)SPWMdutyLUTIndex = 0;
    }
  
    if((TMR1IE) && (TMR1IF)) {
        TMR1IF = 0;
        TMR1H = 0x63;
        TMR1L = 0xC0;
        zcdMimicPin = ~zcdMimicPin;
    }
  
    if((INT0IE) && (INT0IF)) {
        scrGateTriggerPin = 1;
        SPWMdutyLUTIndex = 0;
        INT0IF = 0;
        INTEDG0 = ~INTEDG0;
        if(!TMR2ON)TMR2ON = 1;      
        if((++zcdCount % 50) == 0)LedPin = ~LedPin;     
    }
}
 
void main(void) {
    OSCCON = 0b01110000;
    OSCCON2 = 0b00000111;
    OSCTUNE = 0b01000000;
  
    CM1CON0 = 0b00000000;
    CM2CON0 = 0b00000000;
 
    SLRCON = 0b00000000;
 
    ADCON1 = 0b00000000;
    ADCON2 = 0b10110101;
 
    ANSELA = 0b00000000;
    ANSELB = 0b00000000;
    ANSELC = 0b00000000;
    ANSELD = 0b00000000;
    ANSELE = 0b00000000;
 
    TRISA = 0b00000000;
    TRISB = 0b00000001;
    TRISC = 0b00000000;
    TRISD = 0b11111111;
    TRISE = 0b00000000;
 
    PORTA = 0b00000000;
    PORTB = 0b00000000;
    PORTC = 0b00000000;
    PORTD = 0b00000000;
    PORTE = 0b00000000;
 
    LATA = 0b00000000;
    LATB = 0b00000000;
    LATC = 0b00000000;
    LATD = 0b00000000;
    LATE = 0b00000000;
 
    P1M0 = 1;
    P1M1 = 0;
 
    INTEDG0 = 0;
    INT0IF = 0;
    INT0IE = 1;
  
    CCP1M0 = 1;
    CCP1M1 = 0;
    CCP1M2 = 1;
    CCP1M3 = 1;
  
    CCPR1L = 0;
    DC1B0 = 0;
    DC1B1 = 0;
  
    InitTimer2();
    InitTimer1();
    TRISD = 0b00000000;
  
    PEIE = 1;
    GIE = 1;
  
    while(1) {
        __asm("clrwdt");      
    }
  
    return;
}



Soon I will post the Logic Analyzer screenshot for the signals.

2022-04-03 (3).png
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top