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

18F8722 Half Bridge PWM doesn't work?

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








18F8722 Half Bridge PWM doesn't work?
PostPosted: Wed Feb 03, 2010 8:03 pm     Reply with quote

Hi Folks,

Trying to get a half bridge PWM working using the 18F8722 ECCP module. One of the outputs (P1A on C2) seems to work just great, but I can't seem to get anything out of the other one (P1B on H7). See my code below.

Thanks!
Greg

Header File:
Code:

#include <18F8722.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 for PCM/PCH) (>10mhz for PCD)
#FUSES NOPROTECT                //Code not protected from reading
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV25                   //Brownout reset at 2.5V
#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 NOCPB                    //No Boot Block code protection
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES MCU                      //Microcontroller Mode
#FUSES NOWAIT                   //Wait selections unavailable for Table Reads or Table Writes
#FUSES BW16                     //16-bit external bus mode
#FUSES ABW20                    //20-bit Address bus
#FUSES ECCPE                    //Enhanced CCP PWM outpts multiplexed with RE6 thorugh RE3

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors)
#use i2c(Slave,Fast,sda=PIN_C4,scl=PIN_C3,address=0xA0)

#define PR2 0xFCB
#define CCPR1L 0xFBE
#define ECCP1DEL 0xF79
#define CONFIG3H 0x300005
#define TRISC 0xF94
#define TRISD 0xF95
#define TRISH 0xF99
#define CCP1CON 0xFBD
#define ECCP1 CCP1CON
#define ECCP1AS 0xFB6

#define RED_LED PIN_B5
#define YELLOW_LED PIN_B4
#define GREEN_LED PIN_A5

void Initialize(void);


Code:
Code:

#include "C:\Documents and Settings\Administrator\Desktop\GBCWMII EE4040-PWM\OutputStage.h"
  #include <stdlib.h>


void main() {
   Initialize();
   // TODO: USER CODE!!
   while(1) {
      //output_high(PIN_H7);
      output_high(GREEN_LED);
      delay_ms(100);
      //output_low(PIN_H7);
      output_low(GREEN_LED);
      delay_ms(100);
      //output_high(PIN_H7);
      output_high(YELLOW_LED);
      delay_ms(100);
      //output_low(PIN_H7);
      output_low(YELLOW_LED);
      delay_ms(100);
      //output_high(PIN_H7);
      output_high(RED_LED);
      delay_ms(100);
      //output_low(PIN_H7);
      output_low(RED_LED);
      delay_ms(100);
   }
}

void Initialize(void) {
   *TRISC = 0x00; //Set Port C to outputs.
   *TRISD = 0x00; //Set Port D to outputs.
   *TRISH = 0x00; //Set Port H to outputs.
   output_high(PIN_H7);
   
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF|ADC_TAD_MUL_0);
   setup_psp(PSP_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DIV_BY_1,0,1);//(mode,period,postscale);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_timer_4(T4_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   setup_low_volt_detect(FALSE);
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab
   
   
   SETUP_CCP1(CCP_PWM|CCP_PWM_HALF_BRIDGE|CCP_PWM_H_H);
   //CP1CON = 0x8c;
   *CONFIG3H = 0x81; //Multiplexes P1B from RE6 onto RH7
   *PR2 = 24; //Period = 4 * Tosc *(PR2+1) * TMR2Prescaler
   *CCPR1L = 0x0c; //Duty Cycle = Tosc * (CCPR1L<7:0>:CCP1CON<5:4>) * TMR2Prescaler -- for ease of use, ignore LSBs.
   *ECCP1DEL = 0x03|0x80; //Delay = 4 * Tosc * (ECCP1DEL<6:0>)
   *ECCP1AS = 0x00; //ECCP outputs are operating
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 03, 2010 8:18 pm     Reply with quote

Post your compiler version.
Guest








PostPosted: Wed Feb 03, 2010 8:48 pm     Reply with quote

Hi sorry, it turns out that once I had the fuse set like this #FUSES ECCPE, the PWM output could not be changed in software:

Code:

*CONFIG3H = 0x81;


Changing the fuse to #FUSES ECCPH fixed the problem entirely. Sorry for the bother.

Cheers,
Greg
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