Hi,
Is it possible to have a HWPM but turning ON on the second half and it is set at 50%.
I would like to create alternating devices work at 50%.
thanks
K
Hi,
Is it possible to have a HWPM but turning ON on the second half and it is set at 50%.
I would like to create alternating devices work at 50%.
thanks
K
Why not just invert the HPWM signal with a transistor then you will have two outputs of opposite phase.
Keith
www.diyha.co.uk
www.kat5.tv
that the way I am doing it now, with a pull down mosfet, I wanted to know if there was a software solution. like adding an argument in the HPWM command.
k
Hi Lerameur. Good news. As I’m writing this, I’m looking at my scope. Portb.7 is exactly 180 degrees out of phase with HPWM 1, which is portb.2 on a 16F819.
START:
HPwm 1,127,100 'OUTPUT 100HZ SQUARE WAVE ON PORTB.2
SPLITPHASE:
IF PORTB.2 = 1 THEN LOW PORTB.7 'IF RB2 IS HIGH MAKE RB7 LOW
IF PORTB.2 = 0 THEN HIGH PORTB.7 'IF RB2 IS LOW MAKE RB7 HIGH
GOTO SPLITPHASE
Pete,
thanks, but
Is it intended to be 180 degrees out of phase with HPWM 1 ? is this normal, how would I know which port is 180 degrees out of phase in another pic, 16f88 for example... beside trying them all![]()
You need to read the datasheet for the particular PIC you want to use. On the 16F88, the HPWM 1 module (shown in the pinout as CCP1) is on RB0 instead of RB2. The pin that is 180 degrees out of phase is specified by you in the code. In "SPLITPHASE" I used RB7. You can use any port you want to duplicate and invert the HPWM output by specifying the pin you want.
START:
HPwm 1,127,100 'OUTPUT 100HZ SQUARE WAVE ON PORTB.0 ON 16F88
NEWSPLITPHASE: 'FOR 16F88
IF PORTB.0 = 1 THEN LOW PORTB.X 'IF RB0 IS HIGH MAKE YOUR PORTB PIN LOW
IF PORTB.0 = 0 THEN HIGH PORTB.X 'IF RB0 IS LOW MAKE YOUR PORTB PIN HIGH
GOTO NEWSPLITPHASE
You now have an inverted duplicate of the HPWM output on RB0 on your choice of portb. (In the code as PORTB.X)
2 issues with this method. First, while the signals may appear to be 180 degrees out-of-phase , this appears to be true only at very low frequencies. Try this at a higher frequency - say 10kHZ up and you will see that the complementary phase will be more than 180 degrees out (due to the processing time of the "splitphase" loop). The higher the frequency, the more pronounced this effect will be.
Second, while the code is running, the processor cannot be doing anything else.
A better solution would be to use a PIC with an ECCP (Enhanced Compare Capture) module. Many of the newer PIC's have this feature. Set it up to operate in Half-Bridge mode and you will get a PWM signal on the P1A pin and a complementary signal on P1B. Plus you can control the programmable dead-band delay which is used to prevent shoot-through current in half-bridge devices.
Great suggestion. Quite honestly, I never asked lerameur what his intended frequency was.
sounds good enough for me, thank you
any way to do a search on microchip website for all chips containing ECCP ?
K
Does not appear that microchip lists the devices that have ECCP. What size PIC's are you interested in?
The smallest PIC that I am aware of that has at least one ECCP is the 14-pin PIC16F616. As I mentioned earlier, many of the 16F and 18F PIC's have one or more ECCP's.
BTW, I just tested a PIC18F4620 ECCP PWM at 250kHZ (4uS period) in half-bridge mode. The signals on the scope are EXACTLY 180 degrees out-of-phase with each other. Clock was 32MHz - 8MHz FOsc.
The 8-pin 12F615 has ECCP with 2 PWM outputs & deadband.
Thanks, Bruce. I have not used the PIC12 (only use PIC18, PIC24 and dsPIC33) so am not familiar with it.
If your compiler supports the 615, it's worth looking at. My 1st go-round with this one was
a batch of serial motor control ICs for a customer. Very cool little controllers. We use them
for our 8-pin encoder/decoder ICs now. They're nicely priced even in small qty.
PIC24 are also nice, but I'm not really fond of the Mchip 16-bit C compiler. dsPIC I've never
had a need for. I can do pretty much everything we're asked for with a 14-bit core & PBP
or C.
What I really like about PBP is the open library. If you're into the heavy end, you may want
to look at PBP. It's worth the price of the compiler just for the library.
Back in the old days when I used the 8051 core, I would have paid ten times the cost of
PBP for a similar 51 core library.
If you are into open libraries, take a look at Swordfish. Lots more features than PBP and less money. Only for PIC18F though.
Swordfish is awesome, but isn't the entire library in Swordfish BASIC?
Yes, the library is in SF BASIC. Makes it real easy to extend and/or modify to suit.
I totally agree, but it's not much use unless you own the compiler. PBP libraries are pure
assembler. You can modify them as needed, learn asembler by understanding them, and
cut/paste sections into your own assembler programs.
And of course PBP supports the whole PIC series unlike Swordfish or C18, which are only
for 18F parts, and very limiting.
Most C compilers have open libraries as well, but it's not anything like the PBP library where
you have the assembly language equivalent of each command. Huge difference.
I wrote a small program , mostly copied it from one of the post here. it works but the frequency it gives me is 2,2kHz when I program 500hz, I am doing a HPWM: using picF88.
can someone help me?
INCLUDE "modedefs.bas"
@ DEVICE PIC16F88 , HS_OSC , WDT_OFF , PWRT_ON , BOD_ON , LVP_OFF , PROTECT_OFF, CCPMX_OFF
'HS 20mhz, watchdog off, powerup timer on, mclr external, brown out detect on, low volt program off , code protect off
DEFINE OSC 20 'use external 20mhz crystal
PAUSE 100 ' start-up delay
TRISB=0
DEFINE CCP1_REG PORTB
DEFINE CCP1_BIT 3
HPWM 1,127,500
HERE: GOTO HERE
end
Hi,
I think you are hitting the bottom of the frequency range for that oscillator speed, try changing to 4Mhz x-tal.
EDIT: Just checked the manual....with a 20Mhz clock the lowest HPWM frequency is stated as 1221Hz for the 14bit core PICs - isn't the F88 a 14bit PIC? Don't know why you'd get 2.2kHz.....
/Henrik.
Rmteo..
you mentionned earlier
"A better solution would be to use a PIC with an ECCP (Enhanced Compare Capture) module. Many of the newer PIC's have this feature. Set it up to operate in Half-Bridge mode and you will get a PWM signal on the P1A pin and a complementary signal on P1B. Plus you can control the programmable dead-band delay which is used to prevent shoot-through current in half-bridge devices."
I understand what a half bridge is, but I am bit confused about configuring the pic in half bridge mode.. what do you mean by that?
So far I added an inverter at my HPWM output, I would still like to get two ports, I ordered chips which includes the eccp mode.
K
From the PIC16F690 datasheet:
REGISTER 11-1: CCP1CON: ENHANCED CCP1 CONTROL REGISTER
bit 7-6 P1M<1:0>: PWM Output Configuration bits
If CCP1M<3:2> = 00, 01, 10:
xx = P1A assigned as Capture/Compare input; P1B, P1C, P1D assigned as port pins
If CCP1M<3:2> = 11:
00 = Single output; P1A modulated; P1B, P1C, P1D assigned as port pins
01 = Full-Bridge output forward; P1D modulated; P1A active; P1B, P1C inactive
10 = Half-Bridge output; P1A, P1B modulated with dead-band control; P1C, P1D assigned as port pins
11 = Full-Bridge output reverse; P1B modulated; P1C active; P1A, P1D inactive
Here's an example for the 12F615.
This has a 1uS dead-band with roughly 12kHz PWM, and each output is the compliment ofCode:@ DEVICE PIC12F615, MCLR_OFF, IOSCFS_4MHZ, INTRC_OSC_NOCLKOUT, WDT_OFF, BOD_OFF, PROTECT_OFF DEFINE OSC 4 duty VAR WORD ANSEL = 0 ' 12F615 Set all pins to digital CMCON0 = 0 OPTION_REG = 0 ' Disable internal pullups WPU = 0 ' 12F615 Individual pull-ups disabled VRCON = 0 ' Internal Vref disabled TRISIO = %00111010 ' GPIO.0 = P1B, GPIO.2=P1A outputs PR2 = 82 ' Set PWM for approximately 12kHz CCP1CON = %10001100 ' PWM mode; P1A active-high; P1B active-high T2CON = %00000100 ' %00000110 = TMR2 ON 1:16 prescale PWM1CON = %10000001 ' min dead-band time Duty = 166 ' Roughly 50% duty cycle CCP1CON.4 = duty.0 CCP1CON.5 = duty.1 CCPR1L = DUTY >> 2 MAIN: GOTO MAIN End
the other.
Bookmarks