⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 fft的工业级的EP9315的开发板的所有驱动程序
💻 C
字号:
/****************************************Copyright (c)**************************************************
**                                     研    发    部
**                              http://www.FFTChina.com
**-----------------------------------------文件信息-----------------------------------------------------
**文   件   名: cantest.c
**创   建   人: 
**最后修改日期: 2005年6月30日
**描        述:  
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
/* to produce a pwm of 100khz(10us)and 20% duty cycle with system clock of 14.7456Mhz
   
   Caculate Pwmtermcnt (14.7456M/0.1M) -1 = 146.456 
   Caculate PwmDutyCycle 0.2*(146.456+1)-1= 28.4912
Attention:
   the lowst frequency of pwmout is 224hz,mean that the max cycle is 4.44ms
   the freqency our humanbeing can hear is from 20HZ to 20000HZ
   so the number arrange of  TC is from 737 to 65536 
*/  
#include "stdio.h"
#include "stdlib.h"
#include "sys/types.h"
#include "sys/stat.h"
#include "fcntl.h"
#define PwmStt  1
#define PwmStp  0
int main(void)
{
    int fd1,i;
    unsigned long pwmtc ;
    unsigned long pwmduty;
    unsigned long pwmparmt;
    printf("Begin to test fftpwm0 drivers\n");
    fd1=open("/dev/fftpwm0", O_RDWR);            
    if(fd1==-1) {
       perror("open");
       exit(EXIT_FAILURE);
    }
    for(i = 0;i < 7;i++) {
       switch( i )
       {
          case 0: 
             pwmtc  = 800;                 //set the cycle of 10um,frequency is  20% duty cycle 
             pwmduty= 400;                   
             pwmparmt = (pwmtc | (pwmduty <<16));
             break;
          case 1:
             pwmtc  = 1465;                //100um of cycle ,20% duty cycle.
             pwmduty= 732;
             pwmparmt = (pwmtc | (pwmduty <<16));
             break;
          case 2:
             pwmtc  = 14646;               //1ms of cycle.
             pwmduty= 7323;
             pwmparmt = (pwmtc | (pwmduty <<16));
             break;
          case 3:
             pwmtc  = 64000;             //10ms of cyle 
             pwmduty= 32000;
             pwmparmt = (pwmtc | (pwmduty <<16));
             break;
          case 4:
             pwmtc  = 64000;                
             pwmduty= 50000;
             pwmparmt = (pwmtc | (pwmduty <<16));
             break;
          case 5:
             pwmtc  = 64000;                
             pwmduty= 63500;
             pwmparmt = (pwmtc | (pwmduty <<16));
             break;          
          default:
             pwmtc  = 0;                
             pwmduty= 0;
             pwmparmt = (pwmtc | (pwmduty <<16));
             break;
       }
       ioctl(fd1,PwmStt,pwmparmt);           //set the pwm cycle and duty cycle                     
       sleep(5);
    }
    ioctl(fd1,PwmStp,0);
    if(close(fd1)<0) {
       perror("close");
       exit(EXIT_FAILURE);
    }
    printf("finished FFT pwm test\n");
    exit(EXIT_SUCCESS);

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -