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

tacho of motor

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



Joined: 14 Aug 2007
Posts: 31

View user's profile Send private message

tacho of motor
PostPosted: Sun Oct 18, 2009 9:03 am     Reply with quote

Hi all
Anyone knows why this code not works.
I use 16f877 to control of motor speed using feedback of tachometer signal.
Code:
#use delay(clock=4000000,restart_wdt)
#ROM 0x3ff = {0x3478}

#define Triac PIN_b1     // Triac
#define ZCD PIN_b0       // Zero Cross

#ZERO_RAM

int j=1; int phaseangle=123;   int tacho;

void init()
{
disable_interrupts(GLOBAL);
disable_interrupts(INT_EXT);
disable_interrupts(INT_TIMER0);
output_low(Triac);                //  triac low
delay_ms(10);
}


#INT_TIMER0
void tempo()
{
output_high(Triac);               // triac high
}

#INT_EXT
void externa()
{
set_timer0(phaseangle);
output_low(Triac);                 // triac low
enable_interrupts(INT_TIMER0);

if (j==0)
{
j=1;
ext_int_edge(H_TO_L);
}
else if(j==1)
{
j=0;
ext_int_edge(L_TO_H);
}

}

long rise,fall,pulse_width;

#int_ccp2
void isr()
{
   rise = CCP_1;
   fall = CCP_2;
   pulse_width = fall - rise;     // CCP_1 is the time the pulse went high
}


void main()
{
//init();
enable_interrupts(INT_EXT);
ext_int_edge(L_TO_H);
setup_timer_0(RTCC_INTERNAL | RTCC_DIV_64);
enable_interrupts(GLOBAL);

while(1)
{

int32 freq;
   setup_ccp1(CCP_CAPTURE_RE);      // Configure CCP1 to capture rise
   setup_ccp2(CCP_CAPTURE_FE);      // Configure CCP2 to capture fall
   setup_timer_1(T1_INTERNAL);      // Start timer 1

   enable_interrupts(INT_CCP2);     // Setup interrupt on falling edge
   enable_interrupts(GLOBAL);

   while(TRUE) {
      delay_ms(1000);
freq=(1000000/pulse_width);
output_d(freq);

   }

if(freq<0x59)
{
phaseangle++;
delay_ms(10);
}
if(freq>0x59)
{
phaseangle--;
delay_ms(10);
}

enable_interrupts(INT_EXT);

}

}
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