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

Pwm LED RGB with Timer

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Charles Francês



Joined: 29 Feb 2020
Posts: 7

View user's profile Send private message

Pwm LED RGB with Timer
PostPosted: Mon Apr 27, 2020 10:04 am     Reply with quote

I'm wanting to read the duty cycle values through a matrix and I don't
know how to do it, someone could help me, I'm in doubt in the code.
Code:

Pic <18fxxx   >
#fuses ..........
#int timer0
Int Matrix [1][3] [3]  = {{ 255,76,45,  34,54,0, 45,67,86}
                                       { 255,76,45,  34,54,0, 45,67,86}
                                       {255,76,45,  34,54,0, 45,67,86}};

PWM1= 0; // 255 you know.?
PWM2 = 1; //76
PWM3 = 2; //45
      Help me! Please!
        //PWM4 =
       //PWM5 =
     //PWM6 =
    //PWM7 =
  //PWM8 =[i][/i]


Last edited by Charles Francês on Mon Apr 27, 2020 5:55 pm; edited 1 time in total
Charles Francês



Joined: 29 Feb 2020
Posts: 7

View user's profile Send private message

PostPosted: Mon Apr 27, 2020 10:14 am     Reply with quote

I understand that to read the duty cycle you can also write in the PDC0L / H register.
Example:
Code:

 PDC0H = MATRIX [PWM1] >> 8
 PDC0L = MATRIX [PWM1]

Help me please!
Ttelmah



Joined: 11 Mar 2010
Posts: 19219

View user's profile Send private message

PostPosted: Mon Apr 27, 2020 10:43 am     Reply with quote

You need to say what PIC.

On normal PIC's using the CCP, the period is controlled by the CCPRx
registers, not the PDC registers. The PDC registers are only for chips
with the power control PWM.
To write to these directly, you can simply use:
Code:

#word PCD0 = getenv("SFR:PDC0L")

//Then to write to it:
   PDC0 = 16bitPWMduty;

To put the duty cycle value into the pair of registers.

Now the duty needs to be a 16bit value using this method of access. Your
matrix only contains 8bit values.
Setting the duty cycle is not going to do any good without first setting up
the PWM channels.
So:
What PIC?.
Post your PWM setup.
What PWM range of duty cycles do you want?.
Charles Francês



Joined: 29 Feb 2020
Posts: 7

View user's profile Send private message

PostPosted: Mon Apr 27, 2020 5:20 pm     Reply with quote

Code:
Ttelmah

Ok thanks
I'm trying to vary the duty cycle with a
 matrix, you know? in this case, this three-dimensional matrix increases 3 indices in the first index 0
and in the second index 1 type like this example {1,2,3,   4,5,6,  ...  }
Matrix [  ] [  ] [  ] = {             }
understood,
 three-dimensional matrix,
 I'm trying to light a
 rgb led with the three indices, you know?
 PDC0H = MATRIZ [PWM1] >> 2
 PDC0L = MATRIZ [PWM1]
[/code]
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