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.

How to configure PWM2 module in PIC10F320

Status
Not open for further replies.

djc

Advanced Member level 1
Joined
Jan 27, 2013
Messages
402
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
India
Activity points
4,554
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){}
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top