Hot!Dimmer bouncing whenever any remote button pressed

Page: 123 > Showing page 1 of 3
Author
akibsk
New Member
  • Total Posts : 28
  • Reward points : 0
  • Joined: 2018/10/30 07:07:04
  • Location: 0
  • Status: offline
2018/10/30 10:26:13 (permalink)
0

Dimmer bouncing whenever any remote button pressed

This is the xc8 prog for 4 ON/OFF and 1 Dimmer control with 18f2520 mcu with 20mhz osc.
Problems:::when ever ANY button of remote is pressed, the light-bulb which is connected(at RB1 PIN with MOC and TRIAC) as AC dimmer-control is bounced back (going OFF and again ON on every pressing of any remote keys) and sometimes start flickering on pressing any keys. Even found that if any finger is comes to nearer to 'TSOP-1738' receiver sensor the light-bulb also start flickering..>>how do i stop that bounce??
Code is as:
""
#include <xc.h>
#include<string.h>
#include<stdlib.h>
#include "config.h"
#define tric RB1
#define ir RB2
#define relay1 RC2
#define relay2 RC3
#define relay3 RC4
#define relay4 RC5
#define rly1LED RB3
#define rly2LED RB4
#define rly3LED RB5
#define rly4LED RC1
#define fanLED RC0
int flag=0;
int cmd=0;
int speed=5;
unsigned int dat[100];
int i=0;
char result[10];
int j=0;
   
void delay(int time)
{
    for(int i=0;i<time;i++)
        for(int j=0;j<800;j++);
}
void timer()           // 10 -> 1us
{
   T0PS0=0; 
   T0PS1=0;
   T0PS2=0;
   PSA=0;      //Timer Clock Source is from Prescaler
   T0CS=0;     //Prescaler gets clock from FCPU (5MHz)
   T08BIT=0;   //16 BIT MODE
   TMR0IE=1;   //Enable TIMER0 Interrupt
   PEIE=1;     //Enable Peripheral Interrupt
   GIE=1;      //Enable INTs globally
   TMR0ON=1;      //Now start the timer!
}
void main(void) 
{
   ADCON1=0b00001111;
   TRISB1=0;
   TRISB2=1;
   TRISB3=0;
   TRISB4=0;
   TRISB5=0;
   TRISC=0x00;
   TRISA=0x00;
   PORTA=0xc0;             
   TRISB6=0;
   RB6=1;
    relay1=0;
    relay2=0;
    relay3=0;
    relay4=0;
    rly1LED=0;
    rly3LED=0;
    rly2LED=0;
    rly4LED=0;
    fanLED=0;
        i=0;
    ir=0;
    tric=0;
    timer();
    INTEDG0 = 0; // Interrupt on falling edge
    INT0IE = 1; // Enable the INT0 external interrupt (RB0) 
    INT0IF = 0; // Clears INT0 External Interrupt Flag bit
    PEIE=1;     //Enable Peripheral Interrupt
    GIE=1;      //Enable INTs globally
   while(1)
   {   
       while(ir == 1);
       INT0IE = 0;
       while(ir == 0);
       TMR0=0;
       while(ir == 1);
       i++;
       dat=TMR0;
       
       if(dat[1] > 5000 && dat[1]<12000)
       {
       }
       else
       {
           i=0;
           INT0IE = 1;
       }
       if(i>=33) //----------------------------------------------------------------------------------------------------------------------
       {
        GIE=0;
        delay(50);
        cmd=0;
        for(j=26;j<34;j++)
        {
            if(dat[j]>1000 && dat[j]<2000)
                cmd<<=1;
            else if(dat[j]>3500 && dat[j]<4500)
            {
                cmd|=0x01;
                cmd<<=1;
            }
        }
        cmd>>=1;
         
         if(cmd == 0xAF)
         {
             relay1=~relay1;
             rly1LED=~rly1LED;
         }
         
         else if(cmd == 0x27)
         {
             relay2=~relay2;
             rly2LED=~rly2LED;
         }
         
         else if(cmd == 0x07)
         {
             relay3=~relay3;
             rly3LED=~rly3LED;
         }
         
         else if(cmd == 0xCF)
         {
             relay4=~relay4;
             rly4LED=~rly4LED;
         }
         
         else if(cmd == 0x5f)
         {
             speed++;
             if(speed>5)
             {
                 speed=5; 
             }
         }
         
         else if(cmd == 0x9f)
         {
             speed--;
             if(speed<=0)
             {
                 speed=0; 
             }
         }
         
        if(speed == 5)        // turned off  5x2= 10ms triger    //speed 0
        {
            PORTA=0xC0;           // display 0
            RB6=1;
            fanLED=0;             
        }
        
        else if(speed == 4 )    //  8 ms trigger    //speed 1
        { 
            PORTA=0xfc;        // displaying 1
            RB6=1;
            fanLED=1;
        }
        
        else if(speed == 3)   //   6 ms trigger     // speed 2
        {
            PORTA=0xE4;       // displaying 2                    
            RB6=0;
            fanLED=1;
        }
        
        else if(speed == 2)   // 4ms trigger  // speed 3
        {
            PORTA=0xF0;       // displaying 3
            RB6=0;
            fanLED=1;
        }
        
        else if(speed == 1)    // 2ms trigger  // speed 4
        {
            PORTA=0xD9;          // displaying 4
            RB6=0;
            fanLED=1;
        }
        
        else if(speed == 0)        // 0ms trigger  // speed 5  full power
        {
           PORTA=0xD2;            // displaying 5
           RB6=0;
           fanLED=1;
        }
        
        else
        {
            RB6=1;
            PORTA=0xff;         // display off
            fanLED=0;
        }
        
        i=0;
        INT0IE = 1;
        GIE=1;
       }// if(i>=33) //---------------------------------------------------------------------------------------
}//WHILE//
}//MAIN//
void interrupt isr()
{
    if(INT0IF)
    {
        delay(speed);
        tric=1;
        for(int t=0;t<100;t++);
        tric=0;
        INT0IF=0;
    }
    
   if(TMR0IF)  //Check if it is TMR0 Overflow ISR   
   {
      TMR0IF=0;
   }
    
}
//End of prog.........
 
Although the other pin for ON/OFF control is working fine.
 would anybody help me out....
Tnx
#1

52 Replies Related Threads

    jack@kksound
    code tags!
    • Total Posts : 2816
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: online
    Re: Dimmer bouncing whenever any remote button pressed 2018/10/30 10:42:16 (permalink)
    +1 (1)
    Possible RMW issues, write LATx not PORTx - 
    an example: change
    RB6 = 1; 
    to
    LATB6 = 1; 
    or better yet
    LATBbits.LATB6 = 1;

    Also use code tags around you code in the post,  makes it easier to read.
    #2
    akibsk
    New Member
    • Total Posts : 28
    • Reward points : 0
    • Joined: 2018/10/30 07:07:04
    • Location: 0
    • Status: offline
    Re: Dimmer bouncing whenever any remote button pressed 2018/10/30 10:59:10 (permalink)
    0
    ok i will do that ind update u.
    can it be the problems  of under while(1) loop section in starting and stoping of external  interrupt  (INT0IE) in wrong location in the programe.
    tnx.
    #3
    jack@kksound
    code tags!
    • Total Posts : 2816
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: online
    Re: Dimmer bouncing whenever any remote button pressed 2018/10/30 11:03:27 (permalink)
    +1 (1)
    You are using an edge sensitive interrupt with buttons? Do you have any debounce on the input?
    #4
    akibsk
    New Member
    • Total Posts : 28
    • Reward points : 0
    • Joined: 2018/10/30 07:07:04
    • Location: 0
    • Status: offline
    Re: Dimmer bouncing whenever any remote button pressed 2018/10/30 11:16:05 (permalink)
    0
    where do i place debounce on the input, pl suggest how.
    #5
    Jim Nickerson
    User 452
    • Total Posts : 5439
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: online
    Re: Dimmer bouncing whenever any remote button pressed 2018/10/30 11:23:23 (permalink)
    +1 (1)
    akibsk,
    It would be easier to read your code if you were to use code tags as Ian describes in this post https://www.microchip.com/forums/FindPost/777101
    #6
    jack@kksound
    code tags!
    • Total Posts : 2816
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: online
    Re: Dimmer bouncing whenever any remote button pressed 2018/10/30 11:35:17 (permalink)
    +1 (1)
    akibsk
    where do i place debounce on the input, pl suggest how.


    Button debounce can br done in hardware or software (or both). Hardware debounce is usually simply a low pass filter on the pic input pins. Software debounce can be implemented in a number of ways. You should find many posts and other sources for software debouncing on this forum and the internet.
    #7
    akibsk
    New Member
    • Total Posts : 28
    • Reward points : 0
    • Joined: 2018/10/30 07:07:04
    • Location: 0
    • Status: offline
    Re: Dimmer bouncing whenever any remote button pressed 2018/10/30 11:51:38 (permalink)
    0
    attached akit was done in hw. nothing was improved.

    Attached Image(s)

    #8
    KTrenholm
    Super Member
    • Total Posts : 516
    • Reward points : 0
    • Joined: 2012/08/08 14:04:23
    • Location: Connecticut, USA
    • Status: online
    Re: Dimmer bouncing whenever any remote button pressed 2018/10/30 11:59:31 (permalink)
    +1 (1)
    Here's an example of a single pin debounce routine.
     
    #define PRESSED 0
    #define NOT_PRESSED 1
    #define DEBOUNCE_COUNT 3

    //Call this at regular intervals.  Debounce_Time = (Call_Interval * DEBOUNCE_COUNT)
    //Returns debounced state of Pin A0
    bool A0_IsDebounced(void){
        bool pin_state = PORTAbits.PORTA0; //Using A0 as an example
        static bool state_prev = NOT_PRESSED;
        static uint8_t debounce_count = 0;
        static bool db_retval = false;
        if (btn_state != state_prev){
                state_prev = state;
        } else {
            if (btn_state == PRESSED){
                /*Pressed*/
                if (debounce_count >= DEBOUNCE_COUNT){
                    state_prev = state;
                    db_retval = true;
                } else {
                    debounce_count++;
                    db_retval = false;
                    
                }
            } else {
                /*Released*/
                if (debounce_count == 0){
                    state_prev = btn_state;
                    db_retval = false;
                } else {
                    debounce_count--;
                    db_retval = true;
                }
            }
        }
        return db_retval;
    }

    #9
    akibsk
    New Member
    • Total Posts : 28
    • Reward points : 0
    • Joined: 2018/10/30 07:07:04
    • Location: 0
    • Status: offline
    Re: Dimmer bouncing whenever any remote button pressed 2018/10/30 21:06:04 (permalink)
    0
    Is it denouncing problems or the line //INT0IE and //GIE which not in proper place which required to be shifted or clear or set issues under the //main().
    Request to go through the program once above . It could be the issues of the line INT0IE and GIE.
    Tnx
    #10
    akibsk
    New Member
    • Total Posts : 28
    • Reward points : 0
    • Joined: 2018/10/30 07:07:04
    • Location: 0
    • Status: offline
    Re: Dimmer bouncing whenever any remote button pressed 2018/10/31 07:13:54 (permalink)
    0
    Is it denouncing problems or the line //INT0IE and //GIE which not in proper place which required to be shifted or clear or set issues under the //main().
    Request to go through the program once above . It could be the issues of the line INT0IE and GIE.
    Tnx
    #11
    akibsk
    New Member
    • Total Posts : 28
    • Reward points : 0
    • Joined: 2018/10/30 07:07:04
    • Location: 0
    • Status: offline
    Re: Dimmer bouncing whenever any remote button pressed 2018/10/31 09:13:55 (permalink)
    0
    Is it denouncing problems or the line //INT0IE and //GIE which not in proper place which required to be shifted or clear or set issues under the //main().
    Request to go through the program once above . It could be the issues of the line INT0IE and GIE.
    Tnx
    #12
    jack@kksound
    code tags!
    • Total Posts : 2816
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: online
    Re: Dimmer bouncing whenever any remote button pressed 2018/10/31 09:46:30 (permalink)
    0
    when ever ANY button of remote is pressed, the light-bulb which is connected(at RB1 PIN with MOC and TRIAC) as AC dimmer-control is bounced back (going OFF and again ON on every pressing of any remote keys)

    Your ISR code will toggle the RB1 output hi , wait a delay, then low every time you get an interrupt edge (falling) on the RB2 input pin.
    Does pressing the buttons on the remote result in the RB2 input receiving a falling edge signal?
    #13
    akibsk
    New Member
    • Total Posts : 28
    • Reward points : 0
    • Joined: 2018/10/30 07:07:04
    • Location: 0
    • Status: offline
    Re: Dimmer bouncing whenever any remote button pressed 2018/10/31 10:19:20 (permalink)
    0
    hi Jac sir,
    thx.
    Actually i am not getting it simulate, tried in proteus with ir-link but all try was in vain due to different frequency of transmitter(Remote controller). should i need physical oscilloscope to simulate? or any other option have in software?
     
    thansk
    #14
    jack@kksound
    code tags!
    • Total Posts : 2816
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: online
    Re: Dimmer bouncing whenever any remote button pressed 2018/10/31 10:31:27 (permalink)
    0
    Your ISR code will toggle the RB1 output hi , wait a delay, then low every time you get an interrupt edge (falling) on the RB2 input pin.
    Does pressing the buttons on the remote result in the RB2 input receiving a falling edge signal?

    I was asking if this is how you expect the program and hardware to operate?
    What exactly is connected to the RB2 input? And what does it do?
    #15
    akibsk
    New Member
    • Total Posts : 28
    • Reward points : 0
    • Joined: 2018/10/30 07:07:04
    • Location: 0
    • Status: offline
    Re: Dimmer bouncing whenever any remote button pressed 2018/10/31 11:03:38 (permalink)
    0
    tnx kk sir,
    In details connection are as follows in bearboard mounting::
    RB2>>IR Sensor's signal pin (TSOP1738)
    RB1>>TRIAC through OPTO ISO(MOC3021)
    RB0>>ZERO X ckt(Transformer/Bridge/OPTO 4n35)
    RC2/3/4/5>> all r LED now--all r working properly and no issues found like above so called debounce on any key pressed.
    and all others as required.
    I expect ur reply sir..
    tnx
    #16
    akibsk
    New Member
    • Total Posts : 28
    • Reward points : 0
    • Joined: 2018/10/30 07:07:04
    • Location: 0
    • Status: offline
    Re: Dimmer bouncing whenever any remote button pressed 2018/10/31 11:42:54 (permalink)
    -1 (1)
    KK Sir,
    waiting for your reply.
    #17
    akibsk
    New Member
    • Total Posts : 28
    • Reward points : 0
    • Joined: 2018/10/30 07:07:04
    • Location: 0
    • Status: offline
    Re: Dimmer bouncing whenever any remote button pressed 2018/10/31 11:42:54 (permalink)
    -1 (1)
    KK Sir,
    waiting for your reply.
    #18
    qhb
    Superb Member
    • Total Posts : 7439
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: Dimmer bouncing whenever any remote button pressed 2018/10/31 12:07:59 (permalink)
    +2 (4)
    Be a bit more patient. Others are not available 24 hours to answer your questions.
    Please don't bump a topic unless it has been a day since the last answer.
    #19
    jack@kksound
    code tags!
    • Total Posts : 2816
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: online
    Re: Dimmer bouncing whenever any remote button pressed 2018/10/31 13:48:49 (permalink)
    +1 (1)
    akibsk
    KK Sir,
    waiting for your reply.


    Can you answer the question about the functionality of the ISR in your program? That code toggles the RB1 output in response to the RB2 input, is that what you wanted? That would appear to be the reason for "going OFF and again ON on every pressing of any remote keys".
    #20
    Page: 123 > Showing page 1 of 3
    Jump to:
    © 2018 APG vNext Commercial Version 4.5