Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Hardware ESC 8xSERVO CONTROL on PIC (Oshonsoft BASIC)

Status
Not open for further replies.
??
I ran the original program/Rjenkinsgb from May 2022 in simulator and 100000us real time takes about 15 seconds.
Hi J,
The same for me, but that one doesn't work 'live'
I haven't had time to analise the difference between the #45 program and the #136 one yet.

Would you be good enough to try the #136 program in your SIM please?
C.
 
#136 works in SIM.
I had the oscilloscope (in SIM) for two first servos and they are ok.
To make it faster you can shorten the
if index> 15 to for example if index > 10
 
#136 works in SIM.
I had the oscilloscope (in SIM) for two first servos and they are ok.
To make it faster you can shorten the
if index> 15 to for example if index > 10
Hi J,
Thanks for that.

That's strange! It works live (with a slight jitter) but the SIM doesn't show signals on the Oscilloscope. The May program, plus other later ones, work in SIM ,but not 'live'

NOTE: The #136 program is the earlier program, added into the main REMOTE SLAVE program, so different CONFIG and other relevant settings, which may be conflicting?

I'm pretty sure it's atiming issue, as the earlier program works on 1MHz and the 'full' program is 32Mhz, which may be too fast?

I'm using V4.12 SIM.
C.
 
Last edited:
Probably it works, but so slowly, that you don't wait long enough.
Have you defined WaitMs 1?
My SIM runs the servo loop / 8 servos in about one second.
To speed up:
From Options menu:
- don't use Basic program tracking.
- don't use oscilloscope, use microcontroller view instead.
 
Probably it works, but so slowly, that you don't wait long enough.
Have you defined WaitMs 1?
My SIM runs the servo loop / 8 servos in about one second.
To speed up:
From Options menu:
- don't use Basic program tracking.
- don't use oscilloscope, use microcontroller view instead.
Hi J,
Yes, that did it!
It's something to do with the Oscilloscope, I got it to work with a change of 'display width', but the Microcontroller view, is fine, thanks.
C
 
Hi,
Here's the program, it works in SIM and 'live'
I use a SEROUT for monitoring, and with it commented out, the SERVOs are steady.

It has more outputs, than I asked for, but I'm sure later this will come in handy, perhaps for cameras etc.

I notice it uses the In circuit programming pins, is this ok?

Thanks to all.
C
 

Attachments

  • 18F4431 32MHz XTL REMOTE_SLAVE 090123 1100.bas
    5.8 KB · Views: 227
Hi,
I'm not sure if I said that the reason I'm using this pic is, that this PCB is used also on the BASE station, and the 4431 reads the Incremental encoder (+ GPS). On this pic it is used for GPS and Motor/servo control. It's not out of the question, that I try another PIC, but that's if we can't get this to work.

In the meantime, We're I'm going to go over all of my posts regarding SERVOs and all of the CODE posted (thanks) and see if the best solution can be chosen.
C
 
Hi,
I've just been trying to convert the program in #89 from M, into OSH BASIC, attached:

I followed 'I's example as a guide, but I'm stuck at the moment, if anyone would like to fill any lines please? I've put my lines under the original lines, and ? under the ones still to do.

EDIT: Updated 160123 1715
C
 

Attachments

  • 18F4431 32MHz XTL REMOTE_SLAVE POMMIE BASIC 160123 1715.txt
    3.4 KB · Views: 234
Last edited:
The code:
Code:
'For(uint8_t i = 0; i < num_servos; i++){
Dim num_servos(8) As Word  '?

Is originally a loop. You have to define num_servos as a byte (as in beginning of code) and set the value to =8, as that is the number of servos you are working with. Also, you have to define "i" as a byte somewhere at the beginning of the code as well.
Then you would have code that look like:
Code:
For i = 0 to num_servos-1 'for 8 servos, 0 to 7
....
rest of code
...
next i

If you want to speed up the SIM, you can try to define:
Define SIMULATION_WAITMS_VALUE = 0
 
The code:
Code:
'For(uint8_t i = 0; i < num_servos; i++){
Dim num_servos(8) As Word  '?

Is originally a loop. You have to define num_servos as a byte (as in beginning of code) and set the value to =8, as that is the number of servos you are working with. Also, you have to define "i" as a byte somewhere at the beginning of the code as well.
Then you would have code that look like:
Code:
For i = 0 to num_servos-1 'for 8 servos, 0 to 7
....
rest of code
...
next i

If you want to speed up the SIM, you can try to define:
Define SIMULATION_WAITMS_VALUE = 0
Hi S,
I've updated #148
Thanks.
C
 
This code:
Code:
'For(uint8_t i = 0; i < num_servos; i++){
Dim num_servos(8) As Byte
is wrong.
num_servos is a byte value, and must be declared beforehand and initialized to a value of 8. It is NOT an array, just a value that declares the number of servos that you are going to process.

When declaring variables, it is best to put them all in one spot at the beginning, so you can see what is declared and what values or types. ie:

Code:
Dim i As Byte
Dim servo_pos(8) As Word
Dim servocount As Byte
Dim num_servos as Byte

