djc
Advanced Member level 1
I want to run PWM1 and PWM2 modules for PIC10F320 using MikroC. PWM1 running good. However PWM2 is not running at all. Can anyone tell me what could be the issue? Here is the code.
Code:
#define Channel_1 PORTA.B0
#define Channel_2 PORTA.B1
PortNClock(){
TRISA = 0b00000101; // RA2 as as i/p
PORTA = 0x00;
ANSELA = 0b00000100; //RA2 as ADC i/p
OSCCON = 0b01100000; // 8 MHz internal clock
CWG1CON0 = 0x00; //complementry waveform generator off
CWG1CON1 = 0x00; //complementry waveform generator off
CWG1CON2 = 0x00; //complementry waveform generator off
}
Timer2(){
T2CON= 0b00000000; //Timer2 off,1:1 prescalar
INTCON = 0b11000000;
PIE1 = 0b00000010; //Enable TMR2 to PR2 match interrupt
PIR1.TMR2IF = 0; //Clear the timer 2 interrupt flag
TMR2 = 0;
}
InitPWM1()
{
TRISA.B0 = 1;
Channel_1 = 0;
PWM1CON = 0b00000000; // Clear PWM1CON
//PIR1.TMR2IF = 0;
PWM1DCH = 0b00000000; // Clear duty cycle registers
PWM1DCL = 0b00000000;
PR2 = 0b00010100; // Set period to 20
TMR2ON_bit = 1;
PWM1CON = 0b11000000; //Enable PWM Module,Enable output,Enable pin and Polarity active high
TRISA.B0 = 0;
PWM1DCH = 0b00001110; // Confugure duty cycle registers
PWM1DCL = 0b00000000;
}
InitPWM2()
{
TMR2ON_bit = 0;
TRISA.B1 = 1;
Channel_2 = 0;
PWM2CON = 0b00000000; // Clear PWM1CON
//PIR1.TMR2IF = 0;
PWM2DCH = 0b00000000; // Clear duty cycle registers
PWM2DCL = 0b00000000;
PR2 = 0b00010100; // Set period to 20
TMR2ON_bit = 1;
PWM2CON = 0b11000000; //Enable PWM Module,Enable output,Enable pin and Polarity active high
TRISA.B1 = 0;
PWM2DCH = 0b01111111;
PWM2DCL = 0b10000000;
}
void main() {
PortNClock();
Timer2();
InitPWM1();
InitPwM2();
while(1){}
}