PWM and MEMORY


Closed Thread
Results 1 to 34 of 34

Thread: PWM and MEMORY

Hybrid View

  1. #1
    Join Date
    Apr 2016
    Location
    Plainfield, Illinois
    Posts
    73


    Did you find this post helpful? Yes | No

    Default Re: PWM and MEMORY

    '12f683

    ' ======= config SETUP =================================

    #CONFIG
    cfg = _INTOSCIO
    cfg&= _WDT_ON
    cfg&= _PWRTE_OFF
    cfg&= _MCLRE_OFF
    cfg&= _CP_OFF
    cfg&= _CPD_OFF
    cfg&= _BOD_ON
    cfg&= _IESO_ON
    cfg&= _FCMEN_ON
    __CONFIG cfg
    #ENDCONFIG

    ' ======= Common Settings =================================

    OSCCON = %01110001 ' Internal 8MHz osc.
    DEFINE OSC 8
    CMCON0 = 7
    ANSEL = 0
    OUTPUT GPIO.1
    INPUT GPIO.4

    PLEDOUT var GPIO.2 ' PWM output
    BUTTEN var GPIO.4 ' BUTTON IN

    HERTZ VAR byte
    DUTY VAR byte

    DUTY = 128
    HERTZ = 50


    MAIN:

    pwm pledout,duty,HERTZ ' PLM output

    IF BUTTEN = 0 THEN
    DUTY = DUTY - 2
    IF DUTY < 10 THEN
    DUTY = 128
    ENDIF
    ENDIF

    GOTO MAIN
    END
    My dad never liked you...

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    967


    Did you find this post helpful? Yes | No

    Default Re: PWM and MEMORY

    Quote Originally Posted by pescador View Post
    '12f683

    ' ======= config SETUP =================================

    #CONFIG
    cfg = _INTOSCIO
    cfg&= _WDT_ON
    cfg&= _PWRTE_OFF
    cfg&= _MCLRE_OFF
    cfg&= _CP_OFF
    cfg&= _CPD_OFF
    cfg&= _BOD_ON
    cfg&= _IESO_ON
    cfg&= _FCMEN_ON
    __CONFIG cfg
    #ENDCONFIG

    ' ======= Common Settings =================================

    OSCCON = %01110001 ' Internal 8MHz osc.
    DEFINE OSC 8
    CMCON0 = 7
    ANSEL = 0
    OUTPUT GPIO.1
    INPUT GPIO.4

    PLEDOUT var GPIO.2 ' PWM output
    BUTTEN var GPIO.4 ' BUTTON IN

    HERTZ VAR byte
    DUTY VAR byte

    ' DUTY = 128 ' this is not needed any longer
    HERTZ = 50



    read EE_Duty, Duty ' read from EEPROM address EE_Duty to Duty variable
    if Duty > 128 then Duty = 128 ' limit the duty to 128 if it is > 128

    MAIN:

    pwm pledout,duty,HERTZ ' PLM output

    IF BUTTEN = 0 THEN
    DUTY = DUTY - 2
    IF DUTY < 10 THEN
    DUTY = 128
    ENDIF

    ' save the new duty to eeprom
    write EE_Duty, Duty
    ENDIF

    GOTO MAIN
    END
    Hope this helps

  3. #3
    Join Date
    Apr 2016
    Location
    Plainfield, Illinois
    Posts
    73


    Did you find this post helpful? Yes | No

    Default Re: PWM and MEMORY

    Jerson - I notice you have code on top of main: - the read and if - is that meant to be in the main? It actually compiled - and I have no endif for the if Duty > 128 statement... I dont understand this...

    plus I created a word var - EE_DUTY...

    update - works great - its what I needed.. I reduced the hertz to make it less choppy.

    What I dont understand is the if without the endif above the main. Hope someone can clarify..

    can I quick pay you?
    Last edited by pescador; - 13th May 2016 at 21:29.
    My dad never liked you...

  4. #4
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    967


    Did you find this post helpful? Yes | No

    Default Re: PWM and MEMORY

    Quote Originally Posted by pescador View Post
    Jerson - I notice you have code on top of main: - the read and if - is that meant to be in the main? It actually compiled - and I have no endif for the if Duty > 128 statement... I dont understand this...

    plus I created a word var - EE_DUTY...

    update - works great - its what I needed.. I reduced the hertz to make it less choppy.

    What I dont understand is the if without the endif above the main. Hope someone can clarify..

    can I quick pay you?
    I did not notice that. I meant to give you a quick hand up from where you were.

    And the code

    Code:
     if duty > 128 then duty = 128
    is supposed to lock down the duty value to max 128. This comes in handy when the chip is newly programmed and the eeprom will read the value of duty as $FF.

    Can you quick pay me - of course not - thank you. That's what we are here for. Lend a helping hand. It's you who learnt something out of it and I was once in your shoes.

  5. #5
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    967


    Did you find this post helpful? Yes | No

    Default Re: PWM and MEMORY

    Quote Originally Posted by pescador View Post
    Jerson - I notice you have code on top of main: - the read and if - is that meant to be in the main? It actually compiled - and I have no endif for the if Duty > 128 statement... I dont understand this...

    plus I created a word var - EE_DUTY...

    update - works great - its what I needed.. I reduced the hertz to make it less choppy.

    What I dont understand is the if without the endif above the main. Hope someone can clarify..

    can I quick pay you?
    I meant to give you a quick hand up from where you were.

    And the code

    Code:
     if duty > 128 then duty = 128
    is supposed to lock down the duty value to max 128. This comes in handy when the chip is newly programmed and the eeprom will read the value of duty as $FF.

    Can you quick pay me - of course not - thank you. That's what we are here for. Lend a helping hand. It's you who learnt something out of it and I was once in your shoes.

Similar Threads

  1. Replies: 1
    Last Post: - 4th March 2013, 21:57
  2. Replies: 11
    Last Post: - 17th August 2010, 16:45
  3. Memory use - how much do you use?
    By keymuu in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 10th June 2009, 22:39
  4. Replies: 4
    Last Post: - 2nd March 2007, 06:12
  5. Use internal program memory like DATA memory
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th December 2006, 18:38

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts