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 those edits are after reading the manual and should work.

Mike.
Hi M,
Is it ok to use the 'what works' DIM FRAME and CYCLE H and L BYTES, till later, when we can have another look at CONST? It's using up too much effort!

EDIT: Computer back on! Just remebered you split the 2000 into 2x BYTEs, I'll check tomorrow. 'night.

C.
 
Last edited:
Can you run the above C code through your A.I. program and post the results as well as any errors generated by trying to compile.

Mike.
 
There's lots of things in there that are not in my C code and lots that is in my C code that's not in your code. I have no idea where that code came from.

Can you simply run the above C code (in #339) through your A.I. program and post the results as well as any errors generated by trying to compile. Don't modify it in any way.

Mike.
Edit, just add the defines at the top. I.E.
Define CONFIG1L = 0x00
Define CONFIG1H = 0x06 '8mHz XTL x4 =32mHz
Define CONFIG2L = 0x0c
Define CONFIG2H = 0x20
Define CONFIG3L = 0x04
Define CONFIG3H = 0x80
Define CONFIG4L = 0x80 'Set for HVP
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40

Define CLOCK_FREQUENCY = 32
Define SINGLE_DECIMAL_PLACES = 2
Define STRING_MAX_LENGTH = 20

Define SIMULATION_WAITMS_VALUE = 1 'Comment in for SIM out for PIC
 
There's lots of things in there that are not in my C code and lots that is in my C code that's not in your code. I have no idea where that code came from.

Can you simply run the above C code (in #339) through your A.I. program and post the results as well as any errors generated by trying to compile. Don't modify it in any way.

Mike.
Edit, just add the defines at the top. I.E.
Define CONFIG1L = 0x00
Define CONFIG1H = 0x06 '8mHz XTL x4 =32mHz
Define CONFIG2L = 0x0c
Define CONFIG2H = 0x20
Define CONFIG3L = 0x04
Define CONFIG3H = 0x80
Define CONFIG4L = 0x80 'Set for HVP
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40

Define CLOCK_FREQUENCY = 32
Define SINGLE_DECIMAL_PLACES = 2
Define STRING_MAX_LENGTH = 20

Define SIMULATION_WAITMS_VALUE = 1 'Comment in for SIM out for PIC
Hi M,
This way will take a long time, as most lines aren't accepted. I can see some of the 'wrong' lines would be easy for me to change to OSH format. e,g,
Define CONFIG1H = & h06 '8mHz XTL x4 =32mHz
Would be
Define CONFIG1H = 0x06 '8mHz XTL x4 =32mHz

If it's not too daunting, I think it's best to correct the #345 one.

EDIT: Here's the #339 program, with a fewl changes (I've done only the top obvious ones) commented by £ or commented out
C
 

Attachments

  • 18F4431 32MHz XTL REMOTE_SLAVE 164 310123 0930.bas
    4.1 KB · Views: 205
Last edited:
Hi M,
In the #345 after AI program, I can see:
e,g,
If CCP1IE And CCP1IF Then
Should be
If PIE1.CCP1IE = 1 And PIR1.CCP1IF = 1 Then
--------------------------------
CHR should be CHAR
-----------------------------------
If OERR Or FERR Then
should be:
If RCSTA.OERR Or RCSTA.FERR Then
-----------------------------------
TRISC = & b11111100
Should be
TRISC = %11111000
----------------------------------
PEIE Should have it's PREFIX.PEIE
----------------------------------------
This and more has been done in #347
C
 
Hi M,
In the #345 after AI program, I can see:
e,g,
If CCP1IE And CCP1IF Then
Should be
If PIE1.CCP1IE = 1 And PIR1.CCP1IF = 1 Then
--------------------------------
CHR should be CHAR
-----------------------------------
If OERR Or FERR Then
should be:
If RCSTA.OERR Or RCSTA.FERR Then
-----------------------------------
TRISC = & b11111100
Should be
TRISC = %11111000
----------------------------------
PEIE Should have it's PREFIX.PEIE
----------------------------------------
This and more has been done in #347
C
Doesn't the A.I. program deal with this?
Just post the A.I. code.

It's a pretty crappy A.I program if it doesn't know,
TRISC = & b11111100
Should be
TRISC = %11111000

Why should CHR be CHAR? Is CHR a reserved word?

Where do the lines,
Define CONFIG1H = & h06 '8mHz XTL x4 =32mHz
come from. They're not in my code!!!!

Can you just do what I ask?

Mike.
Edit, does the A.I. program get rid of all indenting?
 
Doesn't the A.I. program deal with this?
Just post the A.I. code.

It's a pretty crappy A.I program if it doesn't know,
TRISC = & b11111100
Should be
TRISC = %11111000

Why should CHR be CHAR? Is CHR a reserved word?

Where do the lines,
Define CONFIG1H = & h06 '8mHz XTL x4 =32mHz
come from. They're not in my code!!!!

Can you just do what I ask?

Mike.
Hi M,
The AI is a child, so as crappy as a child programmer, (or me for that matter) Once it's grown up we'll have to pay for it.

CHR is a RESERVED word, as commented in #345

Define CONFIG1H =
Is from my programs, and is e,g, where PLL is set.

Yes, here's the CODE from AI.
NOTE: The AI is trying to write BASIC, and I sometimes get SPECTRUM BASIC, or other BASICs, and if that happens I have another go, until it looks likely.

If you want ot leave it with me I can check every line, until it works, but the way we're doing it is probably the best way, with [patience. Sorry, I don't read 'C'
C
 

Attachments

  • 339 AI.txt
    4 KB · Views: 208
IF, you put the defines at the top does it then compile?
I.E.
Code:
Define CONFIG1L = 0x00
Define CONFIG1H = 0x06 '8mHz XTL x4 =32mHz
Define CONFIG2L = 0x0c
Define CONFIG2H = 0x20
Define CONFIG3L = 0x04
Define CONFIG3H = 0x80
Define CONFIG4L = 0x80 'Set for HVP
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40

Define CLOCK_FREQUENCY = 32
Define SINGLE_DECIMAL_PLACES = 2
Define STRING_MAX_LENGTH = 20

Define SIMULATION_WAITMS_VALUE = 1 'Comment in for SIM out for PIC

Const NUM_SERVOS = 10
Const BUFFER = 80

Dim Buff(BUFFER) As Byte
Dim StrCount As Byte
Dim Done As Byte
Dim WordTemp As Integer
Dim Ms As Long
Dim Count As Byte
Dim ServoCount As Byte
Dim I As Byte
Dim ServoPos(NUM_SERVOS) As Integer

Sub Main()
    OSCCON = &H70     '8MHz
    PLLEN = 1         'x4=32MHz
    'setup 1mS interrupt = 8,000,000/16 = 500,000/10 = 50,000 set PR2=49 = 50,000/50 = 1000 = 1mS
    T2CON = &H4E      'pre=16 post=10
    PR2 = 49
    TMR2IE = 1        'timer 2 interrupts enable
    T1CON = 0         'timer 1 stopped
    For I = 0 To NUM_SERVOS - 1
        ServoPos(I) = I * 1000 + 8000 '1ms(8000) to 1.875(7/8ths - 15000)ms in 1/8th mS steps
    Next
    TRISC = &HFC           'CCP0 & 1 output
    PEIE = 1
    GIE = 1
    Do
        'adjust servo positions here
    Loop
End Sub

Sub Inter()
    If TMR2IE And TMR2IF Then
        Ms = Ms + 1
        Count = Count + 1
        If Count >= 20 Then          'start every 20mS
            TMR1 = 0                'zero timer 1
            T1CON = 1               'start timer 1
            Count = 0
            CCP1CON = &H8          'CCP1 pin low and high on match - will be first pulse
            CCPR1L = &HD
            CCPR2H = &H7
            CCP1IE = 1              'enable CCP1 interrupts
            CCP1IF = 0              'ensure interrupt flag is clear
            ServoCount = 0          'reset servoCount
            LATC0 = 1               'connected to data in of shift register will clock in a high when CCP1 goes high
        End If
        TMR2IF = 0
    End If
    If CCP1IE And CCP1IF Then
        LATC0 = 0                  'clear the data in pin
        If ServoCount = 9 Then      'have we done all servos?
            CCP1IE = 0             'yes so no more CCP1 interrupts
        End If
        If CCP1CON = &H8 Then      'have we started the 4000 cycle pulse
            CCP1CON = &H9          'yes so end the pulse after 0.5mS
            'CCPR1=CCPR1+4000;   '4000 cycles=0.5mS
            WordTemp = CCPR1H * 256 + CCPR1L
            WordTemp = WordTemp + 4000
            CCPR1L = WordTemp And 255
            CCPR1H = WordTemp / 256
        Else
            CCP1CON = &H8          'No so output the timed gap      
            'CCPR1=CCPR1+servoPos[servoCount++]-4000;   'will generate an interrupt when servo time is up
            WordTemp = CCPR1H * 256 + CCPR1L
            WordTemp = WordTemp - 4000 + ServoPos(ServoCount)
            CCPR1L = WordTemp And 255
            CCPR1H = WordTemp / 256
            ServoCount = ServoCount + 1
        End If
        CCP1IF = 0
    End If
    If RCIE & RCIF Then
        Dim Chr As Byte = RCREG    'get the received character
        If OERR Or FERR Then       'neither of these should ever occur.
            CREN = 0               'this is kinda wishful thinking
            CREN = 1               'as any data received is corrupt
            StrCount = 0           'however, reset everything
            Done = 0               'and hope for the best
         Else                      'no errors so use the data
            If StrCount = 0 And Done = 0 Then 'are we already receiving
                'waiting for $         'no so wait
                If Chr = "$"C Then           'for $ to appear
                    Buff(StrCount) = Chr    'start receiving
                    StrCount = StrCount + 1
                ElseIf Done = 0 Then        'have we collected a full string?
                    Buff(StrCount) = Chr    'no so carry on storing
                    StrCount = StrCount + 1
                    If Chr = "W"C Then       'have we got the "endOfString" character
                        Done = 1             'yes, so set done true
                    End If
                End If
            End If
        End If
    End If
End Sub

Mike.
 
IF, you put the defines at the top does it then compile?
I.E.
Code:
Define CONFIG1L = 0x00
Define CONFIG1H = 0x06 '8mHz XTL x4 =32mHz
Define CONFIG2L = 0x0c
Define CONFIG2H = 0x20
Define CONFIG3L = 0x04
Define CONFIG3H = 0x80
Define CONFIG4L = 0x80 'Set for HVP
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40

Define CLOCK_FREQUENCY = 32
Define SINGLE_DECIMAL_PLACES = 2
Define STRING_MAX_LENGTH = 20

Define SIMULATION_WAITMS_VALUE = 1 'Comment in for SIM out for PIC

Const NUM_SERVOS = 10
Const BUFFER = 80

Dim Buff(BUFFER) As Byte
Dim StrCount As Byte
Dim Done As Byte
Dim WordTemp As Integer
Dim Ms As Long
Dim Count As Byte
Dim ServoCount As Byte
Dim I As Byte
Dim ServoPos(NUM_SERVOS) As Integer

Sub Main()
    OSCCON = &H70     '8MHz
    PLLEN = 1         'x4=32MHz
    'setup 1mS interrupt = 8,000,000/16 = 500,000/10 = 50,000 set PR2=49 = 50,000/50 = 1000 = 1mS
    T2CON = &H4E      'pre=16 post=10
    PR2 = 49
    TMR2IE = 1        'timer 2 interrupts enable
    T1CON = 0         'timer 1 stopped
    For I = 0 To NUM_SERVOS - 1
        ServoPos(I) = I * 1000 + 8000 '1ms(8000) to 1.875(7/8ths - 15000)ms in 1/8th mS steps
    Next
    TRISC = &HFC           'CCP0 & 1 output
    PEIE = 1
    GIE = 1
    Do
        'adjust servo positions here
    Loop
End Sub

Sub Inter()
    If TMR2IE And TMR2IF Then
        Ms = Ms + 1
        Count = Count + 1
        If Count >= 20 Then          'start every 20mS
            TMR1 = 0                'zero timer 1
            T1CON = 1               'start timer 1
            Count = 0
            CCP1CON = &H8          'CCP1 pin low and high on match - will be first pulse
            CCPR1L = &HD
            CCPR2H = &H7
            CCP1IE = 1              'enable CCP1 interrupts
            CCP1IF = 0              'ensure interrupt flag is clear
            ServoCount = 0          'reset servoCount
            LATC0 = 1               'connected to data in of shift register will clock in a high when CCP1 goes high
        End If
        TMR2IF = 0
    End If
    If CCP1IE And CCP1IF Then
        LATC0 = 0                  'clear the data in pin
        If ServoCount = 9 Then      'have we done all servos?
            CCP1IE = 0             'yes so no more CCP1 interrupts
        End If
        If CCP1CON = &H8 Then      'have we started the 4000 cycle pulse
            CCP1CON = &H9          'yes so end the pulse after 0.5mS
            'CCPR1=CCPR1+4000;   '4000 cycles=0.5mS
            WordTemp = CCPR1H * 256 + CCPR1L
            WordTemp = WordTemp + 4000
            CCPR1L = WordTemp And 255
            CCPR1H = WordTemp / 256
        Else
            CCP1CON = &H8          'No so output the timed gap     
            'CCPR1=CCPR1+servoPos[servoCount++]-4000;   'will generate an interrupt when servo time is up
            WordTemp = CCPR1H * 256 + CCPR1L
            WordTemp = WordTemp - 4000 + ServoPos(ServoCount)
            CCPR1L = WordTemp And 255
            CCPR1H = WordTemp / 256
            ServoCount = ServoCount + 1
        End If
        CCP1IF = 0
    End If
    If RCIE & RCIF Then
        Dim Chr As Byte = RCREG    'get the received character
        If OERR Or FERR Then       'neither of these should ever occur.
            CREN = 0               'this is kinda wishful thinking
            CREN = 1               'as any data received is corrupt
            StrCount = 0           'however, reset everything
            Done = 0               'and hope for the best
         Else                      'no errors so use the data
            If StrCount = 0 And Done = 0 Then 'are we already receiving
                'waiting for $         'no so wait
                If Chr = "$"C Then           'for $ to appear
                    Buff(StrCount) = Chr    'start receiving
                    StrCount = StrCount + 1
                ElseIf Done = 0 Then        'have we collected a full string?
                    Buff(StrCount) = Chr    'no so carry on storing
                    StrCount = StrCount + 1
                    If Chr = "W"C Then       'have we got the "endOfString" character
                        Done = 1             'yes, so set done true
                    End If
                End If
            End If
        End If
    End If
End Sub

Mike.
Hi M,
No it won't unless the changes I made earlier are added.

I know very well how much time and effort you've made on this, so I'll keep trying.

I need to make a paper model of it, with CLK and INTERRUPTS etc, so I can visualise your CODE. I'm not sure how to do it, but as I proceed I hope to get it.

Don't worry that you've wasted your time, it will work.
I'll let you know how I get on.

Cheers, C.
 
Let's try a couple of things,
Does this compile?
Code:
Define CONFIG1L = 0x00
Define CONFIG1H = 0x06 '8mHz XTL x4 =32mHz
Define CONFIG2L = 0x0c
Define CONFIG2H = 0x20
Define CONFIG3L = 0x04
Define CONFIG3H = 0x80
Define CONFIG4L = 0x80 'Set for HVP
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40

Define CLOCK_FREQUENCY = 32
Define SINGLE_DECIMAL_PLACES = 2
Define STRING_MAX_LENGTH = 20

Define SIMULATION_WAITMS_VALUE = 1 'Comment in for SIM out for PIC

Const NUM_SERVOS = 10
Const BUFFER = 80

Dim Buff(BUFFER) As Byte
Dim StrCount As Byte
Dim Done As Byte
Dim WordTemp As Integer
Dim Ms As Long
Dim Count As Byte
Dim ServoCount As Byte
Dim I As Byte
Dim ServoPos(NUM_SERVOS) As Integer
end
If not, what error does it give?
If it's the Const lines then try changing Const to Symbol.

Mike.
 
Let's try a couple of things,
Does this compile?
Code:
Define CONFIG1L = 0x00
Define CONFIG1H = 0x06 '8mHz XTL x4 =32mHz
Define CONFIG2L = 0x0c
Define CONFIG2H = 0x20
Define CONFIG3L = 0x04
Define CONFIG3H = 0x80
Define CONFIG4L = 0x80 'Set for HVP
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40

Define CLOCK_FREQUENCY = 32
Define SINGLE_DECIMAL_PLACES = 2
Define STRING_MAX_LENGTH = 20

Define SIMULATION_WAITMS_VALUE = 1 'Comment in for SIM out for PIC

Const NUM_SERVOS = 10
Const BUFFER = 80

Dim Buff(BUFFER) As Byte
Dim StrCount As Byte
Dim Done As Byte
Dim WordTemp As Integer
Dim Ms As Long
Dim Count As Byte
Dim ServoCount As Byte
Dim I As Byte
Dim ServoPos(NUM_SERVOS) As Integer
end
If not, what error does it give?
If it's the Const lines then try changing Const to Symbol.

Mike.
Hi M,
First I tried the earlier program (What I call [1]) with RC0 and RC2 flashing, and using a BREAK at the INTERRUPT while writing a spread sheet of e,g, CLK times, can now see a pattern.

Now I'm trying the last program #355, (What i'm calling [3]) and am working through it.
From memory there have been >10 changes, and I'm not at the bottom yet. Should be compiling soon.

