Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Hi M,All those edits are after reading the manual and should work.
Mike.
Hi M,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
Doesn't the A.I. program deal with this?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,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.
Is from my programs, and is e,g, where PLL is set.Define CONFIG1H =
Hi M,This is rapidly going towards the "Too hard to contemplate bin"
Mike.
I would never pay for that POS.Once it's grown up we'll have to pay for it.
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
Hi M,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.
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
Hi M,Let's try a couple of things,
Does this compile?
If not, what error does it give?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 it's the Const lines then try changing Const to Symbol.
Mike.
Does it give a reason for the errors?'+++++++++++++++++++++++ 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
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++