大致要求:设计一个FSK调制解调器,基带信号码速率为2000B/s,载波速率为4khz和8khz,解调信号要能完整还原基带信号。实现方法多种多样,通信领域内调制解调器的设计大多数用的都是硬件电路,鉴于笔者对编程情有独钟(其实笔者还是懂一点电路设计知识的~),所以最终决定用stm32来设计,纯编程实现。看起来高大上,但实际做起来不难,不过有挺多东西要考虑的。
总的设计思路如下:
首先是基带信号的产生,它也是我们要调制和解调的目标。基带信号由一连串随机的码元序列构成,为了模拟随机的码元序列,笔者用定时器设计8位的PN码序列,码元速率为2000B/s。定时器3定时0.5ms,每进入一次中断,变量num加一,设置一次IO引脚电平,8位PN码只需设置8次,然后num清零。
TIM3_Init(499,71); //基带信号
u8 num=0;
void TIM3_IRQHandler(void)
{
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)
{
num++;
switch (num)
{
case 1: Base_Signal = 1; break;
case 2: Base_Signal = 0; break;
case 3: Base_Signal = 0; break;
case 4: Base_Signal = 0; break;
case 5: Base_Signal = 1; break;
case 6: Base_Signal = 0; break;
case 7: Base_Signal = 1; break;
case 8: Base_Signal = 0; break; //pn码序列
}
if(num == 8)
num = 0;
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
}
}
接下来要产生载波,载波就是正弦波无疑。这里笔者的载波频率要求是4khz和8khz。正弦波的产生用的是stm32的DMA+DAC+TIM2。正弦波的数据用正弦波数据发生器产生,采样点数64,精度12位,保存在Sine12bit[]数组,但是传送给DMA的正弦波数据不是这些原始的数据,而是将这些数据进行了进一步的处理:
uint16_t Sine12bit[64] = {
0x7FF,0x8C8,0x98E,0xA51,0xB0F,0xBC4,0xC71,0xD12,0xDA7,0xE2E,0xEA5,0xF0D,0xF63,0xFA6,0xFD7,0xFF5
,0xFFE,0xFF5,0xFD7,0xFA6,0xF63,0xF0D,0xEA5,0xE2E,0xDA7,0xD12,0xC71,0xBC4,0xB0F,0xA51,0x98E,0x8C8
,0x7FF,0x736,0x670,0x5AD,0x4EF,0x43A,0x38D,0x2EC,0x257,0x1D0,0x159,0x0F1,0x09B,0x058,0x027,0x009
,0x000,0x009,0x027,0x058,0x09B,0x0F1,0x159,0x1D0,0x257,0x2EC,0x38D,0x43A,0x4EF,0x5AD,0x670,0x736
};
uint32_t Idx = 0;
int main(void)
{
评论
查看更多