Having noise in clock generated using TMR0 Interrupt :MCU::PIC16F73

Status
Not open for further replies.

Mithun_K_Das

Advanced Member level 3
Joined
Apr 24, 2010
Messages
899
Helped
24
Reputation
48
Reaction score
26
Trophy points
1,318
Location
Dhaka, Bangladesh, Bangladesh
Visit site
Activity points
8,254
Having noise in clock generated using TMR0 Interrupt :MCU:IC16F73.
What may be the reason of this noise?
Code:
void interrupt()
{
    
      os_cnt++;
      while(os_cnt<=5+feedback)
      {
        RC6_bit = 0;
        RC7_bit = 0;
        break;
      }
      while(os_cnt>=5+feedback && os_cnt<=85-feedback)
      {
        RC6_bit = 1;
        RC7_bit = 0;
        break;
      }
      while(os_cnt>=85-feedback && os_cnt<=90+feedback)
      {
        RC6_bit = 0;
        RC7_bit = 0;
        break;
      }
      while(os_cnt>=90+feedback && os_cnt<=160-feedback)
      {
        RC6_bit = 0;
        RC7_bit = 1;
        break;
      }
      while(os_cnt>=160-feedback)
      {
       RC6_bit = 0;
       RC7_bit = 0;
       break;
      }
      while(os_cnt==161)
      {
       os_cnt=0;
       break;
      }
      TMR0 = 200;                // Timer TMR0 is returned its initial value
    INTCON = 0x20;            // Bit T0IE is set, bit T0IF is cleared
 }




////////////////////
///////////////////
void main()
{
..................
............
while(1)
{


ADCON0=0b00000001;
          adc_rd0 = ADC_Read(0);
          avg_pwm = adc_rd0;
          while(avg_pwm>80)
          {
           if(feedback<50)
           {
            feedback++;
            //Delay_ms(20);
           }
           else
           {
            feedback = feedback;
           }
           break;
          }
           while(avg_pwm<=80)
          {
           if(feedback>1)
           {
            feedback--;
            //Delay_ms(20);
           }
           else
           {
            feedback = feedback;
           }
           break;
          }
          

}
}


This is the main program for the oscillation.
 

Use decoupling Capacitors with Power Supply, How ever it would be more clear if you post your Schematic...
 

What kind of noise do you mean?

If the problem is that the timing seems to 'jitter' (not be as regular as it should be) the problem is that you reload the timer only after a series of decisions have been made in the program. For example, if the first 'while' was true it would reload the timer almost straight away. If none of the 'while' statements were true it would have to do all the previous tests before reloading it. It would be better to put TMR0 = 200 at the top of the routine so the timer was reset consistently.

Setting the value of INTCON inside the interrupt routine is also unadvisable. It would be better to simply reset the T0IF bit, the enable bit (T0IE) shouldn't be changed by the interrupt being called.

Brian.
 

The main work of the program is to generate a reliable oscillation. The system also have a feedback system. here I've done the feedback with 'feedback' variable. The main problem right now is the value of the duty cycle is not stable. its varying within 0-10% which is to much. This is why the system output voltage is changing frequently.

The duty should be changed smoothly and shouldn't change in so range.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…