View previous topic :: View next topic |
Author |
Message |
filjoa
Joined: 04 May 2008 Posts: 260
|
PWM problem |
Posted: Sat Oct 31, 2009 5:13 am |
|
|
Hi
I will try make a little program to test pwm, but I don't know some things...
How I know my range values of pwm? Is it 0-255, 0-512 or 0-1024 ?
How I can determine this?
My program:
Code: |
#include <18F252.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,BROWNOUT,STVREN
#use delay(clock=20000000)
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#build(reset=0x200)
#build(interrupt=0x208)
#org 0x0000,0x01ff
void bootloader() {
#asm
nop
#endasm
} // Reserve space for the bootloader
long inc = 0;
#int_rda
void rda_isr(void)
{
char c;
c=getc();
switch(c)
{
case '+':
inc=inc+20;
break;
case '-':
inc=inc-20;
break;
}
}
void main ()
{
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);
setup_timer_2(T2_DIV_BY_1, 255, 1);
setup_ccp1(CCP_PWM);
set_pwm1_duty(inc);
while(TRUE)
{
if ((inc>=0) || (inc<=255))
{
printf("\rLuminosidade:%3lu",inc);
set_pwm1_duty(inc);
}
if (inc<0) printf("\rLuminosidade:---");
if (inc>250) printf("\rLuminosidade:+++");
}
}
|
Someone can help me?
Best regards |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Thu Nov 26, 2009 3:20 pm |
|
|
hi
To not open other post I edit this... because on older have a stupid question... |
|
|
bungee-
Joined: 27 Jun 2007 Posts: 206
|
|
Posted: Thu Nov 26, 2009 4:26 pm |
|
|
Take datasheet of your PIC and look at PWM section. There is a formula which is used to calculate width of PWM.
There is also the formula from which you can calculate the frequency. |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Fri Nov 27, 2009 5:45 am |
|
|
Hi
I read the datasheet and say there 8bits and 10bits... because that my confusion... but it solve, my PWM is 10bits thanks. |
|
|
|