' Fill in values for fixed variables
num_servos = 8  ' Declare number of servos to process in this code
.
.
.
etc

Also, you declare "servo_pos", but the code uses "servopos" in the interrupt routine. Pick one or the other.

Then, in the MAIN code, you need another loop to initalize the servo position. Original code starts as:
Code:
'For(uint8_t i = 0; i < num_servos; i++){
Dim num_servos(8) As Byte

'servopos[i] = 1.5 * 8000;
servo_pos(i) = 1.5 * 8000
.
.
.
etc

You need to put in a similar loop, similar to:

Code:
For i = 0 To num_servos - 1
servo_pos(i) = 1.5 * 8000
.
.
.
etc
...
next i
 
Last edited:
This code:
Code:
'For(uint8_t i = 0; i < num_servos; i++){
Dim num_servos(8) As Byte
is wrong.
num_servos is a byte value, and must be declared beforehand and initialized to a value of 8. It is NOT an array, just a value that declares the number of servos that you are going to process.

When declaring variables, it is best to put them all in one spot at the beginning, so you can see what is declared and what values or types. ie:

Code:
Dim i As Byte
Dim servo_pos(8) As Word
Dim servocount As Byte
Dim num_servos as Byte

' Fill in values for fixed variables
num_servos = 8  ' Declare number of servos to process in this code
.
.
.
etc

Also, you declare "servo_pos", but the code uses "servopos" in the interrupt routine. Pick one or the other.

Then, in the MAIN code, you need another loop to initalize the servo position. Original code starts as:
Code:
'For(uint8_t i = 0; i < num_servos; i++){
Dim num_servos(8) As Byte

'servopos[i] = 1.5 * 8000;
servo_pos(i) = 1.5 * 8000
.
.
.
etc

You need to put in a similar loop, similar to:

Code:
For i = 0 To num_servos - 1
[QUOTE]
servo_pos(i) = 1.5 * 8000
[/QUOTE]
.
.
.
etc
...
next i
Hi S,
#148 updated 17.15
Note [ ' ] = commented out, either original example or my 'guess ??'
Thanks.
C
 
Yes, I left (quoted) your original text/code, which you have been commenting out (the previous C code).

It seems you just don't understand what the original code was attempting to do. Without understanding the original logic, odds are against you successfully converting it to other code.

Just read your revised code in #148, all wrong again. You are just cutting/pasting other people's segments of code without thinking about what the code is doing. I'm not going to write the code for you, you have to understand what you are going first. You won't learn how to add or fix the code if you don't understand it in the first place, sorry.
 
Last edited:
Hint:
Think about what is wrong with this part of your code. Remember that an interrupt routine is going to write/set values for the servo positions. Your main loop is all wrong...

Code:
servopos(i) = 1.5 * 8000

TRISB = 0

LATB = 0

INTCON.PEIE = 1  'PEIE/GIEL 1 = Enables all unmasked peripheral interrupts
INTCON.GIE = 1  'GIE/GIEH1 = Enables all unmasked interrupts

WaitUs 1

main_loop:

For i = 0 To num_servos - 1
    servopos(i) = 1.5 * 8000
    TRISB = 0
    LATB = 0
    INTCON.PEIE = 1
    INTCON.GIE = 1
    WaitUs 1
Next i

Goto main_loop
 
Hint:
Think about what is wrong with this part of your code. Remember that an interrupt routine is going to write/set values for the servo positions. Your main loop is all wrong...

Code:
servopos(i) = 1.5 * 8000

TRISB = 0

LATB = 0

INTCON.PEIE = 1  'PEIE/GIEL 1 = Enables all unmasked peripheral interrupts
INTCON.GIE = 1  'GIE/GIEH1 = Enables all unmasked interrupts

WaitUs 1

main_loop:

For i = 0 To num_servos - 1
    servopos(i) = 1.5 * 8000
    TRISB = 0
    LATB = 0
    INTCON.PEIE = 1
    INTCON.GIE = 1
    WaitUs 1
Next i

Goto main_loop
Hi S,
Yes, I sense that it's wrong, but so far I'm only trying to parrot the #89 program, then once it all compiles, run it through the simulator to see what's happening.
So is it getting somewhere near #89?

The main obstacle at the moment is: [ ++, &&, |, += ] and their equivalent in OSH BASIC.

I now realise that it needs 1x times for each servo.
C
 
Last edited:
From my very basic understandiing of C (C++), the "&&" is a logical "AND". "++" means to increment the number after use. Things like "||" is a logical "OR".
Not sure about +=, but here is a site that explains all the standard operators:
 
From my very basic understandiing of C (C++), the "&&" is a logical "AND". "++" means to increment the number after use. Things like "||" is a logical "OR".
Not sure about +=, but here is a site that explains all the standard operators:
Hi S,
I started reading the OPERANDs stuff, it's nuts!!

[ | ] = one thing and [ || } = another thing. How do you programmers remember all this?

I'll wade through it and keep trying, thanks.
C
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top