Hi

 > hope this is the correct place.  Can't seem to get PWM working, this 
is my PWM
 > set up routine is below.  Have not tried it in hardware - but gpsim 
shows the
 > correct pin set to an output but it does not have a signal on it.
 >

The code looks ok. I only have 18f2XXX devices here and there the pwm 
pins are on PORTC (TRISCbits.TRISC1 and TRISCbits.TRISC2) by default and 
the TMR2 is enabled with T2CONbits.TMR2ON = 1; In your code you used 
TMR2ON = 1, not sure if that works.

According to the microchip ANs its a good habit to first clear the 
CCPxCON register to completely disable the CCP-Module before setting own 
stuff.

I use the following code to enable both pwm channels on my 18f2XXX devices:

void init_pwm() {
   /* setup timer and prescaler */
   PR2 = PWM_FREQ;
   /* set prescaler */
   T2CONbits.T2CKPS0 = T2_PS0;
   T2CONbits.T2CKPS1 = T2_PS1;
   /* Set the duty cycle initially to zero but dont enable the h-bridge*/
   pwm_set_duty_cycle0(0);
   pwm_set_duty_cycle1(0);
   PORTCbits.RC1 = 0;
   /* clear the CCPxCON regs first to turn off the whole CCP-Module*/
   CCP1CON = 0;
   CCP2CON = 0;
   /* two lower bits of the pwm duty cycle register */
   CCP1CONbits.DC1B0 = 0;
   CCP1CONbits.DC1B1 = 0;
   CCP2CONbits.DC2B0 = 0;
   CCP2CONbits.DC2B1 = 0;
   /* set both CCP modules to PWM Mode */
   CCP1CONbits.CCP1M2 = 1;
   CCP1CONbits.CCP1M3 = 1;
   CCP2CONbits.CCP2M2 = 1;
   CCP2CONbits.CCP2M3 = 1;
   /* finaly make both pins an output */
   TRISCbits.TRISC1 = 0;
   TRISCbits.TRISC2 = 0;
   /*  enable the PWM Module */
   T2CONbits.TMR2ON = 1;
#ifdef DEBUG
   printf("PWM Module enabled");
#endif
}

hope this helps.

regards,

jan

-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to