Do you agree that I should be working on [3] or did you make changes in [1] to get it to work?
In other words, should I be working on your first program, or last?

Here's ERRORS,
I'll change the variables to WROD to 2x BYTEs, in order to get to compile.
I'll ask advice on AAC about the INTEGERS
'+++++++++++++++++++++++ 020223 ++++++++++++++++++++++
Const BUFFER = 80
'Dim Buff(BUFFER) As Byte ERROR
Dim StrCount As Byte
'Dim DONE As Byte error 'I think it has to be w WORD that can be split into 2x BYTEs?
'Dim WordTemp As integer ERROR
Dim ms As Long
'Dim Count As Byte 'I think it has to be w WORD that can be split into 2x BYTEs?
Dim servocount As Byte
'Dim i As Byte
Dim servoPos(num_servos) As integer ERROR
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++



C
 
Last edited:
'+++++++++++++++++++++++ 020223 ++++++++++++++++++++++
Const BUFFER = 80
'Dim Buff(BUFFER) As Byte ERROR
Dim StrCount As Byte
'Dim DONE As Byte error 'I think it has to be w WORD that can be split into 2x BYTEs?
'Dim WordTemp As integer ERROR
Dim ms As Long
'Dim Count As Byte 'I think it has to be w WORD that can be split into 2x BYTEs?
Dim servocount As Byte
'Dim i As Byte
Dim servoPos(num_servos) As integer ERROR
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Does it give a reason for the errors?
I see,
Const BUFFER=80
is fine But
Dim Buff(BUFFER) as byte
isn't, what is the error here?
does,
Dim Buff(80) as byte
compile?
I also notice that num_servos isn't defined hence why
Dim servoPos(num_servos) As integer
is an error.
Does the code in #358 compile?

Mike.
At least we're allowed constants now.
Edit, is oshonsoft not case critical? I.E. Byte is the same as byte or buffer is the same as BUFFER.
Edit2, is integer the same as word I.E. 16 bit variables?
Edit3, if you do x=6-2*3 is the answer zero or 12?
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top