This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

USING CAPTURE COUNT TIMER TO COUNT NO OF PULSE

Other Parts Discussed in Thread: TM4C123GH6PM

HI,Sir i am trying to interface tv remote to tiva.For that purpose i have connected my TSOP SM0038 IR sensor on the PD2 PIN.To count the number of pulses received on IR SENSOR(TSOP),I am using timer wtimer3 which is on pin no PD2 and diplaying the count of pulses on my serial monitor using UART.   SIR,,,Im not gettting any o/p on my serial monitor...?


#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include "driverlib/adc.h"
#include "driverlib/uart.h"
#include "driverlib/interrupt.h"
#include "utils/uartstdio.h"
#include "inc/hw_timer.h"
#include "driverlib/timer.h"
#include "inc/hw_ints.h"
#include "driverlib/pin_map.h"

void InitConsole(void)
{

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    /* Make the UART pins be peripheral controlled. */
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    /* Initialize the UART for console I/O */
    UARTStdioInit(0);
}


void WTimer3AIntHandler(void)
{
    int count=0,state=0;
    // Clear the timer interrupt
    TimerIntClear(WTIMER3_BASE,TIMER_CAPA_EVENT);
    count=TimerValueGet(WTIMER3_BASE,TIMER_A);
    UARTprintf("count elapsed : %d \n",count);

     if(state)
 {GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1,0);
  state=0;
 }
 else {GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1,GPIO_PIN_1);
           state=1;
      }


}


