Forwarded because the tag was wrong, corrected now. Sean >X-Warning: mitvma.mit.edu: Host pool-141-152-153-173.norf.east.verizon.net > claimed to be cv-server.CRED-USA.local >X-Mailer: Microsoft Outlook, Build 10.0.2627 >Importance: Normal >X-OriginalArrivalTime: 13 Jan 2003 02:29:04.0799 (UTC) > FILETIME=[8AA442F0:01C2BAAB] >Date: Sun, 12 Jan 2003 21:29:04 -0500 >Reply-To: williams.engineering@verizon.net >Sender: pic microcontroller discussion list >X-PH: V4.1@mailhub3 >From: James Williams >Organization: Williams Engineering >Subject: [PIC] PWM Refuses to change frequency once set for the first time >To: PICLIST@MITVMA.MIT.EDU > >Hello, > >I am going crazy here now and I don't know what is going on. When I >setup my PWM frequency for the first time for a 20KHz frequency, it >works fine, however when I dynamically try to change the frequency to >5KHz, it does not change the frequency. It continues to remain at >20KHz. I have even tried to hard code the prescale and PR2 registers to >see if my variables where being changed. Even the hard coded values >does not change the PWM frequency once it has been set for the first >time. > >Here is the code I have be trying to work out. >;TRICKEL_PRESCALE = 0x03 >;TRICKEL_DUTY_L = B'00110000' >;TRICKEL_DUTY_H = 0x04 >;TOSC = 40MHz > >;Turn off the timer and disable the PWM by clearing CCP1CON >;Move 0x03 into T2CON for a prescale of 16 > > BCF T2CON,TMR2ON,A > CLRF CCP1CON,A > MOVFF TRICKEL_FREQ_PERIOD,PR2 > ;Now set up the period. > MOVLW B'00000011' > ;ANDWF TRICKEL_PRESCALE,W,BANKED > IORLW B'11111100' > ANDWF T2CON,F,A >;Set the duty cycle > MOVFF TRICKEL_DUTY_H,CCPR1L > MOVLW B'11001111' > ANDWF CCP1CON,W,A > IORWF TRICKEL_DUTY_L,W,BANKED > MOVWF CCP1CON,A >;Turn on timer > BSF T2CON,TMR2ON,A > MOVLW B'00001100' >;Turn on PWM without affecting the LSB of duty cycle. > IORWF CCP1CON,F,A ;Clears the MSB and set for >PWM mode > >Now, you would assume that this would change the period or frequency of >the PWM to 5KHz, but it doesn't. >Now, if I first setup the frequency for 5KHz for the first time, then it >is good, but then when I try to change from 5KHz to 20KHz the same >problem occurs. This above code works for the first attempt and there >affect the PIC PWM refuses to change frequency. I am pulling my hair >out here and I don't have much left. There has got to be a catch >somewhere and I am missing it. > >-- >http://www.piclist.com hint: PICList Posts must start with ONE topic: >[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads