Forums

Question about SDK programming.

Started by ritu_eshar January 28, 2003
Hi All,

Presently am working with 56807 EVM using codewarrior, but am
programming strictly in C.

I collected the following example, which functions such that when a
timer is fed with an input via the function generator, the
GPIO_B_PIN_7 follows suit. I.E. the rising and the falling edges of
the input are seen on the scope when the +ve end of the BNC is
connected to GPIO_B_PIN_7 and the -ve end to the GND.

INPUT SPECIFICATIONS: square waveform, 1 KHz, 50% DC, (0~2.80v) 1. My problem is that in this Timer values layout "/*
AssertWhenForced = */ 0," which BIT does this correspond to in the
Timer_CTRL or Timer_SCR.

2. I tried modifying the given SDK code to strict C, but the program
refuses to respond correctly.

Please find enclosed the SDK code and the strict C code follows that.
Can anyone please tell me where I am going wrong, I have been trying
to get this to work for quite sometime now but am not able to
comprehend as to where the problem lies.

Thanks in advance for your patience and help. Regards. Ritu. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SDK CODE:
#include "fcntl.h"
#include "quadraturetimer.h"

static void CallbackOnOverflow1(qt_eCallbackType CallbackType, void*
pParam);
static void CallbackOnCompare1(qt_eCallbackType CallbackType, void*
pParam);
static void CallbackOnInputEdge1(qt_eCallbackType CallbackType,
void* pParam);

const qt_sState quadParam1 = {
/* Mode = */ qtGatedCount,
/* InputSource = */ qtPrescalerDiv128,
/* InputPolarity = */ qtNormal,
/* SecondaryInputSource = */ qtSISCounter0Input, /* CountFrequency = */ qtRepeatedly,
/* CountLength = */ qtPastCompare,
/* CountDirection = */ qtUp,

/* OutputMode = */ qtAssertWhileActive,
/* OutputPolarity = */ qtNormal,
/* OutputDisabled = */ 1, /* Master = */ 0,
/* OutputOnMaster = */ 0,
/* CoChannelInitialize = */ 0,
/* AssertWhenForced = */ 0,

/* CaptureMode = */ qtBothEdges, /* CompareValue1 = */ 0xFFFF,
/* CompareValue2 = */ 0,
/* InitialLoadValue = */ 0,

/* CallbackOnCompare = */ { 0, 0 },
/* CallbackOnOverflow = */ { CallbackOnOverflow1, 0 },
/* CallbackOnInputEdge = */ { CallbackOnInputEdge1, 0 }
};

static UWord16 PortB;
static UWord16 Timer0;
static LastCounter = 0;

main()
{
PortB = open(BSP_DEVICE_NAME_GPIO_B, NULL);

ioctl(PortB, GPIO_SETAS_GPIO, gpioPin(B,7));
ioctl(PortB, GPIO_SETAS_OUTPUT, gpioPin(B,7));

ioctl(PortB,GPIO_SET,gpioPin(B,7));

#ifdef BSP_DEVICE_NAME_QUAD_TIMER_A_0
Timer0 = open(BSP_DEVICE_NAME_QUAD_TIMER_A_0, 0, &quadParam1 );
#endif

while(1) /* executive loop */
{
}
}

void CallbackOnOverflow1(qt_eCallbackType CallbackType, void* pParam)
{
}

void CallbackOnCompare1(qt_eCallbackType CallbackType, void* pParam)
{
}

void CallbackOnInputEdge1(qt_eCallbackType CallbackType, void*
pParam)
{
static UWord16 i = 0,j=0;
UWord16 NewCounter = 0;
if(i++ == 1)
{
i = 0;
NewCounter = ioctl(Timer0,QT_READ_CAPTURE_REG,NULL);
ioctl(PortB,GPIO_SET,gpioPin(B,7));
}
else
{
LastCounter = ioctl(Timer0,QT_READ_CAPTURE_REG,NULL);

ioctl(PortB,GPIO_CLEAR,gpioPin(B,7));
}
}

********************************************************************** C CODE:

/* File: main.c */

#include "stdio.h"
#include "dsp807Reg.h"

void IntRoutine(void);
void follow(void);
void gpio_clear(void);
void gpio_set(void);
static i = 0;
static lastcounter = 0;

void main (void)
{
TmrA0_CTRL = 0X7E00;
TmrA0_SCR = 0X00C1;
TmrA0_CMP1 = 0XFFFF;
TmrA0_CMP2 = 0X0000;
TmrA0_LOAD = 0X0000;

gpio_clear();

while(1)
{
follow();
}//end of while
return;
}//end of main

