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.

CCS/TM4C123GH6PM: Input edge counter stuck

Part Number: TM4C123GH6PM

Tool/software: Code Composer Studio

Hi for every one 
I'm trying to use timer0 as input edge counter, i did all the steps mentioned in the data sheet but I've no response at all .

this my code

#include "tm4c123gh6pm.h"
void systemClockInit()
{
SYSCTL_RCC_R = 0x0;
SYSCTL_RCC_R |= (1<<0);// Enable the main oscillator
SYSCTL_RCC_R &= ~(3<<4);// configure main oscillator as input
SYSCTL_RCC_R |= (0x15<<6);// 16M OSC.
SYSCTL_RCC_R &= ~(1<<11);// Enable PPL
SYSCTL_RCC_R |= (1<<20);// Disable PWM clock division
}
void enableBusAndClock()
{
SYSCTL_GPIOHBCTL_R = 0x3B;// Enable AHB for Ports {A,B,D,E,F}
SYSCTL_RCGCGPIO_R = 0x3B;// Enable clock for ports {A,B,D,E,F}
}
void alterantivePinSet()
{

GPIO_PORTB_AHB_AFSEL_R = 0xF3;// Alternative Pin set for B {0,1,4,5,6,7} Counter
GPIO_PORTB_AHB_DIR_R = 0xF3;
GPIO_PORTB_AHB_DEN_R = 0xF3;

GPIO_PORTD_AHB_AFSEL_R = 0x01;// Alternative Pin set for D {0} PWM
GPIO_PORTD_AHB_DEN_R = 0x01;// Enable Digital function
/

GPIO_PORTB_AHB_PCTL_R |= (7<<0)|(7<<4)|(7<<16)|(7<<20)|(7<<24)|(7<<28);// Enable counter function on Port B pins

GPIO_PORTD_AHB_PCTL_R |= (5<<0);// Enable PWM function on D {0}

}
void timersConfiguration()
{
SYSCTL_RCGCTIMER_R = 0x07;// Enable clock to Timers {0,1,2}

TIMER0_CTL_R &= ~(1<<0);// Disable the timer 0
TIMER0_CFG_R = 0x4;// Configuring the module 0 as counter
TIMER0_TBMR_R = (0x03)|(1<<4);// Configuring the module (0,B) as counter and as up counter
TIMER0_CTL_R &= ~(3<<10) & ~(3<<2);// Configuring module {A,B} positive edge
TIMER0_TBPMR_R = 0x0;// configuring APMR to 254

TIMER0_TBMATCHR_R = 0xFF;
TIMER0_TBPR_R = 0xFF;
TIMER0_TBILR_R = 0x0000FFFF;

TIMER0_CTL_R |= (1<<0);// Enable the timer 0

}

