PDA

View Full Version : still don't have solution!!!



texas5
- 18th September 2008, 06:15
hi.please help me.i still can't generate my 120khz pwm using pic16f877a.the maximum that i can get is 50khz using hpwm.and 80khz using my own modification pwm(high--puase---low---pause).pleaseeeeeee....help me....

Acetronics2
- 18th September 2008, 09:02
Hi,

... use a 40 Mhz clock !!! ... Pic 18 F xxxx !!!

or a dedicated chip ...

Alain

skimask
- 18th September 2008, 11:47
hi.please help me.i still can't generate my 120khz pwm using pic16f877a.the maximum that i can get is 50khz using hpwm.and 80khz using my own modification pwm(high--puase---low---pause).pleaseeeeeee....help me....

With what code are you trying to generate this 120khz?
I don't see anything either...

Macgman2000
- 19th September 2008, 04:49
Why not just use an LM324 quad opamp. Set up a couple in a feedback oscillator at the frequency of your choice. Run the output of the oscillator (triangle wave) into a third gate as a comparator. From the pic all you need is a couple of resistors to set your DC level at the right place to slice a 50% duty cycle. Easy....you can turn it on and off when ever you want.

Nick

rmteo
- 19th September 2008, 05:05
You will not get 120KHz - the closest is 125KHz. Assuming a clock of 8MHz, this will give you 125KHz on CCP1 (RC2) with a PIC1F877A.


TRISC = 0 'PORTC all outputs
PR2 = 15 'Load Period Register
CCPR1L = 8 'Set 50% duty cycle
CCP1CON = %1100 'PWM mode
T2CON.2 = 1 'Start TIMER2

skimask
- 19th September 2008, 12:34
hi.please help me.i still can't generate my 120khz pwm using pic16f877a.the maximum that i can get is 50khz using hpwm.and 80khz using my own modification pwm(high--puase---low---pause).pleaseeeeeee....help me....

Come to think of it...we've already been over this!!!
If you check one of your other threads, I've already shown that you can generate 120khz using a 'non-standard' crystal.

ardhuru
- 19th September 2008, 17:49
Right, as Skimask says. Check up TipsTricks_41214A.pdf on the Microchip site and scroll down to the X10 carrier generation bit.

Regards,

Anand

rmteo
- 19th September 2008, 18:10
Yes, he can get 120KHz with a standard 12MHz crystal and setting PR2 = 24. I think his problem is that he does not seem to be able to get more than 50KHz with HPWM. It may be a PBP thing, I don't know, that is why I suggested setting up the HPWM manually. With a 8Mhz clock, you can get up to 500MHz PWM, albeit with little to no resolution on the duty cycle.

skimask
- 19th September 2008, 18:41
Yes, he can get 120KHz with a standard 12MHz crystal and setting PR2 = 24.
I don't remember the PR2 value, but I got the same thing using a 9.6Mhz crystal.
Your solution is better though...standard crystal and supported by PBP.


I think his problem is that he does not seem to be able to get more than 50KHz with HPWM. It may be a PBP thing, I don't know
PBP itself won't allow over 32Khz unless using LONG variables (PBPL 2.50), then you can (in theory) get 2Ghz out it...obviously won't happen...or will it? (see below or above whichever)
He's trying to do a square wave manually (bit high, wait, bit low, wait, repeat), bit bang the pins.


that is why I suggested setting up the HPWM manually. With a 8Mhz clock, you can get up to 500MHz PWM, albeit with little to no resolution on the duty cycle.

WOW! 500MHZ from 8MHZ! I want your chip! :D

rmteo
- 19th September 2008, 18:59
Here is a scope trace of 500KHz HPWM using a 8MHz clock:
http://home.earthlink.net/~rmteo/sitebuildercontent/sitebuilderpictures/a_108.jpg
Horizontal is 500ns/division, Vertical is 2V/division.

skimask
- 19th September 2008, 19:10
With a 8Mhz clock, you can get up to 500MHz PWM, albeit with little to no resolution on the duty cycle.
post #8
:D

rmteo
- 19th September 2008, 19:18
OK, here is a brain teaser for you. With an 8MHz clock on a PIC16/18, what is the maximum frequency HPWM that can be achieved, and how would you do it (in terms of register values for CCPR1L and PR2)?
Hint: the answer is in the scope trace above.

rmteo
- 19th September 2008, 19:34
post #8
:D
mea culpa. :D:D Should have been 500KHz.

skimask
- 19th September 2008, 19:47
OK, here is a brain teaser for you. With an 8MHz clock on a PIC16/18, what is the maximum frequency HPWM that can be achieved, and how would you do it (in terms of register values for CCPR1L and PR2)?
Hint: the answer is in the scope trace above.

Can't see the 'scope trace here (server won't let the image thru)...
In the absense of any other information (PIC type, CCP or ECCP, not that it matters), I would guess 1Mhz...
8Mhz / 4 ( crystal vs. Fosc) = 2 Mhz, but still need another cycle to set and/or reset the outputs in the CCP module, hence 1Mhz. Again, don't have enough info, nor datasheets handy.

rmteo
- 19th September 2008, 20:06
Ski, you hit the nail on the head, 1MHz it is. I tested it in hardware and looked at the scope. It would apply to any PIC12/16/18 with either CCP or ECCP at 8MHz clock. You could get 2MHz (fFOsc) out of CLKO though.

BTW, the settings would be:
PR2 = 1
CCPR1L = 1

texas5
- 22nd September 2008, 23:03
thanx everyone.i can get 332khz with 50% duty cycle using OSC 20MHz...

rmteo
- 24th September 2008, 21:06
Can't see the 'scope trace here (server won't let the image thru)...
In the absense of any other information (PIC type, CCP or ECCP, not that it matters), I would guess 1Mhz...
8Mhz / 4 ( crystal vs. Fosc) = 2 Mhz, but still need another cycle to set and/or reset the outputs in the CCP module, hence 1Mhz. Again, don't have enough info, nor datasheets handy.
Amazing as it seems, you can generate a 2MHz PWM with an 8MHz clock. Not only that but you also get 2-bit resolution (4 duty cycles).

skimask
- 24th September 2008, 22:25
Amazing as it seems, you can generate a 2MHz PWM with an 8MHz clock. Not only that but you also get 2-bit resolution (4 duty cycles).

Using the 4xPLL is cheating! :)

rmteo
- 24th September 2008, 22:59
No PLL used, just 8MHz clock. :D

skimask
- 24th September 2008, 23:08
No PLL used, just 8MHz clock. :D

k, I give. how you plan on doing that?
0%, 100%, spikey 1% and spikey 99%?

rmteo
- 24th September 2008, 23:14
Set PR2=0, CCPRxL=0. (Leave prescaler at default 1:1).
Set CCP1CON<5:4> to 01,10 or 11 for 25%,50% or 75% duty cycle.

skimask
- 24th September 2008, 23:27
Set PR2=0, CCPRxL=0. (Leave prescaler at default 1:1).
Set CCP1CON<5:4> to 01,10 or 11 for 25%,50% or 75% duty cycle.

I dunno!!!

I could very well be wrong (in this particular, singular, one time case I don't think I am), but it looks to me (at least in the 18F4620 and 18F4685 datasheet) that Timer2 (which is the base timer for the CCP and ECCP) is driven off of the Fosc/4 (i.e. instruction cycle), therefore, 500khz is max.

See figure 15-3, Note 1, on page 144, of the PIC18F4620 datasheet (DS39626D)

-Note 1: The 8-bit TMR2 value is concatenated with the 2-bit internal Q clock, or 2 bits of the prescaler, to create the 10-bit time base.

Also, see Equation 15-1 on the right side of that same page:

-When TMR2 is equal to PR2, the following three events occur on the next increment cycle:
• TMR2 is cleared
• The CCPx pin is set (exception: if PWM duty cycle = 0%, the CCPx pin will not be set)
• The PWM duty cycle is latched from CCPRxL into CCPRxH

Changing the CCP1 registers will only change frequency, not duty cycle, which won't change anyways because PR2 is 0.

I wish I was near my hardware so I could beat this up...try it out and break something!

But I was just thinking...if it actually did run 2Mhz, this might be a neat way to 'stack PWMs' (if that's even a word or a method of doing anything at all, maybe battery charging?).
You could have a hardware PWM buzzing along at 2Mhz at a few duty cycles, run that output into an AND gate, with the other input to the AND being run by a 'not so fast' software PWM, or even another PWM channel. Something like a boost-converter might benefit from a stacked PWM like that. Gotta have high freq to get good conversion efficiency...

rmteo
- 24th September 2008, 23:52
I thought so too. Anyway, I tried it and indeed you can get a 2MHz PWM with 3 different (4 if you include 0%) duty cycles with an 8MHz clock. Checked it out in hardware and on an oscope. I can post a picture of the scope but you said you can't see it.

With a 4x PLL, you can get a 8MHz PWM. Of course you can just use CLKO and get these frequencies, albeit without any duty cycle resolution.

skimask
- 24th September 2008, 23:56
I thought so too. Anyway, I tried it and indeed you can get a 2MHz PWM with 3 different (4 if you include 0%) duty cycles with an 8MHz clock. Checked it out in hardware and on an oscope. I can post a picture of the scope but you said you can't see it.
I'm on a different PC now (the server that doesn't let me see pictures is at work :D), and of course, not near my hardware.
No crazy glitches or anything? (rough edges, ok, but nothing else wierd?)...
Which PIC are you using anyways?

rmteo
- 25th September 2008, 00:14
I am using a PIC18F4620 (a PIC16 with CCP/ECCP should work too) just because I have it handy. Here is the scope trace:
http://home.earthlink.net/~rmteo/sitebuildercontent/sitebuilderpictures/a_112.jpg
Horizontal is 200nS/div and Vertical is 2V/div. Upper trace is the PWM (50% duty cycle) and lower trace is CLKO (Fosc/4).

skimask
- 25th September 2008, 03:25
Horizontal is 200nS/div and Vertical is 2V/div. Upper trace is the PWM (50% duty cycle) and lower trace is CLKO (Fosc/4).
Well then, that settles it...
Either the datasheet has to be a bit more concise, or I have to read a little bit LESS into it.