/********/
//
void follow(void)
{
static newcounter = 0;
asm(nop);
i++;
if((i%2)==0)
{
i = 0;
newcounter = TmrA0_CAP;
gpio_clear();
}//end of if
else
{
lastcounter = TmrA0_CAP;
gpio_set();
}//end of else
}//end of interrupt void gpio_set(void)
{
GPIO_B_IAR = 0X0000;
GPIO_B_IESR = 0X0000;
GPIO_B_IPR = 0X0000;
GPIO_B_IPOLR = 0X0000;
GPIO_B_IENR = 0X0000;
GPIO_B_PER = 0X0000;
GPIO_B_PUR = 0X0000;
GPIO_B_DDR = 0X00FF;//generate PULSE_HIGH i.e.gpiob7 == 1.
GPIO_B_DR = 0X00FF;
}

void gpio_clear(void)
{
GPIO_B_IAR = 0X0000;
GPIO_B_IESR = 0X0000;
GPIO_B_IPR = 0X0000;
GPIO_B_IPOLR = 0X0000;
GPIO_B_IENR = 0X0000;
GPIO_B_PER = 0X0000;
GPIO_B_PUR = 0X0000;
GPIO_B_DDR = 0X00FF;//generate PULSE_HIGH i.e.gpiob7 == 1.
GPIO_B_DR = 0X0000;
}

void IntRoutine(void)
{
asm(nop);
return;
}



RE: [motoroladsp] Question about SDK programming.

I am curious as to whether or not your code is in fact interrupting and entering both states of the interrupt routine?  if it is always executing the first state (i++==0) then it is no doubt the result of the fact that you have placed the "i" variable inside the scope of the interrupt routine, rather than outside as a global variable.  I am not sure that the "static" keyword will in fact make the variable retain its value through subsequent entries into the interrupt callback routine( The C Language would seem to indicate that it should be a global variable).  Since all uninitialized variables are in fact set to zero, have you tried removing the initialization code?  Does the variable in fact still get initialized to zero each time the interrupt routine is entered? Placing it outside (and probably changing the name) would insure that the state would not be initialized to zero every time the routine is entered.

In the "strict C" version shouldn't the variable 'i' be incremented in the interrupt routine?

Jerry.

-----Original Message-----
From: ritu_eshar <r...@yahoo.com> [mailto:r...@yahoo.com]
Sent: Tuesday, January 28, 2003 10:05 AM
To: m...@yahoogroups.com
Subject: [motoroladsp] Question about SDK programming.


Hi All,

Presently am working with 56807 EVM using codewarrior, but am
programming strictly in C.

I collected the following example, which functions such that when a
timer is fed with an input via the function generator, the
GPIO_B_PIN_7 follows suit. I.E. the rising and the falling edges of
the input are seen on the scope when the +ve end of the BNC is
connected to GPIO_B_PIN_7 and the -ve end to the GND.

INPUT SPECIFICATIONS: square waveform, 1 KHz, 50% DC, (0~2.80v)


1. My problem is that in this Timer values layout "/*
AssertWhenForced = */  0," which BIT does this correspond to in the
Timer_CTRL or Timer_SCR.

2. I tried modifying the given SDK code to strict C, but the program
refuses to respond correctly.

Please find enclosed the SDK code and the strict C code follows that.
Can anyone please tell me where I am going wrong, I have been trying
to get this to work for quite sometime now but am not able to
comprehend as to where the problem lies.

Thanks in advance for your patience and help. Regards. Ritu.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SDK CODE:
#include "fcntl.h"
#include "quadraturetimer.h"

static void  CallbackOnOverflow1(qt_eCallbackType CallbackType, void*
pParam);
static void  CallbackOnCompare1(qt_eCallbackType CallbackType, void*
pParam);
static void  CallbackOnInputEdge1(qt_eCallbackType CallbackType,
void* pParam);

const qt_sState quadParam1 = {
    /* Mode = */                    qtGatedCount,
    /* InputSource = */             qtPrescalerDiv128,
    /* InputPolarity = */           qtNormal,
    /* SecondaryInputSource = */    qtSISCounter0Input,        
       

    /* CountFrequency = */          qtRepeatedly,
    /* CountLength = */             qtPastCompare,
    /* CountDirection = */          qtUp,

    /* OutputMode = */              qtAssertWhileActive,
    /* OutputPolarity = */          qtNormal,
    /* OutputDisabled = */          1,                         
                       

    /* Master = */                  0,
    /* OutputOnMaster = */          0,
    /* CoChannelInitialize = */     0,
    /* AssertWhenForced = */        0,

    /* CaptureMode = */             qtBothEdges,               
       

    /* CompareValue1 = */           0xFFFF,
    /* CompareValue2 = */           0,
    /* InitialLoadValue = */        0,

    /* CallbackOnCompare = */       { 0, 0 },
    /* CallbackOnOverflow = */      { CallbackOnOverflow1, 0 },
    /* CallbackOnInputEdge = */     { CallbackOnInputEdge1, 0 }
};

