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

Delay_ms and PIC12C671

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



Joined: 24 Sep 2003
Posts: 14

View user's profile Send private message

Delay_ms and PIC12C671
PostPosted: Sun Apr 18, 2004 6:50 pm     Reply with quote

Hi,
In the following code it seams the the delay_ms is not working. Any Idea what I am overlooking here?
thanks
Joris H.

h.file:
include <12C671.h>
#device PIC12C671 ADC=8
#fuses NOWDT,PUT,INTRC,NOMCLR
#use delay(clock=4000000)

c.file:
void main() {
int SetDly,i;

setup_adc_ports(AN0_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);


output_high(TRHRLY);
output_high(SafRLY);

SetDly = read_adc();
delay_ms ( 100 );


while ( input(Sensor) );

{
output_low(TRHRLY);
for (i=SetDly;i==0;i--)
{delay_ms ( 1180 );}


delay_ms ( 2000 );
output_low(SafRLY);
}

}
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Sun Apr 18, 2004 7:12 pm     Reply with quote

Loosely translated these are the same.

for (i=SetDly;i==0;i--)

I = setDelay;
While(i==0)
{ .....
I--;
}
Ttelmah
Guest







Re: Delay_ms and PIC12C671
PostPosted: Mon Apr 19, 2004 1:59 am     Reply with quote

Joris H wrote:
Hi,
In the following code it seams the the delay_ms is not working. Any Idea what I am overlooking here?
thanks
Joris H.

h.file:
include <12C671.h>
#device PIC12C671 ADC=8
#fuses NOWDT,PUT,INTRC,NOMCLR
#use delay(clock=4000000)

c.file:
void main() {
int SetDly,i;

setup_adc_ports(AN0_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);


output_high(TRHRLY);
output_high(SafRLY);

SetDly = read_adc();
delay_ms ( 100 );


while ( input(Sensor) );

{
output_low(TRHRLY);
for (i=SetDly;i==0;i--)
{delay_ms ( 1180 );}


delay_ms ( 2000 );
output_low(SafRLY);
}

}


First comment. You select the ADC channel, and then only two instructions latter 'read' the ADC. The capacitor in the ADC circuit, takes time to charge. Normaly you need to allow about 10mSec for this. I'd expect the 'read_adc', to allways return a very low value (assuming the capacitor is charging from 0v), so your loop counter will be programmed with a value of perhaps 0 or 1, and lead to a short delay being seen.
Split the 'delay_ms(100)' instruction, put a delay of perhaps 80mSec, before selecting the ADC, then 20mSecin front of the 'read_adc'. Remember that the external circuitry, will need time to start working.
Seperately, your test in your loop statement is wrong. The second statement in a 'for', is the condition to be met to loop. You need to test for i!=0, to count down from the ADC value.
There is nothing wrong with the 'delay', just in the program using it.

Best Wishes
Joris H



Joined: 24 Sep 2003
Posts: 14

View user's profile Send private message

Delay_ms and PIC12C671
PostPosted: Mon Apr 19, 2004 6:31 pm     Reply with quote

Hello,
I put the delay time in the code as proposed and changed the "for" conditions.
It didn't make a difference. Were I am the most confused with is the second delay_ms(2000). As soon as I enter the "while" loop the two RLY go to low. When the ADC doesn't work or =0 then I need still to have those 2 sec delay what I don't have. Any idea?
Thanks
Joris H
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 19, 2004 6:51 pm     Reply with quote

Post the statements where you define these values:

TRHRLY
SafRLY
Sensor
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