View previous topic :: View next topic |
Author |
Message |
tsen0017
Joined: 25 Nov 2007 Posts: 3
|
Counter overflow? |
Posted: Mon Nov 26, 2007 12:08 am |
|
|
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
|
|
Posted: Mon Nov 26, 2007 12:26 am |
|
|
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
|
|
Posted: Mon Nov 26, 2007 4:29 am |
|
|
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
|
Counter overflow? |
Posted: Tue Nov 27, 2007 1:12 am |
|
|
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
|
Counter overflow? |
Posted: Tue Nov 27, 2007 1:16 am |
|
|
Sorry I forgot to post my compilier version. It's:
CCS PCM C Compiler, Version 4.049, 40044
Thanks,
John |
|
|
Ttelmah Guest
|
|
Posted: Tue Nov 27, 2007 4:07 am |
|
|
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 |
|
|
|