remote Fan controller help

Discussion in 'The Projects Forum' started by aruna1, Aug 6, 2009.

  1. aruna1

    Thread Starter Active Member

    Dec 20, 2008
    46
    0
    I was making a remote fan controller.circuit and programming is finished but there is only one last problem remains.

    sometimes circuit some how change speed(increase count on 7 segment and increases speed) without giving any IR signal.
    its like IR receiver virtually received a IR signal.I'm driving a stand fan.I'm not sure this is because fan is a inductive load and i have no idea where is the problem

    I removed ir sensor and replaced it with push button.with push button i don't have this problem.it seems IR module is generating signals some how.so i replaced it with a new one but it didn't solved the problem.

    circuit responds to IR signal properly

    I have attached my schematic here.

    I use zero cross detector interrupt pic. IR signal is checked using polling.

    can someone point me the error and show me a solution?

    thanks.

    this is the only problem I'm having to finalize my project[​IMG][​IMG][​IMG]
     
  2. jj_alukkas

    Well-Known Member

    Jan 8, 2009
    751
    5
    Are any high frequency light sources falling on the IR reciever?? A CFL lamp or direct sunlight causes these problems. Turn it away from them. Tube lights are also responsible. This is a general precaution to be known when dealing with IR controls..

    Also adding a 1-33uF 16V capacitor between Vout and GND of TSOP 1738 sometimes helps prevent false triggering. You will have to test for the right value. 1uF would be sufficient.
     
    Last edited: Aug 6, 2009
  3. jj_alukkas

    Well-Known Member

    Jan 8, 2009
    751
    5
    Could you give the source code in ASM and hex??
     
  4. aruna1

    Thread Starter Active Member

    Dec 20, 2008
    46
    0
    no bulbs or cfl ,tubelights,direct sunlights alling on IR reciver.i will try adding a cap.

    i dont have it in ASM.i wrote it in C.
    i'll post it here.code is not finished yet.only basic parts are done.and need lot of cleaning

    Code ( (Unknown Language)):
    1. #include "C:\Documents and Settings\Aruna\My Documents\fan project\adding timer\main.h"
    2.  
    3. int speed=0;
    4. int count=0;
    5. int k=0;
    6. int timer0_on=0;
    7. int timer_mode=0;
    8. int16 timer0_count=0;
    9. int timer_set=0;
    10. int time_min=0;
    11. int timer_det_mode = 0;
    12. int timer_set_mode = 0;
    13. int second=0;
    14. int minute=0;
    15. int quater_mili=0;
    16. int x=0;
    17. int first_INT_done=0;
    18. int zero_cross_count=0;
    19.  
    20. void set_timer();
    21. void finalize_timer();
    22. void chk_ir();
    23. void beep(INT times,int length);
    24.  
    25. #INT_EXT
    26.  
    27. void  EXT_isr(VOID)
    28. {
    29.    chk_ir ();
    30.    output_low (PIN_A0);
    31.    zero_cross_count++;
    32.  
    33.    IF (speed == 0)
    34.    {
    35.      
    36.       output_low (PIN_A0);
    37.    }
    38.  
    39.    else IF (speed == 1)
    40.    {
    41.       IF (zero_cross_count == 5)
    42.       {
    43.          delay_ms (1);
    44.          output_high (PIN_A0);
    45.          zero_cross_count = 0;
    46.          delay_ms (1);
    47.          output_low (PIN_A0);
    48.       }
    49.       //delay_ms (8);
    50.       //output_high (PIN_A0);
    51.    }
    52.  
    53.    else IF (speed == 2)
    54.    {
    55.      
    56.       delay_ms (6);
    57.       output_high (PIN_A0);
    58.    }
    59.  
    60.    else IF (speed == 3)
    61.    {
    62.       delay_ms (4);
    63.       output_high (PIN_A0);
    64.    }
    65.  
    66.    else IF (speed == 4)
    67.    {
    68.      
    69.       delay_ms (2);
    70.       output_high (PIN_A0);
    71.    }
    72.  
    73.    else IF (speed == 5)
    74.    {
    75.    
    76.       {
    77.          delay_ms (1);
    78.          output_high (PIN_A0);
    79.          zero_cross_count = 0;
    80.          delay_ms (1);
    81.          output_low (PIN_A0);
    82.       }
    83.      
    84.       //delay_us (1500);
    85.       //output_high (PIN_A0);
    86.    }
    87. }
    88.  
    89. #INT_TIMER1
    90.  
    91. void  TIMER1_isr(VOID)
    92. {
    93.    quater_mili++;
    94.  
    95.    IF (quater_mili == 4)
    96.    {
    97.       quater_mili = 0;
    98.       second++;
    99.  
    100.       IF (second == 60)
    101.       {
    102.          second = 0;
    103.          minute++;
    104.          
    105.          IF (minute == 1)
    106.          {
    107.             disable_interrupts (INT_EXT);
    108.             output_low (PIN_A0);
    109.             //speed=0;
    110.            
    111.             beep (2, 50) ;
    112.             /* output_high (PIN_A5);
    113.             delay_ms (50);
    114.             output_low (PIN_A5);
    115.             delay_ms (50);
    116.             output_high (PIN_A5);
    117.             delay_ms (50);
    118.             output_low (PIN_A5);
    119.            
    120.             output_high (PIN_A4);
    121.             delay_us (100);
    122.             output_low (PIN_A4); */
    123.            
    124.             minute = 0;
    125.             time_min = 0;
    126.             disable_interrupts (INT_TIMER1);
    127.          }
    128.  
    129.          /* IF (minute == time_min)
    130.          {
    131.             output_low (PIN_A0);
    132.             minute = 0;
    133.             time_min = 0;
    134.             disable_interrupts (INT_TIMER1);
    135.          }*/
    136.       }
    137.    }
    138. }
    139.  
    140. #INT_TIMER0
    141.  
    142. void  TIMER0_isr(VOID)
    143. {
    144.    IF (timer_det_mode == 1)
    145.    {
    146.       IF (timer0_count < 5000)
    147.       {
    148.          timer0_count++;
    149.       }
    150.  
    151.       else IF (timer0_count >= 5000)
    152.       {
    153.          //timer mode on
    154.          timer_mode = 1;
    155.          
    156.          disable_interrupts (INT_TIMER0);
    157.          
    158.          timer0_count = 0;
    159.          first_INT_done = 1;
    160.          //set_timer ();
    161.       }
    162.    }
    163.  
    164.    IF (timer_set_mode == 1)
    165.    {
    166.       output_low (PIN_A1);
    167.       //delay_ms (50);
    168.  
    169.       IF (timer0_count < 3000)
    170.       {
    171.          timer0_count++;
    172.       }
    173.  
    174.       else IF (timer0_count >= 3000)
    175.       {
    176.          
    177.          disable_interrupts (INT_TIMER0);
    178.          timer0_count = 0;
    179.          finalize_timer ();
    180.          
    181.          
    182.          //set_timer ();
    183.       }
    184.    }
    185. }
    186.  
    187. void beep(INT8 times,int length)
    188. {
    189.    INT8 i = 0;
    190.    FOR (i = 1; i <= times; i++)
    191.    {
    192.       output_high (PIN_A5);
    193.       delay_ms (length);
    194.       output_low (PIN_A5);
    195.  
    196.       IF (i != times)
    197.       {
    198.          delay_ms (length);
    199.       }
    200.    }
    201.  
    202.    
    203.    
    204.    output_high (PIN_A4);
    205.    delay_us (100);
    206.    output_low (PIN_A4);
    207. }
    208.  
    209. void finalize_timer() // this code does not run
    210. {
    211.    beep (3, 50) ;
    212.    timer_mode = 0;
    213.    timer_set = 1;
    214.    timer_set_mode = 0;
    215.    enable_interrupts (INT_TIMER1);
    216.    enable_interrupts (INT_EXT);
    217. }
    218.  
    219. void set_timer() // this code runs
    220. {
    221.    disable_interrupts (INT_EXT);
    222.    timer_det_mode = 0;
    223.    
    224.    beep (2, 50) ;
    225.    timer0_count = 0;
    226.    timer_set_mode = 1;
    227.    x = 1;
    228.    enable_interrupts (INT_TIMER0); // eneabling for second time
    229.    time_min = 0;
    230.    
    231.    WHILE ( ! timer_set)
    232.    {
    233.      
    234.       output_high (PIN_A1);
    235.  
    236.       IF (! input (PIN_A3) &&time_min <= 270) //time_min should be < 270----- need to add
    237.       {
    238.          delay_ms (1000);
    239.          output_low (PIN_A1);
    240.          timer0_count = 0;
    241.          time_min = time_min + 30;
    242.          output_high (PIN_A5);
    243.          delay_ms (50);
    244.          output_low (PIN_A5);
    245.       }
    246.    }
    247. }
    248.  
    249. VOID chk_ir  ()
    250. {
    251.    IF ( ! input (PIN_A3))
    252.    {
    253.       count++;
    254.       delay_ms (500);
    255.      
    256.      
    257.       if(speed==0)
    258.       {
    259.       }
    260.      
    261.       IF (speed != 5 &&count <= 5)
    262.       {
    263.          output_low (PIN_A1);
    264.          output_high (PIN_A5);
    265.          delay_ms (100);
    266.          output_low (PIN_A5);
    267.          speed++;
    268.       }
    269.  
    270.      
    271.       else IF (count == 6)
    272.       {
    273.          speed = 0;
    274.          
    275.          timer_det_mode = 1;
    276.          enable_interrupts (INT_TIMER0); //eneabling for first time;
    277.          timer0_on = 1;
    278.          output_high (PIN_A1);
    279.          delay_ms(50);
    280.          output_low (PIN_A1);
    281.          delay_ms(50);
    282.          output_high (PIN_A1);
    283.          delay_ms(50);
    284.          output_low (PIN_A1);
    285.          delay_ms(50);
    286.          output_high (PIN_A1);
    287.       }
    288.  
    289.       else IF (count >= 7)
    290.       {
    291.          count = 0;
    292.  
    293.          IF (timer_mode == 0)
    294.          {
    295.             output_low (PIN_A1);
    296.             disable_interrupts (INT_TIMER0);
    297.             first_INT_done = 0;
    298.             output_high (PIN_A4);
    299.             delay_us (100);
    300.             output_low (PIN_A4);
    301.             speed = 0;
    302.          }
    303.       }
    304.       delay_ms (500);
    305.    }
    306. }
    307.  
    308. void main()
    309. {
    310.    setup_adc_ports (NO_ANALOGS|VSS_VDD);
    311.    setup_adc (ADC_OFF);
    312.    setup_timer_0 (RTCC_INTERNAL|RTCC_DIV_4);
    313.    setup_timer_1 (T1_INTERNAL|T1_DIV_BY_4);
    314.    setup_comparator (NC_NC);
    315.    setup_vref (FALSE);
    316.    
    317.    output_low (PIN_A5);
    318.    output_high (PIN_A4);
    319.    delay_ms (10);
    320.    output_low (PIN_A4);
    321.    delay_ms (1000);
    322.    
    323.    enable_interrupts (INT_EXT);
    324.    disable_interrupts (INT_TIMER1);
    325.    disable_interrupts (INT_TIMER0);
    326.    enable_interrupts (GLOBAL);
    327.  
    328.    // TODO: USER CODE!!
    329.    
    330.    
    331.    WHILE (1)
    332.    {
    333.       chk_ir ();
    334.  
    335.       if (first_INT_done == 1)
    336.       {
    337.          first_INT_done = 0;
    338.          set_timer ();
    339.       }
    340.    }
    341. }
    342.  
     
  5. aruna1

    Thread Starter Active Member

    Dec 20, 2008
    46
    0
    ok i tried adding 4.7uF cap.and it seems working now.thanks
     
  6. jj_alukkas

    Well-Known Member

    Jan 8, 2009
    751
    5
    You're welcome.. Hey thanks for the code too..
     
Loading...