• AVR Freaks

Hot!How can I make Dimming functions that has two input variables.

Author
parkcoding
Starting Member
  • Total Posts : 87
  • Reward points : 0
  • Joined: 2019/03/13 16:17:10
  • Location: 0
  • Status: offline
2019/08/25 22:45:42 (permalink)
0

How can I make Dimming functions that has two input variables.

Hi..!!
 
These days,
 
I am studying function making using pwm and adc.
 
I want to make one library that has various C functions.
 
I think, dimming in PWM needs two duty_cycle and period.
 
so I make Dimming function.
 
Doesn't it have problem?
 

 
 
 
void Dimming(unsigned int duty_cycle, unsigned int period)
{
    CCPR4L = duty_cycle;
    CCPR4H = 0;
    PR2 = (unsigned char)(period >>2);
}
 
 
 
 
P.S I want to know how to make Dimming function that has two input variables.
      Could you tell me if I need a different input variables than I thought?
post edited by parkcoding - 2019/08/25 22:57:50
#1

11 Replies Related Threads

    ric
    Super Member
    • Total Posts : 23591
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: How can I make Dimming functions that has two input variables. 2019/08/25 22:47:58 (permalink)
    +2 (2)
    Why do you need to change the period?
    Do you understand how PWM works? (Or what it is?)
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    parkcoding
    Starting Member
    • Total Posts : 87
    • Reward points : 0
    • Joined: 2019/03/13 16:17:10
    • Location: 0
    • Status: offline
    Re: How can I make Dimming functions that has two input variables. 2019/08/25 22:57:07 (permalink)
    0
    Mr.ric
     
    I mean, I want to make dimming function with two input variables
     
    that increases a hundred times in a second.
     
    sorry...:)
    #3
    ric
    Super Member
    • Total Posts : 23591
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: How can I make Dimming functions that has two input variables. 2019/08/25 23:03:47 (permalink)
    +1 (1)
    parkcoding
    I mean, I want to make dimming function with two input variables

    This explains nothing.
     

    that increases a hundred times in a second.

    Pardon?
    Do you mean you want to smoothly ramp a signal up changing a PWM value 100 times a second?
    What is the frequency of the PWM itself?
    (I assume you are trying to vary a DC signal, not an AC one.)
    I will ask again, do you understand what PWM is?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #4
    parkcoding
    Starting Member
    • Total Posts : 87
    • Reward points : 0
    • Joined: 2019/03/13 16:17:10
    • Location: 0
    • Status: offline
    Re: How can I make Dimming functions that has two input variables. 2019/08/25 23:27:25 (permalink)
    0
    Yes, I understand 

    To increase gently, as you say.

    I'm about to create dimming function with two input variables.
     
    PWM frequency is 1.22kHz and Fosc is 20MHz
    post edited by parkcoding - 2019/08/25 23:29:47
    #5
    ric
    Super Member
    • Total Posts : 23591
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: How can I make Dimming functions that has two input variables. 2019/08/25 23:30:26 (permalink)
    +2 (2)
    We're going in circles.
    WHAT do you want each of the two "variables" to represent?
    You ignored both my questions in post#4.
    I'm getting sick of wasting my time re-asking questions.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #6
    parkcoding
    Starting Member
    • Total Posts : 87
    • Reward points : 0
    • Joined: 2019/03/13 16:17:10
    • Location: 0
    • Status: offline
    Re: How can I make Dimming functions that has two input variables. 2019/08/25 23:37:52 (permalink)
    0
    I think, I need each of the two variables,
     
    the time at which dimming ends and the number or time of increasing duty 
     
     
    #7
    ric
    Super Member
    • Total Posts : 23591
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: How can I make Dimming functions that has two input variables. 2019/08/25 23:48:15 (permalink)
    +2 (2)
    Still didn't answer post#4
    I can't be bothered asking again.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #8
    parkcoding
    Starting Member
    • Total Posts : 87
    • Reward points : 0
    • Joined: 2019/03/13 16:17:10
    • Location: 0
    • Status: offline
    Re: How can I make Dimming functions that has two input variables. 2019/08/25 23:53:26 (permalink)
    0
    #4?
     
    "I mean, I want to make dimming function with two input variables" 
     
    isn't it?
     
    I said, I need each of the two variables, the time at which dimming ends and the number or time of increasing duty 
    post edited by parkcoding - 2019/08/25 23:55:16
    #9
    ric
    Super Member
    • Total Posts : 23591
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: How can I make Dimming functions that has two input variables. 2019/08/25 23:57:38 (permalink)
    +1 (1)
    Try reading all the way to the end.
    post#4
    Do you mean you want to smoothly ramp a signal up changing a PWM value 100 times a second?
    What is the frequency of the PWM itself?
    (I assume you are trying to vary a DC signal, not an AC one.)
    I will ask again, do you understand what PWM is?


    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #10
    parkcoding
    Starting Member
    • Total Posts : 87
    • Reward points : 0
    • Joined: 2019/03/13 16:17:10
    • Location: 0
    • Status: offline
    Re: How can I make Dimming functions that has two input variables. 2019/08/26 00:10:36 (permalink)
    0
    Do you mean you want to smoothly ramp a signal up changing a PWM value 100 times a second? - Yes I want it.
    What is the frequency of the PWM itself? - I told you, PWM frequency is 1.22kHz and Fosc is 20MHz
    (I assume you are trying to vary a DC signal, not an AC one.)
    I will ask again, do you understand what PWM is? -  I understand
    post edited by parkcoding - 2019/08/26 00:18:18
    #11
    PStechPaul
    Super Member
    • Total Posts : 2378
    • Reward points : 0
    • Joined: 2006/06/27 16:11:32
    • Location: Cockeysville, MD, USA
    • Status: offline
    Re: How can I make Dimming functions that has two input variables. 2019/08/26 23:59:03 (permalink)
    0
    Your posts indicate that you do NOT understand what PWM does, and your stated requirements do not make any sense. I think you might want to perform dimming of an LED over some period of time, and perhaps you want to change the PWM duty cycle 100 times per second (every 10 mSec). With 10 bit PWM, you would have about 1000 discrete duty cycles, so at 100 changes per second it will take about 10 seconds to dim from 100% to 0%. If that is the case, the programming is straightforward. Post an attempt at applicable code and let us know if you have problems. But please make a reasonable attempt and try it using the simulator or real hardware. You won't learn anything if we give you all the answers.

     
    #12
    Jump to:
    © 2019 APG vNext Commercial Version 4.5