int main(void)
{


    /*Set the clocking to run at 80Mhz from the crystal of 16MHz using PLL*/
    SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

    /* Set the clock for the GPIO Port F */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

    /* Set the type of the GPIO Pin */

    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1);
    GPIOPinTypeGPIOInput(GPIO_PORTD_BASE, GPIO_PIN_2);

    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1,0);

    //TimerDisable(WTIMER1_BASE, TIMER_A);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER3);

    /*Configure GPIO pad with internal pull-up enabled*/
        GPIOPadConfigSet(GPIO_PORTD_BASE, GPIO_PIN_2, GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);

        //GPIOIntTypeSet(GPIO_PORTD_BASE, GPIO_PIN_2, GPIO_FALLING_EDGE);


    TimerConfigure(WTIMER3_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PERIODIC|TIMER_CFG_A_CAP_COUNT);
    TimerControlEvent(WTIMER3_BASE,TIMER_A,TIMER_EVENT_NEG_EDGE);

    /* UART config */
        InitConsole();


    IntMasterEnable();
    TimerIntRegister(WTIMER3_BASE, TIMER_A, WTimer3AIntHandler);
    TimerIntEnable(WTIMER3_BASE, TIMER_CAPA_EVENT);


    IntEnable(INT_WTIMER3A);
    TimerEnable(WTIMER3_BASE,TIMER_A);

    while(1)
    {

    }

}

  • If you can eliminate the use of, "Sir" I'll try to assist.

    You report, "Not getting any output on your serial monitor."  And you reveal nothing further as regards your, "disassembly" of this problem - and logical attempts to resolve.  I'd like you to solve this - here's a roadmap:

    a) Do you not, "hold your project hostage" to the correct/proper functioning of both your MCU's UART and its interconnect to the serial monitor and/or the proper mating of all communication parameters?  Is this wise or efficient?  Is there a better way?

    b) Your project is composed of multiple parts - all individual segments must work - for the final result to please.  Your post reveals only that the (likely) "last piece" - the viewing of the serial monitor - has failed.  Should not you attempt to break this project into smaller, measurable, individual parts?  And then - test each one - on an individual basis.  The method you've used (examine only the end result) provides little (NO) insight into which part (or parts) has failed to perform.

    c) You identify your IR detector - even detailing its package - but provide no insight as to its "match" to the "mated" TV remote.  Depending upon geography - sometimes even brand - the carrier frequency may not be well mated.  This may cause the IR detector to "miss" portions of the TV remote's output - unless very close in range & well aimed.

    d) We know nothing of your test equipment nor experience.  Perhaps it makes sense to irradiate that IR detector - and then confirm that it is responsive to that TV remote.  Scope would be ideal there (these are pulses - after all) to confirm the detector's acceptance of the radiation.  Is this not a proper, "first step?"

    e) Detector's signal routes to your PD2 - surely you've checked/confirmed that no other connections nor components intrude - that pin.  (large cap here could wreak havoc)

    f) If the detector's output does reach PD2 - and if PD2 is indeed a Timer pin (and proper for WTimer3) should you not then attempt to, "Read that timer register?"  There are various IR schemes - some may not be easy/quick to grasp nor decode.  (let's hope that's not your case)  Ideally - you should observe different counter values for different remote button presses.  Alas - some remote codes employ various, "bit on times" - which may not be appropriate for simple counting.  (it's been good 10 years since my group last did something similar - want you to have this awareness)

    g) If you can resolve (f) above then (and only then) does it make sense to attempt the simplest form of UART communication.  Eliminate use of your counter variable - instead transfer simple, "ABC - TEST."  The goal is to verify that the communication link works - later you can "tailor" the critical data to that channel.

    This listing is an example of "KISS" - most always the reduction of a large or bit complex task into its constituent parts speeds, eases & enhances the end result...

  • Hi,cb1_mobile

    sir,

    just in case if you are thinking that i have directly jumped to capture count mode of timer to count the no of pulses received by the ir sensor ,then it is not he case here.MAYBE My setup is correct and working prpoerly ,,problem is with the software part.I am saying this because...

    1.I got my project working using same remote and ir sensor on arduino...so problem related to ir sensor and remote rules out.

    2.Coming back to my present setup ,,,i have already used the same hardware and i was getting output on my serial monitor..which shows that same hardware is compatible with TIVA also.

    3.And in the end regarding that "sir" part you mentioned in the top, I would continue to address you like that,, because by doing so i m paying my respect to the status you have got on the forum.......

     I can also attach my previous working code ..if u want to have a ,look...

    Thanks for the "KISS" part also...i would continue to focus on that part also.

  • Mon ami,

    mahavir dwivedi said:
    just in case if you are thinking that i have directly jumped to capture count mode of timer

    Rather than, "Just in case" - with the limited info you initially supplied - how could anyone here have thought/anticipated otherwise?  ANS: (they could not)

    Let's look @ your (now provided) "past" diagnostic report: 

    1) You used the same remote & IR sensor - that's good input - but if you made "any" changes - then it's possible that past success may not "automatically" continue.  (clearly yours is a prototype - thus "everything" is suspect.  i.e. bad solder joint, miswire etc.)  As you past drove (& connected to) another's MCU - changes necessarily were made...

    2) If we can properly interpret, "same hardware" as your TM4C MCU - then we have reason to believe your serial interconnect & serial parameters are correct.  (but - your final clause, "same hardware is compatible w/TIVA also" may be replaced with: "Tiva is compatible w/Tiva!"   (via replacement logic)  Seems that better detailing is required - does it not?)  Unclear problem listing by posters wastes time/effort - yours, readers & "helpers"...

    3) Might you show better (and more effective) respect by providing necessary detail - as outlined above?  Suggest that you consider the term, "Style over Substance."  Again - real (heartfelt) respect results from focused, well-considered detail...

    Absent - your most recent writing - your report of results obtained via the (e) & (f) details of this reporter's initial post.  Why is that?  Is not that a logical place to probe & investigate?... (as past stated - that's my belief...) 

  • Hello Mahavir,

    I think what is missing is the configuration of the Pin PD2 for timer function (unless I am missing something else).

        GPIOPinTypeTimer(GPIO_PORTD_BASE, GPIO_PIN_2);
        GPIOPinConfigure(GPIO_PD2_WT3CCP0);

    And not setting it in input mode.

    Regards

    Amit

  • cb1_mobile said:
    if PD2 is indeed a Timer pin (and proper for WTimer3) should you not then attempt to, "Read that timer register?

    Appears that guidance was encapsulated by an earlier post.  (above)  Minus register readings - incorrect set-up would be, "prime suspect" - and poster may have, "really learned!"

    There's a proverb, "Teach a man to fish - he can then feed himself for life." 

    My take - "Sir spewing poster" requires such "teaching."  One fish - "wrapped/special delivered" his door - not so much...

    Several have noted past, "Forum Guidelines" sticky has gone EOL after 30 days, "prime-time."  (iirc 800+ views/hits in those 30 days proved reasonable interest {well exceeded "gpio problems'" hit rate})  Thus - "teaching to fish" via templates/methods are trashed while "wrapped/delivered" (thus little taught) continue - and continue...  (and bad habits/methods are encouraged...)

  • Thanks for the reply sir ,,,

    after including the above functions I am getting an error related to the GPIOPinConfigure(GPIO_PD2_WT3CCP0);..The error message is displaying that .........Symbol 'GPIO_PD2_WT3CCP0' could not be resolved......What should i do now?

     

  • Lost in this is the fact that poster reports, "No output from his serial monitor!"  And that is unlikely to result (solely) from any timer set-up/config error - unless the timer directly calls that serial output function.  Such, "unhostage held" use of the serial output function was (long & past) advised by this reporter...  (to silence)

    Let the flow of, "single issue" bandaid code fixes begin.  (cb1 {aka sir} - necessarily departs)

  • Hello Mahavir,

    You would need to include the file driverlib/pin_map.h and also the define for the part which would be something like PART_TM4C12?? where ?? would be based on the part.

    E.g. If the part you have is TM4C123GH6PM then it would be PART_TM4C123GH6PM

    Regards

    Amit