external sensor problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

external sensor problem

865 Views
Dora
Contributor I

Hello,

 

I can't solve this problem over 1 week. It make me headache.

I use MC9S12C32MFU25 chip. I get one problem about port P. Port P read when sensor detect the object , but it doesn't read when sensor doesn't detect the object. Any idea for that?

 

 

if (regEnDiFlag2 && regIntFlag2)     /* Is the device enabled and an interrupt flag is set? */
    PIFP_PIFP1 = 1;                              /* If yes then clear an interrupt flag */
 
if (regEnDiFlag2)
    if (regIntFlag2) {
      OP2_OnInterrupt();
    }
I want to show LED3 when sensor detect the object, and LED1  when sensor doesn't detect the object.
void OP2_OnInterrupt(void)
{
    if(PIFP_PIFP1 = 1)
    doword commandid = LED3;
else
    doword commandid = LED1;
}
Please give me some idea.......
Labels (1)
0 Kudos
7 Replies

643 Views
kef
Specialist I

What are you reading and what "doesn't read"? Port or port interrupt flag? I see you are reading interrupt flag in your code snipets, but I don't see what these snipets are supposed to do. Port and port interrupt flag are two different things.

Do you want interrupt flag set on both rising and falling edge? No, port interrupt can be set up to detect either falling or rising edges. To detect differect edge you need to change your setup.

 

BTW comment below is wrong. You are clearing all PIFP flags here, not just PIFP1 flag. Search the forum to find how to clear  single flag bit:

    PIFP_PIFP1 = 1;                              /* If yes then clear an interrupt flag */

0 Kudos

643 Views
Dora
Contributor I

 

Hello,

 

If I want to use both falling or rising edge, which type of MCU should I use for future?

I am using MC9S12C32MFU25(80pin) now, do you have idea for any MC9S12C family which can use both falling or rising edge?

 

 

Thanks

0 Kudos

643 Views
kef
Specialist I

C32 can register both rising and falling edges using port interrupt. But you need to change polarity on port interrupt. You can have initial setup to wait for say rising edges, then on interrupt you could change polarity to wait for falling edge, then on next interrupt restore polarity back to rising etc. If you have spart interrupt capable pin, then consider connecting two pins together and setting up one of them to detect rising edge, another one to detect falling edge.

 

You can also use timer input capture for the same task. There are 3 capture modes for port T pin. Capture rising edge, capture falling edge and capture both edges. 

0 Kudos

643 Views
Dora
Contributor I

Hello,

 

Where can I change polarity on port interrupt inside MCU's program or  setting.? Do you mean I need to set up on MCU's setting or program?

 

My MCU's setting is http://forums.freescale.com/freescale/attachments/freescale/PEGEN/122/1/port%20p.JPG, and program is which attach as below.

 

I really thank you so much.

0 Kudos

643 Views
kef
Specialist I

Like I said, you may change polarity on interrupt event. See PPSP register description. If you need pull device on this pin, then you should use external pull resistor, since PPSP controls not only active interrupt edge, but also pull direction of internal pull device. In Processor Exprect screen shot you have selected pull up (PPSP is programmed for pull up and falling edges), and that is why you see red explamation signs for rising edge, because it is not possible with internal pull up. So use external pull resistor and toggle PPSP bit on port interrupt.

0 Kudos

643 Views
Dora
Contributor I

Hello,

 

Is it possible to  use Port E pin for sensor instead of Port P?

 

Can Port E  read (1 or 0) when sensor detect or doesn't detect(both falling and rising edge together)?

 

Thanks in advance

 

0 Kudos

643 Views
kef
Specialist I

I still have no idea what are you doing and what are requirements of your sensor. But:

Port E pins are not interrupt capable. So you need to read pin levels periodically to detect if pin levels change or not. Since you probably can't read pin levels too often, you can miss some high->low->high or low->high->low transitions if these are too fast.

Port P pins are interrupts cabale, so you don't have to poll pin levels often. Instead you can set them so that interrupt is triggered when high->low or low->high transition occurs. Further you can determine if it was shor 1->0->1 pulse or 0->1->0 pulse or just falling or rising edge.

 

Please delete your new thread, since it is about the same problem. Don't flood forums with identical messages.

0 Kudos