Hi,
I need to generate a very fast signal (40 KHZ) (which consists of an array of 0s and 1s) and this signal is sent to one of the GPIO pins on ez430-rf2500 board. This array is generated based on the values of the other array that is read from the memory (I declared this other array as a const array at the begining of the code).
I use 16MHz DCO and a TimerB to generate the fast interrupts that will trigger reading of const array values and generate an output signal at the GPIO. Also, I use IAR Workbench 4.11b.
So, my code looks something like this:
main()
{
... // some code goes here
TimerB0_Init();
do
{
__bis_SR_register(LPM0_bits + GIE);
ReadCoeff();
}while(TimerControl==0);
... // some code goes here
}
void ReadCoeff()
{
if (aCounter >= COEFFICIENT_LENGTH-1)
{
TimerControl = 1;
aCounter = 0;
cCounter = 0;
}
if (cCounter == 0) //read new coeff
{
m_coeff = coeffs[aCounter];
aCounter++;
}
if (m_coeff != 0)
{
switch (cCounter)
{
case 0:
P2OUT &= ~(BIT1);
break;
case 3:
P2OUT &= ~(BIT1);
break;
default:
P2OUT |= (BIT1);
break;
}
switch (m_coeff)
{
case 1:
P2OUT |= (BIT2);
break;
case 2:
P2OUT &= ~(BIT2);
break;
default:
break;
}
}
}
void TimerB0_Init()
{
TBCCTL0 = CCIE; // TBCCR0 interrupt enabled
TBCCR0 = TIMER_PERIOD; // TIMER_PERIOD = 100;
TBCTL = TBSSEL_2 + MC_1; // SMCLK, upmode
}
#pragma vector=TIMERB0_VECTOR
__interrupt void Timer_B (void)
{
switch (TimerControl)
{
case 1:
... // some code goes here
break;
default:
__bic_SR_register_on_exit(LPM0_bits);
break;
}
}
However, it seems that I cannot generate the output signal at the GPIO so fast: by looking on the output at the oscilloscope, I see that some signal samples on the GPIO are missing -- like it takes too much time to go through the ReadCoeff() and an interrupt occurs before the end of this function. But, the TIMER_PERIOD, that controls the number of cycles before an interrupt occurs is set to 100 -- by looking into the number of instructions called during the ReadCoeff() on IAR it seems that 100 cycles is enough for the MSP430 to go through the ReadCOeff() function.
So, my question is why I cannot generate the fast signal by using my code?
Is there a better routine that I should use in order to generate a high frequency signal at the GPIO?
Any input is really appreciated, thanks!