CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Software PWM

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
yossihagag1978



Joined: 04 Apr 2013
Posts: 20

View user's profile Send private message

Software PWM
PostPosted: Tue Feb 08, 2022 5:26 am     Reply with quote

Hi
does it work?
https://www.ccsinfo.com/newsdesk_info.php?newsPath=ALL&newsdesk_id=182

if so on what version and pic ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Tue Feb 08, 2022 7:10 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Feb 08, 2022 8:03 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Feb 08, 2022 8:31 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Feb 08, 2022 8:40 am     Reply with quote

will it work on PIC18F8722 ?
or for special series of pic?
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Tue Feb 08, 2022 11:32 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Feb 09, 2022 12:00 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Feb 09, 2022 2:13 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Feb 10, 2022 2:22 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group