AnsweredAssumed Answered

Strange code behavior

Question asked by karpavicius.linas on Nov 7, 2014
Latest reply on Nov 8, 2014 by Clive One
I am working on project where i need to drive pjezo motors ( special triangle wave )

for generating forward or backward step i use timer controlled DMA , that copies triangle wave data to DAC output. This part is working, but i can't found any glitch.

glitch is, code only going to step, if difference is larger than 1, that means, if i try to step, it will not work, if i say, step 10 times, it will step 9 times.
int main(void)
{
  Delay(0xFFFFFF);
  ADC_Configuration();
  fill_array();
  GPIO_Int();
  Enable_Power();
  TIM_Config();
  DMA_Trigger_Config();
  DAC1_Config();
  DAC2_Config();
  EXTI_Int();
 
  while(1)
  {
    update_variables();
    if(pico_x<pico_x_current)
    {
      step1=0; // Go backwards
      pico_x_current--;
    }
    if(pico_x>pico_x_current)
    {
      step1=1; // Go_forward
      pico_x_current++;
    }
    if(pico_x==pico_x_current)
    {
      step1=3; // go nowhere, but use DAC time
    }
    if(pico_y<pico_y_current)
    {
      step2=0;// Go backwards
      pico_y_current--;
    }
    if(pico_y>pico_y_current)
    {
      step2=1;// Go_forward
      pico_y_current++;
    }
    if(pico_y==pico_y_current)
    {
      step2=3;// go nowhere, but use DAC time
    }
    DAC_CH1_Step(step1);
    DAC_CH2_Step(step2);
    DMA_Cmd(DMA1_Stream5, ENABLE);
    DMA_Cmd(DMA1_Stream6, ENABLE);
    NTC_Temp(); // monitor Flyback switch temperature
    DAC_Voltage(); // monitor voltage levels on HV bus
    while((DMA_GetITStatus(DMA1_Stream5, DMA_IT_TCIF5))==RESET);
    while((DMA_GetITStatus(DMA1_Stream6, DMA_IT_TCIF6))==RESET);
    DMA_ClearITPendingBit(DMA1_Stream5,DMA_IT_TCIF5);
    DMA_ClearITPendingBit(DMA1_Stream6,DMA_IT_TCIF6);
     
  }
     
 
}
 
void update_variables(void)
{
  pico_x = SPI_DATA_Rx[0]; // get data from computer
  pico_y = SPI_DATA_Rx[1]; // get data from computer
   
  SPI_DATA_Tx[0] = pico_x_current;//send data to computer
  SPI_DATA_Tx[1] = pico_y_current;//send data to computer
  SPI_DATA_Tx[2] = pico_voltage;/send data to computer
  SPI_DATA_Tx[3] = pico_temp;//send data to computer
  SPI_DATA_Tx[4] = pico_error;//send data to computer
   
}
 
void DAC_CH1_Step(int dirrection)
{
  if(dirrection==0)
  {
    DMA_InitStructure1.DMA_Memory0BaseAddr = (uint32_t)&backward_1;
  }
  else
  {
    DMA_InitStructure1.DMA_Memory0BaseAddr = (uint32_t)&forward_1;
  }
  if(dirrection==3)
  {
    DMA_InitStructure1.DMA_Memory0BaseAddr = (uint32_t)&none;
  }
   
   
  DMA_Init(DMA1_Stream5, &DMA_InitStructure1);
}
 
void DAC_CH2_Step(int dirrection)
{
  if(dirrection==0)
  {
    DMA_InitStructure2.DMA_Memory0BaseAddr = (uint32_t)&backward_2;
  }
  else
  {
    DMA_InitStructure2.DMA_Memory0BaseAddr = (uint32_t)&forward_2;
  }
  if(dirrection==3)
  {
    DMA_InitStructure2.DMA_Memory0BaseAddr = (uint32_t)&none;
  }
  DMA_Init(DMA1_Stream6, &DMA_InitStructure2);
}

Somehow i don't understand why i can step with size smaller than 2. if i make single step, current position tracker will change as it should

I am using spi to copy data from computer over DMA, so no additional code is needed, this part works fine ( Circular buffer)

Outcomes