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.
x++ becomes x = x + 1

x += y becomes x = x + y

Single
& and
| or

are used in comparisons, like IF-THEN

Double && is logical AND, for bitwise results with numbers.
likewise || for logical OR

! is NOT

== is used in IF-THEN equal comparison, to distinguish it from x = y assignment.
 
x++ becomes x = x + 1

x += y becomes x = x + y

Single
& and
| or

are used in comparisons, like IF-THEN

Double && is logical AND, for bitwise results with numbers.
likewise || for logical OR

! is NOT

== is used in IF-THEN equal comparison, to distinguish it from x = y assignment.
Hi R,
Can you imagine what this looks like to a dyslexic? I can :)

I'll make a chart, but it's 100% that I'll avoid it and stick to BASIC, as most times, i can move slowly forward, where if I use these hieroglyphics I'll hit a wall nd go nowhere. I'm amazed at all of you C coders.
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.
Hi S,
I've just seen this reply!
Yes, you're right, I thought I could go through the CODE line by line, and it would work, but as you say, I don't (and never will) be able to understand it enough to convert it, as my mind doesn't work the same as a good coder. I can usually understand code that will run on the simulator, as I can watch all of the registers, and flags etc.

I don't expect anyone to write code for me, but if anyone does, this would be good. Let us know, so it's not done in duplicate.
Note: the other code that 'I' converted for me works, but jitters sometimes, I wanted to compare this one, to see if it is an improvement.

Thanks to all for your contributions, C
 
I'm amazed at all of you C coders.
To me, C is the easiest language to use! I have been using it for around 40 years though.

This is a fragment of one of my standard libraries, that to me is nice and clear so I don't need to add line comments.
if(*rj_i_treg <= 0) {
*rj_i_treg = 0;
rj_i_freg &= (~rj_i_fmask);
}

if(++rj_i_bit > 7) {
rj_i_freg++;
rj_i_bit = 0;
}

If you really want to get a headache, look at some of the example winners programs on this site - they run a competition for the most confused and unreadable (and possibly artistic) C source program!

eg. When run on a machine with a suitable graphics terminal, this creates and plays a game of Minesweeper!
 
To me, C is the easiest language to use! I have been using it for around 40 years though.

This is a fragment of one of my standard libraries, that to me is nice and clear so I don't need to add line comments.


If you really want to get a headache, look at some of the example winners programs on this site - they run a competition for the most confused and unreadable (and possibly artistic) C source program!

eg. When run on a machine with a suitable graphics terminal, this creates and plays a game of Minesweeper!
Hi S,
And I've been programming in BASIC for 40 years (spectrum) it was a present for my son as a bribe to do better at school, he did do better and got a computer degree, and now works for himself in computers. (I've worn out my questions with him, apart from the odd quick one) I have other skills, as compensation, so it's all fine really.

I don't need to go to your 'winners' site to get a headache, as I have one most of the time.

For me, it seems, there's just one thing more to understand, and I can't tell if I'm forgetting earlier stuff, or does it go on forever?
Cheers, C.
 
Hi,
I just tried an artificial interlligence app with a section of CODE to translate. What do you think?
C
 

Attachments

  • Translation.txt
    1.6 KB · Views: 212
If the pointer stuff works then that translation looks pretty good.

Mike.
Hi M,
EDIT: In the OSH manual POINTER is used like this:
==================================
Any integer variable can be used as a pointer to user RAM memory when it is used as an argument of POINTER function. The value contained in the variable that is used as a pointer should be in the range 0-4095. Here is one example:
Dim x As Word
Dim y As Byte
x = 0x3f
y = Pointer(x)
y = y + 0x55
x = x - 1
Pointer(x) = y
y = 0xaa
x = x - 1
Pointer(x) = y
=========================================
Is the POINT in your program the same?
C
 
Last edited:
If the pointer stuff works then that translation looks pretty good.

Mike.

In addition to the pointer code it gets the following two statements wrong:
Code:
            CCPR1+=FRAME-servoPos[servoCount];
