Hey guys, will this work?


Results 1 to 27 of 27

Threaded View

  1. #14
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Refresh your duty cycle only when it need to, unless you'll have problem.

    try something like
    Code:
    START:
            ADCIN 6, CSET 'READ VALUE OF CURRENT SET POT
            ADCIN 4, CSEN   'READ VALUE OF CURRENT SENCE
            IF CSEN > CSET Then LET DUTY = DUTY - 1
            IF CSEN < CSET THEN LET DUTY = DUTY + 1
            if DUTY != OldDuty then
                OldDuty = Duty
                GOSUB NewDuty 
                ENDIF               
            GOTO Start
    
    NewDuty:
            TMR2IF = 0
            while !TMR2IF : wend       ; let current cycle complete
            CCP1CON = 0  
            CCPR1L = Duty >>2   
            CCP1CON.5 = Duty.1
            CCP1CON.4 = Duty.0
            RETURN
    You'll probably need to allow an error margin in your IF-THEN, remember you have a 7 bits or so PWM resolution but 10Bit ADC results. Reduce your ADC resolution to 8 bit may help.

    You also want to make sure you don't overflow the Duty value...

    Seeing your schematic would be nice.
    Last edited by mister_e; - 12th May 2009 at 18:31.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. PortA Doesn't Work
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 11
    Last Post: - 8th September 2015, 18:41
  2. pls help me verify my code not work, why???
    By chai98a in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th January 2010, 09:19
  3. Can't get POT work on P12f675 - Newbie
    By berslan in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 26th March 2008, 21:22
  4. How to set ICD-2 clone to work with PBP?
    By G-R-C in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 20th October 2006, 02:50
  5. Pin RA4 doesn't work
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 0
    Last Post: - 15th July 2004, 12:03

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