View previous topic :: View next topic |
Author |
Message |
ertansuluagac
Joined: 13 Jul 2017 Posts: 135 Location: IZMIR
|
#use pwm feature |
Posted: Sat Jan 04, 2020 2:35 pm |
|
|
What do you think about the #use pwm property, which is the ccs c compiler property. With this feature, I can apply this to more than one pin.Well, you can apply to a pin that doesn't have this hardware, that is it doesn't have a (CCP) pin. How can this be? We also need to add something extra to the output we apply. Or do we see a square wave as a result of the values that we set directly from the output? If so, what is the difference between CCP and #use pwm? which one makes sense to use. Code: |
Setting up the software PWM is simple and easy. Any desired options for duty cycle, period, frequency, etc. may be set while only using one line of code. Below is an example that illustrates the setup of a typical PWM with two outputs, a frequency of 1 kHz, and a duty cycle of 75%.
#use pwm(output=pin_a4, output=pin_b3, timer=1, frequency=1kHz, duty=75) |
_________________ Es |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Sun Jan 05, 2020 6:04 am |
|
|
I have an older version of the compiler
#USE PWM().section.
Selects the PWM pin to use, pin must be one of the CCP pins.
As for how it works, cut a small program,compile , then dump the listing. CCS doesn't hide any of the code.
Others who have a newer compiler may reply |
|
|
ertansuluagac
Joined: 13 Jul 2017 Posts: 135 Location: IZMIR
|
|
Posted: Sun Jan 05, 2020 6:34 am |
|
|
compiler 5.092
In my opinion you know wrong. I think it can be used without CCP. Because CCS C wrote an example. I have tried. it worked at Proteus. I'm gonna set up Boarda circuit and try. But, I would like to get detailed information. So what's the difference with CCP. Will something extra be added to the circuit entrance? It is used for what purposes.
I think that Ttelmah knows best.
_________________ Es |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Sun Jan 05, 2020 6:47 am |
|
|
All the 'details' are in the compiled code. If you set to 'symbolic', the listing will show you exactly what it's doing to setup/load various registers as well as how it's not using CCP. PIC ASM ( instructions) are easy to learn and understand, all in the PIC datasheet. The CCS manual will give 'basic' how-to-use information, to KNOW what's happening and why, you need to read the datasheet for register configs and instruction set.
Since my compiler is older, I can't create a program that uses that preprocessor directive. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19509
|
|
Posted: Sun Jan 05, 2020 7:28 am |
|
|
Ideally #USE PWM, wants a PWM or CCP pin.
However the later compilers can produce a _low frequency_ PWM
using a timer interrupt.
Downsides are:
1) Uses a lot of processor time.
2) Limited frequency.
3) Limited resolution.
4) Not as accurate.
Basically if you setup a PWM on a pin that doesn't support a hardware PWM,
then the processor will generate a timer interrupt, and drive a PWM using this
It changes the time programmed to reset the timer, according to the 'on'
and 'off' times needed. Accuracy will then be affected if any other interrupts
are in use.
The compiler will give you a warning message when this is used, giving the
minimum and maximum duty cycles that can be supported (depends on
how long it'll take to get into and out of the interrupt). |
|
|
ertansuluagac
Joined: 13 Jul 2017 Posts: 135 Location: IZMIR
|
|
Posted: Mon Jan 06, 2020 11:11 am |
|
|
Thank you very much. _________________ Es |
|
|
|