Been away for the last few days and writing this reply on my phone would have been painful.
The
Code:
PIE1.TMR2IF = 0 'Variable argument expected here??????????????
conversion is weird as it (the A.I.) got it right earlier,
Code:
If PIE1.TMR2IE And PIR1.TMR2IF Then
So, yes it should be PIR1.TMR2IF.
All the references to CCPR1 will need to be double writes so,
Code:
CCPR1 = 2000
Will need to be,
CCPR1L=0xD0
CCPR1H=0x07
And the other write to CCPR1 changed as posted previously.
Mike.
edit, 2000 decimal is 0x07D0 hex.
edit2, the code uses timer 2 for the 1mS interrupt and timer 1 for the servo timing via CCP1 in compare mode.
edit3, can you post your current code that you're currently working with - preferably as a text file.
edit4, no idea what is set/clear in the config values but one of those bits moves CCP1 to port B so it won't appear on PortC.1
Hi M,
Glad you're back!
The INTERRUPT is now at the [ If PIE1.CCP1IE And PIR1.CCP1IF Then ] and passing through.
no idea what is set/clear in the config values but one of those bits moves CCP1 to port B so it won't appear on PortC.1
I don't see any PORTB or C, so I assume that there should be a line like [PORTC = SERVOPOS] or similar somewhere. As you say, there is nothing appearing at PORTC.1.
As a text file? Do you mean like this?
'18F4431 32MHz XTL REMOTE_SLAVE 164 280123 0900
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 oscillator frequency
'#define _xtal_freq 32000000
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 = %11011000 '7=OSC, 6=OSC, 4=QEIB 3=QEIA 2=TEMP SEROUT
TRISB = %00000000
TRISC = %01000110 '6=1-slave4431_cs, 2=MOSI 1=74HC164 CLK.
TRISD = %00000000 '6=led, 7=led, 5=synch
TRISE = %00000000
'LATB = %00000000 'SERVO ouput PORT [ No more ]!!!!!!!!
ANSEL0 = 1 '[7:0]1 = Analog input: 1 = Analog input (Used later): REGISTER 21.6
ANSEL1.ANS8 = 0 '[0]Analog Input Function Select bit: 0 = Digital I/O
Disable Low
Disable High
'Define num_servos = 10 'not compile??
Dim num_servos As Byte 'BYTE ??
num_servos = 10
Dim i As Word '??????????
Dim servoPos(10) As Word
Dim ms As Long
Dim Cnt As Byte 'servocount As Byte
Dim frame As Word
frame = 0x07d0 '2000
Dim cycle As Word
cycle = 0x0fa0 '4000
Dim servocount As Byte '???????????
Enable High 'This is set for SERVOS
Enable Low 'This is set for GPS later
main_loop: '\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
OSCCON = %01110000 '& h70
'pllen = 1 'x4=32MHz "#define CONFIG1H = 0x06 'HS oscillator, PLL enabled (clock frequency=4 x FOSC1)#define CONFIG1H = 0x06 'HS oscillator, PLL enabled (clock frequency=4 x FOSC1)"
'setup 1mS interrupt = 8,000,000/16 = 500,000/10 = 50,000 set PR2=49 = 50,000/50 = 1000 = 1mS
T2CON = %01001110 '& h4e
PR2 = 49
PIE1.TMR2IE = 1 'timer 2 interrupts enable
PIE1.CCP1IE = 1
PIR1.TMR2IF = 1 '1 = TMR2 to PR2 match occurred (must be cleared in software)£
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 i
TRISC = %1111100 '& hfc 'CCP0 & 1 output
INTCON.PEIE = 1
INTCON.GIE = 1
While 1
'adjust servo positions here
servoPos(0) = 1.5 * 900 'SERVO pulse times allowing for Clock speed
servoPos(1) = 1.5 * 900
servoPos(2) = 1.5 * 1000
servoPos(3) = 1.5 * 1100
servoPos(4) = 1.5 * 1200
servoPos(5) = 1.5 * 1300
servoPos(6) = 1.5 * 1400
servoPos(7) = 1.5 * 1600
Wend
Goto main_loop
End
'sub inter()
On High Interrupt
Save System
If PIE1.TMR2IE And PIR1.TMR2IF Then
ms = ms + 1
Cnt = Cnt + 1
If Cnt >= 20 Then 'start every 20mS
TMR1 = 0 'zero timer 1
T1CON = 1 'start timer 1
Cnt = 0
CCP1CON = %00001000 '& h8 'CCP1 pin low and high on match - will be first pulse
CCPR1L = frame.LB '2000 'start pulse in 0.25mS (2000 clock cycles)
CCPR1H = frame.HB
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
Endif
PIR1.TMR2IF = 0 ' 0 = No TMR2 to PR2 match occurred
Endif
If PIE1.CCP1IE And PIR1.CCP1IF Then
LATC.0 = 0 'clear the data in pin
If servocount = 9 Then 'have we done all servos?
PIE1.CCP1IE = 0 'yes so no more CCP1 interrupts
Endif
If CCP1CON = %00001000 Then '& h8 Then 'have we started the 4000 cycle pulse
CCP1CON = %00001001 '& h9 'yes so end the pulse after 0.5mS
CCPR1L = CCPR1L + cycle.LB '4000 cycles=0.5mS
CCPR1H = CCPR1H + cycle.HB
Else
CCP1CON = %00001000 '& h8 'No so output the timed gap
CCPR1L = CCPR1L + servoPos(servocount) - cycle.LB + servocount 'will generate an interrupt when servo time is up
CCPR1H = CCPR1H + servoPos(servocount) - cycle.HB + servocount
servocount = servocount + 1
Endif
PIR1.CCP1IF = 0
Endif
Resume
'The code uses timer 2 For the 1ms Interrupt And timer 1 For the servo timing via ccp1 in compare mode.
'No idea what is set / clear in the config values but one of those bits moves ccp1 To
'port b so it won't appear on PortC.1
C