Searching \ for '[PIC] sync problem' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'sync problem'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] sync problem'
2007\07\26@161102 by Andre Abelian

flavicon
face
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
       while(input(trigger)){}            // make sure it is release
       sft_trigger = 1;                   // set 1 sft_trigger for main while {} SYNC
//      output_toggle(PIN_D7);             // for scope only
       putc(byte0);                       //
       putc(byte1);                       //
       putc(byte2);                       // sign bit of left sw /
       putc(byte3);                       // MSB of lefdt switch
       putc(byte4);                       //
       putc(byte5);                       //      
       set_timer0(0xFF00);                // update timer0 for next cycle
            }
 
 }




and here is the while loop

while(TRUE)
        {
       restart_wdt();                      // reset WDT
       led_diag();                         // check is left and right switches are out of range

       enable_interrupts(global);          //
       if (sft_trigger == 1)
            {
       read_ext_adc();
       fpu_calc();    
            }
       }

My question is: the method I am using is it reliable way of syncing together?

I use CCS compiler and 18f4550  

thanks

Andre    

2007\07\26@170609 by Michael Rigby-Jones

picon face


{Quote hidden}

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.
=======================================================================

2007\07\26@173704 by Dario Greggio

face picon face
Andre Abelian wrote:

> When I added interrupt routine I got the speed but it was out if sync very little.

I don't like all of that time spent in ISR, i.e. sending bytes, doing
other things ecc.

ISR should be fast...

2007\07\27@121721 by Andre Abelian

flavicon
face
Dario,

How would you do?

thanks

Andre



-----Original Message-----
From: piclist-bouncesspamKILLspammit.edu [.....piclist-bouncesKILLspamspam.....mit.edu]On Behalf
Of Dario Greggio
Sent: Thursday, July 26, 2007 2:37 PM
To: Microcontroller discussion list - Public.
Subject: Re: [PIC] sync problem


Andre Abelian wrote:

> When I added interrupt routine I got the speed but it was out if sync very little.

I don't like all of that time spent in ISR, i.e. sending bytes, doing
other things ecc.

ISR should be fast...

2007\07\27@123853 by Dario Greggio

face picon face
Andre Abelian wrote:

> How would you do?

Usually my method is to set a flag in the ISR routine, and the main loop
checks this flag on a regular basis, and performs transmission etc. as
needed.
Of course, the responsiveness is slower, as for that one event, but
several events can be triggered by IRQ, since each IRQ does not block
the CPU for so long (preventing other IRQs to be seen).

--
Ciao, Dario

2007\07\27@133327 by Herbert Graf

flavicon
face
On Fri, 2007-07-27 at 18:38 +0200, Dario Greggio wrote:
> Andre Abelian wrote:
>
> > How would you do?
>
> Usually my method is to set a flag in the ISR routine, and the main loop
> checks this flag on a regular basis, and performs transmission etc. as
> needed.
> Of course, the responsiveness is slower, as for that one event, but
> several events can be triggered by IRQ, since each IRQ does not block
> the CPU for so long (preventing other IRQs to be seen).

That is generally the technique I use as well. Only thing I may add is
"quick things" like receiving a character from the UART, throwing it
into a buffer and flagging the main loop.

The number on rule of trouble free ISR usage IMHO is keeping the ISR as
short and quick as possible. The less time you spend in your ISR the
better. Let the main loop do the heavy lifting.

TTYL

2007\07\27@173636 by Andre Abelian

flavicon
face
Ciao,

I did the same as you did. if you look at the code you will see it.

thank you

Andre



-----Original Message-----
From: EraseMEpiclist-bouncesspam_OUTspamTakeThisOuTmit.edu [piclist-bouncesspamspam_OUTmit.edu]On Behalf
Of Dario Greggio
Sent: Friday, July 27, 2007 9:39 AM
To: Microcontroller discussion list - Public.
Subject: Re: [PIC] sync problem


Andre Abelian wrote:

> How would you do?

Usually my method is to set a flag in the ISR routine, and the main loop
checks this flag on a regular basis, and performs transmission etc. as
needed.
Of course, the responsiveness is slower, as for that one event, but
several events can be triggered by IRQ, since each IRQ does not block
the CPU for so long (preventing other IRQs to be seen).

--
Ciao, Dario

2007\07\27@231233 by Xiaofan Chen

face picon face
On 7/27/07, Andre Abelian <@spam@aabelianKILLspamspammason-electric.com> wrote:
> I did the same as you did. if you look at the code you will see it.
>
Apparently not.

You wrote:
>        if (!input(trigger))               // wait for ttlinput pressed active low (was B2)
>              {
>        while(!input(trigger)){}           // wait for release

Dario wrote:
> I don't like all of that time spent in ISR, i.e. sending bytes, doing
> other things ecc.
> ...
> Usually my method is to set a flag in the ISR routine, and the main loop
> checks this flag on a regular basis, and performs transmission etc. as
> needed.


Xiaofan

2007\07\27@231451 by Xiaofan Chen

face picon face
On 7/27/07, Andre Abelian <KILLspamaabelianKILLspamspammason-electric.com> wrote:
> Ciao,
>
> I did the same as you did. if you look at the code you will see it.
>

By the way, Dario is not "Ciao". I believe "Ciao" is like "Bye"
or something similar in Italian.

Xiaofan

2007\07\28@030649 by Dario Greggio

face picon face
Xiaofan Chen wrote:
> On 7/27/07, Andre Abelian <RemoveMEaabelianTakeThisOuTspammason-electric.com> wrote:
>
>>I did the same as you did. if you look at the code you will see it.
>>
>
> Apparently not.


That's what I meant too, Andre.
Thx Xiaofan!

--
Ciao, Dario

2007\07\28@030729 by Dario Greggio

face picon face
Xiaofan Chen wrote:

> By the way, Dario is not "Ciao". I believe "Ciao" is like "Bye"
> or something similar in Italian.

Thx again :)
I saw that mistake in other circumstances too.
No problem anyway!

--
Ciao, Dario

More... (looser matching)
- Last day of these posts
- In 2007 , 2008 only
- Today
- New search...