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

PWM Dimming

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



Joined: 03 Jun 2006
Posts: 14

View user's profile Send private message

PWM Dimming
PostPosted: Mon Jul 11, 2011 11:28 pm     Reply with quote

I am using PIC18F4431 to do PWM dimming for a two string LED. The two PWM signals for dimming the LEDs have to be phase shifted. Also, I am using a voltage on the ADC pin so that I can change the dimming signals so that I can obtain various colors in the LED strings.

I can generate PWM signals using PIC18F4431 and then change the duty cycle using the ADC but I don't have any idea how to make two PWM dimming signals be phase shifted.

I tried using the OVDCOND and OVDCONS registers in the PIC18F4431 but did not get anywhere.

The problem is that my duty cycle can be changed using the ADC. It is not a set duty cycle.

Does anyone have any idea how I can do this?

I want to do this using the PWM module not using I/O pins.Can this be done this way?

Thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19559

View user's profile Send private message

PostPosted: Tue Jul 12, 2011 2:30 am     Reply with quote

It is not the PWM that you phase shift. It is your _modulation_ of it.
So (crude, and lacks the configuration stuff):
Code:

#define OFFSET (0x40L) //offset between the modulations
    int8 sig1=0,sig2;
    int1 up=TRUE;
    //running the pwm using 8bit only

    do {
        if (up) {
           if (sig1<255) ++sig1;
           else {
               up=FALSE;
               --sig1;
           }
        }
        else {
           if (sig1>0) --sig1;
           else {
               up=TRUE;
               ++sig1;
           }
        }
        //Count 0....255....0 etc. Sawtooth output.
        sig2=(sig1+OFFSET)&0xFF; //8bit value offset by 'OFFSET'
        set_pwm1_duty(sig1);
        set_pwm1_duty(sig2);
        delay_ms(10); //Will then take about seconds/cycle - reduce for faster
    } while (TRUE);


On each loop, 'sig1', is fed to PWM1, while 'sig2' is fed to PWM2. Sig1, counts 0...255, then ramps down to 0. Sig2, starts at 'OFFSET', with the waveform 'leading' sig1, by this offset value.

Best Wishes
temtronic



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

View user's profile Send private message

PostPosted: Tue Jul 12, 2011 5:09 am     Reply with quote

Phase shifting is a delay between signals, in your case the 2 LED strings.
You don't say what the delay is to be between the two outputs.
I don't use the PIC you've chosen so I haven't read the datasheet to see if it allows for a programmable delay between the hardware PWMs. Others who use it (or one with same PWM hardware) may know.
Depending on the required shifting it can be done either in software or additional hardware.
jhasan



Joined: 03 Jun 2006
Posts: 14

View user's profile Send private message

PostPosted: Tue Jul 12, 2011 11:29 am     Reply with quote

Hello,

I still did not get the PWM signal to be shifted.

This is my code:
Code:

while(1)
{
set_adc_channel(0);
delay_us(20);
Vsense_adc_read_1  =  read_adc();
delay_us(20);
Vsense_dimm_1  =  (int32)(Vsense_adc_read_1*iADCgain_n16);

PWM_Duty1   =  (signed int16)(Vsense_dimm_1);

PWM_Duty2   =  (signed int16)((PWM_Duty1+400));

PDC0L =  make8(PWM_Duty1,0);
PDC0H =  make8(PWM_Duty1,1);

PDC1L =  make8(PWM_Duty2,0);
PDC1H =  make8(PWM_Duty2,1);
}
}

For PWM_Duty2 I have added a OFFSET but still no luck on shifting the original PWM signal.

I read the value from ADC and then move that value into PWM duty cycle registers.So that I can change the duty cycle using the ADC.

But is there anyway I can phase shift my original signal that PWM_Duty1.

For my case let us say there is delay of 10us between the original and phase shifted signal.

Thanks
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

Dimming PWM
PostPosted: Tue Jul 12, 2011 2:03 pm     Reply with quote

Hi,

I'm not certain what you want.

Draw a diagram of the 'scope traces you expect for your two PWM signals.

Then there is less opportunity for confusion.

Mike Walne
jhasan



Joined: 03 Jun 2006
Posts: 14

View user's profile Send private message

PostPosted: Tue Jul 12, 2011 3:13 pm     Reply with quote

For some reason I cannot download a image here.

If you could bare with me, and go to google and search for the following paper "LED Driver With Self-Adaptive Drive Voltage". On page 4 of that journal they implement phase shifted PWM dimming.

That is what I am trying to accomplish using PIC18F4431 where the PWM signals are phase shifted.

Thanks
temtronic



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

View user's profile Send private message

PostPosted: Wed Jul 13, 2011 10:01 am     Reply with quote

Since the second output will be the same as the first output but phase shifted, simply have a routine to read the status of the first output pin ( high or low), delay whatever phase shift time you want, then set or reset the second PIC I/O pin to follow the first.

Simple and easy.....
..and it does work.
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