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

Using PSMC for High resolution (16 bit) PWM

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



Joined: 23 Apr 2007
Posts: 91
Location: Rochester, England

View user's profile Send private message Visit poster's website

Using PSMC for High resolution (16 bit) PWM
PostPosted: Fri Apr 13, 2018 8:03 am     Reply with quote

Hi folks,

We're trying to get an LED dimmer/mixer working using PSMC on 16F1762.

The reason we're trying to use the 16 bit PWM is that using the standard PWM resolutions, the changes in light level even in 0.1% increments at the low end of the brightness are very significant (Hence the theory that using higher resolution PWM will give us some steps in between).

However - when using standard PWM, you can use the timer interrupt to set the pwm so you only change the mark/space ratio at the begining of the cycle. (Otherwise you get bad flicker when you change mark/space if you do it anywhere).

However with the PSMC we can't see an interrupt that's related to the timer running it (we're not even sure if it's actually using a timer).

Could somebody give us an idiots guide to using it please?

Thanks in advance

James
Ttelmah



Joined: 11 Mar 2010
Posts: 19549

View user's profile Send private message

PostPosted: Fri Apr 13, 2018 8:18 am     Reply with quote

Start by giving us the right PIC number?. 16F1762 doesn't exist.... Sad

The 1764 has 16bit PWM.

On these you have the option to control when new values are transferred to the registers. This is handled by the LDT bit. If this is clear the registers update on first 'end of period' after the values are loaded. If this is set, the update is synchronised to one of the other PWM module end of period. In all cases the actual update only occurs at the trigger point.
JamesW



Joined: 23 Apr 2007
Posts: 91
Location: Rochester, England

View user's profile Send private message Visit poster's website

PostPosted: Fri Apr 13, 2018 8:21 am     Reply with quote

That'll be a typo (Sorry). PICF1782!
JamesW



Joined: 23 Apr 2007
Posts: 91
Location: Rochester, England

View user's profile Send private message Visit poster's website

PostPosted: Fri Apr 13, 2018 8:27 am     Reply with quote

Not to mention The CCS example code is a little unclear, as according to the documentation and the example - you pass the routine setup_psmc() 8 arguments - however the header file for this PIC only has a max of 6!

We're initialising it like this...…
Code:



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

   setup_psmc(1, PSMC_SINGLE,
               PSMC_EVENT_TIME | PSMC_SOURCE_FOSC, us(100),
               PSMC_EVENT_TIME, 0,
               PSMC_EVENT_TIME, us(1));
   
   psmc_pins(1, PSMC_B);

temtronic



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

View user's profile Send private message

PostPosted: Fri Apr 13, 2018 8:49 am     Reply with quote

If you want smooth LED intensity, run as designed, in constant current mode. Also light output is not linear, so you need create a table of 'intensity vs. bits'. And all LEDs are different so the table you create for LED 'A' can't be used for LED 'B'.

Just some 'fun facts' I've picked up over the years.

Jay
JamesW



Joined: 23 Apr 2007
Posts: 91
Location: Rochester, England

View user's profile Send private message Visit poster's website

PostPosted: Fri Apr 13, 2018 8:53 am     Reply with quote

I'd love to run in constant current mode - but am switching a variable number of parallel strings of LED's on boards that are guillotined on site to fit the application (and then panels can be wired in parallel as well). As such we have no idea of how many strings we will be driving at any time.


We're almost there with it, but just need to get that little bit more control of the lower end - and as it's being adjusted using pot's aren't too worried about exact values.
Ttelmah



Joined: 11 Mar 2010
Posts: 19549

View user's profile Send private message

PostPosted: Sat Apr 14, 2018 3:43 am     Reply with quote

The psmc module always synchronises it's actual register updates to something.
You can change the mark/space using psmc_duty. The update sync source is controlled by psmc_sync.
No it doesn't use a timer. It uses a 'time base generator'. The timing of this though is available on interrupts.
The psmc timing itself is available from the psmc interrupts INT_PSMC1S & 1T (or 2). These correspond to the PSMC1SIF PSMC1TIF, PSMC2SIF & PSMC2TIF in the data sheet. The 'T' ones are the timebase interrupt flags (the 'S' ones are shutdown events).
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