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

I/O commutation time or bug ?

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



Joined: 25 Jan 2005
Posts: 5

View user's profile Send private message

I/O commutation time or bug ?
PostPosted: Fri May 06, 2005 2:08 pm     Reply with quote

I try to drive 2 ingectors at the same time with a PIC16F628 but with the follow code I have a big problem

output_low(PIN_A0);
output_low(PIN_A1);
delay_ms(15);
output_high(PIN_A0);
output_high(PIN_A1);
delay_ms(15);

Only the last I/O line (PIN_A1) works! I tryed to drive one line per time and all is ok so the lines work. The result will be a square wave on each line.

If I use the follow code

output_low(PIN_A0);
delay_ms(1);
output_low(PIN_A1);
delay_ms(15);

output_high(PIN_A0);
delay_ms(1);
output_high(PIN_A1);
delay_ms(15);

All work fine but 1ms between lines is too long for my application. What is the problem? Is a bug or each line takes some time for commutation?

Best regards.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri May 06, 2005 2:46 pm     Reply with quote

This is probably caused by the classic Read-Modify-Write problem.

The solution is to maintain a "shadow" register (a byte variable) in RAM
for all of your Port A pins. When you want to change the value of a
pin, you should change it in the Shadow register. Then write the
entire shadow register value to Port A in one operation. Don't do
individual bit set and clear operations.

See my large post in this thread. It has sample code which shows
how to implement a shadow register for Port A.
http://www.ccsinfo.com/forum/viewtopic.php?t=21825&start=15

Also, I'm assuming that you did everything else correctly on the 16F628,
such as disabling the comparators.
firefox78



Joined: 25 Jan 2005
Posts: 5

View user's profile Send private message

PostPosted: Sat May 07, 2005 3:40 am     Reply with quote

Tank you very much. I will try your solution next week.

Best regards
fuzzy



Joined: 26 Feb 2005
Posts: 64

View user's profile Send private message

PostPosted: Sat May 07, 2005 4:15 pm     Reply with quote

I had simlar problem with PIC16F876.
Port A is analog in this MCU so I had to specify, (NO_ANALOG) in ADC setup to have a digital Port. I don't know wether in your pic PORT a is analog .
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