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

Need to start PWM on PIC16F819

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







Need to start PWM on PIC16F819
PostPosted: Sat May 26, 2007 2:47 pm     Reply with quote

Hi guys,

I need a little help with getting PWM to start on pin RB3 of the 'F819.
I've read many of the posts and tried many of the recommended solutions. I just can't get the thing to work!

I'm trying to fire up a h bridge using PWM multiplexed on the low sides.

Any ideas how to solve this?

Here's my code>>

Code:

#include <16F819.h>
//#device ICD=FALSE
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES PUT                      //Power Up Timer
#FUSES MCLR                     //Master Clear pin enabled
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES LVP                      //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOPROTECT                //Code not protected from reading
#FUSES CCPB3                    //CCP1 input/output multiplexed with RB3

#use delay(clock=10000000)

#define PWM_In       PIN_A0    //
#define Current       PIN_A1    //
#define HiSideA       PIN_A2    //
#define HiSideB       PIN_A3    //
#define HiSideC       PIN_A4    // Not used
//#define -----       PIN_A5    // Not used
//#define -----       PIN_A6    // Not used Xtal
//#define -----       PIN_A7    // Not used Xtal

#define LoSideB       PIN_B0
#define LoSideA       PIN_B1
#define LoSideC       PIN_B2
#define Mtr_PWM     PIN_B3
#define Tacho_out   PIN_B4
#define HallC       PIN_B5
#define HallA       PIN_B6
#define HallB       PIN_B7


void InitMCU()
{
   setup_adc_ports(AN0);
   setup_adc(ADC_CLOCK_DIV_2);
   
   setup_spi(FALSE);

   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DIV_BY_1,500,1);

   setup_ccp1(CCP_PWM);

   enable_interrupts(INT_TIMER2);
   enable_interrupts(GLOBAL);

   setup_oscillator(False);

}


void main()
{

    InitMCU();
    InitHW();

        set_pwm1_duty(200L);

        output_high(Tacho_out);
        delay_ms(1000);
        output_low(Tacho_out);
        delay_ms(1000);
        output_high(Tacho_out);
        delay_ms(1000);
        output_low(Tacho_out);
        delay_ms(1000);
       
    do
    { 
        output_high(Tacho_out);
        delay_ms(100);
        output_low(Tacho_out);
        delay_ms(100);

   
    output_high(HiSideA);     
    output_high(LoSideB);
    delay_ms(500);
    output_low(HiSideA);     
    output_low(LoSideB);
    delay_ms(100);
   
    delay_ms(1000);
    }while(TRUE);

}
Ttelmah
Guest







PostPosted: Sat May 26, 2007 2:54 pm     Reply with quote

What pin does LVP use?.
Do you think this will work with a CCP output multiplexed onto it...

Best Wishes
Guest








PostPosted: Sat May 26, 2007 3:16 pm     Reply with quote

Doh!

I've changed the LVP to NOLVP and now it works!

Many thanks Grand Master Ttelmah, many thanks!
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