完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
大家好,我试着在我的DSPIC33 EP256MC506上产生PWM信号。当我在模拟器和逻辑分析仪中测试时,我能看到PWM信号正在产生。但是,当我在微控制器上运行程序并使用示波器来查看PWM信号时,它什么也不显示。我使用MCLV—2开发板,非常感谢您的任何帮助或建议!主系统
以上来自于百度翻译 以下为原文 Hello all, I am trying to generate PWM signals on my dsPIC33EP256MC506. When I test in simulator and logic analyzer, I can see the PWM signals being generated. But on when I run the program on the microcontroller and use an oscilloscope to see the PWM signals, it shows nothing. I am using the MCLV -2 development board. Any help or advice is greatly appreciated! main.c #include #include "system.h" #define Vdd 0xC400 #define Gnd 0xC301 #define NC_ 0xC341 unsigned int StateIndexTable1[] = {Gnd, Vdd, Vdd, NC_, Gnd, Gnd, NC_, Gnd}; unsigned int StateIndexTable2[] = {Gnd, Gnd, NC_, Vdd, Vdd, NC_, Gnd, Gnd}; unsigned int StateIndexTable3[] = {Gnd, NC_, Gnd, Gnd, NC_, Vdd, Vdd, Gnd}; //#include "user.h" /*=======================================================================* * Fixed width word size data types: * * int8_T, int16_T, int32_T - signed 8, 16, or 32 bit integers * * uint8_T, uint16_T, uint32_T - unsigned 8, 16, or 32 bit integers * * real32_T, real64_T - 32 and 64 bit floating point numbers * *=======================================================================*/ typedef signed char int8_T; typedef unsigned char uint8_T; typedef int int16_T; typedef unsigned int uint16_T; typedef long int32_T; typedef unsigned long uint32_T; typedef float real32_T; typedef double real64_T; void Init_ADC(void); void Delay_us(unsigned int); void Delay_ms(unsigned int); int ADCValue, i; int pwmOutput; int indexx = 0; int main(void) { ConfigureOscillator(); Init_Ports(); Init_ADC(); Init_Timers(); Init_PWM(); Delay_us(100); int i = 0; int j = 0; while(1) { /* AD1CON1bits.SAMP = 1; // Start sampling Delay_us(10); // Wait for sampling time (10 us) AD1CON1bits.SAMP = 0; // Start the conversion while (!AD1CON1bits.DONE); // Wait for the conversion to complete ADCValue = ADC1BUF0; // Read the ADC conversion result */ if(j == 0) { for(i = 0; i < 13; i++){ //asm volatile ("disi #0x3FFF"); //pwmOutput = (indexx % 6) + 1; pwmOutput = indexx % 8; IOCON1 = StateIndexTable1[pwmOutput]; IOCON2 = StateIndexTable2[pwmOutput]; IOCON3 = StateIndexTable3[pwmOutput]; //asm volatile ("disi #0"); /*/ IOCON1bits.OVRENH = 0; IOCON1bits.OVRENL = 0; IOCON2bits.OVRENH = 0; IOCON2bits.OVRENL = 0; IOCON3bits.OVRENH = 0; IOCON3bits.OVRENL = 0; */ indexx++; Delay_us(2); } } j++; /* LATDbits.LATD5 = 1; //make LED pin high Delay_ms(10); LATDbits.LATD5 = 0; //make LED pin low Delay_ms(1000); */ } } void Init_ADC(void) { /* Set port configuration */ ANSELA = ANSELB = ANSELC = ANSELE = 0x0000; // Set Port E Pin 13 as analog input ANSELEbits.ANSE13 = 1; TRISEbits.TRISE13 = 1; /* Initialize and enable ADC module */ AD1CON1 = 0x0000; AD1CON2 = 0x0000; AD1CON3 = 0x000F; AD1CON4 = 0x0000; AD1CHS0 = 0x000D; AD1CHS123 = 0x0000; AD1CSSH = 0x0000; AD1CSSL = 0x0000; AD1CON1bits.ADON = 1; Delay_us(1); } // DELAY UP TO 2600 MICROSECONDS void Delay_us(unsigned int delay) { TMR2 = 0; // Resetting timer 2 T2CONbits.TON = 1; // Start timer 2 while(TMR2 < (25 * delay)) nop(); T2CONbits.TON = 0; } // [TMR5][TMR4] holds up to 2147483648 decimal // max value for compare = 214783648 / 97 // DELAY UP TO 22139006 ms void Delay_ms(unsigned int delay) { TMR5HLD = 0; // Reset timer values TMR4 = 0; T4CONbits.TON = 1; // Start 32 bit timer uint32_T timer_4_ticks = 97UL * delay; // Calculate clock ticks to wait uint32_T tmp = 0; while(tmp < timer_4_ticks) { tmp = TMR4; tmp |= (uint32_T) TMR5HLD << 16; } T4CONbits.TON = 0; } /********************************************************************* Function: void __attribute__((interrupt, no_auto_psv)) _T1Interrupt (void) PreCondition: None. Overview: Half-second heartbeat monitor ********************************************************************/ void __attribute__((interrupt, no_auto_psv)) _T1Interrupt (void) { /* LATDbits.LATD6 = 1; //make LED pin high Delay_ms(20); LATDbits.LATD6 = 0; //make LED pin low */ IFS0bits.T1IF = 0; } /********************************************************************* Function: void __attribute__((interrupt, no_auto_psv)) _ADC1Interrupt (void) Overview: The ADC interrupt loads the PDCx registers with pot value. This is only done when the motor is running. *********************************************************************/ void __attribute__((interrupt, no_auto_psv)) _AD1Interrupt (void) { /* PDC1 = 0.975 * ADC1BUF0; // get value, if (PDC1 > 999U) // duty cycle saturation PDC1 = 999U; else if (PDC1 < 0U) PDC1 = 0U; PDC2 = PDC1; PDC3 = PDC1; */ IFS0bits.AD1IF = 0; // reset ADC interrupt flag } system.c /******************************************************************************/ /* System Level #define Macros */ /******************************************************************************/ #include #include "p33EP256MC506.h" /* TODO Define system operating frequency */ /* Microcontroller MIPs (FCY) */ #define SYS_FREQ 50000000L #define FCY SYS_FREQ/2 /******************************************************************************/ /* System Function Prototypes */ /******************************************************************************/ /* Custom oscillator configuration funtions, reset source evaluation functions, and other non-peripheral microcontroller initialization functions go here. */ void ConfigureOscillator(void); /* Handles clock switching/osc initialization */ void Init_Ports(void); void Init_Timers(void); void Init_PWM(void); void nop(void); Thanks |
|
相关推荐
8个回答
|
|
|
你的代码真的在运行吗?你能手动闪动LED在你的主回路吗?(我看到一些注释出来的代码要精确地做)
以上来自于百度翻译 以下为原文 Is your code actually running? Can you manually flash an LED in your main loop? (I see some commented out code there to do precisely that) |
|
|
|
|
|
谢谢你的回复。是的,代码是运行和工作时,我闪烁的LED。我也可以看到在逻辑分析仪上产生pwm信号,但是当我试图在示波器上看到pwm信号时,我什么也得不到。有什么想法吗?再次感谢。
以上来自于百度翻译 以下为原文 Thanks for the reply. Yeah that the code is running and works when I flash the LEDs. I can also see pwm signals being generated on the logic analyzer, but when I try to see the pwm signals on an oscilloscope, I get nothing. Any ideas? Thanks again. |
|
|
|
|
|
而且,我在10kHz下尝试运行PWM信号有困难。我使用数据表中给出的PTPER值的方程,但是当我使用逻辑分析器计算pwm频率时,我看不到期望的pwm频率。你有什么线索,我如何能够达到这种期望的PWM频率?谢谢。
以上来自于百度翻译 以下为原文 Also, I am having trouble trying to run my PWM signals at 10KHz. I use the equations in the data sheet that gives me a value for PTPER, but when I calculate the pwm frequency using logic analyzer, I do not see the desired pwm frequency. Do you have any clue on how I can achieve this desired PWM frequency? Thanks. |
|
|
|
|
|
我在模拟器中使用逻辑分析器。我在pwm状态下使用时钟周期来确定pwm频率,并且当我这样做时,我记录从1Khz到500KHz的频率。我需要10千赫,我不知道如何针点这个频率。有什么线索吗?
以上来自于百度翻译 以下为原文 I am using the logic analyzer in simulator. I use the clock cycles in the the pwm state to determine the pwm frequency and when I do this I record frequencies from 1Khz to 500KHz. I need 10KHz and I don't know how to pin point this frequency. Any clue? |
|
|
|
|
|
谢谢你的反馈,RISC。我需要对dspic33或开发板做些什么才能让它在现实世界中运行吗?我的示波器没有显示任何PWM输出信号,它们显示在模拟器上。如何在现实世界中获得PWM输出?再次感谢。
以上来自于百度翻译 以下为原文 Thank you for your feedback, RISC. Is there something I have to do to the dspic33 or dev board to get it running in real world? My oscilloscope does not show any pwm output signals and they are shown on simulator. How do I go about getting the pwm output in the real world? Thanks again. |
|
|
|
|
|
你的代码是否在做任何其他事情(例如闪烁一个LED)来确认它正在运行吗?
以上来自于百度翻译 以下为原文 Is your code doing anything else at all (e.g. flashing an LED) to confirm that it is running? |
|
|
|
|
|
是的,我可以让DEV板上的LED接通/断开,所以我知道它至少运行正常。
以上来自于百度翻译 以下为原文 Yes, I can make LEDs on the dev board toggle on/off so I know it's at least running alright. |
|
|
|
|
|
算了出来。iOCON锁定在DSSPIC33上,我们必须创建一个解锁序列。你说得对,模拟器根本不像现实世界中的控制器那样工作。示波器现在给我的pwm信号输出和10KHz的期望pwm频率,我正在寻找。再次感谢反馈。
以上来自于百度翻译 以下为原文 Figured it out. The IOCON was getting locked on the dspic33 and we had to create an unlock sequence. You were right that simulator does not work at all like the controller in real world. The oscilloscope now gives me the pwm signal output and the desired pwm frequency of 10KHz that I am looking for. Thanks again for the feedback. |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
473 浏览 0 评论
5793 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1123浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1095浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
873浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 01:37 , Processed in 1.251760 second(s), Total 86, Slave 69 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
2586