PBP projects for R/C models


Results 1 to 40 of 772

Threaded View

  1. #37
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Why is the pulse width jumping all over?

    I had earlier success in getting a servo pulse width to be smooth on a Pic18F2520. But I am now trying to make DT_INTS servo pulse width for a PIC12F683. I have it sweeping from about .95ms to 1.9 ms, but it is not smooth at all. In fact, on the scope, it sometimes switches direction (starts to get wider instead of narrower for a fraction of a second). It is pretty darn ugly in fact.

    Any ideas what I might have done (or not done) to cause this?

    PIC12f683
    Code:
    </i></font><b>DEFINE </b>OSC 8
    <b>INCLUDE </b><font color="#FF0000">&quot;DT_INTS-14.bas&quot; </font><font color="#000080"><i>;interrupt routines
    </i></font><b>INCLUDE </b><font color="#FF0000">&quot;sub16.inc&quot;       </font><font color="#000080"><i>; subtract 16 bit macro
    
    </i></font><b>DEFINE </b>DEBUG_REG	GPIO
    <b>DEFINE </b>DEBUG_BIT	0
    
    <b>DEFINE </b>DEBUGIN_BIT	1
    <b>DEFINE </b>DEBUG_BAUD	38400
    <b>DEFINE </b>DEBUG_MODE	0
    
    INTCON = %10101000 <font color="#000080"><i>'internal oscillator
    </i></font>OSCCON = %01110000 <font color="#000080"><i>'set for 8mhz internal
    </i></font>CMCON0 = 7 <font color="#000080"><i>'TURN COMPARITORS OFF
    </i></font>TRISIO = %010000 <font color="#000080"><i>'Set GSIO 4 INPUT, others to OUTPUT
    </i></font>OPTION_REG = %11000010
    T1CON = %01000001
    T2CON = %01001110
    servo <b>VAR </b>GPIO.2
    servo = 0
    pulse <b>VAR BYTE
    
    </b>pulse = 0
    bittest <b>VAR BIT
    
    ASM
    </b><font color="#008000">INT_LIST  macro    </font><font color="#000080"><i>; IntSource,        Label,  Type, ResetFlag?
            </i></font><font color="#008000">INT_Handler   TMR0_INT,   PulseOut,   ASM,  yes
            INT_Handler   TMR2_INT,   period,     ASM,  yes
            INT_Handler   TMR1_INT,   test,       ASM,  yes
        endm
        INT_CREATE               </font><font color="#000080"><i>; Creates the interrupt processor
    
        </i></font><font color="#008000">INT_ENABLE  TMR0_INT     </font><font color="#000080"><i>; Enable pulseout interrupts  
        </i></font><font color="#008000">INT_ENABLE  TMR2_INT     </font><font color="#000080"><i>; enable period interrupt (20ms)
        </i></font><font color="#008000">INT_ENABLE  TMR1_INT     </font><font color="#000080"><i>; enable interrupt to increment pulse width (test)
    </i></font><b>ENDASM
    
    </b>Main:
        nop
    <b>GOTO </b>Main
    
    <font color="#000080"><i>'---[TMR0_INT - interrupt handler]------------------------------------------
    
    </i></font><b>ASM
    </b><font color="#008000">PulseOut
        btfsc _bittest      </font><font color="#000080"><i>;test status of bittest bit
        </i></font><font color="#008000">goto $+7            </font><font color="#000080"><i>;if high skip 7 lines
        </i></font><font color="#008000">bcf OPTION_REG,5    </font><font color="#000080"><i>;stop timer
        </i></font><font color="#008000">movf _pulse,w       </font><font color="#000080"><i>;load TMR0 with value of pulse variable
        </i></font><font color="#008000">movwf TMR0
        bsf _bittest        </font><font color="#000080"><i>;set bittest bit, indicating we are on second half
        </i></font><font color="#008000">bsf OPTION_REG,5    </font><font color="#000080"><i>;start timer again for second interrupt
        </i></font><font color="#008000">goto $+3            </font><font color="#000080"><i>;skip to return from interrupt
        </i></font><font color="#008000">bcf OPTION_REG,5    </font><font color="#000080"><i>;stop timer
        </i></font><font color="#008000">bcf _servo          </font><font color="#000080"><i>;bring servo pin low for end of pulse width
        </i></font><font color="#008000">INT_RETURN
    
    </font><b>ENDASM
    </b><font color="#000080"><i>'---[TMR2_INT - interrupt handler]------------------------------------------
    </i></font><b>ASM
    </b><font color="#008000">period
        bsf _servo          </font><font color="#000080"><i>;set servo pin high (begin pulse width)
        </i></font><font color="#008000">movlw d'0'          </font><font color="#000080"><i>;set timer0 to 0 (full length of timer)
        </i></font><font color="#008000">movwf TMR0    
        bsf OPTION_REG,5    </font><font color="#000080"><i>;start timer0, now PulseOut interrupt will occur
        </i></font><font color="#008000">bcf _bittest        </font><font color="#000080"><i>;clear bittest bit
        </i></font><font color="#008000">INT_RETURN
    </font><b>ENDASM
    </b><font color="#000080"><i>'---[TMR1_INT - interrupt handler]------------------------------------------
    </i></font><b>ASM
    </b><font color="#008000">test 
        incf _pulse
        INT_RETURN
    </font><b>ENDASM
    
    </b></code></pre><!--EndFragment--></body>
    </html>
    Last edited by ScaleRobotics; - 28th January 2010 at 09:45.

Similar Threads

  1. PBP Book
    By Bruce in forum Off Topic
    Replies: 83
    Last Post: - 4th October 2021, 12:55
  2. PBP Extensions, What are they?
    By PJALM in forum PBP Extensions
    Replies: 9
    Last Post: - 28th September 2021, 11:26
  3. Compiler differences between PBP 2.33 & 2.46
    By nikopolis in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd May 2006, 19:01
  4. Newby- PBP wont compile for 18F (MPLAB)
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th December 2005, 23:30
  5. Making PBP code more modular
    By forgie in forum General
    Replies: 30
    Last Post: - 25th October 2005, 16:24

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