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.
All code will be added to the while 1 loop. If the program has to read the values from an R/C receiver then that can be done with CCP2 in capture mode - what it's designed to do.

Do you have a complete description of what the system is designed to do? I assumed it was some kind of autonomous drone but now an R/C component has been introduced. I also assumed the UART data was from a GPS module, is that correct? You get a complete string from the GPS unit, do some calculation and feed the result to the servos, ish?

Mike.
 
All code will be added to the while 1 loop. If the program has to read the values from an R/C receiver then that can be done with CCP2 in capture mode - what it's designed to do.

Do you have a complete description of what the system is designed to do? I assumed it was some kind of autonomous drone but now an R/C component has been introduced. I also assumed the UART data was from a GPS module, is that correct? You get a complete string from the GPS unit, do some calculation and feed the result to the servos, ish?

Mike.
Hi M,
To explain the whole system, which is complicated also consitantly being developed and changes all of the time, and would take a long email. Would you mind leaving it till later please.

The GPS 'sentence' will be PARSED and used in an RC calculation.

The RC section will be quite large I think.

Here is a link to the AAC thread: https://forum.allaboutcircuits.com/threads/remote-control-by-location-pic-in-oshonsoft.148795/

and the one here: https://www.electro-tech-online.com/threads/remote-control-by-location-part-2.163189/

That will give you something to do :)

C
 
I've got the new file and can look at it,
it has 9 positive pulses of 0.5mS which is correct - 8 for the servos and a ninth for the gap.
logic.png

However, the off time should be the servo time less 0.5mS.
The first one is correct at 500uS giving a total time of 1mS.
The second one is correct at 625uS giving a total time of 1.125mS.
After this they're all wrong, I don't know why.

Can you place a breakpoint just before the while 1 line and confirm that servoPos contains 2000,2250,2500 all the way up to 3750?

Thanks,

Mike.
 
I've got the new file and can look at it,
it has 9 positive pulses of 0.5mS which is correct - 8 for the servos and a ninth for the gap.
View attachment 140472
However, the off time should be the servo time less 0.5mS.
The first one is correct at 500uS giving a total time of 1mS.
The second one is correct at 625uS giving a total time of 1.125mS.
After this they're all wrong, I don't know why.

Can you place a breakpoint just before the while 1 line and confirm that servoPos contains 2000,2250,2500 all the way up to 3750?

Thanks,

Mike.
Hi M,
It only Breaks at 76:75, then keeps running.

I imagine that in the MAIN_LOOP there would be a way for me to change servoPos times, like this:

C main: '\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ servoPos (0) = 1000 'servoPos ON time, this will change once control is added servoPos (1) = 1000 servoPos (2) = 1000 servoPos (3) = 1000 servoPos (4) = 1000 servoPos (5) = 1000 servoPos (6) = 1000 servoPos (7) = 1000 frame = frame - servoPos (0) 'Subtract each servoPos time from Total time frame = frame - servoPos (1) frame = frame - servoPos (2) frame = frame - servoPos (3) frame = frame - servoPos (4) frame = frame - servoPos (5) frame = frame - servoPos (6) frame = frame - servoPos (7) 'For i = 0 To 8 'servopos(i) = i * 1000 + 8000 '1ms(8000) to 1.875(7/8ths - 15000)ms in 1/8th mS steps 'Next i
 

Attachments

  • RC0 ON.jpg
    RC0 ON.jpg
    196.9 KB · Views: 219
  • Wait 1.jpg
    Wait 1.jpg
    199.1 KB · Views: 212
Something is very wrong, servoPos is correct for the first two values and then completely wrong. For example, servoPos(7) should be 7*250+2000 which is 3750 but it's got 2214 in it - how is this possible?

Also, frame should contain 1000 but has 31000 in it which suggests it's executed the code at least once,
frame.png

The (only) good news is the logic output agrees with the values in servoPos.

Mike.
 
frame = frame - servoPos (0) 'Subtract each servoPos time from Total time
This is done automatically by the line,
frame=frame-servoPos(servoCount)
and, The servo time is now a factor of four different so 2000 is 1mS before, 8000 was 1mS. Hence the changed values in the for loop that sets up servoPos.

Note, servoPos(0)=1000 will not work, this is setting servo time to 0.5mS - minimum value is 2000 which is 1mS.
It only Breaks at 76:75, then keeps running.
I don't know what this means.


Mike.
 
Something is very wrong, servoPos is correct for the first two values and then completely wrong. For example, servoPos(7) should be 7*250+2000 which is 3750 but it's got 2214 in it - how is this possible?

Also, frame should contain 1000 but has 31000 in it which suggests it's executed the code at least once,
View attachment 140487
The (only) good news is the logic output agrees with the values in servoPos.

