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 support@ccsinfo.com

PSMC in PIC16F1788
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
temtronic



Joined: 01 Jul 2010
Posts: 7975
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Feb 05, 2021 3:07 pm     Reply with quote

here's a HUGE problem....

Proteus 8

.. please read the PIC101 sticky.....

Proteus is a LOUSY 'simulator', NOT to be trusted

Even the simplest of proteus 'schematics' posted can never truly work in the real World.

BTW ..this..

#define us(time) (int16)(time*(getenv("CLOCK")/1000000))

can be replaced with

delay_us(xxx); //where xxx is the number of microseconds required
Ttelmah



Joined: 11 Mar 2010
Posts: 16935

View user's profile Send private message

PostPosted: Sat Feb 06, 2021 5:12 am     Reply with quote

No Jay.
That is a #define, used to generate the delay time for the PSMC, not a 'delay'.
What he has there is correct.

Agree that Proteus won't work.
First thing wrong is he is trying to enable the PSMC, before calling
the pin setup. Don't. Leave the 'ENABLE_NOW' out of the setup.
Enabling the PSMC here, _will_ result in the very spikes he was talking
about trying to avoid.
Quote:

Normally this call does not start the PSMC. It is expected all the setup functions be called and the psmc_pins() be called last to start the PSMC module.



Then the divisor will be wrong. You are adding a prescaler of 2, when the
divisor macro is for FOSC directly. Get rid of the PSMC_DIV_2 or
recalculate the divisor.

Then the times involved give little spare time for the pulse. He has a 50
(100uSec with divisor) pulse width with the rising edge delayed by 10, and
the falling edge delayed by 50.

The only reason to delay the rise time, is when you are running multiple
parts of the peripheral synchronous to each other to give multi-phase
waveforms. Otherwise, don't.

Then he trying to change the output pin allocation incorrectly.
Several things. He needs to have this set to synchronous, or every
change will result in the the output pulse width being corrupted.
OR this into the psmc_pins setup.

Then the value being used is wrong. What he is sending at present will
put an output on the low three pins only, when he has six pins originally
selected. He probably needs a const array with the correct settings
for the pin patterns he wants, and then index this with his counter,
and output with psmc_pins.

He was also talking originally about four independant pulses, but currently
is just setting up six identical pulses.
temtronic



Joined: 01 Jul 2010
Posts: 7975
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Feb 06, 2021 7:32 am     Reply with quote

oopsy..my bad, I misread the green code again.

I had another read of the datasheet, and I just don't see HOW that peripheral could be setup to provide 4 independent PWM channels.
While it has a LOT of programmable modes of operation, even the most basic of ones... 'single phase mode', only allows ONE PWM signal to go to 1-6 output pins.

It would be nice if the Op could list the 'design requirements' of the project as there's probably a simple solution but the details have to be known first.
Ttelmah



Joined: 11 Mar 2010
Posts: 16935

View user's profile Send private message

PostPosted: Sat Feb 06, 2021 8:34 am     Reply with quote

Each PSMC unit can generate a single PWM source, with distinct timings.
4 modules. 4 PWM's. There are four distinct timers available.
However he is instead trying to output multiple waveforms from one
module. Not what he was asking at the start... Sad
temtronic



Joined: 01 Jul 2010
Posts: 7975
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Feb 06, 2021 9:04 am     Reply with quote

sigh.. Ok, I only quickly scanned the 50-60 PAGES for the 'PSMC' so I must have missed a couple of things...
dang...that one perheral has more documentation the entire 16C84 did !
I did 8 channels of PWM with a 16C84, not fast but it worked
so....it'll still be nice to see the 'specs' for what is really required...

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 16935

View user's profile Send private message

PostPosted: Sat Feb 06, 2021 9:25 am     Reply with quote

The key point is that four sources, he needs to just setup the A output on
each PSMC. None of this fiddling with the outputs...
dmitrboristuk



Joined: 26 Sep 2020
Posts: 16

View user's profile Send private message

PostPosted: Sat Feb 06, 2021 1:36 pm     Reply with quote

I am just mastering this module, so please do not judge me harshly! The possibilities that this module provides to the developer are simply the broadest. I provided a piece of code as an example, of course there are many inaccuracies, I need 6 channels, but there are only 4 oscilloscope channels in Proteus, so I counted up to 7. When I receive the ordered micro controllers, I will look at them real signals, while I am doing software simulation. Thanks to all those who helped me. With the emergence of the questions I will ask you.
temtronic



Joined: 01 Jul 2010
Posts: 7975
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Feb 06, 2021 2:50 pm     Reply with quote

hmm.. I need 6 channels,

so, that chip only has 4 PSMC channels.... !!
dmitrboristuk



Joined: 26 Sep 2020
Posts: 16

View user's profile Send private message

PostPosted: Sat Feb 06, 2021 3:02 pm     Reply with quote

4 PSMC: (2x6) + (2x2) outputs
temtronic



Joined: 01 Jul 2010
Posts: 7975
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Feb 06, 2021 3:10 pm     Reply with quote

from the datasheet....

Identical PWM waveform is presented to all pins
for which steering is enabled.

That means 1 PSMC can have 1 to 6 outputs BUT each will have the same PWM signal..

there's no way you can have 6 different PWM signals with the 4 PSMC channels.
Ttelmah



Joined: 11 Mar 2010
Posts: 16935

View user's profile Send private message

PostPosted: Sun Feb 07, 2021 2:37 am     Reply with quote

If he is using the 1788 or 9, then these have three standard PWM channels
available as well. However very different setups needed for these and
resolutions will be different as well. These would need to be moved to the
alternative pin locations (by default they use the same pins as the PSMC
outputs). These also are not fully independant (share the same period).
Unlike some of the larger chips, only Timer2 can be used for their
period setting. So potentially this chip can give five independant PWM's.

To get six fully independant PWM's, needs a chip that actually offers this. It
is one of the 'annoying' features of the MicroChip parametric search tool,
that it searches on PWM 'outputs', not on physical channels, and even when
you find a chip with enough channels, it does not tell you if the clock source
is shared. The PIC16F1779 would allow six independant PWM's. This has
four normal PWM's, which can be clocked off Timer 2,4,6 & 8, allowing
complete independence. It then has four independant 16bit PWM's which
again support their own clocks, allowing a maximum of 8 independant
periods to be generated. (Beware the 10 bit modules use the standard
timers, so these can't give independant times). The CCP PWM outputs will
need to be routed using PPS, and these will only give 10bit resolution.
So with this chip you can have 4 independant 10bit PWM's and 4
independant 16 bit PWM's.
temtronic



Joined: 01 Jul 2010
Posts: 7975
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Feb 07, 2021 6:49 am     Reply with quote

One day , Mr. T. , your head will explode from the knowledge stored up there ! That will be a very, very sad day....... Crying or Very sad

I'd still like to know what the application parameters are for the project.

Jay
Sad
Ttelmah



Joined: 11 Mar 2010
Posts: 16935

View user's profile Send private message

PostPosted: Sun Feb 07, 2021 8:21 am     Reply with quote

Agree wholeheartedly.
Does he really need independant frequencies?.
What range of frequencies?.
What range of periods?.
How often do they need to update?.
What will modulate the values?.

My head exploding, would at least tend to fill up the dents in the wall, caused
by my having a 'wall, head, impact technology testing' session....
I often want to go and put my head in a bucket of cold water. So maybe the
desire to do this is my subconscious trying to prevent an explosion... Very Happy
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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