Page 1 of 1

PWM help needed

PostPosted: Mon Jun 26, 2006 4:27 am
by Code_Nerd
Hmmmmm you wouldnt happen to be going to VU would you?? hahaha

2KHz = 0.5ms = 5x10^-4
Using the period formula..
(5x10^-4/4x(0.1x10^-6))-1=PR2
Therefore PR2 = 1250/16 = 78
Prescaler = 1:16

15% of 78 = 12

I think the code below is all you would need? Checkout http://forum.microchip.com/ for me info!

code:

#include <pwm.h>

void main()
{
TRISC = 0x00;
for(; ;)
{
OpenPWM1(0x4E); //78 in Hex
SetDCPWM1(12);
}
}


[This message has been edited by Code_Nerd (edited June 26, 2006).]

[This message has been edited by Code_Nerd (edited June 26, 2006).]


Re: PWM help needed

PostPosted: Mon Jun 26, 2006 7:10 am
by fil323
Hi there,
Sorry to have to bust everybody's chops here but I’m really finding it difficult in implementing a C18 example for pulse width modulation.

The problem is to create a 2 KHz PWM waveform with a duty cycle of 15%

Anything remotely similar would truly be appreciated.

Thanks.


Re: PWM help needed

PostPosted: Mon Jun 26, 2006 7:30 am
by fil323
ooo nice guess...yea man, I'm assuming you are also ... with Chlond lol

Btw man, you know how were supposed to load a value in for CCPICON, is this about right:

PWM period = (CCPRIL:CCPICON<5..4> )*Tosc*TMR2(pre)

15%*1ms = x * (0.1*10^-6)*16

1*10-4=x*(0.1*10^-6)*16

x=62.5

00111111
where the last 2 bits is the vlaue to load into CCPICO<5..4>

and the other bits correspond to the upper 10 bits of a 10 bit no.


btw man...have you done question 6 from the revision Question sem1 06, with repspect to the USART...

thanks man


Re: PWM help needed

PostPosted: Tue Jun 27, 2006 1:11 am
by Code_Nerd
Yep that looks right mate..
However you are working out 15% of 1KHz!

Re: PWM help needed

PostPosted: Tue Jun 27, 2006 9:54 am
by fil323
So what are you saying dude? Is it right working it out for the 15% or not?

Re: PWM help needed

PostPosted: Tue Jun 27, 2006 9:57 am
by fil323
O i get it man lol

my bad, tnx for the help


Re: PWM help needed

PostPosted: Tue Jun 27, 2006 9:58 am
by fil323
So have you done question 6 man from the revision sheet?

Pretty hard question true