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 CCS Technical Support

PWM, who is wrong?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mbalderas
Guest







PWM, who is wrong?
PostPosted: Sun Oct 11, 2009 10:31 pm     Reply with quote

With a PIC18F2550, I want to create a PWM.

I don't know what is going on... I just want to know if this is an issue of the compiler or, what's wrong. I want to pass the value of the duty cycle through a variable.

Like in:
Code:

int16 var;
var=100;
set_pwm1_duty(var);

But this doesn't work, the compiler doesn't find errors but in the real world, the output is always low. If I do it with a constant it works fine.
Code:

set_pwm1_duty(100);

Has anyone experienced something similar? How to know if the compiler's wrong?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 11, 2009 10:38 pm     Reply with quote

Quote:

int16 var;
var=100;
set_pwm1_duty(var);

In this case you are using 10-bit mode for the PWM, because you
declared 'var' as 16 bits.

Quote:
set_pwm1_duty(100);

In this case you are using 8-bit mode.

Quote:

int8 var;
var=100;
set_pwm1_duty(var);

To make the 1st case be the same as the 2nd case, you need to
declare 'var' as 8 bits, as shown above in bold.
mbalderas
Guest







PostPosted: Sun Oct 11, 2009 11:06 pm     Reply with quote

Thanks PCM Prog, but it still doesn't go... Is there any way to test it assigning the values directly to the CCPR1L and CCP1CON? Because I'm guessing the compiler is the issue.

Thanks for your time
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 11, 2009 11:24 pm     Reply with quote

Post a short but complete test program. It should compile without errors.
Example of a PWM test program:
http://www.ccsinfo.com/forum/viewtopic.php?t=17729&start=1

Also post your compiler version.
mbalderas
Guest







PostPosted: Sun Oct 11, 2009 11:25 pm     Reply with quote

4.038
mbalderas
Guest







PostPosted: Sun Oct 11, 2009 11:42 pm     Reply with quote

Look:

Code:

#use delay(clock=8000000)

void main()
{

   int8 var;

   set_tris_a(0xFF);
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DIV_BY_16,255,16);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_ccp1(CCP_PWM);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
//Setup_Oscillator parameter not selected from Intr Oscillotar Config tab

   var=50;
   set_pwm1_duty(var);
   
   while(1);
  }
}


But if I assign it directly:
Code:
  set_pwm1_duty(50);


Works.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 12, 2009 12:18 am     Reply with quote

1. Post your fuses statement.

2. Are you testing this on a board, or is it in Proteus ?
mbalderas
Guest







PostPosted: Mon Oct 12, 2009 9:21 am     Reply with quote

Code:
#include <18F2550.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES NOPROTECT                //Code not protected from reading
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES NOPBADEN                 //PORTB pins are configured as digital I/O on RESET
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOCPB                    //No Boot Block code protection
#FUSES MCLR                     //Master Clear pin enabled
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES XINST                    //Extended set extension and Indexed Addressing mode enabled
#FUSES PLL2                     //Divide By 2(8MHz oscillator input)
#FUSES CPUDIV1                  //No System Clock Postscaler
#FUSES USBDIV                   //USB clock source comes from PLL divide by 2
#FUSES VREGEN                   //USB voltage regulator enabled

#use delay(clock=8000000)

I'm using Proteus before going to the board.

Thanks!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 12, 2009 11:36 am     Reply with quote

Quote:
#FUSES XINST

Don't use XINST. It will make your program behave erratically.
Always use NOXINST.
mbalderas
Guest







PostPosted: Mon Oct 12, 2009 2:10 pm     Reply with quote

Gosh, you're a genius! It's working now!

What is that fuse for? I didn't write it, it came from the Wiz...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 12, 2009 2:14 pm     Reply with quote

XINST enables the Extended Instruction Set in the 18F2550. But the
CCS compiler doesn't support it. It's a bug in the Wizard to enable it.
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