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

triac gate question

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
whung.john
Guest







triac gate question
PostPosted: Tue Sep 18, 2007 5:27 am     Reply with quote

hi my friends, how are u .
i try to write a control AC fan program.
but i put key(pin_b1) and the ac fan have operate.
i put other key (pin_b3) and ac fan not turn speed.
fan motor turn not smooth in slow and fast.
PLEASE TELL ME WHAT ERROR AND HOW TO MODIFY
THANKS U VERY MUCH
AC fan is 110V AC AND 60hz.
1/60hz=16.67ms 16.67/2=8.335ms
the theread follow as:

Code:


#include <16F73.h>
#FUSES NOWDT, XT, NOPUT, NOPROTECT, NOBROWNOUT
#use delay(clock=4000000)

BYTE dczero_flag=0;
BYTE  control_motorkey=0;
unsigned int dcspeed;


#INT_TIMER0
void timer0_isr(void)
{
   int16 dc_count;

      output_high(pin_a1);  //the triac can active and my u pin_a1 pin
       set_timer0(255);
       if (DC_count++==dcspeed)   
           {             
             output_low(pin_a1);//the triac NO active and my u pin_a1 pin
             dc_count=0;
             control_motorkey=1;
             dczero_flag=1;
             disable_interrupts(INT_timer0);
          }           
}               
           
void main()
{
  while(1)
 {
   if (!input(pin_b1))  //SET on AC FAN
      {
          control_motorkey=1;
          dczero_flag=1;
          dcspeed=8000; //first fan speed is slower
     }
   
    if (!input(pin_b2))  //SET off AC FAN
      {
          control_motorkey=0;
          dczero_flag=0;
          disable_interrupts(INT_timer0);
     }
 
      if (!input(pin_b3))  //SET AC FAN fast
       {
          control_motorkey=1;
          dczero_flag=1;
          dcspeed=6000; //first fan speed is fast
     }

   if ((input(PIN_A4))&& (control_motorkey==1)&&(dczero_flag==1))
     //find zero point
       {
        dczero_flag=0;
        control_motorkey=0;
        enable_interrupts(INT_timer0);         
          }
}
}

ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Sep 18, 2007 6:07 am     Reply with quote

Code:
          dcspeed=8000; //first fan speed is slower
dcspeed is an 8 bit integer and can't hold these large values. Change to an int16.

Code:
   int16 dc_count;
Declared like this the variable will loose it's value on exiting the interrupt. Declare it static if you want to keep the value.

Code:
      set_timer0(255);
Why do you do this? If timer0 is running in 8 bit mode it will fire again before you have time to exit the interrupt handler.

- Where is your setup code for timer0?
- Your interrupt is not working because you never call enable_interrupts(GLOBAL).
- dccount is never initialized.
- It's nice to disable the TRIAC at program startup.
- Your off-switch will not stop the motor when the TRIAC timer is still counting.

I might have missed an error...
Guest








PostPosted: Tue Sep 18, 2007 6:52 am     Reply with quote

I don't see how your zero crossing detection works, not enough description. You need to start counting at the zero crossing to be consistent.

I set an external interupt to fire at the zero crossing by sampling the line voltage with a large resistor in series with the input pin clamped by a diode. Then reset the timer count on high to low transitions.

Microchip has an app note on this method. The only difference in my application was I used an opto-isolator between the line(120V.ac) and the pic.
whung.john
Guest







lose some code in program
PostPosted: Wed Sep 19, 2007 10:20 am     Reply with quote

ckielstra wrote:
Code:
          dcspeed=8000; //first fan speed is slower
dcspeed is an 8 bit integer and can't hold these large values. Change to an int16.

Code:
   int16 dc_count;
Declared like this the variable will loose it's value on exiting the interrupt. Declare it static if you want to keep the value.

Code:
      set_timer0(255);
Why do you do this? If timer0 is running in 8 bit mode it will fire again before you have time to exit the interrupt handler.

- Where is your setup code for timer0?
- Your interrupt is not working because you never call enable_interrupts(GLOBAL).
- dccount is never initialized.
- It's nice to disable the TRIAC at program startup.
- Your off-switch will not stop the motor when the TRIAC timer is still counting.

I might have missed an error...



hi .Ckielstra
in my program lose post some code.
so i post apain
follow as : Crying or Very sad

Code:

void main()
{
 setup_counters( RTCC_INTERNAL, RTCC_DIV_1);
 disable_interrupts(INT_timer0); //first,let timer0 no operate,wait for other command 
 enable_interrupts(GLOBAL);

  while(1)
 {
   if (!input(pin_b1))  //SET on AC FAN
      {
          control_motorkey=1;
          dczero_flag=1;
          dcspeed=8000; //first fan speed is slower
     }
   
    if (!input(pin_b2))  //SET off AC FAN
      {
          control_motorkey=0;
          dczero_flag=0;
          disable_interrupts(INT_timer0);
     }
 
      if (!input(pin_b3))  //SET AC FAN fast
       {
          control_motorkey=1;
          dczero_flag=1;
          dcspeed=6000; //first fan speed is fast
     }

   if ((input(PIN_A4))&& (control_motorkey==1)&&(dczero_flag==1))
     //find zero point
       {
        dczero_flag=0;
        control_motorkey=0;
        enable_interrupts(INT_timer0);         
          }
}
}


i have write a small program again.
and test ac motor can operate and can operate smooth.
ac motor ouput voltage is 100V.
in my old program ,where has some bug ?
let the motor can't operate smooth.
please teach me ,thanks u very
follow as :

Code:

#include <16F73.h>
#FUSES NOWDT, XT, NOPUT, NOPROTECT, NOBROWNOUT
#use delay(clock=4000000)

void main()
{
 while(1)
 {
   if (input(PIN_A4))
     {
       delay_us(7200);   //delay_us(7200) fast,delay_ms(8320) slow
       output_high(pin_a1);
       delay_us(400); //delay_us(400) is fast set,delay_us(0) is slow
       output_low(pin_a1);
       delay_us(200); //delay_us(200) is fast set,delay_us(0) is slow
       }
  }
}
WHUNG.JOHN
Guest







hardware set
PostPosted: Wed Sep 19, 2007 10:32 am     Reply with quote

Anonymous wrote:
I don't see how your zero crossing detection works, not enough description. You need to start counting at the zero crossing to be consistent.

I set an external interupt to fire at the zero crossing by sampling the line voltage with a large resistor in series with the input pin clamped by a diode. Then reset the timer count on high to low transitions.

Microchip has an app note on this method. The only difference in my application was I used an opto-isolator between the line(120V.ac) and the pic.


my friend. guest
u teach set an external interupt to fire at the zero crossing by sampling the line voltage with a large resistor in series with the input pin clamped by a diode.
my hareware ready have addtion electric parts.
and i send to my electric friends to confirm hareware no error.
he say my software maybe have bugs.
because he dont understand software .
so i must help from other.
thanks u very much . and send a good information for me.
can u find other my code bug again?
wait for u solve .thnks u again.
good nignt.
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