Pumpkin, Inc.

Pumpkin User Forums

PWM help needed

If you can't make Salvo do what you want it to do, post it here.

PWM help needed

Postby Code_Nerd » Mon Jun 26, 2006 4:27 am

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).]

Code_Nerd
 
Posts: 24
Joined: Sun Apr 23, 2006 11:00 pm

Re: PWM help needed

Postby fil323 » Mon Jun 26, 2006 7:10 am

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.

hi
fil323
 
Posts: 14
Joined: Sat Jun 24, 2006 11:00 pm

Re: PWM help needed

Postby fil323 » Mon Jun 26, 2006 7:30 am

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

hi
fil323
 
Posts: 14
Joined: Sat Jun 24, 2006 11:00 pm

Re: PWM help needed

Postby Code_Nerd » Tue Jun 27, 2006 1:11 am

Yep that looks right mate..
However you are working out 15% of 1KHz!
Code_Nerd
 
Posts: 24
Joined: Sun Apr 23, 2006 11:00 pm

Re: PWM help needed

Postby fil323 » Tue Jun 27, 2006 9:54 am

So what are you saying dude? Is it right working it out for the 15% or not?
hi
fil323
 
Posts: 14
Joined: Sat Jun 24, 2006 11:00 pm

Re: PWM help needed

Postby fil323 » Tue Jun 27, 2006 9:57 am

O i get it man lol

my bad, tnx for the help

hi
fil323
 
Posts: 14
Joined: Sat Jun 24, 2006 11:00 pm

Re: PWM help needed

Postby fil323 » Tue Jun 27, 2006 9:58 am

So have you done question 6 man from the revision sheet?

Pretty hard question true

hi
fil323
 
Posts: 14
Joined: Sat Jun 24, 2006 11:00 pm


Return to Coding

Who is online

Users browsing this forum: No registered users and 1 guest

cron