polling i/o pins

Discussion in 'Programmer's Corner' started by cktcrazy, Jul 27, 2011.

  1. cktcrazy

    Thread Starter New Member

    Mar 27, 2011

    can any one tell me about polling method ands its defination

    once in a interview i was asked about polling

    i was given 95% high and 5% low period of a duty cycle of 1msec
    coming into a port pin. write a program in polling method so that the mcu
    recognize the high and low period.

    can any one have any suggestion to this question
    plz help me

  2. lightingman

    Senior Member

    Apr 19, 2007
    In Picbasic it would be along the lines of this to time a pulse:-

    Dim period as dword (create a variable)

    period = Pulsin, pin?, 1 (wait for the pin to go high and time the high period)

    If period > ? then (if the high time is higher than?)
    (code here) do some code
    end if


    If period < ? then (if the high time is lower than?)
    (code here) do some code
    end if
    cktcrazy likes this.
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    Sure. When a computer wants to know what the outside world is doing it has several ways to see what is happening.

    The first is a simple read. A port or pin is read, and that value is what it is.

    The next way involves a little hardware. When something external has some information to send it issues an interrupt. An interrupt is half hardware, half software. When a computer gets an interrupt signal it stops what it is doing, makes a note of where it was, then runs the interrupt code, sometimes called an Interrupt Service Routine (ISR). Once the ISR completes, it looks up what it was previously doing and returns there.

    Interrupts may come from several places and have several priorities, meaning one interrupt can interrupt another interrupt routing.

    Halfway between these two is polling. Here to "poll" has the same meaning as it does on election day: we ask. When there is an input may change sometime, and we don't need to know exactly when it changed (or we'd use an interrupt) we can every so often go out and read the pin or port and see what it is up to.
    cktcrazy likes this.
  4. nigelwright7557

    Senior Member

    May 10, 2008
    Polling is simply looking at an i/o port now and then to see if it has changed.
  5. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    As an interview question it looks like they were wanting to test if you know how often (how fast, ie frequency) you would have to poll to successfully detect the high and low levels of a 1mS period that has 95% HI and 5% LO.

    As the shortest period would be 5% of 1mS (5% * 1000uS = 50uS) you would need to poll the input more frequently than 50uS to detect it.

    So 1 / 50uS = 20kHz. Preferably somewhat higher than that to give a safety margin.
    cktcrazy likes this.