PDA

View Full Version : hpwm more than 2 ch possible in pbp?????????



oscar
- 21st May 2005, 00:23
i am wondering if it is at all possible to have more than 2 ch of hpwm within pbp????????????? i am using a pic16f767 with 3 hpwn chs yet i can only seem to get 2 running?? ch 2 seems to be mixed/ shared with ch 3 for some reason.. ie ccp1 is fine but when i write a value to ccp2 it shows up on ccp3!!!!!!! im boggled.. i have tryed all the possible reg configs i can think of yet still no joy... has anyone got any pointers??? i am totally stuck here !! lol.

thank you
oscar..

Bruce
- 21st May 2005, 06:07
i am wondering if it is at all possible to have more than 2 ch of hpwm
within pbp?

Nope. The HPWM command only supports 2 channels. CCP1 & CCP2. You
would need to modify the 16F library to support CCP3. It's much easier to
just configure hardware PWM manually.

From the examples in your 16F767 datasheet;

Setup 10-bit PWM for 1.22kHz with a 20MHz osc.

' Word vars for 10-bit value of each PWM duty cycle
Duty1 VAR WORD ' Channel #1
Duty2 VAR WORD ' #2
Duty3 VAR WORD ' #3

' Set CCPx pins to outputs
TRISC.2=0 ' CCP1 output
TRISC.1=0 ' CCP2 output (could also be assigned to RB3)
TRISB.5=0 ' CCP3 output

' Set CCP modules to PWM mode
CCP1CON = %00001100 ' Mode select = PWM
CCP2CON = %00001100 ' Mode select = PWM
CCP3CON = %00001100 ' Mode select = PWM

' Set period up for 1.22kHz PWM freq
PR2 = $FF

' Set TMR2 up for 1:16 prescale & turn it on
T2CON = %00000110 ' TMR2 ON 1:16 prescale

Duty1 = 512 ' 50% duty cycle. 1024/2 "10-bit resolution"
CCP1CON.4 = Duty1.0 ' Setup 10-bit duty cycle as
CCP1CON.5 = Duty1.1 ' a 10-bit word
CCPR1L = Duty1 >> 2

Duty2 = 512
CCP2CON.4 = Duty2.0
CCP2CON.5 = Duty2.1
CCPR2L = Duty2 >> 2

Duty3 = 512
CCP3CON.4 = Duty3.0
CCP3CON.5 = Duty3.1
CCPR3L = Duty3 >> 2

You have the same frequency on all three channels since all three channels
share the same period register, but you have individual control of duty cycle
on each channel using the corresponding CCPRxL & CCPxCON registers.

With 10-bit resolution you can have from 0-1023 or 0%-100% duty cycles.

Pretty simple don't you think?

oscar
- 21st May 2005, 12:17
hi bruce, thanx for your reply.

i have tryed in vain to get your code working cos when i try to compile it it says the following..

error hwpm.asm 'ie name of project


undefined symbol ccp3con


it wont recognise the ccp3con setup for some reason.....

hence it wont compile.!!

i had another look at the pbp manual and its very misleading re hpwm as it makes referance to hpwm3 etc yet it does not state that a max of 2 x hpwm are available in pbp!!!! so one would assume that the ref to hpwm3 etc would mean it could use any available hpwm port on a particular chip !!!!!! arrrgggggggggggggggg

oscar :)

Bruce
- 21st May 2005, 15:58
A few things to look for;

Never save your basic code file with the exact same name as a PBP
command, or the same name as the PIC target.

Try saving it with a name like PWM_F767.bas or something. It compiles
fine for me with PM or MPASM assemblers with PBP v2.46.

Be sure you're selecting the 16F767 before compiling, you have a version
of PBP that supports this device (at least v2.45), and if you're using MPASM
make sure you have a version of MPASM that supports this PIC.

Some of the older 17C7xx PIC's had channel 3 which could use timer1. The
PBP define in the manual shows how to assign timer1 to this channel instead
of timer2. There are also defines to assign different pins to CCP outputs, but
I don't see anything in the PBPPIC14.LIB file for the HPWM command that will
support more than CCP1 & CCP2.

I don't have one of the 16F767's to mess with, but that code example should
work assuming you have a version that supports this PIC, you're saving your
basic file with a name that doesn't clash with a PBP command, and you have
all the device header files required for this target.

oscar
- 21st May 2005, 15:58
im so duhhhhhhhhhh.. lol the no ccp3 mystery is sloved... i somehow had another chip type selected!!!!!

question.... would their be any reason with the code u gave me bruce as to why ch2 hpwm2 that is flickers when at a low value?


thanx

oscar

Bruce
- 21st May 2005, 16:04
What exactly do you mean by flicker?

mister_e
- 21st May 2005, 16:32
is this LED flickering happen only with channel2 ? what about if you change the frequency?

oscar
- 21st May 2005, 20:56
hiya lads...

hmmmmm ch3 ie the one i couldnt get to work in the firsr place works 100% nice smooth dimming etc.. ch2 flickers like mad !! the code is the exact same for all 3 ch's with the exception of register names etc.

