CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

RTCC on 18F452 will not work

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Marek
Guest







RTCC on 18F452 will not work
PostPosted: Thu May 08, 2003 5:16 am     Reply with quote

I have not used RTCC before and cannot understand why this code does not seem to work.
Pin D4 goes high but pins D2&D3 do not do anything.
My xtal is 4MHz.
I copied the example code from the reference manual but it did not seem to work. I then realised the 18F452 has a 16 bit RTCC so I removed the if statement from the ISR and decreased the prescaler to 16 so it should still be 1 pulse per second but it still does not work....

Any ideas??

Thanks

#include <1sec.h>
#define high_start 33
byte high_count;
#int_RTCC
RTCC_isr() {

output_low(pin_D2);
output_high(pin_d3);
delay_ms(250);
output_low(pin_D3);
output_high(pin_d2);
//seconds=seconds-1
high_count=high_start; //reset counter
}



void main() {

do{
high_count=high_start;
set_rtcc(0);
setup_counters(RTCC_INTERNAL,RTCC_DIV_16);
enable_interrupts(INT_RTCC);
enable_interrupts(global);
output_high(pin_d4);
}
while(true);
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 14253
Andy Drummond
Guest







Re: RTCC on 18F452 will not work
PostPosted: Thu May 08, 2003 10:22 am     Reply with quote

:=I have not used RTCC before and cannot understand why this code does not seem to work.
:=Pin D4 goes high but pins D2&D3 do not do anything.
:=My xtal is 4MHz.
:=I copied the example code from the reference manual but it did not seem to work. I then realised the 18F452 has a 16 bit RTCC so I removed the if statement from the ISR and decreased the prescaler to 16 so it should still be 1 pulse per second but it still does not work....
:=
:=Any ideas??
:=
:=Thanks
:=
:=#include <1sec.h>
:=#define high_start 33
:=byte high_count;
:=#int_RTCC
:=RTCC_isr() {
:=
:= output_low(pin_D2);
:= output_high(pin_d3);
:= delay_ms(250);
:= output_low(pin_D3);
:= output_high(pin_d2);
:= //seconds=seconds-1
:= high_count=high_start; //reset counter
:=}
:=
:=
:=
:=void main() {
:=
:=do{
:= high_count=high_start;
:= set_rtcc(0);
:= setup_counters(RTCC_INTERNAL,RTCC_DIV_16);
:= enable_interrupts(INT_RTCC);
:= enable_interrupts(global);
:= output_high(pin_d4);
:=}
:=while(true);
:=}

It looks to me like you're sitting in a tight loop setting the RTCC to zero all the time; how do you think it will manage to count up if you keep setting it to zero. Maybe ...

// Set up interrupts etc ...

high_count=high_start;
set_rtcc(0);
setup_counters(RTCC_INTERNAL,RTCC_DIV_16);
enable_interrupts(INT_RTCC);
enable_interrupts(global);
output_low(pin_d4); // So theinterrupt sets it high ...

// Wait while things happen under interrupt control ..

while(true) restart_wdt(); // if you use the WDT ...
___________________________
This message was ported from CCS's old forum
Original Post ID: 14263
nilsener
Guest







Re: RTCC on 18F452 will not work
PostPosted: Thu May 08, 2003 10:26 am     Reply with quote

Dear Marek,

your ISR can not be called because you did not get a timer overflow. You have an endless do while loop in main() where you set the timer to zero 'set_rtcc(0)' every few microseconds.
Change your code so that the initialisation for the timer will be executed once and place a while loop at the end of main() with no code inside the loop, e.g.:

void main() {

high_count=high_start;
set_rtcc(0);
setup_counters(RTCC_INTERNAL,RTCC_DIV_16);
enable_interrupts(INT_RTCC);
enable_interrupts(global);
output_high(pin_d4);

while(true); // endless loop
}

Hope it runs,
Best Regards
Nilsener

:=I have not used RTCC before and cannot understand why this code does not seem to work.
:=Pin D4 goes high but pins D2&D3 do not do anything.
:=My xtal is 4MHz.
:=I copied the example code from the reference manual but it did not seem to work. I then realised the 18F452 has a 16 bit RTCC so I removed the if statement from the ISR and decreased the prescaler to 16 so it should still be 1 pulse per second but it still does not work....
:=
:=Any ideas??
:=
:=Thanks
:=
:=#include <1sec.h>
:=#define high_start 33
:=byte high_count;
:=#int_RTCC
:=RTCC_isr() {
:=
:= output_low(pin_D2);
:= output_high(pin_d3);
:= delay_ms(250);
:= output_low(pin_D3);
:= output_high(pin_d2);
:= //seconds=seconds-1
:= high_count=high_start; //reset counter
:=}
:=
:=
:=
:=void main() {
:=
:=do{
:= high_count=high_start;
:= set_rtcc(0);
:= setup_counters(RTCC_INTERNAL,RTCC_DIV_16);
:= enable_interrupts(INT_RTCC);
:= enable_interrupts(global);
:= output_high(pin_d4);
:=}
:=while(true);
:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 14264
marek
Guest







Re: RTCC on 18F452 will not work
PostPosted: Fri May 09, 2003 2:14 am     Reply with quote

Thanks guys, that was the problem.
By the way, when the ISR finishes is the PIC supposed to jump back to the start of main or back to where it was before the ISR?
The reason I ask is that when I removed the DO loop, as you suggested, and replaced it with a loop at the very end with no internal code the problem was still there although in theory MAIN should only have executed once.....
___________________________
This message was ported from CCS's old forum
Original Post ID: 14279
nilsener
Guest







Re: RTCC on 18F452 will not work
PostPosted: Fri May 09, 2003 2:34 pm     Reply with quote

Dear Marek,

if the ISR is finished, the PIC jumps back to where it was before, in your case it jumps back to the endless loop at the end of main.
If the PIC jumps back to the start of main it may be that something reset the PIC ? One reason may be an overflowing watchdog timer. If you have the watchdog enabled introduce a restart_wdt() command inside the endless loop to refresh the watchdog.
If you post your current code i will take a look.

Best Regards
Nilsener

:=
:=Thanks guys, that was the problem.
:=By the way, when the ISR finishes is the PIC supposed to jump back to the start of main or back to where it was before the ISR?
:=The reason I ask is that when I removed the DO loop, as you suggested, and replaced it with a loop at the very end with no internal code the problem was still there although in theory MAIN should only have executed once.....
___________________________
This message was ported from CCS's old forum
Original Post ID: 14314
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group