Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Successful simulation of Capture/Compare register in PIC18 series

Status
Not open for further replies.

mikeOJ

Member
Im trying to use the Capture register in a PIC18F series micro using remapable pin 0 as the input for the Capture register and Timer 1 as the timer.

When i try to simulate it however i can't seem to get the timer running at all. No interrupts are generated.

Ive selected the correct stimulus pin, and pulse direction
Ive enabled interrupts
Ive set the corresponding TRIS direction bit
and made the port digital, theres nothing else i can think of..

Anyone successfully simulated a capture, Any ideas?
 
Ive got the capture register set up as I would need to be in the actual application and it would be a low to high edge pulse coming from the output of one pin, hardwired to the remappable input pin of the capture reg. (which would be a square wave i guess)

Then i used the stimulus workbook in MPLAB to fire a High pulse at that pin however the capture doesn't begin
 
would you like the file inboxed or the code pasted ( its still got all my comments on it with data sheet page numbers so its a little messy)
 
would you like the file inboxed or the code pasted ( its still got all my comments on it with data sheet page numbers so its a little messy)

Any way you want ( I prefer C, but I'll manage..)
 
I've had a bit of time on this.... It's not as simple as once perceived...


In your code you keep swapping from CCP1 to CCCP2 There was no interrupt set in the PIE1 register and you were selecting IPR2 (ECCCP2) priority.

However The Remapable pins are locked down... You have to unlock them to change them....

Code:
//*************************************
// Unlock Registers
//*************************************
_asm
; PPS registers are in BANK 14
MOVLB 0x0E
MOVLW 0x55
MOVWF EECON2, 0
MOVLW 0xAA
MOVWF EECON2, 0
; PPS Write Protect off
BCF   PPSCON, IOLOCK, BANKED
_endasm
//***************************
// Configure Input Functions
// (See Table 9-13)
//***************************
// Assign RX2 To Pin RP0
//***************************
_asm
MOVLW 0x00
MOVWF RPINR16, BANKED
_endasm
//***************************
// Configure Output Functions
// (See Table 9-14)
//***************************
// Assign TX2 To Pin RP1
//***************************
_asm
MOVLW 0x05
MOVWF RPOR1, BANKED
_endasm
//*************************************
// Lock Registers
//*************************************
_asm
MOVLW 0x55
MOVWF EECON2, 0
MOVLW 0xAA
MOVWF EECON2, 0
; PPS Write Protected
BSF   PPSCON, IOLOCK, BANKED
_endasm

This is an example from the datasheet...

Once this has been done the ECCP I/O set in RPINR7... This appears to be a binary code ( Although Microchip, in there infinite wisdom ) haven't documented it. so to input on RP0 the RPINR7 should read 0...

I'll try the code again when I get home...
 
Im going to have a look at the example from the datasheet now, from what i have seen with reference to the link you sent me earlier i think another issue im encountering is that i am having trouble setting CCP1 to be used with timer 1, which in tern is being counting from the instruction cycle, i simulated the code from the link you found and it worked however when i modified it slightly for it to run using timer 1 as the counter it once built it wouldn't simulate. so...

I'm going to have a further look into that too and just re-write that part of the code from the ground up.

.. and ill remember to use the #include function this time

Cheers
 
so this is the section of code i modified to try and get timer 1 to count from the instruction cycle.

;initilisation sequence
org 0x00
goto start
org 0x08
retfie
org 0x18
retfie
;
start
MOVLW 0X70
MOVFF WREG, OSCCON

bsf TRISC,2 ; configure CCP1 pin for input
CLRF TMR1L
movlw 0x05 ; set CCP1 to capture on every rising edge
movwf CCP1CON,A ; "

clrf T1CON
BSF T1CON, RD16 ;16 bit counter with instruction cycle source

MOVLW 0X01
MOVFF WREG, TCLKCON

bcf PIE1,CCP1IE,A ; disable CCP1 capture interrupt


bcf PIR1,CCP1IF,A ; clear the CCP1IF flag

BSF T1CON, TMR1ON

(forgive the mixture of caps/lowercase, some of the code was recycled)
However still no joy, cant get it to start. Im sure thats what this issue hinges on, once the counter is in motion the capture should follow..

i have found a few resources on the capture in general and they all (unfortunately for me) show that im doing everything i should be doing, which isnt too helpful but they are all using different timers. thus spawns my prognosis


Pages 4+5 of this thread are quite similar:
https://www.electro-tech-online.com/threads/can-ccp-do-this-on-16f876a.37071/

and from page 6 on here:
https://www.electro-tech-online.com/custompdfs/2013/02/ccpwm.pdf

thanks
 
I hope not! that doesn't put me in a very good position..

Although i did have success with the code in the link that u previously sent but that was using timer 3 to capture and timer one as the source clock which would defeat the purpose of what I'm trying to achieve overall.. theres something missing. i just can't figure it out yet..
 
What chip is it? Does it show up as fully supported by MPSIM (in MPLAB, look at <select device> under the <configure> tab)?
 
Hi Mike pic18f24j11 ( not supported yet in ISIS either ) I can get the RP0 assigned but the ECCP module wont see it.

I tried again for about an hour last night.... The remapable pin isn't being assigned correctly... Having said that. Even the TMR3 isn't running on the sim even though there is nothing to stop it.


OK.... The MPLAB sim release notes say that timer 1 isn't working on the pic18f46j11 devices... I'm wondering if the same applies to this chip..
 
Keep me posted, I've found this online book which features a code on page 173 that it says its able to successfully obtain a capture using timer 1.

https://www.electro-tech-online.com...Cs20-20Fundamentals20and20Appl20with20PIC.pdf

Trouble is its using a different PIC. Im going to try again going through this section once i get home this evening and see if there's any joy, if not and it turns out that it is a problem with the pic, i guess the only alternative is to try a different Micro to achieve the desired result right?


OK.... The MPLAB sim release notes say that timer 1 isn't working on the pic18f46j11 devices... I'm wondering if the same applies to this chip.
.

i also need to find where it says this in the release notes as i would need to doccument it, so im going to have a look for that tonight too.

Thanks
 
Just had a look, Ian, Mike, i think you're right if timer 1 has problems in the 18F46j11, then the same can be said for that of the one that i chose.

They're one in the same, in fact the datasheet for the PIC18F46J11 always talks in terms of the former...

Screen Shot 2013-02-08 at 14.04.37.png

Its unfortunate..

The search begins for a pic with two WORKING timers and capture registers:rolleyes:
 
Status
Not open for further replies.

Latest threads

Back
Top