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

PIC18F4550

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



Joined: 08 Aug 2020
Posts: 2

View user's profile Send private message

PIC18F4550
PostPosted: Tue Apr 05, 2022 1:25 am     Reply with quote

Sir,
I am using the Half-bridge code for CCP1.
How can I add dead time between each switching eg 10n-sec?

Code:

#include <18F4550.h> 
#device ADC = 10                           
#fuses NOMCLR ,HS
#use delay(clock=8M)

INT i,j;
void main()
{
char duty_cycle[100]={0,1,1,2,3,4,5,6,8,10,11,14,16,18,21,23,26,29,32,35,38,41,44,47,50,53,
56,59,62,65,68,71,74,77,79,82,84,86,89,90,92,94,95,96,98,98,99,100,
100,100,100,100,99,98,98,96,95,94,92,90,89,86,84,82,79,77,74,71,68,
65,62,59,56,53,50,47,44,41,38,35,32,29,26,23,21,18,16,14,11,10,8,6,5,
4,3,2,2,2,1,0};

setup_timer_2(T2_DIV_BY_1,100,1);
setup_ccp1(CCP_PWM | CCP_PWM_HALF_BRIDGE);   
while(true)
      {
         if (interrupt_active(INT_TIMER2))
            {
               clear_interrupt(INT_TIMER2);             
               i++;
               if(i==100) {i=0; j++; if(j==2) j=0;}             
            }     
        set_pwm1_duty(duty_cycle[i]);
      }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 05, 2022 1:55 am     Reply with quote

Enter the deadtime amount after a comma. Example:
Code:
setup_ccp1(CCP_PWM | CCP_PWM_HALF_BRIDGE, 1);
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Tue Apr 05, 2022 10:09 am     Reply with quote

Be aware that a single count will give 500nSec deadband at this clock rate.
The count is in instruction cycles.
You can't get a short delay like 10nSec.
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