Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] On and off pwm wave at output of pic controller using single button

Status
Not open for further replies.

RONY11

Newbie level 4
Joined
Jun 3, 2016
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
40
On and off pwm wave at output of pic controller using single button

i connected other 2 button for increment and decrement
but when i push off button then pwm must start after push same on/off button
 

On and off pwm wave at output of pic controller using single button

i connected other 2 button for increment and decrement
but when i push off button then pwm must start after push same on/off button


Hi,

Are you using assembly language? Can you share the corresponding code? I believe it is a software problem.

Ogulcan
 

Code:
while(1)
  {
    if(KEY_1==1  && i<1000)
    {
    
        i=i+20;
    
    }
     
    else if(KEY_2==1 && i>0)
    {
        i=i-20;
    
    }    
    
    else if(KEY_3==1)
        
    {
        i=800;
    }
    else if( KEY_4==1 )
    {
        
        while(1)
        {
         j=1;
        i=0;
        PWM1_Duty(i);
        
        }
       
    }
        
       WHEN I PRESS KEY_4  DUTY CYCLE GO TO 0 AND PROGRAMME REMAIN IN THAT WHILE LOOP....TELL ME PLS HOW TO GET OUT FROM THAT SMALL WHILE LOOP WHEN I PRESS SAME KEY_4...........THIS IS FOR ON AND OFF PWM OUTPUT USING SAME KEY_4 
        
        
        
        
        
    PWM1_Duty(i);
    __delay_ms(100);
  
  }
 
Last edited by a moderator:

Hi,

I recommend to generate the PWM with the built in hardware. It generates fixed and clean timing for your PWM without processing power.
So your program just needs to check key status.

This solves your problem doing multiple timing critical tasks at once.

Klaus
 

I recommend to generate the PWM with the built in hardware
I presume the latest code already does with statement pwm1_duty().

First step should be to remove the inappropriate inner while(1) loop. Secondly implement a toggle variable which changes between 1 and 0 on consecutive KEY_4 presses.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top