View previous topic :: View next topic |
Author |
Message |
yossihagag1978
Joined: 04 Apr 2013 Posts: 20
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Tue Feb 08, 2022 7:10 am |
|
|
Yes, that has existed since about 5.050.
However it has very significant limitations, with the frequency available
depending on the chip speed. If you push the frequency, the code spends
more and more time in the interrupt handlers for this. For a low frequency
relative to the CPU frequency it works well. So ask for a 1KHz PWM on a
chip at 32MHz, and it'll work well. On some of the more basic PIC's timer
limitations will cause problems.
If you compile with this the 'info' line on the compiler will tell you the
maximum and minimum duty cycles it can achieve. |
|
|
yossihagag1978
Joined: 04 Apr 2013 Posts: 20
|
|
Posted: Tue Feb 08, 2022 8:03 am |
|
|
can i user any timer? even 1 or 3 ?
can i get 50hz pwm with 2mhz osc in software pwm ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Tue Feb 08, 2022 8:31 am |
|
|
Yes.
The resolution will change according to the capabilities of the timer involved.
You will probably have a minimum pulse width of perhaps 2% at those
frequencies. |
|
|
yossihagag1978
Joined: 04 Apr 2013 Posts: 20
|
|
Posted: Tue Feb 08, 2022 8:40 am |
|
|
will it work on PIC18F8722 ?
or for special series of pic? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Tue Feb 08, 2022 11:32 am |
|
|
It works on all PIC's. A few of the minor ones that have very limited
numbers and types of timers, can be rather limited.
Understand that the timings will go wrong if (for example), you
are sitting in a UART interrupt routine, when the timer triggers. |
|
|
yossihagag1978
Joined: 04 Apr 2013 Posts: 20
|
|
Posted: Wed Feb 09, 2022 12:00 pm |
|
|
I use ccs 5.068.
For some reason I can't get 50 hz pwm on software pwm.
I am using 2Mhz external oscillator.
Also I can't use timer1 in it. It's scream to use only timer 2 or 4 ? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Wed Feb 09, 2022 2:13 pm |
|
|
Time to show us your code...
Maybe there's something 'silly' you can't see that a fresh pair of eyes can ?
50Hz sounds like RC servo rate to me....
Or 'mains' frequency on the other side of the pond... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Thu Feb 10, 2022 2:22 am |
|
|
The problem here is that the slow rate needed requires a 16bit timer.
As I said, the capabilities of the timer involved does matter.
Problem is that generic questions like 'can I use timer1', have very specific
answers depending on the PIC involved, and the frequencies involved. |
|
|
|