>-----Original Message----- >From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] >On Behalf Of Andre Abelian >Sent: 26 July 2007 21:13 >To: Microcontroller discussion list - Public. >Subject: [PIC] sync problem > > >Hi to all, > >well same project came back with sync problem. One of the pin >is requesting data every 8 ms and data I have to send when it >does high then low transition. When I added interrupt routine >I got the speed but it was out if sync very little. what I did >is in ISR I set variable to set 1 when it sending data and in >while loop since ADC and MATH routines are slow by using if >statement I was able sync them together. At this moment it is >working but I worry about if the method I came up is reliable. >see code below > > >///////////////////////////////////////////////// >// Read ADC and Send all 6 bytes out >///////////////////////////////////////////////// >#int_rtcc >void output_data_isr() > { > set_timer0(0xFF00); > sft_trigger = 0; > if (!input(trigger)) // wait for ttl >input pressed active low (was B2) > { > while(!input(trigger)){} // wait for release This seems dangerous, you are waiting within the ISR for a transition on a pin. If this transition is late, your watchdog timer will reset the PIC. It would probably be a better idea to use a simple state machine inside the ISR to handle edge detection. Do you have anything in place to prevent the ISR sending the data whilst it's being written by the main loop? How often is your timer interrupt occuring? How long is the incomming pulse? The code mentions "was B2", which pin are you polling now? Regards Mike ======================================================================= This e-mail is intended for the person it is addressed to only. The information contained in it may be confidential and/or protected by law. If you are not the intended recipient of this message, you must not make any use of this information, or copy or show it to any person. Please contact us immediately to tell us that you have received this e-mail, and return the original to us. Any use, forwarding, printing or copying of this message is strictly prohibited. No part of this message can be considered a request for goods or services. ======================================================================= -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist