12F683 PWM output not remembering.


Results 1 to 7 of 7

Threaded View

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

    Default 12F683 PWM output not remembering.

    I have a circuit using a 12F683. It uses a PWM output that controls LED brightness. When the user turns off the circuit and turns it back on - it needs to remain at the same brightness as when was turned off. The problem is it doesn't always save the last setting.

    Can someone look at my code and evaluate? I can provide diagram of circuit - but I tihnk the code is my culprit.

    thanks everyone..



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

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

    'OSCCON = %01110001 ' Internal 8MHz osc.
    'DEFINE OSC 4
    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
    EE_DUTY var word

    HERTZ = 10

    pause 500

    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 ' is button pushed?
    DUTY = DUTY - 1 ' decrement duty cycle by 1
    IF DUTY < 5 THEN DUTY = 115 ' prevents all led power off
    write EE_Duty, Duty ' save the new duty to eeprom
    ENDIF

    write EE_Duty, Duty ' save the new duty to eeprom

    GOTO MAIN
    END
    Last edited by pescador; - 26th April 2018 at 02:22.
    My dad never liked you...

Similar Threads

  1. 12F683 2 x PWM Outputs
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 29
    Last Post: - 23rd July 2021, 21:20
  2. PWM using the 12F683
    By pescador in forum General
    Replies: 6
    Last Post: - 26th April 2016, 02:13
  3. 12F683 Logic Output Problem?
    By shockwave in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 25th February 2012, 20:48
  4. What's the best way to output 30 to 40 kHz from a 12F683 pin?
    By fizyxman in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 1st June 2009, 01:08
  5. 12f683 comparator and pwm
    By Automan in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 23rd May 2007, 19:05

Members who have read this thread : 0

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

Tags for this Thread

Posting Permissions

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