asm says:
banksel PIE6
bsf PIE6,CCP1IE
so thats ok.
using "CCP1CON = CCP1CON AND 0x10000101" had no effect.
The code is identical between the 1938 and the 18856 except setting pir6 rather than pir1 for the interrupt reset.
As far as timer1 goes, I'm using it for both chips. In capture mode, it only reads and stores timer1, but I don't use the results, I just wanted the interrupt.
For what it's worth, I just tried it on an 18F27K42 and it didn't work on that chip either.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here's a test program I just ran. Works for 1938, not for 18856.
' Test of ccp1 on 16F18856' turn on led if rc2 (pin13) is captured by pressing switch hooked to +
#optionExplicit'#chip 16F1938, 32
#chip16F18856, 32'#chip 18F27K42, 32'Generated by PIC PPS Tool for Great Cow Basic'PPS Tool version: 0.0.5.28'PinManager data: v1.78.0'Generated for 16F18856
#startupInitPPS, 85
#definePPSToolPart16F18856SubInitPPS'Module: CCP1CCP1PPS=0x0012'RC2 > CCP1RC2PPS=0x0009'CCP1 > RC2 (bi-directional)EndSubdirrc3out' indicator led for debugdirrc2in' reset timer (using ioc)' also 32k crystal on rc0-rc1 SOSC' This is the way I use the timer in the full appInitTimer1SOSC,0' 32768 crystal time keeperOnInterruptTimer1OverflowCallCheckClockStartTimer1subCheckClockTMR1L=0TMR1H=0x80' set up for one second delay' real program sets flag hereendsubTMR1L=0dowhileTMR1L=0: loop' wait for timer to actually start, often takes 5 secondsOnInterruptCCP1callGotReset' watch for reset signal'CCP1CON=b'00000101''everyrisingedgeCCP1CON=CCP1CONAND0x10000101'enable and rising edgesubGotReset'PIR1.C1IF=0 'resetinterrupt(16f1938)PIR6.CCP1IF=0' 16f18856rc3=1' turn on ledendsubdoloop'Optimise code
#defineUSE_Timer0false
#defineUSE_Timer2false
#defineUSE_Timer3false
#defineUSE_Timer4false
#defineUSE_Timer5false
#defineUSE_Timer6false
And as it said earlier, I'm only doing a capture, not a compare, so CCP only copies the value of timer1, and I don't use what it copies.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just to add confusion, I did it again without using timer1 for my own purposes, and added the "C1TSEL = 0x01" line. The compiler didn't know what C1TSEL was, so I changed it to "CCPTMRS1 = CCPTMRS1 or 0x01"
New program:
' Test of ccp1 on 16F18856' turn on led if rc2 (pin13) is captured by pressing switch hooked to +
#optionExplicit'#chip 16F1938, 32
#chip16F18856, 32'#chip 18F27K42, 32'Generated by PIC PPS Tool for Great Cow Basic'Generated for 16F18856
#startupInitPPS, 85
#definePPSToolPart16F18856SubInitPPS'Module: CCP1CCP1PPS=0x0012'RC2 > CCP1RC2PPS=0x0009'CCP1 > RC2 (bi-directional)EndSubdirrc3out' indicator led for debugdirrc2in' reset timer (using ioc)CCPTMRS1=CCPTMRS1or0x01OnInterruptCCP1callGotReset' watch for reset signal'CCP1CON=b'00000101''everyrisingedgeCCP1CON=CCP1CONAND0x10000101'enable and rising edgesubGotReset'PIR1.C1IF=0 'resetinterrupt(16f1938)PIR6.CCP1IF=0' 16f18856rc3=1' turn on ledendsubdoloop
Same results.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Clocking Timer1 from the system clock (FOSC) should not be used in Capture mode. In order for Capture mode to recognize the trigger event on the CCPx pin, Timer1 must be clocked from the
instruction clock (FOSC/4) or from an external clock source. But, I cannot get MPLAB-IDE to accept SOSC as a valid clock source for TMR1 which means an external source is forbidden. I can only select FOSC/4 in MPLAB-IDE as the clock source.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
' Test of ccp1 on 16F18856' turns on led if rc2 (pin13) capture is triggered by pressing switch hooked to +
#optionExplicit
#chip16F18856, 32dirrc3out' indicator led for debugdirrc2in' reset timer (using ioc)OnInterruptCCP1callGotReset' watch for reset signalCCP1CON=b'10000101''every rising edgesubGotResetPIR6.CCP1IF=0' reset interruptrc3=1' turn on ledendsubdoloop
Sorry about this messy thread, feel free to delete the whole mess.
All caused by one messed up bit.
Last edit: Jim giordano 2019-11-11
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm trying to get capture mode working on a 16f18856.
This is the code I'm using:
But it's not working. What else do I have to set?
For the 16f1938, this works-
So there must be something different about the 18856.
Last edit: Jim giordano 2019-11-11
More info.... ignoring what I wrote... use
and
CCP1CON = CCP1CON AND 0x10000100
'enable and falling edgeCCP1CON = CCP1CON AND 0x10000101
'enable and rising edgeAnd, check
CCP1IE
is set to 1. Should be by the compiler. Do not add to your code. Check compile is setting.And, did you have to set timer 1, 3 or 5 on the old part?
And, is CCP/RC2 an input?
asm says:
banksel PIE6
bsf PIE6,CCP1IE
so thats ok.
using "CCP1CON = CCP1CON AND 0x10000101" had no effect.
The code is identical between the 1938 and the 18856 except setting pir6 rather than pir1 for the interrupt reset.
As far as timer1 goes, I'm using it for both chips. In capture mode, it only reads and stores timer1, but I don't use the results, I just wanted the interrupt.
For what it's worth, I just tried it on an 18F27K42 and it didn't work on that chip either.
Oh dear.... I should have mentioned.
PPS.... got this?
According to the datasheet, CCP1 is on RC2 by default, do I really need to do a pps for it?
Oh yes.
ok,
added the "CCP1PPS = 0x12 'RC2->CCP1:CCP1" line, but that didn't work.
so deleted that line and added the full pps output-
Still doesn't work.
Post the code.... the whole code. I am guessing to much
Give me a few minutes.
Guessing here.. cant see you code.
Select timer1.
C1TSEL = 0x01
Here's a test program I just ran. Works for 1938, not for 18856.
And as it said earlier, I'm only doing a capture, not a compare, so CCP only copies the value of timer1, and I don't use what it copies.
Just to add confusion, I did it again without using timer1 for my own purposes, and added the "C1TSEL = 0x01" line. The compiler didn't know what C1TSEL was, so I changed it to "CCPTMRS1 = CCPTMRS1 or 0x01"
New program:
Same results.
Version of Great Cow BASIC please.
;Program compiled by Great Cow BASIC (0.98.06 2019-06-12 (Windows 32 bit))
Clocking Timer1 from the system clock (FOSC) should not be used in Capture mode. In order for Capture mode to recognize the trigger event on the CCPx pin, Timer1 must be clocked from the
instruction clock (FOSC/4) or from an external clock source. But, I cannot get MPLAB-IDE to accept SOSC as a valid clock source for TMR1 which means an external source is forbidden. I can only select FOSC/4 in MPLAB-IDE as the clock source.
I think this is the issue.
1938 is ECCP and the 18856 is CCP
See http://ww1.microchip.com/downloads/en/devicedoc/30673a.pdf
May be not.. but, I would follow the PDF
Ok, got it. Everything I was doing was okay and working, so GCB accept SOSC correctly, and MPLAB is wrong.
Anyway, the fix you gave me earlier was the key.
Had to set
CCP1CON=b'10000101' 'every rising edge
and it works.
The line you game me,
"CCP1CON = CCP1CON AND 0x10000101 'enable and rising edge"
is wrong. That would just keep bits that were already on.
I couldn't contruct a line with ands and ors that would work, but the simple line
CCP1CON=b'10000101'
works!
I think the Line Evan intended was:
"CCP1CON = CCP1CON OR b’10000101’ 'enable and rising edge"
That would Set the required Bits and Leave the rest unchanged.
Oh yes... dim
Final working test program:
Sorry about this messy thread, feel free to delete the whole mess.
All caused by one messed up bit.
Last edit: Jim giordano 2019-11-11
Just an OR isn't correct either. If mode was already set to 0x0111, capture every 16th for example, an or wouldn't change the mode.
It would have to be something like
CCP1CON=(CCP1CON and b'11110000') or b'10000101'
Also notice that PPS is not required in this case since CPP1 is indeed already associated with RC2.