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 support@ccsinfo.com

Using CCS PIC C Wizard PWM and Internal OSC

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



Joined: 24 Sep 2008
Posts: 9

View user's profile Send private message

Using CCS PIC C Wizard PWM and Internal OSC
PostPosted: Sat Oct 18, 2008 11:22 pm     Reply with quote

I am newbie to microcontroller programming i am using the CCS PIC C 4.057.

Microcontroller PIC18F4550

Using the Project Wizard option, i am trying to setup a internal oscillator to run at 8MHz. i am confused on how to setup the fuzes:

Should i choose the Internal RC OSC or Internal RC Osc, NO CLKOUT.
I would really appreciate it if someone could guide me through all the options on which to turn off or on.

Another thing i am using the Wizard to setup the PWM, i am using CCP2, i am just trying to run DC motor using Electronic speed Controller on a RC Car (TRAXXAS), which option should i select, full bridge, full bridge reverse, or half bridge.
(CCP1 is running a servo to control steering).

The PWM is at 50Hz with varying duty cycle.

This my current setup.

#include <18F4550.h>
#device adc=8

#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC //Internal RC Osc
#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 LVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#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 PBADEN //PORTB pins are configured as analog input channels 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 PLL1 //No PLL PreScaler
#FUSES CPUDIV1 //No System Clock Postscaler
#FUSES USBDIV //USB clock source comes from PLL divide by 2
#FUSES VREGEN //USB voltage regulator enabled
#FUSES ICPRT //ICPRT enabled

#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

Thank you
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Oct 18, 2008 11:47 pm     Reply with quote

Code:
#FUSES INTRC_IO 

Use this fuse to select the internal oscillator. The i/o pins for the crystal
can also be used for other things:


Quote:
#FUSES LVP

This is wrong. Change it to NOLVP.


Quote:
#FUSES XINST

This is very wrong. Change it to NOXINST.
MicroManiac



Joined: 21 Aug 2008
Posts: 34

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Sat Oct 18, 2008 11:54 pm     Reply with quote

Regarding the clock, use the internal RC OSC, and then in the in the "internal oscillator configuration" tab choose the enable internal oscillator and system clock is form Primary oscillator, then choose the 8Mhz.

Regarding the PWM,
click the :Other" Tab, choose CCP1, then under the CCPX settings, click PWM and choose the correct freuend and duty cycle, ignore the other tabs
_________________
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction."
Albert Einstein
RF_Geek



Joined: 24 Sep 2008
Posts: 9

View user's profile Send private message

PostPosted: Sun Oct 19, 2008 12:03 am     Reply with quote

if i use CCP1 for the motor i need to use CCP2 for the Servo, in that case what settings do i use.
RF_Geek



Joined: 24 Sep 2008
Posts: 9

View user's profile Send private message

PostPosted: Sun Oct 19, 2008 1:29 am     Reply with quote

Thank you everyone, i wanted to know does it matter if you use CCP1 or CCP2 because i want control two devices with PWM.


here is the updated code, do you guys see any problems.

Code:

#include <18F4550.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES EC                       //External clock with CLKOUT
#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 LVP                      //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#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 PBADEN                   //PORTB pins are configured as analog input channels 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 NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL12                    //Divide By 12(48MHz oscillator input)
#FUSES CPUDIV4                  //System Clock by 4
#FUSES USBDIV                   //USB clock source comes from PLL divide by 2
#FUSES VREGEN                   //USB voltage regulator enabled
#FUSES ICPRT                    //ICPRT enabled

#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)


and here is the code for the PWM

Code:

void main()
{

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   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,1);
   setup_ccp1(CCP_PWM);
   set_pwm1_duty(51);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   setup_oscillator(OSC_8MHZ|OSC_NORMAL|OSC_31250|OSC_PLL_OFF);


Thank you
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 19, 2008 1:47 am     Reply with quote

You've still got LVP in there, and EC will certainly not invoke the internal
oscillator. Your setup_oscillator() statement has got conflicting
frequencies. You have got to clean all this stuff up and you have got
to pay attention to detail. Here is sample code for two PWM channels:
http://www.ccsinfo.com/forum/viewtopic.php?t=17729&start=1
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