thanks rmteo...just seen your reply, I shall look at all tha tomorrow.
ok, so I got too big for my boots, thought I'd go hardcore & try to get HPWM working with the PIC's regsiters (vs the HPWM command) - eeeugghh! (it was worth doing - just to remind myself that I'll always be the type who graps in the dark!)
I've got it working, but only by directly loading the PWM 'period' registers directly like this (important bits in red)
Code:
PR2= 63 'THIS SETS THE PWM FREQUENCY (15.625KHZ @4MHZ)
CCPTMRS0 = %11110011 'CCP Timer select register - select CCP2 USING TIMER2
T2CON = %00000100 'TIMER2 ON 1:1 PRESCALER 1:1 POSTSCALER
TRISC.3 = 0 'Enable the CCP2 pin output driver by setting the bit
temp:
CCP2CON.4 = 1 ' these three lines set the duty cycle to be 255
CCP2CON.5 = 1 ' these three lines set the duty cycle to be 255
CCPR2L = 255 ' these three lines set the duty cycle to be 255 (2 MSBs ignored)
pause 1000
CCP2CON.4 = 0 ' these three lines set the duty cycle to be 0
CCP2CON.5 = 0 ' these three lines set the duty cycle to be 0
CCPR2L = 0 'these three lines set the duty cycle to be 255 (2 MSBs ignored)
pause 1000
goto temp
the problem with that method (& it works - get a flashing LED at about 1 sec on, 1 sec off), is that setting the duty cycle is brainache. So I wanted to use the method discussed earlier with Henrik (where I map the bts to my easier to massage variable called "duty")...
Code:
Duty var byte
CCP2CON.4 = Duty.0 'Bit 0
CCP2CON.5 = Duty.1 'Bit 1
CCPR2L = Duty >> 2 'Bit 2-7
temp:
duty = 255 ' these three lines set the duty cycle to be 255 (2 MSBs ignored)
pause 1000
duty = 0 'these three lines set the duty cycle to be 255 (2 MSBs ignored)
pause 1000
goto temp
Problem is now ...the LED he no flashee!!
Anyone got a clue why I can't map the PWM 'period' bits to my variable called Duty? (or more to the point why it doesn't appear o work, whereas the top code does)
Edit: Ok, think I've got a kludge, but this isn't working how I'd imagined...
Code:
temp10:
DUTY = 0
CCP2CON.4 = Duty.0 'Bit 0
CCP2CON.5 = Duty.1 'Bit 1
CCPR2L = Duty >> 2 'Bit 2-7
pause 1000
DUTY = 1
CCP2CON.4 = Duty.0 'Bit 0
CCP2CON.5 = Duty.1 'Bit 1
CCPR2L = Duty >> 2 'Bit 2-7
pause 1000
goto temp10
in other words, I'm having to update the 'mapped' period register bits every time I change the duty variable? (I'd have thought Henrik's way of mapping them would mean if I change the contents of the duty variable then the mapped bits would automatically change too?)
Bookmarks