Author Topic: PWM duty cycle question  (Read 1879 times)

Offline kronosslayer

  • ½ Pint
  • *
  • Posts: 36
  • Post quality +6/-0
  • Gender: Male
  • Acidmods User
PWM duty cycle question
« on: August 08, 2011, 01:29:27 PM »
I have a question regarding the duty cycle. I understand that fading an led on and off is not linear, but i would like to increase the duty cycle in a linear pattern, for now.
I seen to have a problem though. It doesn't seem as simple as to just increase a register by one, because the values associated with the duty cycle are concatenated from two registers.
(CCPR1L:CCP1CON<4:5>), and is 10 bits.
I'm wondering if there's a simple trick i can use to increase my duty cycle.

Thank you, Kronoss

If you need my code just pm me
« Last Edit: August 08, 2011, 01:53:40 PM by kronosslayer »
I'm a java developer, Graphic Designer, and an a**hole.

Offline Hazer

  • x4675636B4E7574
  • Acidmods Alumni
  • Acid Modder
  • *
  • Posts: 583
  • Post quality +59/-0
Re: PWM duty cycle question
« Reply #1 on: August 09, 2011, 02:44:52 AM »
Those 2 bits in the CCP1CON are the LSB bits, you use them if you really want 10 bits of resolution. You dont really need it though. If you just simply leave them alone, you now have 8 bits of resolution.

If you want 10 steps, then 8 bits = 256 steps. So just add 25 (or 0x19) to the CCPR1L register to to step up 1/10 of the range at a time. I would have 25 as the lowet (dont leave it 0) and 250 as the highest.
[Quote from Gamermodz via Viking forums]
Don't be jealous your not half as smart. I hate ****tards like you. An ignorant redneck. Your nothing but a posing ******. Get the **** out of here, really, your claim to fame is an open source rapid fire code? You make me laugh. You think you have control over the modding market?  You couldn't create what I can and do. You are too ignorant with your outrageous assumptions and accusations. [/Quote]

Offline kronosslayer

  • ½ Pint
  • *
  • Posts: 36
  • Post quality +6/-0
  • Gender: Male
  • Acidmods User
Re: PWM duty cycle question
« Reply #2 on: August 09, 2011, 12:27:37 PM »
Ok, so i have the PWM working. I have everything declared up front, then, my program goes to an infinite loop while TMR2 counts up. When Tmr2 overflows the ISR is called, then i clear my TRISIO bits and increment my DC. It seems that im only able to see the LED at 10% duty cycle and no visual increment is happening.  :eyebrow: . According to the datasheet i clear my TRISIO bits before a new PWM starts, does that mean i must re-declare all registers related to the PWM to be able to see the new signal? :confused:
I'm a java developer, Graphic Designer, and an a**hole.

Offline 802Chives

  • Sargeant at Arms
  • Acidmods Alumni
  • Millennium Poster
  • *
  • Posts: 1304
  • Post quality +10/-0
  • Gender: Male
Re: PWM duty cycle question
« Reply #3 on: November 20, 2011, 10:02:40 AM »
fading an LED on or OFF is not linear, if you want smoother fade, use a TABLE to get your duty cycle values and Use a GAMMA CORRECTION curve for the values in the table.

As for how you accomplish your PWM, that can be done any number of ways, using a Timer is how I would do it rather then CCP because the PWM function of most pics can only handle 1 or 2 hardware produced PWM signal.  Bit banging a timer is much more expandable.


 

SMF spam blocked by CleanTalk
SimplePortal 2.3.5 © 2008-2012, SimplePortal