A discussion group for the PICMicro microcontroller. Also called the Microchip PIC, this list is dedicated to the use and abuse of this fine, simple, microcontroller. Close to topic posts are welcome, ie. general electronics.
Question about INT0 interruption - rodr...@petrobras.com.br - Feb 6 12:54:18 2009
Hi,
I read on 18F252 datasheet that the INT0 interrupt can be activated on the
rising or falling edges. I want to measure the length of the hi and low
peaks of a variable square ware. So, I thought on using TMR0 to start
counting on this interrupt, then it will reset when the wave change. The
question is, I have to change the interrupt actiavtion type each time the
interrupt occurs to be able to catch the length, right? Otherwise I will
catch only the wave 'period' (not exactly the period because it's a
variable wave).
Am I on the right way?
Best regards,
Rodrigo Basniak
=20
"O emitente desta mensagem =E9 respons=E1vel por seu conte=FAdo e endere=E7=
amento. Cabe ao destinat=E1rio cuidar quanto ao tratamento adequado. Sem a =
devida autoriza=E7=E3o, a divulga=E7=E3o, a reprodu=E7=E3o, a distribui=E7=
=E3o ou qualquer outra a=E7=E3o em desconformidade com as normas internas d=
o Sistema Petrobras s=E3o proibidas e pass=EDveis de san=E7=E3o disciplinar=
, c=EDvel e criminal."
=20
"The sender of this message is responsible for its content and addressing. =
The receiver shall take proper care of it. Without due authorization, the p=
ublication, reproduction, distribution or the performance of any other act=
ion not conforming to Petrobras System internal policies and procedures is =
forbidden and liable to disciplinary, civil or criminal sanctions."
=20
"El emisor de este mensaje es responsable por su contenido y direccionamien=
to. Cabe al destinatario darle el tratamiento adecuado. Sin la debida autor=
izaci=F3n, su divulgaci=F3n, reproducci=F3n, distribuci=F3n o cualquier otr=
a acci=F3n no conforme a las normas internas del Sistema Petrobras est=E1n =
prohibidas y ser=E1n pasibles de sanci=F3n disciplinaria, civil y penal."
------------------------------------
to unsubscribe, go to http://www.yahoogroups.com and follow the instruction=
s

(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )
Re: Question about INT0 interruption - Mike Harpe - Feb 6 12:56:44 2009
The input capture system is the better way to do it. PWM does much the
same thing.
Mike Harpe
On Fri, Feb 6, 2009 at 12:54 PM,
w=
rote:
>
> Hi,
>
> I read on 18F252 datasheet that the INT0 interrupt can be activated on th=
e
> rising or falling edges. I want to measure the length of the hi and low
> peaks of a variable square ware. So, I thought on using TMR0 to start
> counting on this interrupt, then it will reset when the wave change. The
> question is, I have to change the interrupt actiavtion type each time the
> interrupt occurs to be able to catch the length, right? Otherwise I will
> catch only the wave 'period' (not exactly the period because it's a
> variable wave).
>
> Am I on the right way?
>
> Best regards,
> Rodrigo Basniak
> "O emitente desta mensagem =E9 respons=E1vel por seu conte=FAdo e endere=
=E7amento. Cabe ao destinat=E1rio cuidar quanto ao tratamento adequado. Sem=
a devida autoriza=E7=E3o, a divulga=E7=E3o, a reprodu=E7=E3o, a distribui=
=E7=E3o ou qualquer outra a=E7=E3o em desconformidade com as normas interna=
s do Sistema Petrobras s=E3o proibidas e pass=EDveis de san=E7=E3o discipli=
nar, c=EDvel e criminal."
>
> "The sender of this message is responsible for its content and addressing=
. The receiver shall take proper care of it. Without due authorization, the=
publication, reproduction, distribution or the performance of any other a=
ction not conforming to Petrobras System internal policies and procedures i=
s forbidden and liable to disciplinary, civil or criminal sanctions."
>
> "El emisor de este mensaje es responsable por su contenido y direccionami=
ento. Cabe al destinatario darle el tratamiento adecuado. Sin la debida aut=
orizaci=F3n, su divulgaci=F3n, reproducci=F3n, distribuci=F3n o cualquier o=
tra acci=F3n no conforme a las normas internas del Sistema Petrobras est=E1=
n prohibidas y ser=E1n pasibles de sanci=F3n disciplinaria, civil y penal."
> ------------------------------------
>
> to unsubscribe, go to http://www.yahoogroups.com and follow the instructi=
ons

(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )Re: Question about INT0 interruption - Don Pomplun - Feb 6 13:00:35 2009
Without knowing exactly how this works, my guess is that executing the
instructions that change the activation mode will affect your
calculation. That said, you should also be able to determine how many
clock cycles it takes to do that. That should work unless your period is
less than the turnaround time.
If your waveform is symmetrical, or you only want a full (vs half) period,
you could count times between rise events.
At 09:54 AM 2/6/2009, you wrote:
>Hi,
>
>I read on 18F252 datasheet that the INT0 interrupt can be activated on the
>rising or falling edges. I want to measure the length of the hi and low
>peaks of a variable square ware. So, I thought on using TMR0 to start
>counting on this interrupt, then it will reset when the wave change. The
>question is, I have to change the interrupt actiavtion type each time the
>interrupt occurs to be able to catch the length, right? Otherwise I will
>catch only the wave 'period' (not exactly the period because it's a
>variable wave).
>
>Am I on the right way?
>
>Best regards,
>Rodrigo Basniak
>"O emitente desta mensagem é responsável por seu conteúdo e endereçamento.
>Cabe ao destinatário cuidar quanto ao tratamento adequado. Sem a devida
>autorização, a divulgação, a reprodução, a distribuição ou qualquer outra
>ação em desconformidade com as normas internas do Sistema Petrobras são
>proibidas e passíveis de sanção disciplinar, cível e criminal."
>
>"The sender of this message is responsible for its content and addressing.
>The receiver shall take proper care of it. Without due authorization, the
>publication, reproduction, distribution or the performance of any other
>action not conforming to Petrobras System internal policies and procedures
>is forbidden and liable to disciplinary, civil or criminal sanctions."
>
>"El emisor de este mensaje es responsable por su contenido y
>direccionamiento. Cabe al destinatario darle el tratamiento adecuado. Sin
>la debida autorización, su divulgación, reproducción, distribución o
>cualquier otra acción no conforme a las normas internas del Sistema
>Petrobras están prohibidas y serán pasibles de sanción disciplinaria,
>civil y penal."
>------------------------------------
>
>to unsubscribe, go to http://www.yahoogroups.com and follow the
>instructionsYahoo! Groups Links
>

(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )
Re: Question about INT0 interruption - Rodrigo - Feb 9 5:15:10 2009
Thanks for the answers... I'm just a hobbist starting with pics. Then
sometimes I may not be doing the things by the easier way. I never
managed do really understand the compare/capture hardware, I'll take a
careful look there again.
The wave I want to measure is a PPM signal from a RC radio. It has
peaks 8 peaks of 1-2ms each, all these 8 peaks are sampled a every ~20ms.
That's what I was thinking (though not yet burned in a PIC to see if
it would work):
unsigned short low_byte, hi_byte;
unsigned short send;
void interrupt() {
low_byte =3D TMR1L;
hi_byte =3D TMR1H ;
=20=20
TMR1L =3D 0; // Reset value on timer0
TMR1H =3D 0; // Reset value on timer0
send =3D 1;
INTCON2.INTEDG0 =3D !INTCON2.INTEDG0; // Invert falling/rising edge
detection
PIR1.INT0IF =3D 0; // Clear interrupt flag
}
void main() {
T0CON.TMR0ON =3D 1; // Timer0 on
T0CON.T08BIT =3D 0; // 16-Bit timer
T0CON.T0CS =3D 0; // External
T0CON.PSA =3D 1; // No prescaler
TRISB =3D 0; // PORTB is input
INTCON.GIE =3D 1; // Enable interrupts
INTCON.PEIE =3D 1; // Enable interrupts
INTCON.INT0 =3D 1; // Enable RB0 interruption
=20=20
INTCON2.INTEDG0 =3D 1; // Interrupt on rising edge
USART_Init(115200); // Initialize USART
=20=20
send =3D 0;
=20=20=20=20=20
for(;;)
{
if ( send =3D=3D 1 ) {
USART_Write(low_byte);
USART_Write(hi_byte);
send =3D 0;
}
}
}
Regards,
Rodrigo Basniak
--- In p...@yahoogroups.com, rodrigobasniak.plena@... wrote:
>
>=20
> Hi,
>=20
> I read on 18F252 datasheet that the INT0 interrupt can be activated
on the
> rising or falling edges. I want to measure the length of the hi and low
> peaks of a variable square ware. So, I thought on using TMR0 to start
> counting on this interrupt, then it will reset when the wave change. The
> question is, I have to change the interrupt actiavtion type each
time the
> interrupt occurs to be able to catch the length, right? Otherwise I will
> catch only the wave 'period' (not exactly the period because it's a
> variable wave).
>=20
> Am I on the right way?
>=20
> Best regards,
> Rodrigo Basniak
>=20
>=20=20
> "O emitente desta mensagem =E9 respons=E1vel por seu conte=FAdo e
endere=E7amento. Cabe ao destinat=E1rio cuidar quanto ao tratamento
adequado. Sem a devida autoriza=E7=E3o, a divulga=E7=E3o, a reprodu=E7=E3o,=
a
distribui=E7=E3o ou qualquer outra a=E7=E3o em desconformidade com as norma=
s
internas do Sistema Petrobras s=E3o proibidas e pass=EDveis de san=E7=E3o
disciplinar, c=EDvel e criminal."
>=20=20
> "The sender of this message is responsible for its content and
addressing. The receiver shall take proper care of it. Without due
authorization, the publication, reproduction, distribution or the
performance of any other action not conforming to Petrobras System
internal policies and procedures is forbidden and liable to
disciplinary, civil or criminal sanctions."
>=20=20
> "El emisor de este mensaje es responsable por su contenido y
direccionamiento. Cabe al destinatario darle el tratamiento adecuado.
Sin la debida autorizaci=F3n, su divulgaci=F3n, reproducci=F3n, distribuci=
=F3n
o cualquier otra acci=F3n no conforme a las normas internas del Sistema
Petrobras est=E1n prohibidas y ser=E1n pasibles de sanci=F3n disciplinaria,
civil y penal."
>
------------------------------------
to unsubscribe, go to http://www.yahoogroups.com and follow the instruction=
s

(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )