xuanhiendk2
28-07-2009, 07:11 PM
Thạch anh 20MHz bạn phải lắp tụ 15pF thôi. Theo kinh nghiệm của mình thì thạch anh tần số càng cao thì tụ ổn định dao đọng phải giảm xuống. Mà bạn có thể pót sơ đồ lên cho anh em xem thử.
Mình đã test lại mạch. Vẫn dùng tụ 33pF. Xung đo ra đã đúng nhưng không hiểu sao chỉ chạy được một lúc là Pic lại tịt ngỏm. (Nếu không dùng hai tụ 104 ở hai chân VDD nối xuống mass) hoặc chạy nhưng tần số không chính xác(nếu dùng 2 tụ 104 ở hai chân VDD nối xuống mass)
Mình không post file lên được
Hx hx! Mong mọi người giúp đỡ
#include "E:\POWER CONTROL MOTOR\XUANHIEN.h"
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT
#use delay(clock=20000000)
int16 TB,TA,HALF_T0,TS,MODULATION_INDEX;
int8 DEGREE_CONSTANT,REQUIRED_MOTOR_SPEED;
INT16 PHASE_R_DUTY,PHASE_Y_DUTY,PHASE_B_DUTY;
unsigned INT8 i = 0;
CONST INT16 TABLE_TB[256] = {0,4,8,12,16,20,24,28,32,36,40,44,48,52,55,59,63,6 7,71,
75,79,83,87,91,95,99,103,107,111,115,119,123,126,1 30,134,138,142,146,150,154,158,
162,166,170,173,177,181,185,189,193,197,201,205,20 8,212,216,220,224,228,232,235,
239,243,247,251,255,258,262,266,270,274,278,281,28 5,289,293,296,300,304,308,311,
315,319,323,326,330,334,338,341,345,349,352,356,36 0,363,367,371,374,378,382,385,
389,393,396,400,403,407,411,414,418,421,425,429,43 2,436,439,443,446,450,453,457,
460,464,467,471,474,478,481,484,488,491,495,498,50 1,505,508,512,515,518,522,525,
528,532,535,538,541,545,548,551,555,558,561,564,56 7,571,574,577,580,583,586,590,
593,596,599,602,605,608,611,614,617,621,624,627,63 0,633,636,639,642,644,647,650,
653,656,659,662,665,668,671,673,676,679,682,685,68 7,690,693,696,699,701,704,707,
709,712,715,717,720,723,725,728,731,733,736,738,74 1,743,746,748,751,753,756,758,761,
763,766,768,770,773,775,777,780,782,784,787,789,79 1,794,796,798,800,803,805,807,809,
811,813,816,818,820,822,824,826,828,830,832,834,83 6};
Void GENERATE_PWM()
{
set_power_pwm0_duty(PHASE_R_DUTY);
set_power_pwm2_duty(PHASE_Y_DUTY);
set_power_pwm4_duty(PHASE_B_DUTY);
}
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF|ADC_TAD_MUL_0);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_oscillator(False);
setup_power_pwm_pins(PWM_COMPLEMENTARY,PWM_COMPLEM ENTARY,PWM_COMPLEMENTARY,PWM_COMPLEMENTARY);
setup_power_pwm(PWM_CLOCK_DIV_4|PWM_UP_DOWN|PWM_DE AD_CLOCK_DIV_4,1,0,250,0,1,8);
MODULATION_INDEX = 1;
TS = 1000; //PWM_DC_MAX
i = 0;
while (1)
{
TB = TABLE_TB[i]*MODULATION_INDEX; //VALUE OF TB
TA = TABLE_TB[255-i]*MODULATION_INDEX; //VALUE OF TB
HALF_T0 = (TS-(TA+TB))/2; //T0/2
PHASE_R_DUTY = HALF_T0; //PHASE R DC = T0/2
PHASE_Y_DUTY = TA + HALF_T0; //PHASE Y DC = T0/2 + TA
PHASE_B_DUTY = TS - HALF_T0; //PHASE B DC = TS - T0/2
GENERATE_PWM();
PHASE_Y_DUTY = HALF_T0; //PHASE Y DC = T0/2
PHASE_R_DUTY = HALF_T0 + TB; //PHASE R DC = T0/2 + TB
PHASE_B_DUTY = TS - HALF_T0; //PHASE B DC = TS - T0/2
GENERATE_PWM();
PHASE_R_DUTY = TS - HALF_T0; //PHASE R DC = TS - T0/2
PHASE_Y_DUTY = HALF_T0; //PHASE Y DC = T0/2
PHASE_B_DUTY = HALF_T0 + TA; //PHASE B DC = T0/2 + TA
GENERATE_PWM();
PHASE_R_DUTY = TS - HALF_T0;
PHASE_Y_DUTY = HALF_T0 + TB;
PHASE_B_DUTY = HALF_T0;
GENERATE_PWM();
PHASE_R_DUTY = HALF_T0 + TA;
PHASE_Y_DUTY = TS - HALF_T0;
PHASE_B_DUTY = HALF_T0;
GENERATE_PWM();
PHASE_R_DUTY = HALF_T0;
PHASE_Y_DUTY = TS - HALF_T0;
PHASE_B_DUTY = HALF_T0 + TB;
GENERATE_PWM();
i++;
if (i >=255 )
{i=0;
}
}
}
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.