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 support@ccsinfo.com

Counter overflow?

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



Joined: 25 Nov 2007
Posts: 3

View user's profile Send private message

Counter overflow?
PostPosted: Mon Nov 26, 2007 12:08 am     Reply with quote

Hi,

I'm new to this and have some basic questions. Here is a portion of my code:

void main() {
setup_comparator(NC_NC);
setup_adc_ports(NO_ANALOGS);
port_a_pullups(8);
for(CYCLES=108000;CYCLES!=0;--CYCLES) {
send_pulses();
output_low(PIN_A5);
delay_ms(60);
}
output_low(PIN_A2);
output_low(PIN_A5);
delay_ms(3);

I use CYCLES as a counter to control the microcontroller (When the counter expires, the microcontroller outputs LOW on PIN_A2 and PIN_A5). The microcontroller does NOT output LOW WHEN the counter expires if CYCLES is set to 108000 ( instead it happened about two hours AFTER the counter expires) ; it works correctly if CYCLES is a smaller number (I tried 450 and 900). I use int32 for the variable CYCLES.

Could anyone point out why this is causing me problems? Maybe overflow?? Any suggestions? I'm using PIC12F675.

Your help is highly appreciated.


John
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 26, 2007 12:26 am     Reply with quote

1. Post a complete test program that shows the problem. In other words,
add the #include, #fuses, and #use delay() statements to the program.
Also add the variable declarations. Show the closing brace of main().
Test the program, verify that it fails, and post it.

2. Post your compiler version.

3. Describe any external circuits that you have connected to the PIC.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Nov 26, 2007 4:29 am     Reply with quote

Quote:
instead it happened about two hours AFTER the counter expires

108000 * 60ms = 1.8 hours
Doesn't look like coincidence.... Check your code again.
tsen0017



Joined: 25 Nov 2007
Posts: 3

View user's profile Send private message

Counter overflow?
PostPosted: Tue Nov 27, 2007 1:12 am     Reply with quote

Thanks a lot for your reply. I have posted the code below.

Basic I expect the microcontroller to output LOW (and stops sending pulses) on both A2 and A5 after ~108000 * (24*1ms + 60ms) = 2.5 hrs. Output of maybe 10 times I tried, it only worked 3 times (it stopped sendig pulses after 2.5 hrs, which is expected). For other 7 times, it continued sending pulses (after the 2.5 hrs) for quite a while (~ 2 hrs, but this extra time varies).

Besides VDD pin and GND pin, MCRL is connected to VDD(5V) through a 47K resistor. A2 and A5 are not connected to anything.

I really appreciate your help.


John





Code:
#include <12f675.H>
#fuses intrc_io,nomclr,nowdt,noprotect
#use delay(clock=4000000)


int32 CYCLES;                         
int PULSES;                             

#inline
void pulse_A5() {
      output_high(PIN_A2);
      output_high(PIN_A5);
      delay_us(500);
      output_low(PIN_A5);
      delay_us(500);
}

#separate
void send_pulses() {
   int pulses;                           
   PULSES=24;
   for(pulses=PULSES; pulses!=0; --pulses) {
      pulse_A5();
   }
}

#pragma zero_ram
void main() {
   setup_comparator(NC_NC);
   setup_adc_ports(NO_ANALOGS);
   port_a_pullups(8);
   for(CYCLES=108000;CYCLES!=0;--CYCLES) {
        send_pulses();
        output_low(PIN_A5);
        delay_ms(60);
  }
  output_low(PIN_A2);
  output_low(PIN_A5);
  delay_ms(3);                                 
}
tsen0017



Joined: 25 Nov 2007
Posts: 3

View user's profile Send private message

Counter overflow?
PostPosted: Tue Nov 27, 2007 1:16 am     Reply with quote

Sorry I forgot to post my compilier version. It's:

CCS PCM C Compiler, Version 4.049, 40044

Thanks,

John
Ttelmah
Guest







PostPosted: Tue Nov 27, 2007 4:07 am     Reply with quote

How is the supply generated?. What capacitance have you got between Vss and Vdd (amount, and where placed)?.
I'd suspect something is 'spiking' the chip, and the code is restarting. Hence the variable times involved.

Best Wishes
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