me thinks this is not possible...................... i have gone through everything here 10 times over.!!!

Bruce
- 21st May 2005, 22:22
What happens if you enable only 1 channel at a time?

I.E. CCP1CON=0 : CCP3CON=0

Does channel 2 still flicker?

Are you sure it's not the circuit channel 2 is connected
to that's causing the flicker?

oscar
- 21st May 2005, 23:28
yet again tis me thats at fault.... many thanx to bruce for his code example. the mistake i was making was that i was calling the hpwm routine which seemed to be causing a conflict. instead i just wrote the duty val directly to the port ie portb.5=duty5 ... simple! lol this took many hours of hair loss and alcohol !!!!!!. only 1 teeny weeny prob left lol... i cant get the ch's to go to full off . they get to say 9% and stay there. so a faint glow is visible but apart from that everything is aok. dimming is as smooth as a babys ass and im a happy bunny.( irish saying).. many many thanks to bruce n the rest of u guys.. slainte...

thanx
oscar.

peu
- 3rd February 2006, 19:59
Im refloating this thread because I have a question:

I tried the example provided by Bruce succesfully, but now I want to use ON Interrupt on portb changes.

The problem I encounter is that CCP3 uses RB5 and the interrupt is triggered by changes in the portb.4 to portb.7

What can be done?

Thanks

mister_e
- 3rd February 2006, 20:46
Help us a litle bit ;) Pic model?

How bad/good it is if in the INT routine you test the PORTB and if it's just related to the HPWM, it goes out of there ?

peu
- 3rd February 2006, 22:08
Sorry :) Im using the same pic as Bruce example: 16F767

but Im having more basic problems, when I wasnt able to run the program as desired I started to remove parts of it, and now I see it does not work at all, so I may be missing some register configuration.

Here is the header of my program:




@ device pic16F767, wdt_on, intrc_osc_noclkout, mclr_off, protect_off


trisb =%11000000
trisa =%00000001
cmcon =%00000111 'Comparators Off
intcon =%10001000 'interrupts enable

; Set CCP modules to PWM mode
CCP1CON = %00001100 ' Mode select = PWM
CCP2CON = %00001100 ' Mode select = PWM
CCP3CON = %00001100 ' Mode select = PWM

PR2 = $20 ; Set period

pie2.1=0 ;disable interrupts on CCP3 (I think this should work)

; Set TMR2 up for 1:1 prescale & turn it on
T2CON = %00000100 ' TMR2 ON 1:1 prescale

porta=0:portb=0:portc=0

pause 100


high porta.1
pause 200
low porta.1
pause 200
high porta.1
pause 200
low porta.1

end


As you can see very basic, and I dont even started with the pwm/interrupts stuff.

I program the pic via ICSP and power it, it seems to run at turtle speed :) , the 200ms pause takes 28seconds...


What I am missing? Thanks

BigWumpus
- 4th February 2006, 12:03
I program the pic via ICSP and power it, it seems to run at turtle speed :) , the 200ms pause takes 28seconds...


What I am missing? Thanks


What is about a DEFINE OSC ?
At what speed does the PIC work ?
What speed did you tell the PBP-Compiler ?

;-)

peu
- 4th February 2006, 14:09
Oh I didnt post it in my previous post sorry, there is a define osc 4 below the @device statement

but it still goes slow...


Pablo

peu
- 6th February 2006, 03:24
any idea? Thanks

peu
- 10th February 2006, 15:32
I could use some help :) Thanks in Advance

docwisdom
- 1st March 2006, 03:24
This seems to be a very popular comment. Bruce mentioned that you could modify the 16F library to accomodate for the 3rd HPWM channel. Could any of the advanced members take on this project and post the library? Seems that it would solve many repeat posts for the same problem.

peu
- 9th March 2006, 16:15
This seems to be a very popular comment. Bruce mentioned that you could modify the 16F library to accomodate for the 3rd HPWM channel. Could any of the advanced members take on this project and post the library? Seems that it would solve many repeat posts for the same problem.


If someone has just a tip on what to look, I will really appreciate it. Thanks!

sougata
- 10th March 2006, 07:28
The post is the next one

sougata
- 10th March 2006, 07:28
Hi,

That's the library bruce was talking about. This contains the PBP function which is used by the compiler to extract and create codes and fits into the target processor. So portions only needed by your code are compiled according to PIC and placed in the top part of your compiled prog.

The problem with the HWPM command is that it calculates the PR2 (Freq) and CCP1CON + CCPCON (Duty Cycle) every time you use it in your code. That's the reason why changes do not take place immediately. So it is always a better idea to modify the duty cycle registers directly. To make life easy use the HPWM once then go on varying the duty cycle yourself. Depending on the PR2 values (read the datasheet for the Math) you should have a limit on the max duty cycle value to ensure smooth rollover.

It was Bruce's code found in a thread which gave me the wayout. Thanks bruce. I should have thanked you much earlier for showing the path.

I do not have a chip lying around that has 3 channels HPWM. I would sure like to give a try modifying the library. No commitments however (My firm is a design house and basically one man army on the development front!!!)