1222.FlashingLight_14122013_0537.zip
Hello All,
I am working for a project in which i am using SM470R1B1M micro-controller,
I am facing an issue while using the real time timer. after filling up the
registers which appropriate PRELOAD and Counter values, i am not getting
the timer for which i configured.
Here for example i have added my code in attachment in which i am using a
OSCIN as 8MHz & configured SYSCLK of 32 MHz,and as per that if i am writing
PRELOAD as 1 and upcounter value as 1, it should give me interrupt at every
(1/(32MHz)), but i am getting interrupt at every 2,1 us. which is not
matching with my register settings and the clock.
Settings:
Crystal Clock = 8MHz
SYSCLK = 32MHz using PLL
RTIPCTL = 1
RTICMP1 = 1
Comparator 1 enabled.
Here is my code :-
#include <intrinsics.h> #include <TexasInstruments/iotms470r1b1m.h> #include <TexasInstruments/tms470r1B1m_bit_definitions.h> int * ip; void SM470LedSet(int mask); void COMP1_irq_handler(void); void toggle_led(void); int main(void) { static unsigned char flag = 0; unsigned int temp; // Set up peripheral registers. // First disable interrupts. __disable_interrupt(); /*ip = led_table; // Setup system. PCR = CLKDIV_4; // ICLK = SYSCLK/4 PCR |= PENABLE; // enable peripherals GCR = ZPLL_CLK_DIV_PRE_1; // SYSCLK = 8 x fOSC REQMASK = (1 << CIM_COMP1); // Enable SPI Interrupt mask*/ GCR &= ~ZPLL_MULT4;// SYSCLK = 8x 8MHz = 64MHz //--------Divides the clock by 2 so sysclock becomes 64/2 = 32 MHz---// GCR |= ZPLL_CLK_DIV_PRE1; GCR &= ~ZPLL_CLK_DIV_PRE2; GCR &= ~ZPLL_CLK_DIV_PRE3; //------------------------------------------------------------------// PCR &= 0x0000; // ICLK = SYSCLK (32MHz) PCR |= PENABLE; // Enable peripherals CLKCNTL |= CLKDIR | CLKSR_SYSCLK; // Setup periodic interrupt using RTI with RTICMP1 RTICNTEN = CNTEN_NOCNT; // Stop counting RTICNTR = 0x00; // clear 21-bits CNTR // Setup periodic interrupt timer // CMP1 used to generate interrupt. RTIPCTL = 1; // preload 11-bits MOD -> 32 MHz/32 = 1MHz RTICMP1 = 1; // 1 MHz/1000000 = 1 Hz RTICNTL = 0x00; // clear and disable tap // interrupt control, clear CMP1 and enable CMP1 interrupt RTICINT = 0x00; RTICINT |= CMP1ENA; // Start count, CNTR and MOD will count in both USER and SYSTEM mode RTICNTEN = CNTEN_UP; REQMASK |= (1 << CIM_COMP1); //FIRQPR |= (1 << CIM_COMP1); HETDIR |= 0x0100; // HET8 are outputs HETDCLR = 0x0100; // Clear HET8 outputs //__enable_fiq(); __enable_interrupt(); // Enable Interrupts RTICNTR = 0x00; // clear 21-bits CNTR // Loop forever. while (1) { #if 0 temp = RTICINT; if((temp & 0x80) == 0x80) { RTICINT &= ~CMP1FLAG; // interrupt control, clear CMP1 RTICNTR = 0x00; if(flag) { HETDSET = 0x0100; // Set HET8 outputs //flag = 0; } else { HETDCLR = 0x0100; // Clear HET8 outputs //flag = 1; } flag = ~flag; } // else // HETDSET = 0x0100; #endif } } //------------------------------------------------------------------------------ // TMS470R1B1M Standard Interrupt Handler //------------------------------------------------------------------------------ __irq __arm void IRQ_Handler(void) { static unsigned char flag = 0; switch((0xff & IRQIVEC)-1) { case CIM_COMP1 : &= ~CMP1FLAG; // interrupt control, clear CMP1 RTICNTR = 0x00; // clear 21-bits CNTR if(flag) { HETDSET = 0x0100; // Set HET8 outputs //flag = 0; } else { HETDCLR = 0x0100; // Clear HET8 outputs //flag = 1; } flag = ~flag; break; } }
Any type of help regarding this will be appreciated.
P.S. I have also attached the Project which i used for the timer setup.
Regards,
Amjad
+919920553779