camerart
Well-Known Member
Hi S,CCP1CON=CCP1CON XOR 1
Who is this addressed to?
Is
a question or an answer?CCP1CON=CCP1CON XOR 1
C
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 S,CCP1CON=CCP1CON XOR 1
a question or an answer?CCP1CON=CCP1CON XOR 1
Hi M or S?And what? As I said in $444,
The instruction I'm not sure of is,
CCP1CON=CCP1CON XOR 1
This should toggle bit zero of CCP1CON
Mike.
Edit, you may be able to use Toggle CCP1CON.0
Mike.
Why, the code will work fine without any priority. The background code ( which currently does nothing) can do what it needs to. Why is it an error when the manual says it's correct?I don't understand the ON INTERRUPT error, but this CODE will be added to larger CODE, where a GPS INTERRUPT will be, which could be LOW INTERRUPT, so this is why I chose it.
Hi M,Why, the code will work fine without any priority. The background code ( which currently does nothing) can do what it needs to. Why is it an error when the manual says it's correct?
Mike.
'18F4431 32MHz XTL REMOTE_SLAVE 164 389 030223 1200
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 SIMULATION_WAITMS_VALUE = 1 'Comment in for SIM out for PIC
Dim servoCount as byte
Dim i as byte
Dim wordTemp As Word
Dim servoPos(8) as word
Dim frame as word
'need to ensure the 164 is reset at power on.
OSCCON = %01110000 '& h70
TRISA = %11000000 '7=OSC, 6=OSC,
TRISC = %11111010 '6=1-slave4431_cs, 2=74HC164 CLK, 0=74HC164 DATA
For i = 0 to 7
servoPos(i)=i*250+2000 '1ms(2000) to 1.875(1 7/8ths - 3750)ms in 1/8th mS steps
Next i
TRISC=0b11111010 'CCP0 (RC2) & RC0 output
servoCount=8 'cause it to reset
T1CON=0b00100000 'prescaler = 4
T1CON.0=1 'start timer
CCP1CON=0b1000 'will go high on interrupt - will start a 0.5mS pulse
frame=1000 'start everything in 4000 cycles
While 1
If PIR1.CCP1IF Then 'has CCP1 triggered?
wordtemp.HB = CCPR1H 'get value of CCPR1 into wordTemp
wordtemp.LB = CCPR1L
If CCP1CON = 0x08 Then 'have we started the 1000 cycle pulse
CCP1CON = 0x09 'yes so end the pulse after 0.5mS
wordtemp = wordtemp + 1000 'adding 1000 will make pulse 0.5mS long
Else
LATC.0=0 'clear the data pin
CCP1CON = 0x08 'No so output the timed gap
if servoCount<8 then
'still doing the servos so add remainder of time
wordtemp = wordtemp+servoPos(servoCount)
wordTemp=wordTemp-1000 'knock of the 1000 already elapsed
frame=frame-servoPos(servoCount)
servoCount = servoCount + 1
Else
'done all the servos so just the frame gap to do
wordtemp = wordtemp +frame
frame=31000 '40,000(20mS) minus time of positive pulse(0.5mS)
servoCount=0 'start all over again
LATC.0=1 'will become first pulse
Endif
Endif
CCPR1H = wordtemp.HB 'put value back into CCPR1
CCPR1L = wordtemp.LB
PIR1.CCP1IF = 0 'clear interrupt flag
Endif
'change any servo positions here
Wend
End
Hi M,I've been thinking and as the 1kHz program worked well, why not do everything without interrupts?
As we're not sure what Oshonsoft is doing with Interrupts, here's a CCP1 only version without interrupts,
Code:'18F4431 32MHz XTL REMOTE_SLAVE 164 389 030223 1200 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 SIMULATION_WAITMS_VALUE = 1 'Comment in for SIM out for PIC Dim servoCount as byte Dim i as byte Dim wordTemp As Word Dim servoPos(8) as word Dim frame as word 'need to ensure the 164 is reset at power on. OSCCON = %01110000 '& h70 TRISA = %11000000 '7=OSC, 6=OSC, TRISC = %11111010 '6=1-slave4431_cs, 2=74HC164 CLK, 0=74HC164 DATA For i = 0 to 7 servoPos(i)=i*250+2000 '1ms(2000) to 1.875(1 7/8ths - 3750)ms in 1/8th mS steps Next i TRISC=0b11111010 'CCP0 (RC2) & RC0 output servoCount=8 'cause it to reset T1CON=0b00100000 'prescaler = 4 T1CON.0=1 'start timer CCP1CON=0b1000 'will go high on interrupt - will start a 0.5mS pulse frame=1000 'start everything in 4000 cycles While 1 If PIR1.CCP1IF Then 'has CCP1 triggered? wordtemp.HB = CCPR1H 'get value of CCPR1 into wordTemp wordtemp.LB = CCPR1L If CCP1CON = 0x08 Then 'have we started the 1000 cycle pulse CCP1CON = 0x09 'yes so end the pulse after 0.5mS wordtemp = wordtemp + 1000 'adding 1000 will make pulse 0.5mS long Else LATC.0=0 'clear the data pin CCP1CON = 0x08 'No so output the timed gap if servoCount<8 then 'still doing the servos so add remainder of time wordtemp = wordtemp+servoPos(servoCount) wordTemp=wordTemp-1000 'knock of the 1000 already elapsed frame=frame-servoPos(servoCount) servoCount = servoCount + 1 Else 'done all the servos so just the frame gap to do wordtemp = wordtemp +frame frame=31000 '40,000(20mS) minus time of positive pulse(0.5mS) servoCount=0 'start all over again LATC.0=1 'will become first pulse Endif Endif CCPR1H = wordtemp.HB 'put value back into CCPR1 CCPR1L = wordtemp.LB PIR1.CCP1IF = 0 'clear interrupt flag Endif 'change any servo positions here Wend End
Hopefully, this will work and then the UART stuff can be added the same way (without interrupts).
Another thing to consider is resetting the 164 at powerup either with a spare pic pin of an RC reset circuit or it could be done in software.
Also attached is the C file.
Mike.
Hi M,That looks very promising.
Mike.
Hi M,I've been thinking and as the 1kHz program worked well, why not do everything without interrupts?
As we're not sure what Oshonsoft is doing with Interrupts, here's a CCP1 only version without interrupts,
Code:'18F4431 32MHz XTL REMOTE_SLAVE 164 389 030223 1200 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 SIMULATION_WAITMS_VALUE = 1 'Comment in for SIM out for PIC Dim servoCount as byte Dim i as byte Dim wordTemp As Word Dim servoPos(8) as word Dim frame as word 'need to ensure the 164 is reset at power on. OSCCON = %01110000 '& h70 TRISA = %11000000 '7=OSC, 6=OSC, TRISC = %11111010 '6=1-slave4431_cs, 2=74HC164 CLK, 0=74HC164 DATA For i = 0 to 7 servoPos(i)=i*250+2000 '1ms(2000) to 1.875(1 7/8ths - 3750)ms in 1/8th mS steps Next i TRISC=0b11111010 'CCP0 (RC2) & RC0 output servoCount=8 'cause it to reset T1CON=0b00100000 'prescaler = 4 T1CON.0=1 'start timer CCP1CON=0b1000 'will go high on interrupt - will start a 0.5mS pulse frame=1000 'start everything in 4000 cycles While 1 If PIR1.CCP1IF Then 'has CCP1 triggered? wordtemp.HB = CCPR1H 'get value of CCPR1 into wordTemp wordtemp.LB = CCPR1L If CCP1CON = 0x08 Then 'have we started the 1000 cycle pulse CCP1CON = 0x09 'yes so end the pulse after 0.5mS wordtemp = wordtemp + 1000 'adding 1000 will make pulse 0.5mS long Else LATC.0=0 'clear the data pin CCP1CON = 0x08 'No so output the timed gap if servoCount<8 then 'still doing the servos so add remainder of time wordtemp = wordtemp+servoPos(servoCount) wordTemp=wordTemp-1000 'knock of the 1000 already elapsed frame=frame-servoPos(servoCount) servoCount = servoCount + 1 Else 'done all the servos so just the frame gap to do wordtemp = wordtemp +frame frame=31000 '40,000(20mS) minus time of positive pulse(0.5mS) servoCount=0 'start all over again LATC.0=1 'will become first pulse Endif Endif CCPR1H = wordtemp.HB 'put value back into CCPR1 CCPR1L = wordtemp.LB PIR1.CCP1IF = 0 'clear interrupt flag Endif 'change any servo positions here Wend End
Hopefully, this will work and then the UART stuff can be added the same way (without interrupts).
Another thing to consider is resetting the 164 at powerup either with a spare pic pin of an RC reset circuit or it could be done in software.
Also attached is the C file.
Mike.
Nope, we definitely don't have any interrupts. No on anything interrupt wise.So with CCPR, we still have an INTERRUPT.
Hi M,No need to understand interrupts as we're no longer using them. I don't know what Osh does with them so it's better to not use them.
Nope, we definitely don't have any interrupts. No on anything interrupt wise.
A while 1 statement loops forever so it'll never get out of that loop so no need for any GOTOs either.
BTW, the code in the loop is very rarely executed and probably uses less than 1% of the processor time so lot's of time left.
Let me know what "control program" you want to write.
Mike.
In the code the RC section doesn't exist, the UART code can go in the While 1 loop and get a sentence, parse that sentence and then adjust the servos as needed.In your CODE where will the RC section go?
Hi M,In the code the RC section doesn't exist, the UART code can go in the While 1 loop and get a sentence, parse that sentence and then adjust the servos as needed.
What is the RC section?
Mike.
BTW, I still believe you only need one pic for this project and a second one will just cause problems.
That does't make sense. There's no code but where does it go?so there is no RC section, but where will it go in this CODE?
Hi M,To try to explain it further, the while loop normally does nothing and then about once every 4000 instructions it executes code which takes about 30 instructions. So it's basically idling and can do lots more, like reading the UART. Even doing all of that it'll probably still be less that 1%(2%?) of the processor time.
Mike.