|
|
View previous topic :: View next topic |
Author |
Message |
Jean FOUGERON
Joined: 30 Nov 2012 Posts: 110 Location: France
|
#INT_EXT behaviour |
Posted: Wed Jul 27, 2016 4:03 am |
|
|
Does anybody knows the details of #INT_EXT ?
I use it in my project.
I need to monitor a 4/20mA loop
The signal applied to my PIC18F2550 is like series of squares 2 times a second
Each serie is a number of up levels during 10ms, and spaced 14ms (I mean 10ms up, the 4ms down ...) apart from the first one (to identify) which is 5ms long iso 10ms, and the last one which is 15ms
When a problem occurs on the sets that it is monitoring, one (or many) top (10 or 15ms) disapears
So, I have a bar of 2 colors leds and I light in green or red each led wether the corresponding top is present or not
To detect the top I use #INT_EXT
Code: | #INT_EXT high
void Boucle()
{
L_Compteur_Flanc=L_Compteur;
if (!B_Flanc) B_Flanc=TRUE;
} |
and in main I have
Code: | void main()
{
initialisation();
while(TRUE)
{
restart_wdt(); // resetter le watch dog !
if (B_Flanc) Flanc_Pulse();
...
if(SFLS.Changed) Action();
}
} |
I also have a clock which allow me to measure the length and delay between tops
Code: | /******************************************************************************
appelé tous les 200µs ??
*******************************************************************************/
#INT_TIMER3 high
void Counter()
{
set_timer3(L_Period);
L_Compteur++; //doit donc battre PERIODXXX
} |
The procedure Flanc_Pulse compares the value of L_Compteur with the different delays (5, 10, 14 and 15 ms) taking in account the possible dispersion (+/- 1,2 ms) and can adjust the clock period (value of L_Period) a little bit to correct variations (eg temperature of the monitored sets)
When Flanc_Pulse has detected a correct slope (L_2_H or H_2_L) it inverses the detecting slope of th #INT_EXT (when it detects a L_2_H slope 14ms after the previous one, it considers it as OK and switches to H_2_L expecting a descending signal in 10 or 15ms)
It, globally works well but ...
I observe that there are faulty calls of #INT_EXT, I mean that the interrupt goes without "seeing" any voltage variation of the current loop signal on PIN_RB0 where it is applied
Of course it falses the treatment and I loose green led or red one
I added a 100nF capacitor on the PIN_RB0 but nothing. The signal seems OK is 5V hight and without noise. Supply is 5VDC
In Microchip datasheet, I understand a logical 0 is detected below 0,8V and a logical 1 is >2V. There is never noise of this amplitude, so I gess something happens inside the PIC but what ?
I have tried and observe any correlation with any event, but noticed nothing
Has anybody already seen similar behaviour and understtod what happend and made correction ? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9217 Location: Greensville,Ontario
|
|
Posted: Wed Jul 27, 2016 4:52 am |
|
|
hmm.. first suggestion, delete the 'restart WDT' code. Traditionally WDT is enabled in the final production code, to restart the PIC should there be a hardware or software problem.
Without seeing your setup code, it could be the WDT is timing out.
In 20+ years of PICking, I've never had to use the WDT.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19481
|
|
Posted: Wed Jul 27, 2016 2:26 pm |
|
|
As a further comment, why not just use the CCP?.
Program it to detect rising edge, when it triggers record the time, and set it to record the falling edge. When this triggers record this time. It is exactly what the CCP is designed to do.
Then have you read the data sheet?.
You say:
"it inverses the detecting slope of the #INT_EXT".
If you look in the data sheet you will find that changing the edge on INT_EXT, can result in this giving a spurious trigger. So the sequence has to be:
Code: |
disable_interrupts(INT_EXT);
ext_int_edge(H_TO_L); //or L_TO_H
clear_interrupt(INT_EXT);
enable_interrupts(INT_EXT);
|
This may be what is giving the wrong detection... |
|
|
|
|
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
|