int main(void) {


systemClockInit();
enableBusAndClock();
alterantivePinSet();
timersConfiguration();

while(1)
{

}

}

 

  • Hi Ahmed,

    I did not follow you code completely, however here are few quick observations:

    - I don't see any interrupt ISR for your counter.match.

    - Have tried using Tivaware for your peripheral config ? Its lot easier and better way of doing it. If in case you make you mind to use Tivaware, refer this link below.....  

    Hope this help.

    BR,

    Pranav.

  • I'm sorry for not mention that but i just want to read the value of GPTMTAR ( the number of counts ) every 200ms ( that will be done later using Systick ) but as i said input edge counter is responding
  • Please refer to tip #4 in this FAQ. e2e.ti.com/.../695568

    In general we don't support DRM. If you have a special requirement where you must use DRM then you can reference how the TivaWare API implements the DRM code.

    Use the register browser window to see if all the registers are properly configured and check if the counter is counting.
  • Ahmed khudair said:
    I'm trying to use timer0 as input edge counter, i did all the steps mentioned in the data sheet but I've no response at all .

    When a timer is (really) employed as an 'Edge Counter' - it is usual to provide an input signal to that timer's 'I/O pin' - is it not?      Earlier  arriving posters  appear to have missed or discounted this (very) real need!

    You've not described your having provided this vital input signal ...  although my quick scan of your code reveals PD0 (which your code starts to configure as a candidate PWM output signal) to be a  'likely suspect.'      Thus - should my 'reconstruct' of your intent prove correct - you must complete the configuration of PD0 to serve as your 'Signal Generator' - which drives your timer0 - set to count  (input) signal edges.     No mention of  that 'Signal Generation and Routing to your chosen Timer' input pin was noted - it is (surely) required.

    Note too - if you're using the 123 LPad - that you (as hundreds before you) may have become impaled by the vendor's 'delightful' decision - to, 'Tie PD0 to PB6!'    (also PD1 to PB7 - those 'Devil Pair'  joined via 0Ω resistors (R9/10) best described as 'Plague-istors.')    Depending upon how PB6 has been ordered - it may prevent PDO from outputting your desired signal - intended to exercise timer0.     Often it proves wise to use 'other than' PD0/PD1 as your signal generator - or remove & 'tombstone' those devil parts - so that the board's 'FIX' is clearly noted...    ('tombstone' - tack solder (only) 1 lead - w/the device vertical - as in a graveyard)

    As others have noted - use of 'DRM' (especially only 'sporadically commented' DRM) adds great time/effort to the task of your hapless helpers - which proves NOT to your advantage.

    You must insure the creation of a proper pulse input signal (and most often - confirm its presence)  to your Timer's input pin - before there is ANY hope - to see that timer increment/decrement...

  • the PD0 is used as PWM for controlling  a motor ( but PWM initialization is not mentioned her because it worked well  ), PB6 is used to count the number of pulses from optical encoder, the signal of the encoder is tested on Oscilloscope,  

  • Those two (new) facts you've supplied are helpful - perhaps should have been included w/in your initial posting.     (note that I was able to discern your use of (both) PB6 (as timer input) and PD0 (as PWM Generator - although its routing to a motor was (of course) unknown.)      While those 2 'new facts' are helpful - they prove insufficient - to properly diagnose your issue.    

    It is uncertain (still) if you are using the TM4C123's Launch Pad (LPad).     That  IS important - as my initial post noted - as  your two key/critical (and self-chosen) MCU pins (PD0 & PB6) are shorted together by a 0Ω resistor - 'inconveniently & unexpectedly' placed (despite user protests) upon the 123 LPad!      (I'm at a loss as to why your use of the '123's LPad - remains a 'mystery.'    I'd bet highly that you've chosen the LPad - and if that's so - the 'dead short' imposed between those 2 pins (again, PD0 & PB6) - cannot AID your efforts!)

    You note the, 'Signal of the encoder is tested on a scope' - while that's 'good' - the (necessary) 'operating conditions' of such 'test' were omitted!      Was the scope connected to PB6 - while your code was running - and while the (still suspected 'LPad') was, "Shorting PB6 (timer input) to PD0!"     (your PWM output)

    Unexplained is which Timer Register you've chosen to examine - which resulted in your report of, "No response at all ."     Register 'GPTMTBR' seems a 'likely candidate.'     (possibly GPTMTBV as well.)     I must note that your use of,  'Timer B' (rather than Timer A - which simplifies) is also unexplained...

    All helpers responding to you have noted the added complexity which the use of  DRM imposes - it is assumed that this extra effort/inefficiency  has been 'forced' upon you.     You may fully study the individual MCU Registers 'in play' - while employing the vastly more efficient (and heavily exampled) MCU's API.      (the API exists for (very) good reason - those using DRM (MOST ALWAYS) wind up here!)    The 'promise' of 'advanced learning' (via DRM) - somehow (NEVER) being quite delivered - 'pain/suffering'  (as you've witnessed) is the  (FAR more) expected  DRM  'norm!'

  • Hi cb1,

     Thanks for your guidance.   It seems like the poster is not enabling the timer0_B but rather timer0_A when his intention is to use timer0_B. He has configured timer0_B for the load and match registers but the timer0_B enable bit is at bit position 8, not bit 0. Bit 0 of CTL_R is to enable timer0_A instead. 

    TIMER0_CTL_R &= ~(1<<0);// Disable the timer 0

    TIMER0_CFG_R = 0x4;// Configuring the module 0 as counter

    TIMER0_TBMR_R = (0x03)|(1<<4);// Configuring the module (0,B) as counter and as up counter

    TIMER0_CTL_R &= ~(3<<10) & ~(3<<2);// Configuring module {A,B} positive edge

    TIMER0_TBPMR_R = 0x0;// configuring APMR to 254

    TIMER0_TBMATCHR_R = 0xFF;

    TIMER0_TBPR_R = 0xFF;

    TIMER0_TBILR_R = 0x0000FFFF;

    TIMER0_CTL_R |= (1<<0);// Enable the timer 0

  • Hi Charles,

    Booth Duty (Automatica's last day) calls - yet the 'expected' DEAD-SHORT (imposed by '123 LPad') upon (both) poster's PD0 and (timer input) PB6 MUST RECEIVE 'high and continued note!'    (even though - especially though - the issue has LONG BEEN KNOWN ... and been ALLOWED TO PERSIST!)

    It is (even) possible that PD0's, 'OUTPUT CONTENTION' with poster's Motor Encoder - has 'KILLED' his encoder!     (that would be especially unfortunate - yet again is a consequence of vendor's AVOIDING the ELIMINATION of the (very) RISKY BUSINESS: 'Shorting PD0-PB6 & PD1-PB7!')

    Poster was asked multiple times to confirm, "Use of LPad..."

  • Hi cb1,
    I acknowledge your concern. In poster's intended timer operation he chooses timer0_B which corresponds to PB7 which is also connected to PD1 via the 0ohm resistor. However, he is not using PD1 for PWM at the moment. I agree that the best solution is to break the the two 0ohm resistors. With that said, the poster should first fix the code to enable/disable the proper timer. As indicated, he is enabling timer0_A while his choice of the timer is timer0_B which is still disabled.