Created
February 2, 2020 11:41
-
-
Save gresan-gits/0506c144118d8338794dc917676c3a45 to your computer and use it in GitHub Desktop.
CCS C PWM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <main.h> | |
/* | |
Cach tinh gia tri dutu thong qua set value | |
8bit value = period+1*duty_cycle | |
16bit value= 4*(period+1)*duty_cycle | |
*/ | |
void main() | |
{ | |
setup_timer_2(T2_DIV_BY_4,124,1); //100 us overflow, 100 us interrupt//Khoi tao timer 2 tao tan so pwm(10k) | |
//mode T2_DIV_BY_4 | |
// period=124 | |
//Postscale =1 | |
//set_pwm2_duty((int16)248);//Dieu chinh do dong la 50% | |
while(TRUE) | |
{ | |
set_pwm2_duty((int16)150);//Dieu chinh do dong la 30% | |
delay_ms(3000); | |
set_pwm2_duty((int16)248);//Dieu chinh do dong la 50% | |
delay_ms(2000);; | |
setup_ccp2(CCP_OFF);//Tat PWM | |
delay_ms(5000); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<18f4520.h> | |
#device adc=16 | |
#FUSES NOWDT //No Watch Dog Timer<br> | |
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale<br> | |
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD) | |
#FUSES NOBROWNOUT //No brownout reset<br> | |
#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=20000000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment