Page 1 of 1

missing signal on PA6

Posted: Wed Nov 11, 2020 7:49 pm
by stan
Hi
This is a generator code, I have a signal on PB7 but can't get second output on PB6.

Code: Select all

#define SAMPLES 77
#include <libmaple/dma.h>
dma_tube_config dma_cfg, dma_cfg2;
int flag = 0;
int flag1 = 0;
int out = PB6;
int out1 = PB7;
int val[SAMPLES];
int val1[SAMPLES];


int16 shift = 0;


int amp = 40;
int cnt = 0;
int time_track = 0;
float stp = 6.2831 / SAMPLES;
int ret = 17;


timer_dev *dev = PIN_MAP[out].timer_device;
uint8 cc_channel = PIN_MAP[out].timer_channel;
timer_dev *dev1 = PIN_MAP[out1].timer_device;
uint8 cc_channel1 = PIN_MAP[out1].timer_channel;


void fun()
{
  flag++;
}
void fun1()
{
  flag1++;
}


void timer_conf()
{
  /////////////
  timer_dma_set_base_addr(dev, TIMER_DMA_BASE_CCR2);
  timer_dma_set_burst_len(dev1, 1);
  timer_dma_enable_req(dev, cc_channel1);
  timer_set_reload(dev, 102);
  timer_set_prescaler(dev, 0);
  ///////////////
  timer_dma_set_base_addr(dev1, TIMER_DMA_BASE_CCR2);
  timer_dma_set_burst_len(dev1, 1);
  timer_dma_enable_req(dev1, cc_channel1);
  timer_set_reload(dev1, 102);
  timer_set_prescaler(dev1, 0);
}


void dma_conf()
{
  dma_init(DMA1);
  /* T4C2 DMA C4 */
  dma_cfg.tube_dst = &(dev->regs.gen->DMAR);
  dma_cfg.tube_dst = &(dev1->regs.gen->DMAR);
  dma_cfg.tube_dst_size = DMA_SIZE_32BITS;
  dma_cfg.tube_src = val;
  dma_cfg.tube_src = val1;
  dma_cfg.tube_src_size = DMA_SIZE_32BITS;
  dma_cfg.tube_nr_xfers = SAMPLES;
  dma_cfg.tube_flags = DMA_CFG_SRC_INC | DMA_CFG_CIRC | DMA_CFG_CMPLT_IE;
  dma_cfg.tube_req_src = DMA_REQ_SRC_TIM4_CH1;
  dma_cfg.tube_req_src = DMA_REQ_SRC_TIM4_CH2;
  dma_cfg.target_data = 0;


  ret = dma_tube_cfg(DMA1, DMA_CH4, &dma_cfg);
}


void dma_start()
{
  dma_attach_interrupt(DMA1, DMA_CH4, fun);
  dma_enable(DMA1, DMA_CH4);
  timer_resume(dev1);
    dma_enable(DMA1, DMA_CH1);
  dma_enable(DMA1, DMA_CH2);


}


void init_wave()
{
  int i;
  for (i = 0; i < SAMPLES; i++)
  {
    val[i] = 40 + amp * sin(stp * i);
    val1[i] = 40 + amp * sin(stp * i);
    //**************************************************************************
   // val1[i] = 40 + amp * cos(stp * i);//
   //***************************************************************************


  }
}


void setup()
{
  int i;
  // pinMode(out1, PWM);
  pinMode(out, OUTPUT);
  pinMode(out1, OUTPUT);
  timer_conf();
  dma_conf();
  dma_start();
  init_wave();
}


void loop()


{
  int i;
  for (i = 0; i < SAMPLES; i++)
    //if ( val1[i]  > 40)
    if ( val1[i]  > 38)
    {
      digitalWrite(PB7, HIGH);
    }
    else
    {
      digitalWrite(PB7, LOW);
    }


}

Re: missing signal on PA6

Posted: Wed Nov 11, 2020 7:55 pm
by fpiSTM
Check your dma conf. You override several params... so only out1 is really set...

Re: missing signal on PA6

Posted: Wed Nov 11, 2020 8:00 pm
by stan
I was checking many times but can't find the problem

Re: missing signal on PA6

Posted: Wed Nov 11, 2020 8:03 pm
by stevestrong
In timer_conf, the first

Code: Select all

 timer_dma_set_burst_len(dev1, 1);
I think it should be dev instead dev1.

Re: missing signal on PA6

Posted: Wed Nov 11, 2020 8:12 pm
by stan
I changed it = no difference

Re: missing signal on PA6

Posted: Wed Nov 11, 2020 8:32 pm
by stan
I turned off the lines related to out1 = PB7, so I have to deal with one channel

Code: Select all

#define SAMPLES 77
#include <libmaple/dma.h>
dma_tube_config dma_cfg, dma_cfg2;
int flag = 0;
int flag1 = 0;
int out = PB6;
int out1 = PB7;
int val[SAMPLES];
int val1[SAMPLES];


int16 shift = 0;


int amp = 40;
int cnt = 0;
int time_track = 0;
float stp = 6.2831 / SAMPLES;
int ret = 17;


timer_dev *dev = PIN_MAP[out].timer_device;
uint8 cc_channel = PIN_MAP[out].timer_channel;
//timer_dev *dev1 = PIN_MAP[out1].timer_device;
//uint8 cc_channel1 = PIN_MAP[out1].timer_channel;


void fun()
{
  flag++;
}
void fun1()
{
  flag1++;
}


void timer_conf()
{
  /////////////
  timer_dma_set_base_addr(dev, TIMER_DMA_BASE_CCR2);
  timer_dma_set_burst_len(dev, 1);
  timer_dma_enable_req(dev, cc_channel1);
  timer_set_reload(dev, 102);
  timer_set_prescaler(dev, 0);
  /*
  ///////////////
  timer_dma_set_base_addr(dev1, TIMER_DMA_BASE_CCR2);
  timer_dma_set_burst_len(dev1, 1);
  timer_dma_enable_req(dev1, cc_channel1);
  timer_set_reload(dev1, 102);
  timer_set_prescaler(dev1, 0);
  */
}


void dma_conf()
{
  dma_init(DMA1);
  /* T4C2 DMA C4 */
  dma_cfg.tube_dst = &(dev->regs.gen->DMAR);
 // dma_cfg.tube_dst = &(dev1->regs.gen->DMAR);
  dma_cfg.tube_dst_size = DMA_SIZE_32BITS;
  dma_cfg.tube_src = val;
//  dma_cfg.tube_src = val1;
  dma_cfg.tube_src_size = DMA_SIZE_32BITS;
  dma_cfg.tube_nr_xfers = SAMPLES;
  dma_cfg.tube_flags = DMA_CFG_SRC_INC | DMA_CFG_CIRC | DMA_CFG_CMPLT_IE;
  dma_cfg.tube_req_src = DMA_REQ_SRC_TIM4_CH1;
  dma_cfg.tube_req_src = DMA_REQ_SRC_TIM4_CH2;
  dma_cfg.target_data = 0;


  ret = dma_tube_cfg(DMA1, DMA_CH4, &dma_cfg);
}


void dma_start()
{
  dma_attach_interrupt(DMA1, DMA_CH4, fun);
  dma_enable(DMA1, DMA_CH4);
  //timer_resume(dev1);
    dma_enable(DMA1, DMA_CH1);
  dma_enable(DMA1, DMA_CH2);


}


void init_wave()
{
  int i;
  for (i = 0; i < SAMPLES; i++)
  {
    val[i] = 40 + amp * sin(stp * i);
    val1[i] = 40 + amp * sin(stp * i);
    //**************************************************************************
   // val1[i] = 40 + amp * cos(stp * i);//
   //***************************************************************************


  }
}


void setup()
{
  int i;
  // pinMode(out1, PWM);
  pinMode(out, OUTPUT);
  pinMode(out1, OUTPUT);
  timer_conf();
  dma_conf();
  dma_start();
  init_wave();
}


void loop()


{
  int i;
  for (i = 0; i < SAMPLES; i++)
    //if ( val1[i]  > 40)
    if ( val1[i]  > 38)
    {
      digitalWrite(PB7, HIGH);
    }
    else
    {
      digitalWrite(PB7, LOW);
    }


}

, and have this error

Arduino: 1.8.9 (Mac OS X), Board: "Generic STM32F103C series, STM32F103C8 (20k RAM. 64k Flash), STLink, 72Mhz (Normal), Smallest (default)"

/Users/Documents/Arduino/missing_signal_on_PA6/missing_signal_on_PA6.ino: In function 'void timer_conf()':
missing_signal_on_PA6:43:29: error: 'cc_channel1' was not declared in this scope
timer_dma_enable_req(dev, cc_channel1);
^~~~~~~~~~~
/Users/Documents/Arduino/missing_signal_on_PA6/missing_signal_on_PA6.ino:43:29: note: suggested alternative: 'cc_channel'
timer_dma_enable_req(dev, cc_channel1);
^~~~~~~~~~~
cc_channel
exit status 1
'cc_channel1' was not declared in this scope

