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] PIC18Fx5K22..Cannot get a a single pin PWM CCP1 RC2 to work

Status
Not open for further replies.

Hoffman

Newbie level 3
Newbie level 3
Joined
Jun 19, 2015
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
94
Despite reading the spec sheet (and especially section 14.13.2) and although carefully following the steps, I cannot seem to get CCP1 pin RC2 to output a PWM signal.

All though there are many possible complex PWM bridge output configurations, I would really like to know how many single-output simple PWM's are possible.

My code attempt to get CCP1 RC2 TMR4 to work:
----------------------
I can see with the initialization below that TMR4 is counting and overlowing, but RC2 pin stays always at Vss.


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
void PWM1Setup(void)// CCP1 cbit2 using TMR4
{
TRISC2=0; //PWM  requires the PWM pin TRIS'd as output
 
//Select 8-bit Timer TMR4: Choices for CCP1 are TMR2/TMR4/TMR6,using  CxTSEL<1:0> bits of CCPTMRS0
//C1TSEL=0x01; //TMR4 selected   options are: 10=TMR6 00=TMR2 01=TMR4
CCPTMRS0=(CCPTMRS0 & 0xFC); //Mask to leave C3TSEL and C2TSEL unchanged
CCPTMRS0=(CCPTMRS0 | 0x01); //C1TSEL=0x01 TMR4 selected
 
/* T4CON
   Bit  7      6      5     4      3     2      1   0
 ------------------------------------------------------------------------
        x      0      0     0      1     1      0   0
               TxOUTPS<3:0>
               POSTSCALER 1:2 to 1:16  TMxOn    PRESCALER
                                                1:1=00 01=1:4 1x1:/16
*/
T4CON=0b00001100;
 
//CCP1CON holds duty cycle LSb in bits<5:4>LSbs, but CCPR1L=MSbits
CCP1CON=0;//(CCP1CON & 0xCF); //Mask P1M bits, MSbits of DCyc=0, CPR1H not used
PR4=0xFF; //overflow count 0XFF for 10-bit resolution for any PWM freq.
CCP1IE=0; // Disable CCP1 IRQ enable not used for PWM only mode
          //For 10-bit resolution, Switching P/S inductor must be >900uH/18v
          //19.53KHz period approx 50uSec                         >600UH/12v
TMR4IE = 0;    // enable TIMER4 interrupt
PEIE   = 1;    // enable peripheral interrupts
TMR4ON = 1;    //Turn on TMR4  used for duty cycle period
}
 
//setting duty cycle: DCyc is set in the low-priority isr that is working ok, periodically triggered at 100uSec using TMR0:
 
//--------------------SET PWM Duty Cycle-------------------------------
    CCP1CONbits.DC1B0 = DCyc & 1; //set low bit
    CCP1CONbits.DC1B1 = (DCyc >> 1) & 1;  //set second lowest
    CCPR1L = (DCyc >> 2); //sets DCycH hi 8 hi-bits
 
    TMR4IF=0;
//--------------------------------------------------------------------------------------------------------------------
//main() initialization:
void main(void)
{
  Init_PIC();
  Init_TMR0();
  PWM1Setup();//Setup CCP1 cbit2 PWM
 
  IPEN  =1;   //Priority interrupts enabled
 
  TMR0IE=1;  
  TMR0ON=1;
  TMR0IP=0;
  TMR4IP=0;
  TMR4ON=1;
  TMR4IP=0;  
  TMR4IE=0; 
  CCP1IE=0;   //these settings may not be necessary
  CCP1IP=0;  
//  PIE1=1;   //Not Needed for TMRx
//  PIE2=1;   //Not Needed for TMRx
    PLLEN =1;
    PEIE  =1;   //Needed for TMRx interrupts
    GIEL=1;   //Enables Low-Priority if GIEH/GIE=1
    GIEH=1;   //Ok to use INTCONbits.GIE = 1; to enable all interrupts     
 //======================== START =======================================
  Start:
  DCyc=500;
 
 goto Start;
 
 //I have set RC6 pin to toggle on/off, verified TMR0 IRQ's are fine, TMR4 counter is running and overflowing.
 
//but RC2 stays at Vss
 
}

 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top