PIC18F452 & C18: capture module set-up ?

Hi all,

I've been trying to set up the ccp1 on this MCU for two days now. I got to the point where I have the ccp1 irq working (here is the irq fragment)

//------------------ code fragment begins ----------------------- if (PIR1bits.CCP1IF==(unsigned int)1){ newCCPval=ReadCapture1(); newCaptureDataFlag=1;

Reply to
Rodo
Loading thread data ...

T1_OSC1EN_ON & T1_SYNC_EXT_ON);

I'm not familiar with C on the PIC18. I assume the use of & is correct. I seem to remember someone mentioning a compiler that worked that way.

Do you ever turn Timer1 on? In the OpenTimer1 call, I see you enabling the oscillator, but you might want to check if bit 0 of TCON1 is 1 (timer1 enabled). I'm not sure the TIMER_INT_OFF is the right flag to pass to OpenTimer1.

Reply to
Gary Kato

formatting link
Page 109 states that the external clock for Timer1 should be: "External clock from pin RC0/T1OSO/T13CKI (on the rising edge)" You have indicated that there is a 32kHz crystal on "OSC ".

If you are sure that the crystal is on the right pin, then change T1_SYNC_EXT_ON to T1_SYNC_EXT_OFF and use the internal clock just to make sure the count changes. If it does, then you know its a problem with the oscillator. If it doesn't, then you know the problem is with the timer setup.

Reply to
g9u5dd43_nospam

I changed from ext to int osc. No change on the numbers. I've tried so many variations I lost track of what I've done but I did check this right before I left work yesterday.

Thanks

to

same

how

4MHz.
Reply to
Rodo

I've used the timers for other stuff before and the "OpenTimer1(...)" call does turns it on. TIMER_INT_OFF prevents the time-out (FFFF -> 0000) from generating an interrupt that you have to service in the ISR. The capture just reads the free running timer1 value and stores it when an event occurs. If you see my code, I check for an overflow flag because there could be a rollover from the previous captured timer1 value.

This is how I understand this thing ... but then ... I'm unable to capture ... yet :-).

Thanks

seem

Reply to
Rodo

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.