Hi Rob,
As I continued my project, I discovered a new problem for me.
Here after the initial draft:
--************************************************************************
--****** Programme POULE3 -Ouverture crépusculaire du poulailler ********
--***************************************Michel MORICE 16 juillet 2020****
include 12f675
pragma target clock 4_000_000
pragma target OSC INTOSC_NOCLKOUT -- horloge interne à 4 MHz
pragma target MCLR internal -- make MCLR pin available I/O
--conditionnement du PIC
ANSEL = 0b_0000_0011 --ports 0 et 1 en analogique, entrées du comparateur
TRISIO = 0b_0000_1011 --ports 0, 1, 3 en input, 2, 4 et 5 en output
CMCON = 0b_0000_0001 --comparateur + en 0, - en 1, sortie en 2
PIE1_CMIE = ON --Comparator changing Interrupt ON
INTCON_PEIE = ON --Peripheral Interrupt On
INTCON_GIE = ON --Global Interrupt On
--paramétrage des portes
alias COMPS is pin_A2 --sortie du comparateur
alias ILS is pin_A3 --ILS contrôlant la fermeture de porte
alias OUVRE is pin_A4 --commande l'ouverture
alias FERME is pin_A5 --commande la fermeture
--paramétrage général
--ON OFF TRUE FALSE définis par include 12f675 et constants_jallib
const dword seconde = 1_000_000
const bit OUVERTE = ON
const bit FERMEE = OFF
var bit changeLum = FALSE
OUVRE = OFF
FERME = OFF
--****************************************************************
procedure changeLuminosite() is pragma INTERRUPT
if PIR1_CMIF == ON then --changement de luminosité détecté
PIR1_CMIF = OFF --reset du flag de détection
INTCON_GIE = OFF --Stop global interrupt
changeLum = TRUE --flag de détection de changement activé
end if
end procedure
--***************************************************************
procedure ouverturePorte() is
OUVRE = ON --on ouvre la porte - moteur ON+
_usec_delay(seconde * 3) --pendant 3 secondes
OUVRE = OFF --arrêt du moteur
end procedure
--***************************************************************
procedure fermeturePorte() is
FERME = ON --on ferme la porte - moteur ON-
while ILS == OUVERTE loop --tant que la porte n'est pas fermée
end loop
FERME = OFF --arrêt moteur
end procedure
--****************************************************************
--***********programme principal******************************
forever loop
while !changeLum loop
end loop
if COMPS == ON then --passe au jour
ouverturePorte()
else --passe à la nuit
fermeturePorte()
end if
changeLum = FALSE
INTCON_GIE = ON
end loop
--*********************************************************************
That doesn'nt work and I found this solution (in blue):
--************************************************************************
--****** Programme POULE5 -Ouverture crépusculaire du poulailler ********
--***************************************Michel MORICE 2 août 2020****
include 12f675
pragma target clock 4_000_000
pragma target OSC INTOSC_NOCLKOUT -- horloge interne à 4 MHz
pragma target MCLR internal -- make MCLR pin A3 available as I/O
pragma target WDT disabled
--conditionnement du PIC
ANSEL = 0b_0000_0011 --ports 0 et 1 en analogique, entrées du comparateur
TRISIO = 0b_0000_1011 --ports 0, 1, 3 en input, 2, 4 et 5 en output
CMCON = 0b_0000_0001 --comparateur + en 0, - en 1, sortie en 2
PIE1 = 0b_0000_1000 --comparateur enable bit
INTCON = 0b_1100_0000 --global interrupt et peripheral interrupt
--paramétrage des portes
alias ILS is pin_A3 --ILS contrôlant la fermeture de porte
alias OUVRE is pin_A4 --commande l'ouverture
alias FERME is pin_A5 --commande la fermeture
--paramétrage général
--ON OFF TRUE FALSE définis par include 12f675 et constants_jallib
const dword seconde = 1_000_000
const bit OUVERTE = TRUE
const bit FERMEE = FALSE
var bit lumChange = FALSE --flag de changement de luminosité
var bit etatCout --etat de la sortie du comparateur
OUVRE = OFF
FERME = OFF
--****************************************************************
procedure changeLuminosite() is pragma INTERRUPT
if PIR1_CMIF then --changement de luminosité détecté
PIR1_CMIF = OFF --reset du flag détecté
INTCON_GIE = OFF --stop interrupts
etatCout = CMCON_COUT --mise en mémoire de la sortie
lumChange = TRUE --flag de changement de luminosité
end if
end procedure
--***************************************************************
procedure ouverturePorte() is
OUVRE = ON --on ouvre la porte - moteur ON+
_usec_delay(seconde * 3) --pendant 3 secondes
OUVRE = OFF --arrêt du moteur
end procedure
--***************************************************************
procedure fermeturePorte() is
FERME = ON --on ferme la porte - moteur ON-
while ILS == OUVERTE loop --tant que la porte n'est pas fermée
end loop
FERME = OFF --arrêt moteur
end procedure
--********************************************************************
--*************programme principal********************************
forever loop
while !lumChange loop --tant qu'il n'y a pas de changement
end loop --on boucle
_usec_delay(seconde)
if etatCout == HIGH then --si c'est de nuit à jour
ouverturePorte()
else --si c'est de jour à nuit
fermeturePorte()
end if
lumChange = FALSE --reset du flag de changement
INTCON_GIE = ON --remise en attente des interrupts
asm sleep --mise en sommeil
end loop
--*************************************************************************
I don't no exactly the reason, perhaps a timing problem again.
Now * tutto va bene , grazie mille*
Thank you again. Merci beaucoup
Michel
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
Garanti
sans virus. www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
Le sam. 1 août 2020 à 14:00, Michel MORICE <[email protected]> a écrit :
> Hi Rob,
>
> Sorry for not answering sooner, I was enjoying the sun for a few days.
>
> Thank you for this solution, it's perfect. The problem was actually there
> and is fixed now.
> I'ill finally be able to continue my project.
>
> Best regards
>
> Michel
>
>
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
> Garanti
> sans virus. www.avast.com
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
> <#m_1664721968544230734_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>
> Le mar. 28 juil. 2020 à 19:52, Rob CJ <[email protected]> a écrit :
>
>> Hi Michel,
>>
>> Sorry for the spam but I saw that you did not enable the external
>> interrupt in INTCON0. I was confused because you mentioned "An interrupt
>> on A2 changing should start the process but that doesn't work."
>>
>> But the statement about hanging in the interrupt routine still stands.
>>
>> You have to change the code in your interrupt routine into the following:
>>
>> procedure changeLuminosite() is pragma INTERRUPT
>> if PIR1_CMIF then --changement de luminosité détecté
>> PIR1_CMIF = FALSE
>> changeLum = TRUE
>> end if
>> end procedure
>>
>> Otherwise the PIC will re-enter the interrupt routine as soon as it has
>> left it.
>>
>> Kind regards,
>>
>> Rob
>>
>>
>>
>> ------------------------------
>> *Van:* [email protected] <[email protected]> namens Rob CJ <
>> [email protected]>
>> *Verzonden:* dinsdag 28 juli 2020 19:10
>> *Aan:* [email protected] <[email protected]>
>> *Onderwerp:* Re: [jallib] PIC12F675 INTERRUPT WITH COMPARATOR OUTPUT
>> CHANGING doesn't work
>>
>> Hi Michel,
>>
>> Sorry missed that one. Then your problem may be the following.
>>
>> I do not see that you service the external interrupt. This will result in
>> the PIC being continuous in the interrupt routine since the INTF flag
>> remains set.
>>
>> It then appears as if the PIC hangs (believe me I have also run into this
>> issue).
>>
>> So you have to least service the external interrupt otherwise it will not
>> work.
>>
>> Kind regards,
>>
>> Rob
>>
>> ------------------------------
>> *Van:* [email protected] <[email protected]> namens Michel
>> MORICE <[email protected]>
>> *Verzonden:* dinsdag 28 juli 2020 17:57
>> *Aan:* [email protected] <[email protected]>
>> *Onderwerp:* Re: [jallib] PIC12F675 INTERRUPT WITH COMPARATOR OUTPUT
>> CHANGING doesn't work
>>
>> Hi Rob,
>> Thank you for trying to help me.
>> Yes it's necessary to enabling INTCON_PEIE. It is what I did with INTCON
>> = 0b_1100_0000.
>> The mystery is elsewhere
>>
>>
>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
>> Garanti
>> sans virus. www.avast.com
>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
>> <#m_1664721968544230734_m_6362723913766002535_x_x_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>>
>> Le lun. 27 juil. 2020 à 21:42, Rob CJ <[email protected]> a écrit :
>>
>> Hi Michel,
>>
>> Maybe I was too quick. You mentioned that you have connected something to
>> A2 so I assume you use the external interrupt.
>>
>> Next to that you are using a comparator which is a peripheral device.
>>
>> This means that you also have to enable interrupts from peripheral
>> devices by enabling those interrupts with: INTCON_PEIE = TRUE
>>
>> Kind regards,
>>
>> Rob
>>
>> ------------------------------
>> *Van:* Rob CJ <[email protected]>
>> *Verzonden:* maandag 27 juli 2020 21:38
>> *Aan:* [email protected] <[email protected]>
>> *Onderwerp:* Re: [jallib] PIC12F675 INTERRUPT WITH COMPARATOR OUTPUT
>> CHANGING doesn't work
>>
>> Hello Michel,
>>
>> If you want to use the external interrupt you have to enable it by:
>> INTCON_INTE = TRUE
>>
>> Initially it is disabled by default.
>>
>> Kind regard,
>>
>> Rob
>>
>> ------------------------------
>> *Van:* [email protected] <[email protected]> namens Michel
>> MORICE <[email protected]>
>> *Verzonden:* maandag 27 juli 2020 12:06
>> *Aan:* jallib <[email protected]>
>> *Onderwerp:* [jallib] PIC12F675 INTERRUPT WITH COMPARATOR OUTPUT
>> CHANGING doesn't work
>>
>> Hi
>> On a PIC12F675 I use A0 and A1 as analogic input to control the light of
>> the day to open/close a door
>> A2 as logic output with a led to control the right operating.
>> An interrupt on A2 changing should start the process but that doesn't
>> work.
>> Hereafter a little program to try the function.
>> Thanks for helping me.
>>
>> --************************************************************************
>> --****** Programme POULE2 -Ouverture crépusculaire du poulailler ********
>> --***************************************Michel MORICE 16 juillet 2020****
>> include 12f675
>> pragma target clock 4_000_000
>> pragma target OSC INTOSC_NOCLKOUT -- horloge interne à 4 MHz
>> pragma target MCLR internal -- make MCLR pin A3 available as I/O
>> pragma target WDT disabled
>> --conditionnement du PIC
>> ANSEL = 0b_0000_0011 --ports 0 et 1 en analogique, entrées du
>> comparateur
>> TRISIO = 0b_0000_1011 --ports 0, 1, 3 en input, 2, 4 et 5 en output
>> CMCON = 0b_0000_0001 --comparateur + en 0, - en 1, sortie en 2
>> PIE1 = 0b_0000_1000 --comparateur enable bit
>> INTCON = 0b_1100_0000 --global interrupt et peripheral interrupt
>> --paramétrage des portes
>> alias COMPS is pin_A2 --sortie du comparateur
>> alias ILS is pin_A3 --ILS contrôlant la fermeture de porte
>> alias OUVRE is pin_A4 --commande l'ouverture
>> alias FERME is pin_A5 --commande la fermeture
>> --paramétrage général
>> --ON OFF TRUE FALSE définis par include 12f675 et constants_jallib
>> const dword seconde = 1_000_000
>> const bit OUVERTE = ON
>> const bit FERMEE = OFF
>> var bit changeLum = FALSE
>> --***************************************************************
>> --****************************************************************
>> procedure changeLuminosite() is pragma INTERRUPT
>> if PIR1_CMIF then --changement de luminosité détecté
>> changeLum = TRUE
>> end if
>> end procedure
>> --****************************************************************
>> --programme principal
>> forever loop
>> if changeLum then
>> PIR1_CMIF = OFF
>> INTCON_GIE = OFF
>> OUVRE = ON
>> _usec_delay(seconde * 3)
>> OUVRE = OFF
>> end if
>> INTCON_GIE = ON
>> changeLum = FALSE
>> end loop
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "jallib" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/jallib/cdf66d12-1e34-4563-9d26-345617726af0o%40googlegroups.com
>> <https://groups.google.com/d/msgid/jallib/cdf66d12-1e34-4563-9d26-345617726af0o%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "jallib" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/jallib/AM0PR07MB6241E981A94CAD71E293ABCFE6720%40AM0PR07MB6241.eurprd07.prod.outlook.com
>> <https://groups.google.com/d/msgid/jallib/AM0PR07MB6241E981A94CAD71E293ABCFE6720%40AM0PR07MB6241.eurprd07.prod.outlook.com?utm_medium=email&utm_source=footer>
>> .
>>
>>
>>
>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
>> Garanti
>> sans virus. www.avast.com
>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
>> <#m_1664721968544230734_m_6362723913766002535_x_x_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "jallib" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/jallib/CAD9DK3KRQ%3DwE4NuYqB_h4qWFUCbDjGOej9s3qGHd3EJ7my_-sQ%40mail.gmail.com
>> <https://groups.google.com/d/msgid/jallib/CAD9DK3KRQ%3DwE4NuYqB_h4qWFUCbDjGOej9s3qGHd3EJ7my_-sQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "jallib" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/jallib/AM0PR07MB624194A0ECB1FA0C696F7E9BE6730%40AM0PR07MB6241.eurprd07.prod.outlook.com
>> <https://groups.google.com/d/msgid/jallib/AM0PR07MB624194A0ECB1FA0C696F7E9BE6730%40AM0PR07MB6241.eurprd07.prod.outlook.com?utm_medium=email&utm_source=footer>
>> .
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "jallib" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/jallib/AM0PR07MB62411E45F1DBD56F30C83C29E6730%40AM0PR07MB6241.eurprd07.prod.outlook.com
>> <https://groups.google.com/d/msgid/jallib/AM0PR07MB62411E45F1DBD56F30C83C29E6730%40AM0PR07MB6241.eurprd07.prod.outlook.com?utm_medium=email&utm_source=footer>
>> .
>>
>
--
You received this message because you are subscribed to the Google Groups
"jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jallib/CAD9DK3Ka-wBWpMkcROqskhdvxfvbB1t%3DjnKzi3pUv0eSQyMnww%40mail.gmail.com.