PDA

View Full Version : sending a 120khz pwm with 50% duty cycle at several time(delay)



texas5
- 7th October 2008, 07:29
hi all.i want to send the 120khz with 50% duty cycle pwm signal only for 1ms.how can i do it.i'm using pic16f877a.the following code show how the pic generate the pwm signal:

define osc 8
TRISC = 0 'PORTC all outputs

main:

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

goto main

i only want my pic inject the pwm signal for only 1ms...please help me...

Darrel Taylor
- 7th October 2008, 10:55
The Hardware PWM is like the Energizer Bunny.
It keeps going and going and ....
And in the middle of the main loop, his going problem is getting really bad.

Got to be something in there to disconnect the furry little b_______.

A timer could work, a software loop could work. something to stop it after 1ms (maybe a PAUSE 1).

Depends on what you want to shoot the Rabbit with. :eek:

texas5
- 7th October 2008, 11:24
thanx Darrel Taylor...did u mean this:

define osc 8
TRISC = 0 'PORTC all outputs

main:

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

PAUSE 1

end

Darrel Taylor
- 7th October 2008, 12:39
Closer, but it seems to me, if you want a 1ms burst of 120Khz, you'll probably want lot's of them, and most likely timed with a Zero-crossing reference.

Which if true, means you're trying to do X-10 stuff.

Which if true, you might want to look at this thread ...

XOUT and HPWM
http://www.picbasic.co.uk/forum/showthread.php?p=20318

Yes, I've just given you a sharp sword, with which to commit sepuku ... (a.k.a. Hari-Kari).

texas5
- 7th October 2008, 13:16
i really don't understand how to use the XOUT command.i just want to send the pwm signal at several time delay.lets say 1ms...so,is that correct if i use the following coding:

define osc 8
TRISC = 0 'PORTC all outputs

main:

PR2 = 15 'Load Period Register
CCPR1L = 8 'Set 50% duty cycle
T2CON.2 = 1 'Start TIMER2

CCP1CON = %1100 'PWM on
PAUSE 1 'generate 1ms burst
CCP1CON = 0 'PWM off

end

skimask
- 7th October 2008, 13:33
With the code above you'll only get a 1/2 ms delay...
http://www.picbasic.co.uk/forum/showthread.php?t=558

Darrel Taylor
- 8th October 2008, 02:46
With the code above you'll only get a 1/2 ms delay...

Not necessarily true.
If compiled with PM.exe which is NOT case sensitive. It'll do just fine at 8mhz.

texas5,
Much closer, but there's still one issue.
That will work good for the first burst. But since timer2 is still running, the next time you try to send a burst, timer2 may have already past the PR2 value when you start the PWM. Then it will have to wait for it to roll over at 256 counts before it starts up the PWM again.

That would cause the loss of up to 17 of the anticipated 125 cycles you would get during the 1ms period.

After stopping the PWM you should also STOP and RESET Timer2 to 0 ...
<br>

texas5
- 8th October 2008, 06:05
thanx skimask...thanx Darrel Taylor...your explanation seem clear to me.so i just need to set the 'T2CON.2 = 0' after stopping the pwm and set it to 'T2CON.2 = 1' back if i want to burst it one more time.

Darrel Taylor
- 8th October 2008, 06:35
Yes, but also set ...

TMR2 = 0
<br>

dhouston
- 8th October 2008, 11:15
That would cause the loss of up to 17 of the anticipated 125 cycles you would get during the 1ms period.Which is not a deal-breaker as X-10 receivers only look for 48 cycles during a window that extends from ZC+250uS to ZC+900uS. Still, one should follow X-10's recommendations to start the 120kHz burst within ZC+100uS. You're already losing some of that window as the PIC is late detecting ZC on rising edges (assuming the ZC detector given in AN236).