and
Code:
            If(++servoCount>=NUM_SERVOS){
                servoCount=0;
            }
 
In addition to the pointer code it gets the following two statements wrong:
Code:
            CCPR1+=FRAME-servoPos[servoCount];
and
Code:
            If(++servoCount>=NUM_SERVOS){
                servoCount=0;
            }
Hi T,
It's been busy all day, so I haven't been able to finish the resto of the CODE.

I think I can see what those 2x lines are trying to do, and I hope to correct them.
Thanks.
C
 
In addition to the pointer code it gets the following two statements wrong:
Code:
CCPR1+=FRAME-servoPos[servoCount];
Yes, it just needs a little tweek to,
Code:
CCPR1 = CCPR1 + FRAME - servoPos(servoCount)
Weird how it got += right in other parts but wrong in this part.

I also thought that,
Code:
          If(++servoCount>=NUM_SERVOS){
                servoCount=0;
            }
was wrong. However, in the conversion the increment is done in the else part,
Code:
      If servoCount = NUM_SERVOS - 1 Then
        servoCount = 0
      Else
        servoCount = servoCount + 1
      End If

One other thing, MPLABX (spit,spit) has CCPR1 defined as a 16 bit variable (word) and treats it as one. Does Oshonsoft do the same. There are three definitions for CCPRx, CCPRxL, CCPRxH (both 8 bit) and CCPRx (16 bit).

Mike.
 
Hi M,
Here is the whole translated program, including the AI explanations of both sections of CODE.

I'll have to start again in OSH and try to get it to compile, while looking through suggestions and the AI explanation.

(There may be clear errors in this post, ignore for now)

I may be a while ;)
C
 
However, in the conversion the increment is done in the else part,
I get that, but the comparison is wrong... it translates to:

Code:
 servoCount = servoCount + 1
 if (servoCount >= NUM_SERVOS) then
     servoCount = 0
endif
 
If non incremented servo count = 7 (servoCount-1) then it should go to zero else be incremented. That's what both those pieces of code do. The >= was me being lazy.
It could also do,
Code:
servoCount = servoCount + 1
 if (servoCount >= NUM_SERVOS) then
     servoCount = 0
endif

But it's actually less efficient as it always increments servoCount.

For A.I. I think it did pretty well.

Mike.
Edit, servoCount has to go from 0 to 7 which is what it does.
 
Hi,
Here is the full AI (Artificial intelligence) program, combined with MI (mediocre intelligence)

I have looked at how POINTERS work. Is the POINT in this program the same, so it points to updateable addresses where the timings are held?

The program compiles without the commented out line [ Pointer = varptr(rb0pps) ]
NOTE the readings so far.

I haven't added the above comments yet, or given it much thought apart from copying it parrot style.
C
 

Attachments

  • AI 180123 1000.jpg
    AI 180123 1000.jpg
    197.8 KB · Views: 199
I see you've defined varptr as a byte. I (think) it needs to be a word as it will point to anywhere in RAM (SFRs).
I also see you didn't correct the line, CCPR1 = CCPR1 + FRAME - servoPos(servoCount)

Mike.
BTW, can you post stuff (code) as text rather than an image?
 
I see you've defined varptr as a byte. I (think) it needs to be a word as it will point to anywhere in RAM (SFRs).
I also see you didn't correct the line, CCPR1 = CCPR1 + FRAME - servoPos(servoCount)

Mike.
BTW, can you post stuff (code) as text rather than an image?
Hi M,
I changed [ varptr ] to WORD , It still shows the ERROR on #177 image.

I don't know how to correct the [ CCPR1 = frame - servopos(servocount) ] but i'll give it a try.

Is the POINT the same as OSH POINTER, where values are in set array of memory locations?

I usually post the CODE, but in this case I was showing the ERROR and the watched variables.
C
 
Last edited:
The error says it's not defined as an array.
Try,
Code:
dim varptr() as word

Mike.
Edit, that won't work, It'll just be an array of words not a byte pointer. Do you have a link to somewhere that discusses pointers?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top