From: Peter C. <pe...@pe...> - 2008-07-13 12:40:12
|
Chaps, 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. Thoughts? Pete void pwm_setup() { //Set PR2 to 255 - set PWM period PR2 = 0xFE; //Set up timer 2 prescaler which is also used by the PCM module // 00 = 1:1 prescaler // 01 = 1:4 prescaler // 1x = 1:16 prescaler T2CKPS0 = 0; T2CKPS1 = 0; //With the above settings and 4MHz crystal we are looking at about 3.9 kHz PWM //period. //LSB for the PWM period counter, bits 5 and 4 - set to zero //CCP1CON = CCP1CON & 207; //CCP1CON = CCP1CON | 1 | 2| 4| 8; //set them high! CCP1CON = 15; //MSB - set at something mid way for testing. Will be zero for final set up; CCPR1L = 0x80; //Timer 2 on TMR2ON = 1; //Set up TRISB bit 3 as output - clear this bit TRISB = TRISB & 247; } Can post full code and make file if it helps. Pete -- Peter Chant http://www.petezilla.co.uk |