mbed产生啁啾信号

问题描述 投票:0回答:1

我正在使用LPCXpresso1549生成频率在35000 Hz和45000 Hz之间的啁啾信号。首先,我在matlab上生成DAC啁啾样本,并将它们存储在const uint16_t chirpData []中。样品频率为96000 Hz,因此为96001个样品。然后,我将定时器设置为每隔1/96000秒逐个发送样本。但是,我的信号频率在3200 Hz到44000 Hz之间。那是因为计时器很慢吗?

enter code here
const uint16_t chirpData[NUM_SAMPLES] = { 2048, ...., 1728, 2048} //96001 sampels

 #include "mbed.h"
 #include "chirp.h"

 Serial pc(USBTX, USBRX);
 Timer t;
 AnalogOut aout(P0_12); 

 int main()
 {   
     int i = 0;

     while(true) {
         // Write the sample to the analog

         t.start(); //start timer
         if(t.read() >= 0.00001){ // 1/samplef = 0.00001
              aout.write_u16(chirpData[i]);

              i++;
              t.reset(); // reset timer to zero

              if(i > 96000) {
                  i = 0;
              }
          }
     }
 }
mbed dac lpcxpresso
1个回答
0
投票

在这种情况下,我建议您使用线程执行任务:

#define xTaskCreate( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask ) xTaskGenericCreate( ( pvTaskCode ), ( pcName ), ( usStackDepth ), ( pvParameters ), ( uxPriority ), ( pxCreatedTask ), ( NULL ), ( NULL ) )
xTaskHandle taskHandle;
xTaskCreate(..); //Check Task.h

然后你可以设置你的任务周期

void your_task() {
  unsigned task_cycle_ms = 1/freq; //Careful, convert to ms.
  portTickType xLastWakeTime = 0;
  portTickType xFrequency = task_cycle_ms/portTICK_RATE_MS;
  for(;;) {
    vTaskDelayUntil( &xLastWakeTime, xFrequency );
    //your code to execute every cycle here
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.