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">"DT_INTS-14.bas" </font><font color="#000080"><i>;interrupt routines
</i></font><b>INCLUDE </b><font color="#FF0000">"sub16.inc" </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>
Bookmarks