Re: missing signal on PA6

Posted: Wed Nov 11, 2020 8:38 pm
by stan
alternative suggestion gives signal on PB7

Re: missing signal on PA6

Posted: Wed Nov 11, 2020 8:44 pm
by ag123
i'm not too sure if you are hitting an issue i've once encountered
for alternate functions such as timer outputs, you'd need to set the alternate function multiplexers registers
to choose the alternate function that you need e.g. timer output
viewtopic.php?p=2681#p2681

Re: missing signal on PA6

Posted: Wed Nov 11, 2020 10:38 pm
by stan
Now I can have signal on PB6 or PB7 but not both on one time.
by making changes in those lines

Code: Select all

 timer_dma_set_base_addr(dev1, TIMER_DMA_BASE_CCR2)

Code: Select all

timer_dma_set_base_addr(dev2, TIMER_DMA_BASE_CCR1);
CCR1, CCR1 = signal only on PB6
CCR1, CCR2 = signal only on PB7
CCR2, CCR2 = signal only on PB7
CCR2, CCR1 =signal only on PB6

Code: Select all

#define SAMPLES 100
#include <libmaple/dma.h>




dma_tube_config dma_cfg, dma_cfg2;
int val1[SAMPLES];
int val2[SAMPLES];                   // *******************


int amp = 35;
int cnt = 0;
int time_track = 0;
float stp = 6.2831 / SAMPLES;
int ret = 17;


int out1 = PB7; // TIM4_CH2 DMA_CH4 . 
int out2 = PB6; // TIM4_CH1 DMA_CH3 .                     *************************** 
timer_dev *dev1 = PIN_MAP[out2].timer_device;   
timer_dev *dev2 = PIN_MAP[out2].timer_device;






void timer_conf()
{


  // PB7 TIM4_CH2 DMA_CH4
  timer_dma_set_base_addr(dev1, TIMER_DMA_BASE_CCR1); //
  timer_dma_set_burst_len(dev1, 1);
  timer_dma_enable_req(dev1, PIN_MAP[out1].timer_channel);
  timer_set_reload(dev1, 102);
  timer_set_prescaler(dev1, 0);


  // PB6 TIM4_CH1 DMA_CH3 .                                  *********************
  timer_dma_set_base_addr(dev2, TIMER_DMA_BASE_CCR);
  timer_dma_set_burst_len(dev2, 1);
  timer_dma_enable_req(dev2, PIN_MAP[out2].timer_channel);
  timer_set_reload(dev2, 102);
  timer_set_prescaler(dev2, 0);




}
void dma_conf()
{
  dma_init(DMA1);


  // PB7 TIM4_CH2 DMA_CH4
  // PB6 TIM4_CH1 DMA_CH3
  dma_cfg.tube_dst = &(dev1->regs.gen->DMAR);                // PB7
  dma_cfg.tube_dst = &(dev2->regs.gen->DMAR);                // PB6********************
  dma_cfg.tube_src = val1;                                   // PB7
  dma_cfg.tube_src = val2;                                   // PB6********************
  dma_cfg.tube_src_size = DMA_SIZE_32BITS;
  dma_cfg.tube_nr_xfers = SAMPLES;
  dma_cfg.tube_flags = DMA_CFG_SRC_INC | DMA_CFG_CIRC;
  dma_cfg.tube_req_src = DMA_REQ_SRC_TIM4_CH2;               //PB7
  dma_cfg.tube_req_src = DMA_REQ_SRC_TIM4_CH1;               //PB6 ********************
  dma_cfg.target_data = 0;
  ret = dma_tube_cfg(DMA1, DMA_CH4, &dma_cfg);
  ret = dma_tube_cfg(DMA1, DMA_CH3, &dma_cfg);




}
void dma_start()
{
  // PB7 TIM4_CH2 DMA_CH4
  dma_enable(DMA1, DMA_CH4);
 timer_resume(dev1);
  dma_enable(DMA1, DMA_CH3);
  timer_resume(dev2);






}
void init_wave()
{
  int i;
  for (i = 0; i < SAMPLES; i++)
  {
    val1[i] = 50 + amp * sin(stp * i);
    val2[i] = 50 + amp * sin(stp * i);                      //************************
  }
}
void setup() {
  pinMode(out1, PWM);
  pinMode(out2, PWM);


  timer_conf();
  dma_conf();
  dma_start();
  init_wave();
}
void loop() {
}