Maker Pro
Maker Pro

PIC16F877, 250Hz PWM

aymensmurf

Mar 14, 2016
28
Joined
Mar 14, 2016
Messages
28
Hi,
I need 250Hz PWM out of a 20MHz clock.
I'm using PIC16F877.
any help ?
 
Last edited by a moderator:

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
Firstly welcome to EP. Secondly, it's quite a good idea to give as much information as possible of your requirements. Unfortunately you haven't. Questions I would like answered are :

1) What language are you programing in?
2) What is the % of duty cycle you require?
3) How far have you got already yourself?

And out of interest what's the project, anything interesting?

Thanks
Adam
 

aymensmurf

Mar 14, 2016
28
Joined
Mar 14, 2016
Messages
28
1) What language are you programing in?
->C
2) What is the % of duty cycle you require?
->50%
3) How far have you got already yourself?
->so far, I'm doing everything using the delay function.

And out of interest what's the project, anything interesting?
->I'm trying to command the speed of a subway, using three Pulses, every pulse command a Thyristor.
The thing is, the pulses have to be "=1 in 50us and =0 in 150us" in a 4ms periode.

(srry, my english is kinda bad)

Thanks
 

Minder

Apr 24, 2015
3,478
Joined
Apr 24, 2015
Messages
3,478
Then you may have to use a low freq clock in such as external osc or crystal input, I have used the 32khz watch crystals for some low freq apps to run TMR1.
I would think the 16F877 has this feature.
M.
 

aymensmurf

Mar 14, 2016
28
Joined
Mar 14, 2016
Messages
28
#M.
I think i have to use a 4Mhz external osc to get 250Hz PWM.
and that won't help, coz the program will go slow.
 

Minder

Apr 24, 2015
3,478
Joined
Apr 24, 2015
Messages
3,478
Yes of course, I was thinking of capture, you can go down to 1.2Khz with 20mhz system clk is that too high? What is the application?
M.
 

Alec_t

Jul 7, 2015
3,587
Joined
Jul 7, 2015
Messages
3,587
"=1 in 50us and =0 in 150us" in a 4ms period
:confused: I make that a 200uS period (5kHz) with a 25% duty cycle. Or does the "1 in 50uS" and "0 in 150uS" relate to the pulse rise and fall times, respectively?
 

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
There should be no problem doing that using delays. 50uS is 250 instruction times.

Bob
 

aymensmurf

Mar 14, 2016
28
Joined
Mar 14, 2016
Messages
28
Yes of course, I was thinking of capture, you can go down to 1.2Khz with 20mhz system clk is that too high? What is the application?
M.
I'm trying to command the speed of a subway, using three Pulses, every pulse command a Thyristor.
The thing is, the pulses have to be "=1 in 50us and =0 in 150us" in a 4ms periode.
 

aymensmurf

Mar 14, 2016
28
Joined
Mar 14, 2016
Messages
28
There should be no problem doing that using delays. 50uS is 250 instruction times.
the problem using the delay is that the cpu lose some time (us) repeating the (loop, for ... do, while(), if () ).
 

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
Then you need to use interrupts. Determine when each pulse starts and stops and use the timer to interrupt at those times and toggle the outputs.

Bob
 

aymensmurf

Mar 14, 2016
28
Joined
Mar 14, 2016
Messages
28
Then you need to use interrupts. Determine when each pulse starts and stops and use the timer to interrupt at those times and toggle the outputs.

Bob
it will get really really complicated to do interrupts for every pulse
 

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
Then I guess you should just give up.

Seriously, though:

If the pulses are all on increments of 50uS you can set an interrupt to occur every 50uS and decide what needs to be done at each interrupt. This would be less complicated, but more overhead. How much of the processor time is needed for the other tasks?

Bob
 
Top