View previous topic :: View next topic |
Author |
Message |
wings1122
Joined: 27 May 2015 Posts: 2
|
how to add dead band delay with half bridge PWM with ccsc 5 |
Posted: Wed May 27, 2015 2:31 pm |
|
|
i am the newer of ccsc with PIC, i would like to generate a half bridge PWM driver for test, but I dont know how to setup the dead band delay on ccsc. Could any help
Code: |
#include <18F4550.h>
#device ADC=16
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#use delay(clock=48MHz,crystal=20000000)
#define LED PIN_B7
#define DELAY 50
#include <main.h>
void main()
{
setup_timer_2(T2_DIV_BY_1,1,1); //0.2 us overflow, 0.2 us interrupt
setup_ccp1(CCP_PWM|CCP_PWM_HALF_BRIDGE|CCP_SHUTDOWN_AC_L|CCP_SHUTDOWN_BD_L);
set_pwm1_duty((int16)4);
//Example blinking LED program
while(true)
{
output_low(LED);
delay_ms(DELAY);
output_high(LED);
delay_ms(DELAY);
}
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19510
|
|
Posted: Wed May 27, 2015 2:49 pm |
|
|
add CCP_DELAY to your declaration, and put the value into the ECCP1DEL register. It's not explained properly, but this is the value that can optionally be placed _after_ the mode settings. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 27, 2015 10:14 pm |
|
|
If I compile your posted program with vs. 5.046, the compiler sets the deadband delay to 0, as shown below in the .LST file:
Code: |
.................... setup_ccp1(CCP_PWM|CCP_PWM_HALF_BRIDGE|CCP_SHUTDOWN_AC_L|CCP_SHUTDOWN_BD_L);
0046: BCF TRISC.TRISC2
0048: BCF LATC.LATC2
004A: BCF TRISD.5
004C: MOVLW 8C
004E: MOVWF CCP1CON
0050: [b]CLRF ECCP1DEL[/b] // Set deadband delay to 0
0052: CLRF ECCP1AS |
The CCS manual says this:
Quote: | setup_ccp1 (mode, pwm)
pwm parameter is an optional parameter for chips that includes ECCP module. This parameter allows setting the shutdown time. The value may be 0-255. |
But if I do this (with a parameter of 5, for example), I get code that sets
the ECCP1DEL register to 5. This is the deadband delay register.
Quote: |
.................... setup_ccp1(CCP_PWM|CCP_PWM_HALF_BRIDGE|CCP_SHUTDOWN_AC_L|CCP_SHUTDOWN_BD_L, 5);
0046: BCF TRISC.TRISC2
0048: BCF LATC.LATC2
004A: BCF TRISD.5
004C: MOVLW 8C
004E: MOVWF CCP1CON
0050: MOVLW 05 // Set deadband delay to 5
0052: MOVWF ECCP1DEL
0054: CLRF ECCP1AS
|
I submit that the CCS manual is wrong, and that the 2nd parameter is
really the deadband delay. I am going to email them about this right now. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19510
|
|
Posted: Thu May 28, 2015 8:23 am |
|
|
Totally agree.
I did say "It's not explained properly, but this is the value that can optionally be placed _after_ the mode settings."
It has been mentioned here in the past in another thread, which is why I knew it was this value. |
|
|
wings1122
Joined: 27 May 2015 Posts: 2
|
|
Posted: Fri May 29, 2015 11:30 am |
|
|
thank you all. |
|
|
|