[PIC] pic18f1330 pwm help needed

Status
Not open for further replies.

ruben91

Junior Member level 3
Joined
Nov 17, 2014
Messages
29
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
209
can anyone provide me with PWM coding in C to control led brightness for pic18f1330?i was using pic18f4580 previously, but here in pic18f1330 the port is totally different and i'm facing some difficulties here. thank u
 

Hi ruben,

Port difference in what sense? What kind of difficulties you are facing? You have to look at the port placement in the datasheet and modify the code to use the ports in p18f1330. A lot of time, you just have to modify a small part of the code to get it run. Maybe you want to paste the code here so that we can help out better.
 


Code:
*
 #include <p18f1330.h>
 #pragma config WDT = OFF
 #pragma config MCLRE = ON, DEBUG = OFF
 #pragma config CP0 = OFF, CP1 = OFF, WRTC = OFF, WRTD = OFF, EBTR0 =* OFF, EBTR1 = OFF, EBTRB = OFF
 #pragma config OSC=INTIO2 // Internal oscillator, port function on RA6 and RA7** IO1 has FOSC on RA6
 #pragma config PWRT = OFF
 
void pwm1(void);
void pwm2(void);
void pwm4(void);

 void main (void)
 {

 OSCCONbits.IRCF2 = 1; 
 OSCCONbits.IRCF1 = 1; 
 OSCCONbits.IRCF0 = 0; 

 *PTCON0 = 0xF;
 *PTCON1 = 0x0;********// the entire register set to 0
  PWMCON0 = 0x28;
 *PWMCON1 = 0x0; 
 *FLTCONFIG = 0x00;*
  PTMRL = 0;* //PWM start at 0;
 *PTMRH = 0;
 *PTPERL = 1;* //PWM time base period set to 10 bits
 *PTPERH = 0xFF;* //the higher bits will not be used here.
 *PDC0H = 10;****** //set period
 *PDC0L= 0xFF;
**PTCON1bits.PTEN* = 1;* // Enable PWM Timerbase !*** 
 
 for(;;){           //infinite loop
 }  //end for
 
 }


Hello d3javu,

above is my code for the pwm in p18f1330, and it works fine, what i meant by different, is in the sense of programing. Previously i was using ccp pin for pwm in pic18f4580, thats wat i mean, and i can make use of ccp roggramming as its not available in the series, tq

Hope the above coding can help others.
 

Hi Ruben,

I get what you mean. I roughly went through the datasheet of both microcontroller and yes, pic18f4580 has One Capture/Compare/PWM (CCP) module and Enhanced Capture/Compare/PWM (ECCP) module which are not available on pic18f1330. These are the sacrifices you have to make if you are going for lower end microcontrollers. But you still able to build almost similar function through coding, slightly more that is.
 
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…