PDA

View Full Version : Multi servo interrupt program in Mikro Basic converting to PBP



queenidog
- 21st May 2015, 21:34
I found a neat multi-servo program using interrupts, written in Mikro Basic (I think - looks familiar). I translated as much as I could into PBP, but I cannot get the system to work. I've gone over it many times and ran the ICD in MCS+ trying to troubleshoot it. (Unfortunately ICD doesn't seem to work for interrupts).

I uploaded both programs for "someone" to take a look at to see if there is something obvious I'm doing wrong.

FYI, some things that I did change: 1) I don't have the For-Next loop to add all the servos, I only use one for now. 2) my servo is servo1 at PortA.0. 3) Mikro program used a 16F877 at 20MHz, I am using a 16F887 at 4 MHz so I changed the timer preload and prescaler accordingly. I'm comfortable with timers and interrupts, but i'm certainly no expert.

Any help is appreciated of course.

Original Mikro Basic is Servo8_1000. My PBP attempt is Servo8_100FEMOD

Oh...I have some difficulties with loading the 16bit timer TMR1

richard
- 22nd May 2015, 10:50
the original code cycles through 8 servos 2.5ms at a time to give a refresh rate for each servo of 2.5*8 ms (20ms) , the standard servo refresh rate.
won't your code of 1 servo try to refresh every 2.5 ms ------ the servo won't like that.
also the flakey timing of oninterrupt will probably give you a twitchy servo .
dt ints would be more stable
4mhz won't allow for much resolution for servo commands too, I seem to recall dismal results from similar efforts years ago a twitchy servo is apitb

mark_s
- 22nd May 2015, 17:17
I am experimenting with this version that uses ccp1 and ccp2. It works really well. It can run 8 servos with a 1uS resolution at 8mhz. What I found important is using a separate power supply for the motors and the pic. Once I started loading the motors, the current could spike over 1 amp and this was resetting the pic and or feeding back into the adc. This caused twitchy and erratic movements.

The code in this link will not compile until you add a underscore to the variable in the assembly line. I hope to also port this to PBP

http://www.mikroe.com/forum/viewtopic.php?f=10&t=13607&hilit=+servo