Soft_PWM_Library
http://www.libstock.com/projects/view/1042/software-pwm
تحياتي
جميل في الامر تدعم ترددات قليله مثل 50 هيرتز وهذا ممتاز
ولكن مشكله تخرج لطرف واحد وسنحاول أضافه عده تايمرات لتوليد أكثر من طرف وفق الكود أدناه وأتمنى من لديه فكره أفضل فليساعدنا في تطويرها
هذا كود مكتبه لاطلاع عليها
كود:
//============================================================================
// Library: Soft_PWM_16F.
// Author : Arezki YOUYOU
// Date:16/07/2014
//this library allow you to use the Soft PWM in the device 16Fxx in any PIN.
//the precision increases as the frequency of the microcontroller increases,
//or decreases the frequency of Soft_PWM.
//==============Importante========================//
//this Library use the TMR0, you can't use it.
//============================================================================
// Contact me:
// email: arezkiyouyou*gmail.com
//============================================================================
unsigned long Soft_PWM_clock,Soft_PWM_duty,Soft_PWM_flip_flop=0;
unsigned long Soft_PWM_duty_bis=0;
extern sfr sbit Soft_PWM_PIN;
extern sfr sbit Direction_Soft_PWM_PIN;
void Soft_PWM_Inter();
/********************************************/
void Soft_PWM_Inter(){
if (TMR0IF_bit){
TMR0IF_bit = 0;
Soft_PWM_flip_flop++;
if(Soft_PWM_flip_flop<=Soft_PWM_duty){
Soft_PWM_PIN=1;
}
else if(Soft_PWM_flip_flop>Soft_PWM_duty && Soft_PWM_flip_flop<Soft_PWM_clock){
Soft_PWM_PIN=0;
}
else {Soft_PWM_flip_flop=0; if(Soft_PWM_duty>0)Soft_PWM_PIN=1;}
}
}
/***********************************************/
unsigned long Soft_PWM_Init(unsigned long frequance_HZ){
unsigned long clk;
Direction_Soft_PWM_PIN=0;
Soft_PWM_PIN=0;
clk = clock_kHz();
clk*=250;
Soft_PWM_clock = clk/frequance_HZ;
if(Soft_PWM_clock<256) return (0);
Soft_PWM_clock=Soft_PWM_clock/256;
T0CS_bit=0;
PSA_bit=1;
GIE_bit = 1;
TMR0IE_bit= 0;
Soft_PWM_duty=0;
return Soft_PWM_clock;
}
/*************************************************/
char Soft_PWM_set_duty(char set_Soft_PWM_duty){
if (set_Soft_PWM_duty>100) return (0xFF);
Soft_PWM_duty_bis=set_Soft_PWM_duty*Soft_PWM_clock;
Soft_PWM_duty_bis/=100;
Soft_PWM_duty=Soft_PWM_duty_bis;
return Soft_PWM_duty_bis;
}
/****************************************/
void Soft_PWM_Start(){
Soft_PWM_flip_flop=0;
TMR0IE_bit=1;
}
/****************************************/
void Soft_PWM_Stop(){
TMR0IE_bit=0;
Soft_PWM_PIN=0;
}
/****************************************/