完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
HeloIIM尝试用PIC32 MZ2048 EFH100生成占空比为50%的PWM信号,这是我的代码,对于头文件[/Fix],IFNDEF SPIPWMH H/*防止多个包含*/y*定义SPIPWMYH//C’源代码配置语句//DEVCFG3//USERID=不设置HeNETRMII/MII启用(RMII使能)Apple TracMa配置FETHOI= ON/Ethernet I/O PIN选择(默认以太网I/O)α-PracMA配置PGL1WORE = / /允许组锁定单向配置(仅允许一个重新配置)* PrimaMac配置PMDL1WORE = / /外围模块禁用配置(允许)仅一个重新配置)(PLL Input Divider)PraceMac配置IOL1WOR/ONEXT PIN选择配置(仅允许一个重新配置)α-PracMA配置FuBidio= ON//USB UBID选择(由USB模块控制)//DEVCFG2* PrimaMatg配置FPLLIDEV=DIVIO1//系统(2x除法器)FFG LFLLRNG=RangeE551010MHZ/系统PLL输入范围(5-10MHz输入)μ-PracMA配置FPLILKK=PLLY-FRC//系统PLL输入时钟选择(FRC输入到系统PLL)α-PrAPMA配置FPLLMult=Mulr50//PLL乘法器(PLL乘50)tput Clock Divider(2x除法器)α-PrimaMac配置,LoFLQ24MH//USB PLL输入频率选择(USB PLL输入为24 MHz)//DVCFG1α-PrAPMA配置FFONC=PLSL/ /振荡器选择位(系统PLL)α-PrimaMatg配置DMtinv= WiNe127Al128//DMT计数窗口间隔(窗口/间隔值I)S 127/128计数器值(Ox PracMA配置)FSOSCEN=OF//次级振荡器使能(禁用SOSC)α-PrimaAcOfIOS= OF//内部/外部切换(禁用)α-PracMA配置POSCMOD=EC//主振荡器配置(初级OSC禁用)α-PracMA配置OSCIOFNC=OF//CLKO输出S在OSCO PIN(禁用)中,IGOC(Timer Postscaler)的PraceMac配置,FCKSM=CSEMME//时钟切换和监视器选择(启用时钟开关,启用FSCM)α-PrAPMA CONFIG WDTPS=PS1048 57 6/ /看门狗(1∶1048 57)DT在Flash编程过程中停止运行,{ Trac-PracMaMig.CONFIG =正常/ /看门狗定时器窗口模式(看门狗定时器是在非窗口模式)中,Trac-MaqMa配置FFDTEN= OF//看门狗定时器启用(WDT禁用)α-PrAPMA配置FWDTWISZZ=WiSZZ25//看门狗定时器窗口大小(窗口大小为25%)G DMTCNT=DMT31//死人定时器计数选择(2 ^ 31(2147483648))*GMA配置ICSIL=ICSU-PGX2//ICE/ICD COMM信道选择(通信在PGEC2/PGED2)上。KE//动态Flash ECC配置(ECC和动态ECC被禁用(ECCCON位可写)),γ-PracMaMig-COFIG FSHIL= OF//FLASH睡眠模式(当设备处于休眠模式时Flash被关闭)* PrimaMac配置= dggPul//Debug模式CPU访问权限(允许CPU访问所有的CPU)任务区域)SyPrimaMac配置,SMCLR=MCLRYNORM//软主清除允许位(MCLR引脚产生正常系统复位)α-PracMA配置SFOSGRAMP=GAAIN 2X//次级振荡器增益控制位(2X增益设置)α-PrAPMA配置SCOSBOOST=ON / /次振荡器Boost启动启动位提高振荡器的开机启动)(γ)PrimaMatg配置,POCSGROW=GAAIN 2X//主振荡器增益控制位(2X增益设置)α-PrAPMA配置POSBOOST=ON /主振荡器Boost启动启动位(提高振荡器的开机启动)Oracle EJTAG功能性//DEVCP0X-PARMARMA配置CP=关闭/ /代码保护(/SED3//DEQADC0//DEVADC1//DEVADC2//DEVADC3//DEVADC4//DEVADC7//OXY)PracMA配置语句应该在Project文件之前包含.//使用Project EnMUX代替ON定义ON和OFF。h & gt;//5ls- l复制粘贴,α-IFDEF,CpulsPullSuthn“C”{0—172MV,有时我得到正确的形状,我不确定如果主代码不正确,或者是随机行为的头文件,谢谢你的时间。
以上来自于百度翻译 以下为原文 hello im trying to generate a pwm signal with duty cycle 50% with the pic32MZ2048EFH100 here is my code, OC1CON = 0x0000; // Turn off the OC1 when performing the setup T2CON=0x0; OC1R = (uint16)(PR_2+1)/2; // Initialize primary Compare register OC1RS = OC1R; // Initialize secondary Compare register OC1CON = 0x0006; // Configure for PWM mode without Fault pin enabled, timer2, 16bit comparaison, SIDL continue in idle mode PR2 = PR_2; // desired periode TMR2=0; IFS0CLR = 0x00000100; // Clear the T2 interrupt flag IEC0CLR = 0x00000100; // disable T2 interrupt //IPC2SET = 0x0000001C; // Set T2 interrupt priority to 7 IEC0bits.OC1IE=0;//disable output compare interrupt T2CONSET = 0x8000; // Enable Timer2 PBCLK3=100MHZ , prescale 1:1 OC1CONSET = 0x8000; // Enable OC1 for the header file [/code] #ifndef SPIPWM_H /* Guard against multiple inclusion */ #define SPIPWM_H // 'C' source line config statements // DEVCFG3 // USERID = No Setting #pragma config FMIIEN = OFF // Ethernet RMII/MII Enable (RMII Enabled) #pragma config FETHIO = ON // Ethernet I/O Pin Select (Default Ethernet I/O) #pragma config PGL1WAY = ON // Permission Group Lock One Way Configuration (Allow only one reconfiguration) #pragma config PMDL1WAY = ON // Peripheral Module Disable Configuration (Allow only one reconfiguration) #pragma config IOL1WAY = ON // Peripheral Pin Select Configuration (Allow only one reconfiguration) #pragma config FUSBIDIO = ON // USB USBID Selection (Controlled by the USB Module) // DEVCFG2 #pragma config FPLLIDIV = DIV_1 // System PLL Input Divider (2x Divider) #pragma config FPLLRNG = RANGE_5_10_MHZ // System PLL Input Range (5-10 MHz Input) #pragma config FPLLICLK = PLL_FRC // System PLL Input Clock Selection (FRC is input to the System PLL) #pragma config FPLLMULT = MUL_50 // System PLL Multiplier (PLL Multiply by 50) #pragma config FPLLODIV = DIV_2 // System PLL Output Clock Divider (2x Divider) #pragma config UPLLFSEL = FREQ_24MHZ // USB PLL Input Frequency Selection (USB PLL input is 24 MHz) // DEVCFG1 #pragma config FNOSC = SPLL // Oscillator Selection Bits (System PLL) #pragma config DMTINTV = WIN_127_128 // DMT Count Window Interval (Window/Interval value is 127/128 counter value) #pragma config FSOSCEN = OFF // Secondary Oscillator Enable (Disable SOSC) #pragma config IESO = OFF // Internal/External Switch Over (Disabled) #pragma config POSCMOD = EC // Primary Oscillator Configuration (Primary osc disabled) #pragma config OSCIOFNC = OFF // CLKO Output Signal Active on the OSCO Pin (Disabled) #pragma config FCKSM = CSECME // Clock Switching and Monitor Selection (Clock Switch Enabled, FSCM Enabled) #pragma config WDTPS = PS1048576 // Watchdog Timer Postscaler (1:1048576) #pragma config WDTSPGM = STOP // Watchdog Timer Stop During Flash Programming (WDT stops during Flash programming) #pragma config WINDIS = NORMAL // Watchdog Timer Window Mode (Watchdog Timer is in non-Window mode) #pragma config FWDTEN = OFF // Watchdog Timer Enable (WDT Disabled) #pragma config FWDTWINSZ = WINSZ_25 // Watchdog Timer Window Size (Window size is 25%) #pragma config DMTCNT = DMT31 // Deadman Timer Count Selection (2^31 (2147483648)) #pragma config FDMTEN = OFF // Deadman Timer Enable (Deadman Timer is disabled) // DEVCFG0 #pragma config DEBUG = OFF // Background Debugger Enable (Debugger is disabled) #pragma config JTAGEN = OFF // JTAG Enable (JTAG Disabled) #pragma config ICESEL = ICS_PGx2 // ICE/ICD Comm Channel Select (Communicate on PGEC2/PGED2) #pragma config TRCEN = OFF // Trace Enable (Trace features in the CPU are disabled) #pragma config BOOTISA = MIPS32 // Boot ISA Selection (Boot code and Exception code is MIPS32) #pragma config FECCCON = OFF_UNLOCKED // Dynamic Flash ECC Configuration (ECC and Dynamic ECC are disabled (ECCCON bits are writable)) #pragma config FSLEEP = OFF // Flash Sleep Mode (Flash is powered down when the device is in Sleep mode) #pragma config DBGPER = PG_ALL // Debug Mode CPU Access Permission (Allow CPU access to all permission regions) #pragma config SMCLR = MCLR_NORM // Soft Master Clear Enable bit (MCLR pin generates a normal system Reset) #pragma config SOSCGAIN = GAIN_2X // Secondary Oscillator Gain Control bits (2x gain setting) #pragma config SOSCBOOST = ON // Secondary Oscillator Boost Kick Start Enable bit (Boost the kick start of the oscillator) #pragma config POSCGAIN = GAIN_2X // Primary Oscillator Gain Control bits (2x gain setting) #pragma config POSCBOOST = ON // Primary Oscillator Boost Kick Start Enable bit (Boost the kick start of the oscillator) #pragma config EJTAGBEN = NORMAL // EJTAG Boot (Normal EJTAG functionality) // DEVCP0 #pragma config CP = OFF // Code Protect (Protection Disabled) // SEQ3 // DEVADC0 // DEVADC1 // DEVADC2 // DEVADC3 // DEVADC4 // DEVADC7 // #pragma config statements should precede project file includes. // Use project enums instead of #define for ON and OFF. #include //5lss lcopy paste #ifdef __cplusplus extern "C" { #endif #ifdef __cplusplus } #endif #endif /* _EXAMPLE_FILE_NAME_H */ /* ***************************************************************************** End of File */ [/code] sometimes im reading the low value from the oscilloscope a negative value instead of zero -172mv and sometimes i obtain a correct shape im not sure if the code in the main is incorrect or is it the header file with random behavior thank you for your time |
|
相关推荐
6个回答
|
|
您可以使用OC和定时器驱动程序使用和声配置器生成PWM。您必须生成静态OC驱动程序,并且根据计时器值,可以改变占空比。
以上来自于百度翻译 以下为原文 You can generate PWM using OC and Timer driver using Harmony configurator. You have to generate static oc driver and according to timer value, the duty cycle can be varied. |
|
|
|
在我的代码中,我使用OC和计时器来产生PWM信号。我没有低估你的方法,它和我的不同吗?
以上来自于百度翻译 以下为原文 in my code i used the oc and timer to generate the pwm signal. i didn't understrand your method is it different than mine? |
|
|
|
以上来自于百度翻译 以下为原文 void pwm2_set(unsigned short int a, unsigned short int b) { OC2CON = 0x0000; // Turn off OC2 while doing setup. OC2R = a; // Initialize primary Compare Register OC2RS = a; OC2CON=0x000E; // Select timer 2 for the generation of PWM PR2 = b; // For setting the duty cycle of various percentage TRISDbits.TRISD1 = 0; IFS0CLR = 0x100; // Clear the Timer2 interrupt flag. IEC0SET = 0x100; // Enable Timer2 interrupt. IPC2SET = 0x17; // Timer Priority 5 and sub priority 3 . T2CONSET = 0x8000;//0x8000; // Enable Timer2 and prescaler is default 1:1. OC2CONSET = 0x8000; // Enable OC2. //provoding clk sourc timer 2 for PWM INTEnableSystemMultiVectoredInt();//Enable the multivector interrupt } |
|
|
|
无符号短INT B是计时器计数。假设B=10000,无符号短T A是主比较寄存器计数,假设A= 5000定时器在溢出时产生中断(0到10000)。它将产生50%占空比。
以上来自于百度翻译 以下为原文 unsigned short int b is timer count.lets say b=10000, unsigned short int a is primary compare register count,lets say a= 5000 timer will generate interrupt when it overflows(0 to 10000) .it will generate 50% duty cycle. |
|
|
|
你好,Slight oscillations,在方波的示波器显示的角落里,是测量的副作用。在线路或示波器探头中可能有信号反射,或者从电源或其他来源拾取的噪声。这种干扰与微控制器PW无关。M设置源代码或头文件,并且不能通过引入和声工具、中断或其他开销来帮助。
以上来自于百度翻译 以下为原文 Hi, Slight oscillations in the corners of oscilloscope display of a square wave, are side effects of the measurement. There may be signal reflections in wiring, or in oscilloscope probe, or noise picked up from power supply or other sources. Such disturbances have nothing to do with microcontroller PWM setup source code or header file, and cannot be helped by introducing Harmony tools, interrupts, or other overhead. Regards, Mysil |
|
|
|
嗨,艾哈迈达马拉克,我在PIC32 MZ好奇心板上工作,检查下面的链接讨论:HTTP://www. McCHIP.COM/FUMMS/M997 36ASPXOND
以上来自于百度翻译 以下为原文 Hi ahmadmalak, I got it to work on the PIC32MZ Curiosity Board, check the link below for the discussion: http://www.microchip.com/forums/m979736.aspx Kind regards Charles |
|
|
|
只有小组成员才能发言,加入小组>>
5198 浏览 9 评论
2016 浏览 8 评论
1940 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3188 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2243 浏览 5 评论
753浏览 1评论
639浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
526浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
650浏览 0评论
552浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-3 07:25 , Processed in 1.667216 second(s), Total 87, Slave 71 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号