Mike.
Hi M,
I test your CODE in your folder, and copy the CODE into my test folder, so I can play. I'll try a few things to see if I can figure it out, while getting used to the CODE.
C
 
This is done automatically by the line,
frame=frame-servoPos(servoCount)
and, The servo time is now a factor of four different so 2000 is 1mS before, 8000 was 1mS. Hence the changed values in the for loop that sets up servoPos.

Note, servoPos(0)=1000 will not work, this is setting servo time to 0.5mS - minimum value is 2000 which is 1mS.

I don't know what this means.


Mike.
Hi M,
I asked this before, but will there be a LOOP for the RC program? In the LOOP, the will be SPI inputs from the other PIC on the PCB, and CODE to deal with calculations etc, where the SERVOPOS's will be changed.

Re: The 'It only BREAKS at 76:75, then keeps running' line!
I don't know when the BREAK is expected to 'fire' but it only 'fires' once at 76.75 us.

C.
 
Re: The 'It only BREAKS at 76:75, then keeps running' line!
I don't know when the BREAK is expected to 'fire' but it only 'fires' once at 76.75 us.
It should only execute that Break instruction once as it's outside the while loop and frame should equal 1000 but it doesn't!!!! How is this even possible? I'm rapidly loosing faith in Oshonsoft.

I asked this before, but will there be a LOOP for the RC program? In the LOOP, the will be SPI inputs from the other PIC on the PCB, and CODE to deal with calculations etc, where the SERVOPOS's will be changed.
Lots of code can be added as long as it's not blocking code (no pauses etc.).


Mike.
 
But first, this needs to work. Can we try and get the break to work?

Mike.
Hi M,
Yes, let's get the BREAK to work. I was just making sure, so we don't go along a dead end.

Regarding Oshonsoft, from experience, it usually works in the end.
What actually should the BREAK do? Should it BREAk each 20ms?

To clarify: Does the CODE jump in and out of the WHILE/WEND loop?
C
 
Last edited:
What actually should the BREAK do? Should it BREAk each 20ms?
As I said, it's outside the while loop so should only be executed once before any of the while code is executed and therefore frame should contain 1000 as that instruction is directly before the break.

I can't understand HOW the break gets executed after the loop has been executed (indicated by frame containing 31,000).

Mike.
 
camerart, does your compiler really accept binary values starting 0b.
I have older version, which accepts only % at the beginning or b at the end.
 
As I said, it's outside the while loop so should only be executed once before any of the while code is executed and therefore frame should contain 1000 as that instruction is directly before the break.

I can't understand HOW the break gets executed after the loop has been executed (indicated by frame containing 31,000).

Mike.
Hi M,
Ok. I can run it in the sim, and try to see what happens. It's a bit time consuming, and needs careful speed control. Leave it with me for a while.

I'm a bit puzzled why you set SERVOPOS with a calculation, when it will be set by other inputs. The #486 shows my fixed settings for testing, don't you think this would be better?

C.
 
Can we at least get the indenting right? I was trying to read the code and completely missed the line
If CCP1CON = 0x08 Then
Due to there being no indenting.
The code I posted had all the indenting correct.

camerart, does your compiler really accept binary values starting 0b.
I have older version, which accepts only % at the beginning or b at the end.
Wouldn't this cause an error? And if not, why not?

Mike.
 
camerart, does your compiler really accept binary values starting 0b.
I have older version, which accepts only % at the beginning or b at the end.
Hi J,
I c#accepted 0b as i try not to change someone's CODE, but I know I use %, so I'll try changing it in my test folder. 0b compiles, but I suspect some things squeeze by in OSH.

Would you mind running the latest CODE, in your sim, you may be faster than me?

Thanks. C
 
Hi M,
Ok. I can run it in the sim, and try to see what happens. It's a bit time consuming, and needs careful speed control. Leave it with me for a while.

I'm a bit puzzled why you set SERVOPOS with a calculation, when it will be set by other inputs. The #486 shows my fixed settings for testing, don't you think this would be better?

C.
Have you read my replies? As I stated, 1000 WILL NOT WORK. As explained above.
Note, servoPos(0)=1000 will not work, this is setting servo time to 0.5mS - minimum value is 2000 which is 1mS.

The only place servoPos is written is in the for loop and should contain values between 2000 and 3750. How can other values be in there?

Mike.
 
Can we at least get the indenting right? I was trying to read the code and completely missed the line
If CCP1CON = 0x08 Then
Due to there being no indenting.
The code I posted had all the indenting correct.


Wouldn't this cause an error? And if not, why not?

Mike.
Hi M,
The way you post the CODE looses the indent, I think it has to be in a text file and attached, perhaps you could look at one of text CODEs and see if it's indented.

I would have thought 0b would cause an error, but it may have slipped by. This is the kind of thing, I try, when I'm testing. Previously, I have done this kind of test, but I think sometimes they get lost in the many exchanges.
C
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top