אני מנסה להפעיל מנוע סרוו קטן(Futaba s3004) בעזרת software pwm עם pic 16f877,ולוח פיתוח olimex pic-p40-usb .
זה הקוד שאני עובד איתו:
- קוד: בחר הכל
#include <16F877A.H>
#fuses HS, NOLVP
#use delay(clock = 20000000)
#define PWM_PIN PIN_B1
#define LOOPCNT 400
int32 width;
static int32 loop = LOOPCNT;
static int32 pulse;
//-------------------------------
#INT_RTCC
void tick_interrupt(void);
void init_main();
//====================================
void init_main()
{
set_tris_b(0x00); // servo port
output_b(0x00);
}
void main()
{
width = 40;
setup_counters(RTCC_INTERNAL | RTCC_8_BIT, RTCC_DIV_1);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
while(1);
}
//====================================
#INT_RTCC
void tick_interrupt(void)
{
if(--loop == 0)
{
loop = LOOPCNT;
pulse = width;
}
if(pulse)
{
output_high(PWM_PIN);
pulse--;
}
else
{
output_low(PWM_PIN);
}
}
הבעיה היא שהמנוע רוב הזמן רק עושה רעש של גלגלי שיניים מסתובבים ללא סיבוב מעשי,אך לפעמים הוא כן מסתובב כאשר לא שיניתי דבר בקוד.
האם לדעתכם יש איזו שהיא בעיה בקוד או שהבעיה יותר בכיוון של המנוע,המתחים או אולי המומנט שחסר למנוע?
תודה מראש על העזרה.



