View previous topic :: View next topic |
Author |
Message |
JamesW
Joined: 23 Apr 2007 Posts: 91 Location: Rochester, England
|
Using PSMC for High resolution (16 bit) PWM |
Posted: Fri Apr 13, 2018 8:03 am |
|
|
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: 19496
|
|
Posted: Fri Apr 13, 2018 8:18 am |
|
|
Start by giving us the right PIC number?. 16F1762 doesn't exist....
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
|
|
Posted: Fri Apr 13, 2018 8:21 am |
|
|
That'll be a typo (Sorry). PICF1782! |
|
|
JamesW
Joined: 23 Apr 2007 Posts: 91 Location: Rochester, England
|
|
Posted: Fri Apr 13, 2018 8:27 am |
|
|
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: 9221 Location: Greensville,Ontario
|
|
Posted: Fri Apr 13, 2018 8:49 am |
|
|
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
|
|
Posted: Fri Apr 13, 2018 8:53 am |
|
|
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: 19496
|
|
Posted: Sat Apr 14, 2018 3:43 am |
|
|
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). |
|
|
|