Ken,
Can you do a LED blinky without using PAUSE (or any other delay commands)? Try to do a 1 second blinky using a timer. When you can do that, you will be well on your way to solving your motor ESC problem.
Ken,
Can you do a LED blinky without using PAUSE (or any other delay commands)? Try to do a 1 second blinky using a timer. When you can do that, you will be well on your way to solving your motor ESC problem.
Guys and maybe Gals,
I am getting frustrated. I can not find the documentation that I need. I need Assembler Language details for the 16-bit chips. I need 16-bit BASIC libraries (Microchip talks C, not Basic). Darrel Taylor is rebuilding his site. He is not accepting new members.
Microchip has screwed up on this link:
MPLAB Assembler, Linker and Utilities for 16-Bit Devices User's Guide
which points to-->
http://ww1.microchip.com/downloads/e...Doc/51317G.pdf
But when you download51317G you discover it is about the 24-BIt devices. It is the same document that -->
DS51317 - MPLAB Assembler, Linker and Utilities for PIC24 MCUs and dsPIC DSCs User's Guide
points to.
What is the number for the 16-Bit devices user's guide?? I have not found a complete list of Assembly language code, syntax, structure whatever! Without that I do not see how I can understand what this 16F887 is doing.
Also it is late. I am going to bed.
Ken
Ken,
Darrel's site must have been down for what evere reason. It seems to work now.
http://www.PBPgroup.com/
ASM instuctions are normally in the devices data sheet. But... Please do not take this the wrong way. If you are having trouble with Basic I doubt it ASM will do much good.
I like remto's sugesstion about blinky. Give that a shot.
Dave
Always wear safety glasses while programming.
Ken, I highly recommend taking Dave's advise. You need a better understanding of what makes a PIC tick (hint, read the free book I linked to). When you have that under your belt, then the coding is the really easy part. It doesn't matter whether you use C, BASIC (PBP or some other variant) or ASM - the situation is the same.
Here is some code that will measure an RC receiver pulse width coming in on GPIO.2, perform a little math on the value, and put out the wave form out on GPIO.1, using DT Interrupts.
It's on a little 12F683 and was written for 8mhz internal. Looks pretty good on the scope. I need to test it on a motor controller though. But time for bed.....
Code:<html> <head></head> <body><!--StartFragment--><pre><code><font color="#000080"><i> </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>' </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>ANSEL = %00000000 <font color="#000080"><i>'Set A/D OFF </i></font>ADCON0 = %00000000 <font color="#000080"><i>'Analog converter OFF </i></font>TRISIO = %010100 <font color="#000080"><i>'Set GSIO 4 and 2 to INPUT, others to OUTPUT </i></font>OPTION_REG = %11000010 T1CON = %00110001 T2CON = %01001110 CCP1CON = %00000101 risetime <b>VAR WORD </b><font color="#000080"><i>;used for pulse width measure start of pw </i></font>falltime <b>VAR WORD </b><font color="#000080"><i>;time at end of pulse width </i></font>falltime_l <b>VAR </b>falltime.Byte0 falltime_h <b>VAR </b>falltime.Byte1 risetime_l <b>VAR </b>risetime.Byte0 risetime_h <b>VAR </b>risetime.Byte1 pulsewidth <b>VAR WORD </b>pulsewidth_l <b>VAR </b>pulsewidth.Byte0 pulsewidth_h <b>VAR </b>pulsewidth.Byte1 ServoOut <b>VAR </b>GPIO.1 ServoOut = 0 pulse <b>VAR BYTE </b>TMR0 = 0 pulse = 255 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 CCP1_INT, PWMeasure, 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 CCP1_INT </font><font color="#000080"><i>; enable interrupt to increment pulse width (test) </i></font><b>ENDASM PAUSE </b>200 Main: <b>PAUSE </b>20 <font color="#000080"><i>;debug dec pulsewidth," ",10,13 </i></font>pulse = ((pulsewidth * 8)/10)-167 <font color="#000080"><i>;scale to fit into a byte </i></font>pulse = 255 - pulse <font color="#000080"><i>;reverse the stick </i></font><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 INTCON,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 INTCON,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 INTCON,5 </font><font color="#000080"><i>;stop timer </i></font><font color="#008000">bcf _ServoOut </font><font color="#000080"><i>;bring ServoOut 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 movlw d'72' </font><font color="#000080"><i>;fine tune timer2 period </i></font><font color="#008000">movwf TMR2 bcf INTCON,2 </font><font color="#000080"><i>;clear timer flag if set </i></font><font color="#008000">movlw d'17' </font><font color="#000080"><i>;set timer0 first 1ms time base </i></font><font color="#008000">movwf TMR0 bsf INTCON,5 </font><font color="#000080"><i>;enable timer0 interrupt </i></font><font color="#008000">bsf _ServoOut </font><font color="#000080"><i>;set ServoOut pin high (begin pulse width) </i></font><font color="#008000">bcf _bittest INT_RETURN </font><b>ENDASM </b><font color="#000080"><i>'---[CCP1_INT - interrupt handler]------------------------------------------ </i></font><b>ASM </b><font color="#008000">PWMeasure BTFSS CCP1CON, CCP1M0 </font><font color="#000080"><i>; Check for falling edge watch </i></font><font color="#008000">GOTO FALL_EDGE </font><font color="#000080"><i>; Go pick up the falling edge </i></font><font color="#008000">MOVF CCPR1L,W </font><font color="#000080"><i>; else store leading edge value </i></font><font color="#008000">MOVWF _risetime_l </font><font color="#000080"><i>; into 16 bit word risetime </i></font><font color="#008000">MOVF CCPR1H,W MOVWF _risetime_h BCF CCP1CON, CCP1M0 </font><font color="#000080"><i>; Now capture the trailing edge </i></font><font color="#008000">GOTO ISR_2 </font><font color="#000080"><i>; Exit the interrupt service routine </i></font><font color="#008000">FALL_EDGE: BSF CCP1CON, CCP1M0 </font><font color="#000080"><i>; Re-set for trailing edge capture </i></font><font color="#008000">MOVF CCPR1L,W </font><font color="#000080"><i>; Store the captured value into </i></font><font color="#008000">MOVWF _falltime_l </font><font color="#000080"><i>; falltime_l and ... </i></font><font color="#008000">MOVF CCPR1H,W MOVWF _falltime_h </font><font color="#000080"><i>; ... falltime_h ; ; 16 bit subtract ; falltime = falltime - risetime ; </i></font><font color="#008000">SUB16 _falltime, _risetime </font><font color="#000080"><i>;do 16 bit subtraction to find width </i></font><font color="#008000">movf _falltime_l,w movwf _pulsewidth_l movf _falltime_h,w movwf _pulsewidth_h ISR_2 INT_RETURN </font><b>ENDASM </b></code></pre><!--EndFragment--></body> </html>
At last I am getting the correct reference materials.
DS33014K is telling me about MPASM Assembler, Library and Linker.
I have ordered from Belgrade "PIC Microcontrollers". It is being shipped by air. That alone is pretty amazing. Just a little paperback book.
I have also found an online book at:
http://www.mikroe.com/en/books/picmcubook/ch0/
It may be the same book only on line. I am old fashioned. I like to read from paper.
I have plenty of studying to do. Thank you again and again.
Ken
I copied your code snip from POST #73 at 3:02 on the 28th of January.
I noticed in the .asm code that it wanted to:
INCLUDE "MACKRA~1.MAC"
There is no such file in my computer. Do I need a copy? May I have one?
Also the compiler complained that:
Error 118: "Overwriting previous address contents (2007)
Page 157 of DS33014K says that Error 118 occurred because "Code was previously generated for this address" I assume it is talking about address (2007). I do not see where in the .asm code this is happening. I do not even know what to look for.
Ken
Mackrackit,
From what I understand your code will do a PWM every time TMR0 overflows.
What I need to do is make this overflow happen every 20ms. That is 50 pulses per second. We have a 4 meg oscillator. If I were designing this counter I think I would have it set to 20,000 each time it overflows. I gather from page 74 of the Data Sheet that this is not possible. The biggest prescaler is 256.
How about a routine that counts these interrupts until 1/50 of a second has elapsed then calls PWM? I would have it send one pulse out pin 1 with the duty as defined by "duty". It would look like
PWM 1,duty,1
I have found a section on Timers in a book called Running Small Motors with PIC Microcontrollers that has an example of MicroEngineering Labs code that makes an eight digit LCD display the time in hours, minutes and seconds. I think this code must do something like I need.
Ken
Looks like you have the code named MACKRACKIT?
The *.MAC file is the macro file generated by PBP. It will be in your project directory. The name is chopped to the 8.1? standards.
Looks like you are setting the configs in the *.inc file. I have them in the code. Just comment that line out and it should be OK.Also the compiler complained that:
Error 118: "Overwriting previous address contents (2007)
Page 157 of DS33014K says that Error 118 occurred because "Code was previously generated for this address" I assume it is talking about address (2007). I do not see where in the .asm code this is happening. I do not even know what to look for.
Ken
Dave
Always wear safety glasses while programming.
Firstly, your PIC16F887 is a 14-bit core device and the ASM manual is here MPASM™ Assembler, MPLINK™ Object
Linker MPLIB™ Object Librarian User’s Guide
Next thing you really need to download is the data sheet PIC16F887
Also, download this FREE book and read it to understand how a PIC works PIC Microcontrollers
The last one is the most useful - I pointed this out to you in an earlier post.
Ken,
I do not know anything about RC stuff, but here is something to play with.
Code:<font color="#000080"><i>'16F887 INT RUPT '44 PIN DEMO BOARD </i></font>@ <font color="#0000FF"><b>__config _CONFIG1</b></font>, <font color="#0000FF"><b>_INTRC_OSC_NOCLKOUT </b></font>& <font color="#0000FF"><b>_WDT_ON </b></font>& <font color="#0000FF"><b>_MCLRE_OFF </b></font>& <font color="#0000FF"><b>_LVP_OFF </b></font>& <font color="#0000FF"><b>_CP_OFF INTCON</b></font>.<font color="#800000"><b>5 </b></font>= <font color="#800000"><b>1 </b></font><font color="#000080"><i>'ENABLE TMR0 DATA SHEET SECTION 14.3.2 </i></font><font color="#0000FF"><b>OSCCON </b></font>= <font color="#800000"><b>%01110000 </b></font><font color="#000080"><i>'8 Mhz </i></font><font color="#0000FF"><b>OPTION_REG </b></font>= <font color="#800000"><b>%10000111 </b></font><font color="#000080"><i>' 1:256 PRESCALE </i></font><font color="#FF0000"><b>ON INTERRUPT GOTO </b></font><font color="#0000FF"><b>TLOOP CNT </b></font><font color="#FF0000"><b>VAR BYTE </b></font><font color="#0000FF"><b>D </b></font><font color="#FF0000"><b>VAR BYTE </b></font><font color="#0000FF"><b>D </b></font>= <font color="#800000"><b>0 </b></font><font color="#0000FF"><b>START</b></font>: <font color="#FF0000"><b>FOR </b></font><font color="#0000FF"><b>CNT </b></font>= <font color="#800000"><b>0 </b></font><font color="#FF0000"><b>TO </b></font><font color="#800000"><b>150 </b></font><font color="#FF0000"><b>PWM </b></font><font color="#0000FF"><b>PORTD</b></font>.<font color="#800000"><b>7</b></font>,<font color="#0000FF"><b>D</b></font>,<font color="#800000"><b>100 </b></font><font color="#0000FF"><b>D </b></font>= <font color="#0000FF"><b>D </b></font>+ <font color="#800000"><b>2 </b></font><font color="#FF0000"><b>NEXT </b></font><font color="#0000FF"><b>CNT </b></font><font color="#FF0000"><b>GOTO </b></font><font color="#0000FF"><b>START </b></font><font color="#FF0000"><b>DISABLE </b></font><font color="#0000FF"><b>TLOOP</b></font>: <font color="#0000FF"><b>INTCON</b></font>.<font color="#800000"><b>2</b></font>=<font color="#800000"><b>0 </b></font><font color="#000080"><i>' DATA SHEET SECTION 14.3.2 </i></font><font color="#FF0000"><b>TOGGLE </b></font><font color="#0000FF"><b>PORTD</b></font>.<font color="#800000"><b>4 </b></font><font color="#FF0000"><b>RESUME ENABLE </b></font>
Dave
Always wear safety glasses while programming.
http://www.picbasic.co.uk/forum/showthread.php?t=222
Might also help??
Dave
Always wear safety glasses while programming.
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>
Last edited by ScaleRobotics; - 28th January 2010 at 09:45.
Hi,
I remember some batches of 12F683 did not like the duty value to be changed " on the fly " and needed to stop and restart the CCP module.
Was written on the µChip datasheet ( prior to D release )...
I think some lines about it exist on this forum.
But you don't use the CCP module ...
What I see more is you want to stop Timer0
Option.5 is the TOCS bit ... and that's not a good thing to switch clock to TockI pin ...Code:bcf OPTION_REG,5 ;stop timer
Alain
Last edited by Acetronics2; - 28th January 2010 at 12:45.
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
Bookmarks