Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

12F683 - CCP (Compare) Support

2 posters

Go down  Message [Page 1 of 1]

112F683 - CCP (Compare) Support Empty 12F683 - CCP (Compare) Support Fri Mar 12, 2021 12:10 pm

Andrew Jameson



I've reduced the problem to the few lines below.  Timer1 is running.  An interrupt is created whenever Timer1 count matches the CCP register value and Timer1 is reset.

This works on an 12F683 but not in SimulIDE.

I really want to create an interrupt whenever the Timer1 count matches the CCP register value and leave the Timer1 count to continue untouched.  According to the datasheet :

1010 = Compare mode, generate software interrupt on match (CCP1IF bit is set, CCP1 pin
is unaffected)

- I can't get that to work on the real chip or SimulIDE so any idea what I'm doing wrong ?  (I need GP2/AN2/T0CKI/INT/COUT/CCP1 as input as I'm using the INT configuration)

==============================

#chip 12f683, 1
#option explicit

T1CON       = 0b00000001
TRISIO      = 0b00000100

'CMCON1 = 0

CCP1CON = 0b00001011

CCPR1L  = 255         ; Test who cares values
CCPR1H  = 10          ;

INTCON  = 0b11000000  ; Enable GIE, PEIE
PIE1    = 0b00100000  ; Enable CCP1IE

GPIO    = 0b00000000

On Interrupt CCP1 Call CCP1_Interrupt_Handler
sub CCP1_Interrupt_Handler
end sub

do
 if (CCP1IF = 1) then
   CCP1IF = 0
   GPIO.5 = 1
   Wait 15 mS
   GPIO.5 = 0
 end if
loop

==============================

Thanks

Andrew



Last edited by arcachofo on Fri Dec 24, 2021 3:15 am; edited 1 time in total (Reason for editing : Marked as solved (green color))

212F683 - CCP (Compare) Support Empty Re: 12F683 - CCP (Compare) Support Fri Mar 12, 2021 6:32 pm

arcachofo

arcachofo

I will have a look...

312F683 - CCP (Compare) Support Empty Re: 12F683 - CCP (Compare) Support Fri Mar 12, 2021 6:50 pm

arcachofo

arcachofo

Just to clarify, if I understan well there are 2 issues included in your post:

1- This is related to te code you posted that does not work in simulide:
I've reduced the problem to the few lines below.  Timer1 is running.  An interrupt is created whenever Timer1 count matches the CCP register value and Timer1 is reset.

This works on an 12F683 but not in SimulIDE.
   CCP1CON = 0b00001011

1011 = Compare mode, trigger special event (CCP1IF bit is set, TMR1 is reset and A/D
conversion is started if the ADC module is enabled. CCP1 pin is unaffected.)

Look like this mode does not generate an interrupt but an "special event", anyway the flag is set, so your code should work.


2- Then you want to try another mode, but not working as espected:
I really want to create an interrupt whenever the Timer1 count matches the CCP register value and leave the Timer1 count to continue untouched.  According to the datasheet :

1010 = Compare mode, generate software interrupt on match (CCP1IF bit is set, CCP1 pin
is unaffected)

- I can't get that to work on the real chip or SimulIDE so any idea what I'm doing wrong ?  (I need GP2/AN2/T0CKI/INT/COUT/CCP1 as input as I'm using the INT configuration)

412F683 - CCP (Compare) Support Empty Re: 12F683 - CCP (Compare) Support Fri Mar 12, 2021 8:01 pm

Andrew Jameson



Yes and yes !

The first example works on a "real" chip but not from SimulIDE - still new to this so I'll investigate "special events".

The second one is more real life - the documentation infers that I should be able to do a comparison that does not reset the timer nor involve the CCP1 pin but I can't !

Thanks for your help and patience.



Last edited by Andrew Jameson on Fri Mar 12, 2021 8:02 pm; edited 1 time in total (Reason for editing : Typo)

512F683 - CCP (Compare) Support Empty Re: 12F683 - CCP (Compare) Support Fri Mar 12, 2021 11:28 pm

arcachofo

arcachofo

Confirmed that there is a bug, CCP1IF is not set for 12F683.
It is solved in development version.

The second one is more real life - the documentation infers that I should be able to do a comparison that does not reset the timer nor involve the CCP1 pin but I can't !
Yes.. that is what I understand reading the datasheet.
What part is not working?

612F683 - CCP (Compare) Support Empty Re: 12F683 - CCP (Compare) Support Sat Mar 13, 2021 1:07 am

Andrew Jameson



From the same code fragment, I'd expect to still see CCP1IF = 1 when there's a match.

So setting CCP1CON = 0b00001010 should now cause the same result without resetting Timer1 but CCP1IF is never set.

Reminder to everyone - the problem is with the real chip.

Andrew

How / where do I get the development version ?

712F683 - CCP (Compare) Support Empty Re: 12F683 - CCP (Compare) Support Sat Mar 13, 2021 2:38 pm

Andrew Jameson



Got it working without having to reset Timer1. The CCP1IF bit flag seems to be only valid from within the interrupt handler :

CCP1CON = 0b00001010

On Interrupt CCP1 Call CCP1_Interrupt_Handler
sub CCP1_Interrupt_Handler
if (CCP1IF = 1) then
CCP1IF = 0
CCPMatchFlag = 1
end if
end sub ;(CCP1_Interrupt_Handler)

This works only in the "real" 12F683 !

Andrew

812F683 - CCP (Compare) Support Empty Re: 12F683 - CCP (Compare) Support Sat Mar 13, 2021 5:44 pm

arcachofo

arcachofo

Got it working without having to reset Timer1. The CCP1IF bit flag seems to be only valid from within the interrupt handler :
That's weird...
Maybe GcBasic is clearing the flag by itself in the  interrupt subroutine?

What happens if you run this code (without interrupt) in a real device?
Code:
#chip 12f683, 1
#option explicit

TRISIO = 0b00000100
GPIO = 0b00000000

T1CON = 0b00000001
CCP1CON = 0b00001010

CCPR1L = 255         ; Test who cares values
CCPR1H = 10          ;

do
 if (CCP1IF = 1) then
   CCP1IF = 0
   GPIO.5 = 1
   Wait 100 mS
   GPIO.5 = 0
   Wait 100 mS
 end if
loop

912F683 - CCP (Compare) Support Empty Re: 12F683 - CCP (Compare) Support Sat Mar 13, 2021 6:00 pm

Andrew Jameson



#chip 12f683, 1
#option explicit

T1CON = 0b00000001
TRISIO = 0b00000100
GPIO = 0b00000000
CCP1CON = 0b00001010

CCPR1L = 255 ; Test "who cares" values
CCPR1H = 30 ;

do
if (PIR1.CCP1IF = 1) then
PIR1.CCP1IF = 0
GPIO.5 = 1
Wait 5 mS
GPIO.5 = 0
end if
loop

No idea - it all works as expected !!! There was a moment when I'd used PIE1.CCP1IF which certainly wouldn't have helped and with SimulIDE not working either added to the sense of confusion. Just one of those days when nothing works !

Thanks for everyone's input.

Andrew

arcachofo likes this post

1012F683 - CCP (Compare) Support Empty Re: 12F683 - CCP (Compare) Support Sat Mar 13, 2021 7:19 pm

arcachofo

arcachofo

Nice to know you got it working.

How / where do I get the development version ?
I forgot to mention.
Sources are here:
https://launchpad.net/simulide

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum