Microchip
直播中

潘凌

8年用户 174经验值
私信 关注
[问答]

PWM生成在MPLABX仿真器中工作,但在现实世界中进行测试时不在dsPIC33E上工作?

大家好,我试着在我的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)

王焕树

2019-6-5 12:02:42
你的代码真的在运行吗?你能手动闪动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)
举报

h1654155275.5814

2019-6-5 12:18:41
谢谢你的回复。是的,代码是运行和工作时,我闪烁的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. 
举报

h1654155275.5814

2019-6-5 12:26:15
而且,我在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. 
举报

h1654155275.5814

2019-6-5 12:56:39
我在模拟器中使用逻辑分析器。我在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?
 
 
 
 
举报

更多回帖

发帖
×
20
完善资料,
赚取积分