News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

PIC16F18313 CCP Function

Started by JackB, Today at 12:44 AM

Previous topic - Next topic

JackB


Hi everyone, looking for comments about the PIC16F19313 CCP Module.

From the PIC datasheet the CCP CAPTURE/COMPARE/PWM MODULES is controlling the PWM on the C1_Output

can this module generate in the background a continious PWM signal with no interrupt or sleep from the main program

also does positron8 PWM commands can control the frequency and duty cycle and output.

I'm looking to use this PIC as a continious PWM generator and feed the signal back to a PORT to count

pulses and / or use the ADC to evaluate the voltage level.

Tanks for all comments.



 

Stephen Moss

#1
Quote from: JackB on Today at 12:44 AMFrom the PIC datasheet the CCP CAPTURE/COMPARE/PWM MODULES is controlling the PWM on the C1_Output
can this module generate in the background a continious PWM signal with no interrupt or sleep from the main program

I have only had a quick glance through the datasheet so may have missed something but generally once you have configured the CCP CAPTURE/COMPARE/PWM MODULE to output PWM it should keep running without any need to do anything else unless you want to manually stop it or change frequency/modulation depth. That said, section 19.5.4 states...
QuoteIn Sleep mode, the TMRx register will not increment
and the state of the module will not change. If the CCPx
pin is driving a value, it will continue to drive that value.
When the device wakes up, TMRx will continue from its
previous state.
So the PWM output will remain in its current High or Low state while the PIC is asleep and not change until the PIC wakes and operation resumes.

Quote from: JackB on Today at 12:44 AMalso does positron8 PWM commands can control the frequency and duty cycle and output.
If you are referring to it controlling the peripheral, then no as it is a software command and so has no effect on the PICs CCP CAPTURE/COMPARE/PWM MODULES.
You can tell it is a software generated PWM as it allows you to select any digital I/O pin (not exclusively uses for a particular purpose) as the output pin of the PWM signal, with CCP CAPTURE/COMPARE/PWM MODULES the output is either fixed to a single I/O Pin, or you can select from a limited number of alternatives if the PIC has PPS capabilities.

Also the commands overview states...
QuoteOutput pulse-width-modulation on a pin, then return the pin to input state.
The output from the command is only active for the specified number of cycles, then the I/O pin used reverts to being an input, thus the output is not continuous, there will be no further PWM output resulting from the PWM command once the number of cycles has elapsed until the command is executed again (i.e., when you main code loops).

There are two ways the command could work, one would be to use a Timer which would block that Timer (probably Timer 1) for any other use while the PWM command is being executed, but could allow the code following the PWM command to execute immediately, however as there is no mention of a Timer being used in the description I presume it uses simple loops instead (you would have to check the Assembler code to confirm either way). In which case there would probably be an outer loop counting the number of cycles and within that something like...
Set I/O Pin High
Loop for calculate number of NOP instructions for modulation depth
Set I/O pin Low
Loop for calculate number of NOP instructions to complete the PWM Period (cycle time)

If that is the case, then the code following the PWM command will be blocked from executing until the command completes outputting the specified number of cycles, so if you want a continuous PWM output that does not block other code from running it would be better to use the PICs CCP CAPTURE/COMPARE/PWM MODULES, otherwise you could use compilers PWM command.
The compilers commands can be a quick and useful way of achieving certain things, especially for those just starting with PIC programming but you don't get anything for free, there is always a trade off for that convivence. Therefore, depending on what you want to achieve they are not necessarily the best way of doing it and learning how to configure and use the PIC hardware modules directly can sometimes be the better way of achieving what you want.

JackB

well done,

many thanks for your details explanation of the CCP, I was confused about the continuity of the PWM

now it's clear.

my goal is to use an PIC SOT-23-5 package (small footprint) that I can control and generate waveform

to accomodate my project.

I guess I'll need an external PWM chip.


Best regards.