PDA

View Full Version : HPWM on a 628 is not changing freq.



dtit
- 24th February 2005, 08:51
I tried differnent settings, but when i put a scope on it's allways 1ms freq.
snip:
@ DEVICE HS_OSC,MCLR_OFF,LVP_OFF,WDT_OFF,PROTECT_OFF
DEFINE OSC 20
CMCON = 7
VRCON = 0
TRISB = %00000000
PR2 = 130 ' 38KHz
CCPR1L = 63 ' 50%
CCP1CON = %00001100 ' Mode PWM
T2CON = %00000100 ' Timer2 ON + 1:1 prescale

Allsow tried:
@ DEVICE XT_OSC,MCLR_OFF,LVP_OFF,WDT_OFF,PROTECT_OFF
DEFINE OSC 4
CMCON = 7
VRCON = 0
TRISB = %00000000
PR2 = 25 ' 38KHz
CCPR1L = 13 ' 50%
CCP1CON = %00001100 ' Mode PWM
T2CON = %00000100 ' Timer2 ON + 1:1 prescale

Hardware: 22pF on crystal, 1uF between Vss&Vdd = Vdd 5V Ok

But the freq is not changing from 1ms wathever PR2,CCPR1L i tried
Has anyone experied this problem?

mister_e
- 24th February 2005, 14:38
do you want to change frequency or duty cycle?

do you want to change frequency or duty while your program's runing?

what about if you enable watch dog timer???

BTW at 38KHZ, If i refer to PIC16F628's datasheet :
@ 20Mhz,38KHZ 50% duty cycle:
period = 2.63 uSec
duty = 512


PR2 = 130
CCP1CON = %00001100 ' 2 LSB of 512 at bit 5 & 4
' PWM mode bit 3 & 2

CCPR1L = 128 ' 8 MSB of 512
TRISB=0
T2CON = %00000100 ' set timer2 prescaller to 1:1


what about now...

dtit
- 25th February 2005, 10:34
thanks mister_e fore your concern

The only thing i tried to do is get a 38.5Khz to drive a IRled array, wanted a duty at max 50% tough gona overdrive them a little.
With the trusth in your tips, i stripped down my setup to a minimum and start testing. (hard decision)
Did found two broken 628 and some bad cable connection. One did just put out 1V on ccp1 when a scoped it.
Yes i got to work, but figured out that your suggestion of CCPR1L = 128 equals a duty very high. Tested with 63 and get a 50/50. After two late night a have learn me a lesson to keep testboard small and tidy. When expanding, make circuit board and solder down your stuff. Afterwords use board again. It's very time costing to have right code and wrong in hardware setup.
Thanks to you I have new way of thinking