static UWord16  PortB;
static UWord16  Timer0;
static LastCounter = 0;

main()
{
        PortB = open(BSP_DEVICE_NAME_GPIO_B, NULL);
       
        ioctl(PortB, GPIO_SETAS_GPIO, gpioPin(B,7));
        ioctl(PortB, GPIO_SETAS_OUTPUT, gpioPin(B,7)); 
       
        ioctl(PortB,GPIO_SET,gpioPin(B,7));
       
#ifdef BSP_DEVICE_NAME_QUAD_TIMER_A_0
    Timer0 = open(BSP_DEVICE_NAME_QUAD_TIMER_A_0, 0, &quadParam1 );
#endif
   
    while(1) /* executive loop */
    {
    }
}

void  CallbackOnOverflow1(qt_eCallbackType CallbackType, void* pParam)
{
}

void  CallbackOnCompare1(qt_eCallbackType CallbackType, void* pParam)
{
}

void  CallbackOnInputEdge1(qt_eCallbackType CallbackType, void*
pParam)
{
        static UWord16 i = 0,j=0;
        UWord16 NewCounter = 0;
        if(i++ == 1)
        {      
                i = 0;
                NewCounter = ioctl(Timer0,QT_READ_CAPTURE_REG,NULL);
                ioctl(PortB,GPIO_SET,gpioPin(B,7));
        }
        else
        {      
                LastCounter = ioctl(Timer0,QT_READ_CAPTURE_REG,NULL);
               
                ioctl(PortB,GPIO_CLEAR,gpioPin(B,7));
        }
}

**********************************************************************


C CODE:

/* File: main.c */

#include "stdio.h"
#include "dsp807Reg.h"

void IntRoutine(void);
void follow(void);
void gpio_clear(void);
void gpio_set(void); 
static i = 0;
static lastcounter = 0;

void main (void)
{
TmrA0_CTRL = 0X7E00;
TmrA0_SCR  = 0X00C1;
TmrA0_CMP1 = 0XFFFF;
TmrA0_CMP2 = 0X0000;
TmrA0_LOAD = 0X0000;

gpio_clear();

while(1)
{
follow();
}//end of while
return;         
}//end of main

/********/
//
void follow(void)
{
static newcounter = 0;
asm(nop);
i++;
if((i%2)==0)
{
i = 0;
newcounter = TmrA0_CAP;
gpio_clear();
}//end of if
else
{
lastcounter = TmrA0_CAP;
gpio_set();
}//end of else
}//end of interrupt


void gpio_set(void)
{
GPIO_B_IAR    = 0X0000;
GPIO_B_IESR   = 0X0000;
GPIO_B_IPR    = 0X0000;
GPIO_B_IPOLR  = 0X0000;
GPIO_B_IENR   = 0X0000;
GPIO_B_PER    = 0X0000;
GPIO_B_PUR    = 0X0000;
GPIO_B_DDR    = 0X00FF;//generate PULSE_HIGH i.e.gpiob7 == 1.
GPIO_B_DR     = 0X00FF;
}

void gpio_clear(void)
{
GPIO_B_IAR    = 0X0000;
GPIO_B_IESR   = 0X0000;
GPIO_B_IPR    = 0X0000;
GPIO_B_IPOLR  = 0X0000;
GPIO_B_IENR   = 0X0000;
GPIO_B_PER    = 0X0000;
GPIO_B_PUR    = 0X0000;
GPIO_B_DDR    = 0X00FF;//generate PULSE_HIGH i.e.gpiob7 == 1.
GPIO_B_DR     = 0X0000;
}

void IntRoutine(void)
{
asm(nop);
return;
}



_____________________________________
Note: If you do a simple "reply" with your email client, only the author of this message will receive your answer.  You need to do a "reply all" if you want your answer to be distributed to the entire group.

_____________________________________
About this discussion group:

To Join:  m...@yahoogroups.com

To Post:  m...@yahoogroups.com

To Leave: m...@yahoogroups.com

Archives: http://www.yahoogroups.com/group/motoroladsp

More Groups: http://www.dsprelated.com/groups.php3
 

" TARGET="_blank">http://docs.yahoo.com/info/terms/



________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs SkyScan
service. For more information visit http://www.messagelabs.com
________________________________________________________________________


________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs SkyScan
service. For more information visit http://www.messagelabs.com
________________________________________________________________________