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 buf_len = 80
Dim Buff(buf_len) As Byte
Dim StrCount As Byte
Dim isDone As Bit
Dim WordTemp As word
Dim Ms As Long
Dim Count As Byte
Dim ServoCount As Byte
Dim I As Byte
Dim ServoPos(NUM_SERVOS) As word
Dim Char As Byte
Hi M,Ssometimes I get a reason, and sometimes, I have to check D/SDoes 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?
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.
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
Dim buff(80) As Byte
Dim sCount As Byte
Dim isDone As Bit
Dim WordTemp As word
Dim Ms As Long
Dim Count As Byte
Dim ServoCount As Byte
Dim i As Byte
Dim ServoPos(NUM_SERVOS) As word
Dim Char As Byte
end
Hi m,Does this fix the errors?
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 Dim buff(80) As Byte Dim sCount As Byte Dim isDone As Bit Dim WordTemp As word Dim Ms As Long Dim Count As Byte Dim ServoCount As Byte Dim i As Byte Dim ServoPos(NUM_SERVOS) As word Dim Char As Byte end
Mike.
Edit, changed strCount to sCount.
Hi M,Hi M,
It may be good for you to download the evealuation free compy of the Oshonsoft simulator here:
I think you get 30 free goes, so you'll get the errors I get.
C
'18F4431 32MHz XTL REMOTE_SLAVE 164 3 020223 1600
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
TRISA = %11000000 '7=OSC, 6=OSC,
TRISB = %00000000
TRISC = %11110000 '6=1-slave4431_cs, 2=74HC164 CLK, 0=74HC164 DATA
TRISD = %00000000 '6=led, 7=led, 5=sync
TRISE = %00000000
Dim wordtemp As Word
Dim ms As Long
Dim cnt As Byte
Dim servocount As Byte
Dim i As Byte
Dim servoPos(9) As Word 'Byte 'integer 'BYTE is an INTEGER?
Enable High 'This is set for SERVOS
Enable Low 'This is set for GPS later
main: '\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
OSCCON = %01110000 '& h70
'setup 1mS interrupt = 8,000,000/16 = 500,000/10 = 50,000 set PR2=49 = 50,000/50 = 1000 = 1mS
T2CON = %01001110 'pre=16 post=10
PR2 = 49 'This is timer 2 period register. I.E. reset after 50 clocks (0 to 49 = 50 counts)
PIE1.TMR2IE = 1 'timer 2 interrupts enable
T1CON = 0 'timer 1 stopped
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
INTCON.PEIE = 1
INTCON.GIE = 1
While 1 'loop forever because everything is done on interrupts
'adjust servo positions here
Wend
On High Interrupt
Save System
Break '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
If PIE1.TMR2IE And PIR1.TMR2IF Then 'Is it a timer 2 interrupt
ms = ms + 1 'Yes, so increment ms variable
cnt = cnt + 1 'If cnt >= 20 Then 'start every 20mS
If cnt >= 20 Then 'start every 20mS
T1CON = 0 'stop timer 1
TMR1L = 0 'zero timer 1
TMR1H = 0 'zero timer 1
cnt = 0 'Reset count
CCP1CON = %00001000 ' & h8 'CCP1 pin low and high on match - will be first pulse
CCPR1L = 0x13 '& hd 'Start pulse in 0.25mS (2000 clock cycles)?
CCPR2H = 0x07 '& h7
PIE1.CCP1IE = 1 'enable CCP1 interrupts
PIR1.CCP1IF = 0 'ensure interrupt flag is clear
servocount = 0 'reset servoCount
LATC.0 = 1 'connected to data in of shift register will clock in a high when CCP1 goes high
T1CON = 1 'start timer 1
Endif
PIR1.TMR2IF = 0 '0 = no TMR2 To PR2 match occurred
Endif
If PIE1.CCP1IE And PIR1.CCP1IF Then 'Is it a CCP1 interrupt
LATC.0 = 0 'Yes, so clear the data in pin as the high has already been clocked in
If servocount = 9 Then 'have we done all servos?
PIE1.CCP1IE = 0 'yes so no more CCP1 interrupts
Endif
If CCP1CON = 0x08 Then '& h8 Then 'have we started the 4000 cycle pulse
CCP1CON = 0x09 '& h9 'yes so end the pulse after 0.5mS
wordtemp = CCPR1H * 256 + CCPR1L
wordtemp = wordtemp + 4000
CCPR1L = wordtemp And 255
CCPR1H = wordtemp / 256
Else
CCP1CON = 0x08 '& h8 'No so output the timed gap
wordtemp = CCPR1H * 256 + CCPR1L
wordtemp = wordtemp - 4000 + servoPos(servocount)
CCPR1L = wordtemp And 255
CCPR1H = wordtemp / 256
servocount = servocount + 1
Endif
PIR1.CCP1IF = 0
Endif
Resume
Hi M,There's some silly mistakes in there, the most obvious one being,
If PIE1.TMR2IE And PIR1.TMR2IF Then 'Is it a CCP1 interrupt
Which should be,
If PIE1.CCP1IE And PIR1.CCP1IF Then 'Is it a CCP1 interrupt
There's also zeroing timer 1 isn't a 16 bit write.
I've made some changes to fix these things and removed the UART code,
I've also removed the two lines that write to CCPR1 as this is not a 16 bit write. Nothing should ever write to CCPR1, don't know why they bothered to convert the Pic file and change a word variable into a byte - stupid.Code:'18F4431 32MHz XTL REMOTE_SLAVE 164 3 020223 1600 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 TRISA = %11000000 '7=OSC, 6=OSC, TRISB = %00000000 TRISC = %11110000 '6=1-slave4431_cs, 2=74HC164 CLK, 0=74HC164 DATA TRISD = %00000000 '6=led, 7=led, 5=sync TRISE = %00000000 Dim wordtemp As Word Dim ms As Long Dim cnt As Byte Dim servocount As Byte Dim i As Byte Dim servoPos(9) As Word 'Byte 'integer 'BYTE is an INTEGER? Enable High 'This is set for SERVOS Enable Low 'This is set for GPS later main: '\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ OSCCON = %01110000 '& h70 'setup 1mS interrupt = 8,000,000/16 = 500,000/10 = 50,000 set PR2=49 = 50,000/50 = 1000 = 1mS T2CON = %01001110 'pre=16 post=10 PR2 = 49 'This is timer 2 period register. I.E. reset after 50 clocks (0 to 49 = 50 counts) PIE1.TMR2IE = 1 'timer 2 interrupts enable T1CON = 0 'timer 1 stopped 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 INTCON.PEIE = 1 INTCON.GIE = 1 While 1 'loop forever because everything is done on interrupts 'adjust servo positions here Wend On High Interrupt Save System Break '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< If PIE1.TMR2IE And PIR1.TMR2IF Then 'Is it a timer 2 interrupt ms = ms + 1 'Yes, so increment ms variable cnt = cnt + 1 'If cnt >= 20 Then 'start every 20mS If cnt >= 20 Then 'start every 20mS T1CON = 0 'stop timer 1 TMR1L = 0 'zero timer 1 TMR1H = 0 'zero timer 1 cnt = 0 'Reset count CCP1CON = %00001000 ' & h8 'CCP1 pin low and high on match - will be first pulse CCPR1L = 0x13 '& hd 'Start pulse in 0.25mS (2000 clock cycles)? CCPR2H = 0x07 '& h7 PIE1.CCP1IE = 1 'enable CCP1 interrupts PIR1.CCP1IF = 0 'ensure interrupt flag is clear servocount = 0 'reset servoCount LATC.0 = 1 'connected to data in of shift register will clock in a high when CCP1 goes high T1CON = 1 'start timer 1 Endif PIR1.TMR2IF = 0 '0 = no TMR2 To PR2 match occurred Endif If PIE1.CCP1IE And PIR1.CCP1IF Then 'Is it a CCP1 interrupt LATC.0 = 0 'Yes, so clear the data in pin as the high has already been clocked in If servocount = 9 Then 'have we done all servos? PIE1.CCP1IE = 0 'yes so no more CCP1 interrupts Endif If CCP1CON = 0x08 Then '& h8 Then 'have we started the 4000 cycle pulse CCP1CON = 0x09 '& h9 'yes so end the pulse after 0.5mS wordtemp = CCPR1H * 256 + CCPR1L wordtemp = wordtemp + 4000 CCPR1L = wordtemp And 255 CCPR1H = wordtemp / 256 Else CCP1CON = 0x08 '& h8 'No so output the timed gap wordtemp = CCPR1H * 256 + CCPR1L wordtemp = wordtemp - 4000 + servoPos(servocount) CCPR1L = wordtemp And 255 CCPR1H = wordtemp / 256 servocount = servocount + 1 Endif PIR1.CCP1IF = 0 Endif Resume
Mike.
Hi M,I think we can do (well, according to the manual we can)
Dim CCPR1word As word @ CCPR1L
Dim TMR1word As word @ TMR1L
Does this compile?
Mike.
Hi M,Can you add these two line before the servo initialisation loop.
ms=0
tempWord=0
Hi M,I did, of course, mean wordTemp.
Does
Dim CCPR1word As word @ 0x0FBE
I realise it's your bedtime now so no more questions for now.
Mike.
Hi M,The stupid byte comment was not your doing.
Each Pic chip has a file which describes all the SFRs and each 16bit SFR has 3 definitions, E.G.
TMR1L the low byte of timer one
TMR1H the high byte of timer one
TMR1 the word definition of timer one
Oshonsoft left the word definition as a byte.
Can you add these two line before the servo initialisation loop.
ms=0
tempWord=0
Before
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
Note, this is setting up 9 servos as the start of servo 9 is the end of servo 8's pulse and so is needed.
And see what's in them at the break.
Is the interrupt definitely executing the lower CCP1 code? CCP1IE can only get set if cnt reaches 20.
cnt should be counting to 19 and resetting to zero. Is this happening?
Are we executing the code in #371?
Mike.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?