PBP projects for R/C models - Page 2


Closed Thread
Page 2 of 20 FirstFirst 12345612 ... LastLast
Results 41 to 80 of 772
  1. #41
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kenjones1935 View Post
    Scalerobotics,

    How did you know of the contents of:
    http://darreltaylor.com/DT_INTS-14/asm_ints.html
    and
    http://www.picbasic.co.uk/forum/show...39postcount=38

    Is there a centralized resource?
    Ken
    I learned about them from the great folks on this forum. Without it, I couldn't do any of the things I think are pretty slick. Really, everything that I think is pretty amazing, was learned from reading, searching, and asking on this forum. Aside from the 222 page PicBasicPro manual, the forum is the most centralized resource that you will find.

    I would agree with Alain, after reading the PBP manual and it's examples, the next best resource of examples is www.parallax.com site will have the best examples of basic. I have a Pic Basic Pro book that I hate, and I have browsed a few others that I dislike equally. Most are using examples of PIC16C devices and such that are older than my dog, and don't talk much on timers, interrupts, etc. I say save your money, and get the free examples that Parallax has in their documentation, and use this forum. Also read your manual from cover to cover two or three times. It will start to sink in, as you use the commands.

    You can learn more about the DT_INTS by searching the forum. Besides Darrel's page, this is the only other source for information on how to use his interrupts.
    Last edited by ScaleRobotics; - 22nd January 2010 at 18:48.

  2. #42
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Default How does PICkit 2 Logic Tool work?

    As I said, the wheels go round, but...

    The wheels are not going round and round in the pattern I expected. In particular they only go backwards. The code claims to sweep from 20% to 80% cuty cycle.

    SOOO, can I use my USB connection and PICkit 2 Logic and Analyze Tool to see what is actually happening?

    Ken

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


    Did you find this post helpful? Yes | No

    Default

    I believe you are using the PWM example here: http://www.melabs.com/resources/samples/pbp/hardpwm.bas

    This is a PWM that is not supposed to work with RC servo's. It's wave form is different. It is used to dim LED's etc. I am a little surprised that it can turn the wheels at all. I have a scope to help me view wave forms. I have tried for a few minutes to see what the pickit's logic tool can do, but I have not had any success. I am pretty sure it is just a problem with the operator (me).
    Last edited by ScaleRobotics; - 23rd January 2010 at 00:00.

  4. #44
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    This is what the program header says:
    Code:
    ' PicBasic Pro Program to demonstrate hardware PWM.
    ' Output is a 1Khz signal with duty cycle sweeping
    ' from 20% to 80% once per second
    Since the frequency is 1KHz, its period is 1mS. The duty cycle is sweeping from 20% to 80% therefore the pulse width is varying from 0.2mS to 0.8mS. There are 2 problems here. For R/C signals, the period should be 20mS or 50Hz. Second, the pulse width should be 1.5mS for neutral, 1.0mS for extreme left (or full reverse) and 2.0mS for extreme right (or full forward). So your car is responding to a very short pulse (even less than full reverse). You have to modify the values in the program to get it to do what you expect.

  5. #45
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Default Thank you for your analysis

    Thanks gang.

    I came to much the same conclusion myself. I have been trying to figure out what exactly this PWM code does so that I can modify it meet the RC specs. The comments in the program are fairly clear. My first attempts have not worked but I am optimistic.

    Interesting how rusty my brain has become.

    Ken

  6. #46
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Default All Right, I get it!

    Here is the code that makes the wheels spin.

    http://www.melabs.com/resources/samples/pbp/hardpwm.bas

    There are no PBP commands that overtly make pulses. They are created by appropriately loading CCP1CON and CCPR1L. I found CCP1CON easily enough. It is listed in the INDEX of the 16F887 Data Sheet. CCPRxL and CCPRxH are not in INDEX. They are quietly mentioned on page 127. But why is there no HPWM command per page 86 in the PBP manual?


    Although I see how this might be a low cpu overhead way to create PWM, I don't want to learn about this now. I want to use PBP and ASM commands to control my motor and servo. Maybe tomorrow all this will make sense.

    Ken

  7. #47
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Default I need help

    The code in

    http://www.melabs.com/resources/samples/pbp/hardpwm.bas

    makes the wheels of my car go backwards in bursts. The bursts last, maybe 3/4 second then the wheels stop for a 1/4 second. I look at the code . I think that it is supposed to sweep through all pulse sizes in a second. I surmise the short ones are too short so the wheels don't move. As they get longer the come up near the low end of the electronic speed control spec. They start to move. Then the second is over.

    I would like to pump PWM pulses out CCP1 that have a frequency of one every 20 msec (50 per second) and a pulse width that I can (by changing the code) vary from 1 msec to 2 msec. Am I correct in guessing that the frequency of the pulses is dictated by the PAUSE command. One pulse per loop through mainloop:

    So far all my attempts have created no forward wheel motion at all! If one of you has the time please modify hardpwm.bas so that I understand it. Or, better yet, show me how to use PULSOUT. That does not work for me either.

    Ken

  8. #48
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Default Progress

    I've got code that searches for "duty" that runs the motor. I have found the region that drives it backwards and that keeps it motionless. So far i have not found the forward moving pulse size, but it will not be long now.

    Ken

  9. #49
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    A DC motor needs to have the polarity reversed to change the rotation???
    Dave
    Always wear safety glasses while programming.

  10. #50
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Default Yes, that is certainly true, but

    Yes, DC motors need the polarity changed to change direction. I was led to believe that there is something magical in this electronic speed control that made it work differently. Thank you for reminding me to question assumptions.

    Ken

  11. #51
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Default Maybe I need to use my dtdp switches

    If the electronic speed control does not reverse polarity as a function of pulse size, then I will need to use the technique Fritsl used in his wall hugging robot.

    http://letsmakerobots.com/node/928

    (which seems no longer available)

    He cross wired the motor with multiple DPDT relay switches controlled by his PIC. I was going to copy that idea, but then I started believing the story of the magical ESC.

  12. #52
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Hi Ken,
    This may or may not be helpful, I think diagram "A" on page #3 might be to your fancy.
    http://www.picbasic.co.uk/forum/atta...4&d=1228220843
    Dave
    Always wear safety glasses while programming.

  13. #53
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Wink

    I would like to pump PWM pulses out CCP1 that have a frequency of one every 20 msec (50 per second) and a pulse width that I can (by changing the code) vary from 1 msec to 2 msec. Am I correct in guessing that the frequency of the pulses is dictated by the PAUSE command. One pulse per loop through mainloop:
    CCP1 PWM @ 50 Hz ??? ... just read your Datasheet first !!!

    NOW ... triggering the CCP1 module ( in compare mode ) @ 50 Hz ( from a timer ) looks much better ...

    might be the PULSOUT could also do the trick for a CPU " locking time " of 2 ms ... if possible.

    Now, a good program flow allows many, many things for R/C systems without using interrupts or peripherals ...

    Alain
    ************************************************** ***********************
    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 " !!!
    *****************************************

  14. #54
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Default Here's a snip from FATUBA FAQ page.

    FATUBA manufactured the radio receiver in my RC car. It is the output of that box that I am trying to emulate coming out of my 16F887. They say here that reversing direction is done by controlling the PWM pulse size above or below 1.5ms. That is what I have been doing - I thought.

    Attached is a quote from Electronic Control for DC Motors Using Discrete Bridge Circuits. It seems to say that my ESC should accept servo type PWM signals.

    Is the output signal digital?

    Output signals are ANALOG. Receivers vary by design on how they RECEIVE and ENCODE signals. But all deliver very similar output pulse signals, which is used to drive the servo to the desired location. This output pulse ranges from 1000uS to 2000uS, with 1500uS typically being center.
    Is the output signal an on/off signal or does it have an internal regulator?

    The output signal for each channel is a pulsed signal. The pulse width (commonly 1000uS to 2000uS) is determined by the corresponding channel of the transmitter. When activated by one of the proportional channels (such as elevator, aileron, throttle, rudder, or knob control) the pulse width will vary. This controls the servo movement. Most servos will be centered when the pulse is at 1500uS. Channels that are controlled by a switch (such as the gear channel) will operate the pulse width from two set values such as 1100uS when in one position and 1900uS when set to the other position to activate servo movement.
    What signal does the receiver emit to differentiate forward or backward movement?

    Direction of movement is determined by the direction in which the respective pulse is shifted off of center (neutral). Center being 1500uS, if the pulse is shifted above 1500uS, the direction of travel is one direction. If the pulse is shifted below 1500uS, the direction of travel is in the opposite direction.
    Attached Images Attached Images  

  15. #55
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    I gave you that info in post #44.

    Quote Originally Posted by rmteo View Post
    Since the frequency is 1KHz, its period is 1mS. The duty cycle is sweeping from 20% to 80% therefore the pulse width is varying from 0.2mS to 0.8mS. There are 2 problems here. For R/C signals, the period should be 20mS or 50Hz. Second, the pulse width should be 1.5mS for neutral, 1.0mS for extreme left (or full reverse) and 2.0mS for extreme right (or full forward). So your car is responding to a very short pulse (even less than full reverse). You have to modify the values in the program to get it to do what you expect.

  16. #56
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Default Yes, we are all in agreement except..

    Thank you all for your help. I posted those quotes because they back up what you have been saying and what I thought I coded.

    Trouble is my PIC code only makes my car wheels go backwards and stop. I have not been able to create a PWM stream that drives the wheels forward. I know the ESC works because the wheels go fine under radio control.

    Oscilloscope, here I come.

    Ken

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


    Did you find this post helpful? Yes | No

    Default Oscilloscope = Good!

    Quote Originally Posted by Kenjones1935 View Post
    Oscilloscope, here I come.
    Great idea Ken. I don't know how much you have modified hardpwm.bas, but here it is in it's native form. First pic is about 20 percent, and second pic is about 80 percent (of a 1ms pulse):





    You will notice that the min is about 0.2ms and max is 0.8ms.

    Your servo or speed controller requires a pulse width between 1.0ms and 2.0ms. It would probably like to see these pulses every 20ms or so, not every 1 ms (as seen here).

    And here is what you want it to look like (from my rc receiver):
    Attached Images Attached Images    
    Last edited by ScaleRobotics; - 26th January 2010 at 19:18.

  18. #58
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Default Thank you!!

    The pictures you attached match my mental picture of what I have created. First I modified the .bas to make consistant 1.35ms pulses. The PAUSE command creates the spacing in time. This drove the car quite fast backwards with no hesitations. Next 1.5ms. The wheels stopped. From that point I increased (not automatically) the pulse width up past 2ms to no avail. I never got the car wheels to turn forward.

    Where can I find the assembly language code for the Basic commands?

    I gather from reading the manual that PAUSE is not a pure interrupt driven behavior. I can not use that command if it shuts down the PIC between pulses.

    I have two plans.

    1. Study Assembly Language programming. I do not see enough explanation in the PBP manual to feel confident in what Basic Pro is actually doing. I should be able to get the PIC to better communicate to me what it is doing via the LED's.

    2. Attach CCP1 to the servo that steers the car instead of the drive wheels. I know what a servo is and I know this one works.

    3. Make the effort to find an oscilloscope. My only access at this time is the CS department at Fitchburg State College. I would rather not use them. I do not really know them that well.

    Ken

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


    Did you find this post helpful? Yes | No

    Default

    First I modified the .bas to make consistant 1.35ms pulses. The PAUSE command creates the spacing in time.
    The "Pause 17" lets you adjust how fast it moves from 20% and 80%. However, it does not adjust the pulse width, which is what you need to be adjusting. I can't explain why it works at all though, but it might be so confused from receiving pulses every 1ms, instead of every 20ms.

    Where can I find the assembly language code for the Basic commands?
    I suppose MeLabs could have just given us all the assembly code, but that probably does not make good business sense for the company. You can TRY to read some of the assembled code after you compile, but it looks a little jiberish. It is nameofyourfile.lst . Some people have suggested getting a dis-assembler, and disassemble the hex file ... but then I think you loose syntax then.

    I gather from reading the manual that PAUSE is not a pure interrupt driven behavior. I can not use that command if it shuts down the PIC between pulses.
    In my mind, an interrupt is better, as it will not stall your processing. Pauses can work well with servo's. I have not tried them much with motor controllers. The fact that the pulse code you were using sort of worked is encouraging for simplifying code, and staying away from interrupts.

    I have two plans.

    1. Study Assembly Language programming. I do not see enough explanation in the PBP manual to feel confident in what Basic Pro is actually doing. I should be able to get the PIC to better communicate to me what it is doing via the LED's.

    2. Attach CCP1 to the servo that steers the car instead of the drive wheels. I know what a servo is and I know this one works.

    3. Make the effort to find an oscilloscope. My only access at this time is the CS department at Fitchburg State College. I would rather not use them. I do not really know them that well.
    I count three plans ..... here is my personal take on them which might be worth less than two cents...

    Your plan 1 is for someone that really wants to learn all about each register and each bit, and what they control. This will require reading a lot of the 375 page datasheet. Picbasic takes care of a lot of these details for you, making it easier for most people to create useful projects in a much smaller amount of time. Yes, it masks many of these processes from you, but to me, this is a very good thing!

    Plan 2, good idea. I still do not think you are really creating 1.5ms pulses. Why don't you PM me your code, or post it here, and I will PM you back, or post here what I see on my scope using your code.

    Plan 3 See above.

    Why don't you try this code, just don't use the analog. Change pos value to change servo, or motor controller. It will give you an idea if it only does servo's or if your motor controller will like it.

    EDIT:

    Ok this code http://www.melabs.com/resources/samp...bp/servox2.bas
    Last edited by ScaleRobotics; - 27th January 2010 at 05:27.

  20. #60
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Default I think I should take a different tack

    I am realizing that using PAUSE can not work if my PIC is meant to do some thinking between pulses. I just discovered

    http://darreltaylor.com/DT_INTS-14/SPWM.html

    He is using interrupts. That is what I was hoping to do in the first place. I'll see if I can figure out what he is saying.

    Meanwhile, would you be willing to take pictures of the pulses that my code is making if I posted the code?

    Ken

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


    Did you find this post helpful? Yes | No

    Default

    Sure! Post what you have, and I will send you some oscilloscope shots.

  22. #62
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Default This drives the wheels very fast backwards.

    Scalerobotics:

    This snippet has the capabiltiy to increment the pulse size a little bit at a time.

    With this code the car starts out driving very fast backwards, then after five to ten seconds it stops, but never starts up forward.

    My theory is that the (PAUSE 20) is what is causing the 50 pulses per second, Is that correct?


    Code:
    duty	VAR	WORD		' Duty cycle value (CCPR1L:CCP1CON<5:4>)
    range   VAR word
    segment   var word 
    		TRISC.2 = 0				' Set PORTC.2 (CCP1) to output
    		CCP1CON = %00001100		' Set CCP1 to PWM 
    		T2CON = %00000101		' Turn on Timer2, Prescale=4
    
    ' Use formula to determine PR2 value for a 1KHz signal, 
    ' 4MHz clock, and prescale=4. (4E6/(4*4*1E3))-1=249
    '		PR2 = 249				' Set PR2 to get 1KHz out
    '		PR2 = 499				' Set PR2 to get 2KHz out
    	
    ' Use formula to determine CCPR1L:CCP1CON<5:4> value for
    ' ends of range 20% to 80%.  (249+1)*4*0.2=200 (20% value)
    ' (249+1)*4*0.8=800 (80% value)
    '       duty = 200	' Set duty cycle to 20%
    
           range = 25
           duty = 1650	' Set duty cycle to 1.65msec      
           segment = 0
    
    mainloop:	CCP1CON.4 = duty.0		' Store duty to registers as
    		CCP1CON.5 = duty.1		' a 10-bit word
    		CCPR1L = DUTY >> 2
    		Pause 20				' Pause 1/50 of second
           duty = duty + 2    ' Increase duty cycle
    
    
    
    
    		IF (duty < (1650 + segment + range)) Then mainloop	' Do it again unless 2 msec
    
    		duty = duty + 2				' Reset to 20% duty cycle
    
    		segment = segment + range
            
            PAUSE 2000      'Pause 2 seconds				
            
           	GoTo mainloop				' Do it forever

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


    Did you find this post helpful? Yes | No

    Default

    Here is the result. It changes from off through the percentage points to all the way on, but the period remains constant at about 1.023ms. (I finally got my oscilloscope USB driver to work today!)

    Attached Images Attached Images  

  24. #64
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Default PAUSE has no effect it would seem

    Thank you soooo much. What a great tool..

    Two things for me to consider.

    1. PAUSE seems to not have the affect I expected.
    2. The PR2 constant must mean something to PBP, but I can not figure out what.

    Lastly, which version of oscilloscope software do you use? Is it freeware or did it cost money. If so, how much?

    Ken

  25. #65
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Default Success!!!

    The following code makes the car go full speed backwards, then stop, then full speed forwards, then stop etc. Using the RC system I can control the motor continuously though varying speed. I have not yet figured what HPWM parameters produce various speeds to the ESC. It may be that the over-specification fast pulse frequency is overriding that nuance.

    To really discover what this is doing I need to study and understand the ASM code. I think HPWM is interrupt driven. I am concerned because page 87 of the PBP Manual seems to say that the slowest pulse frequency is 245 hz. I want 50 hz.

    Code:
    '****************************************************************
    '*  Name    : HPWMcommand.BAS                                   *
    '*  Author  : Ken Jones                                         *
    '*  Notice  : Copyright (c) 2010 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 1/27/2010                                         *
    '*  Version : 1.0                                               *
    '*  Notes   : PBP has a HPWM command.  Let's try it.                                                  *
    '*          :                                                   *
    '****************************************************************
    ' Don't forget. The duty cycle is 0 to 256 resolution
    MAINLOOP:
      HPWM 1,110,50     ' Neutral discovered by experiment.
      PAUSE 5000
      HPWM 1,64,50      ' Full backwards
      PAUSE 2000
      HPWM 1,110,50
      PAUSE 5000
      HPWM 1,164,50     ' Full forward
      PAUSE 2000
     goto mainloop

    Ken

  26. #66
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kenjones1935 View Post
    ....I am concerned because page 87 of the PBP Manual seems to say that the slowest pulse frequency is 245 hz. I want 50 hz.
    Period = [(PR2) + 1] * 4 * TOSC *(TMR2 Prescale Value)
    Frequency = 1/Period

    Therefore with a 4MHz clock, the lowest frequency is 244Hz.

  27. #67
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Default I a not happy

    I think I am being told that HPWM can not do the job that I need done. Who has a suggestion?

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kenjones1935 View Post
    I think I am being told that HPWM can not do the job that I need done. Who has a suggestion?
    Did you just open the floor to my broken record again?! Here is my view, but I agree, you (we all) need to hear more viewpoints than mine.

    Darrel Taylor Interrupts using TMR0 for pulse width, and TMR2 for 20ms period, and receiver pulse width sensing with CCP1_INT and TMR1. Your chip has them, just need to utilize them.

    If you always have an RC receiver on, then you can use that as your time base for 20ms. So, you could use the CCP1_INT to read the pulse width coming from the receiver. (This will use TMR1). Then you could use TMR0, or TMR2 for the pulse width. Every time you calculated the pulse from your CCP1_INT, you would send out your servo pulse on whatever pin you like, or control multiple pins, using the same timer.

    You really just need to start playing around with these timers and interrupts, and pulse some pins to get your head around it. But without a scope, it will be pretty difficult in my opinion.

    Here some scope info that you asked me about. It is a stand alone, but has a USB port and free software that comes with it. It cost just under $300.00. http://picbasic.co.uk/forum/showthread.php?t=12483
    Last edited by ScaleRobotics; - 27th January 2010 at 22:45.

  29. #69
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    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.

  30. #70
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Default I need documentation

    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

  31. #71
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    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.

  32. #72
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    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.

  33. #73
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    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>&amp; <font color="#0000FF"><b>_WDT_ON </b></font>&amp; <font color="#0000FF"><b>_MCLRE_OFF </b></font>&amp; <font color="#0000FF"><b>_LVP_OFF </b></font>&amp; <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.

  34. #74
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Dave
    Always wear safety glasses while programming.

  35. #75
    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 10:45.

  36. #76
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Wink one idea

    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

    Code:
    bcf OPTION_REG,5    ;stop timer
    Option.5 is the TOCS bit ... and that's not a good thing to switch clock to TockI pin ...

    Alain
    Last edited by Acetronics2; - 28th January 2010 at 13: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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    Thanks Alain, that was it!

    I changed those to:
    Code:
    bsf INTCON,5        ;enable timer0 interrupt
    
    and 
    
    bcf INTCON,5        ;disable timer0 interrupt
    and now the pulse runs smoothly. Only I don't get the initial set timer0 to 0, then add the second half of pulse width. I only get the second half where TMR0=pulse. So pulse width is between 0 and 1ms.

    But I will work on that!

    Thanks again,

    Walter

  38. #78
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Default ds33014K is it!!

    Thank you for setting me straight on which document is which.

    DS33014K is just what I have been looking for.

    Tuesday Darrel Taylor's site said that it was under construction and that it would not accept new membership.

    I have coded in C and in Assembly. More recently in shell and tcl. I never had a reason to use Basic as none of my professional work used a PC.

    I think this 33014 will get me started.

    Scalerobotics, if you get a chance see if you can record the radio receiver output signals for the other channels. In particular one which is just ON-OFF from the point of view of the transmitter.

    Ken - thanks gang.

  39. #79
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Ken,

    ....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.
    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.

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


    Did you find this post helpful? Yes | No

    Default 12f683 servo pass through

    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">&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>'
    </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,&quot; &quot;,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>

Similar Threads

  1. PBP Book
    By Bruce in forum Off Topic
    Replies: 83
    Last Post: - 4th October 2021, 13:55
  2. PBP Extensions, What are they?
    By PJALM in forum PBP Extensions
    Replies: 9
    Last Post: - 28th September 2021, 12: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, 20:01
  4. Newby- PBP wont compile for 18F (MPLAB)
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th December 2005, 00:30
  5. Making PBP code more modular
    By forgie in forum General
    Replies: 30
    Last Post: - 25th October 2005, 17:24

Members who have read this thread : 5

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