shukeli 发表于 2016-12-2 15:07

求助:用拨动开关控制发脉冲,编程遇到问题,得不到想...

本帖最后由 shukeli 于 2016-12-2 15:55 编辑

#include "DSP2833x_Device.h"   // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h"   // DSP2833x Examples Include File
void StopPulse(void);//封锁脉冲
Uint16    *ExRamStart = (Uint16 *)0x100000;
void EPwmSetup();


Uint16i;
int Sw ;

void main(void)
{
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.
   InitSysCtrl();

         GpioCtrlRegs.GPCPUD.bit.GPIO80 = 0;
            GpioCtrlRegs.GPCMUX2.bit.GPIO80 = 0;
            GpioCtrlRegs.GPCDIR.bit.GPIO80 = 1;
            Sw = 0;

// Step 2. Initalize GPIO:
// This example function is found in the DSP2833x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio();// Skipped for this example
   InitXintf16Gpio();      //zq

// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
   DINT;

// Initialize the PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP2833x_PieCtrl.c file.
   InitPieCtrl();

// Disable CPU interrupts and clear all CPU interrupt flags:
   IER = 0x0000;
   IFR = 0x0000;

// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example.This is useful for debug purposes.
// The shell ISR routines are found in DSP2833x_DefaultIsr.c.
// This function is found in DSP2833x_PieVect.c.
   InitPieVectTable();

// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.

// Step 4. Initialize the Device Peripheral. This function can be
//         found in DSP2833x_CpuTimers.c
// InitCpuTimers();   // For this example, only initialize the Cpu Timers

// Configure CPU-Timer 0, 1, and 2 to interrupt every second:
// 150MHz CPU Freq, 1 second Period (in uSeconds)

   //ConfigCpuTimer(&CpuTimer0, 150, 1000000);
   //ConfigCpuTimer(&CpuTimer1, 150, 1000000);
   //ConfigCpuTimer(&CpuTimer2, 150, 1000000);
//      StartCpuTimer0();
//   StopPulse();

    for(; ;)
      {
             Sw = GpioDataRegs.GPCDAT.bit.GPIO80;
            if(Sw==1 )

                                          {

                                       EPwmSetup();
                                          }

                else
                            {

                                       StopPulse();//闭锁脉冲
                            }
       }

}

void StopPulse(void)//闭锁脉冲
{
      GpioDataRegs.GPACLEAR.bit.GPIO0=1;
      GpioDataRegs.GPACLEAR.bit.GPIO1=1;
      GpioDataRegs.GPACLEAR.bit.GPIO2=1;
      GpioDataRegs.GPACLEAR.bit.GPIO3=1;
      GpioDataRegs.GPACLEAR.bit.GPIO4=1;
      GpioDataRegs.GPACLEAR.bit.GPIO5=1;
}







//===========================================================================
// No more.
//===========================================================================
一个简单的程序,我却出现如下几个问题:
1、Sw = GpioDataRegs.GPCDAT.bit.GPIO80;这句话如果放在for循环外面,就根本发不出波形。
2、按照如上的程序,我的本意是Sw=1的时候,即开关闭合时,发脉冲。否则,闭锁脉冲。但是最后示波器上显示出,当开关打开时,是有发脉冲,开关闭合,反而没有脉冲或者脉冲为1.
3、当把for循环里面的if(Sw==1)改为(Sw==0)时,能得到我大概想要的结果。但是整个程序的设计和我正好相反。。。。   
不知道哪里错了???@zhangmangui    还有各位前辈

JY-DX-JY 发表于 2016-12-2 15:24

拨码开关闭合一般是为0的吧,看你硬件电路

shukeli 发表于 2016-12-2 15:54

JY-DX-JY 发表于 2016-12-2 15:24
拨码开关闭合一般是为0的吧,看你硬件电路

哦哦,我打错了,是拨动开关

zhangmangui 发表于 2016-12-2 22:09

1.肯定不能放外面   放外面不是实时监测IO口的变化
2.从硬件设计较多一般开关闭合设计为0打开被上拉为1
3.贴出你的硬件设计就明白了

zhangmangui 发表于 2016-12-2 22:10

像这种监测按键开关的最好加上去抖动

shukeli 发表于 2016-12-3 18:21

zhangmangui 发表于 2016-12-2 22:09
1.肯定不能放外面   放外面不是实时监测IO口的变化
2.从硬件设计较多一般开关闭合设计为0打开被上拉为1 ...


1、这是开关的硬件图。从图中怎么能够看出来当sw拨向1时,就是断开?sw拨向3时就是闭合呢?
2、假如确实是这样,那为什么sw=1时,脉冲有的时候是没有,有的时候却全是高?是因为我没有设置抖动吗?多谢!!

shukeli 发表于 2016-12-3 18:24

zhangmangui 发表于 2016-12-2 22:09
1.肯定不能放外面   放外面不是实时监测IO口的变化
2.从硬件设计较多一般开关闭合设计为0打开被上拉为1 ...


1、这是开关的硬件图。从图中怎么能够看出来当sw拨向1时,就是断开?sw拨向3时就是闭合呢?
2、假如确实是这样,那为什么sw=1时,脉冲有的时候是没有,有的时候却全是高?是因为我没有设置抖动吗?多谢~~~

zhangmangui 发表于 2016-12-3 22:29

shukeli 发表于 2016-12-3 18:21
1、这是开关的硬件图。从图中怎么能够看出来当sw拨向1时,就是断开?sw拨向3时就是闭合呢?
2、假如确实 ...

你这个开关应该是单刀双掷开关   推向1端应该是高电平 3端应该是低电平
脉冲时有时无可能是开关接触不好   你一直拿手摁着试试

shukeli 发表于 2016-12-4 20:59

zhangmangui 发表于 2016-12-3 22:29
你这个开关应该是单刀双掷开关   推向1端应该是高电平 3端应该是低电平
脉冲时有时无可能是开关接触不 ...

开关接触貌似挺好的!封锁脉冲那个函数难道有问题?感觉也没问题啊

zhangmangui 发表于 2016-12-4 22:53

shukeli 发表于 2016-12-4 20:59
开关接触貌似挺好的!封锁脉冲那个函数难道有问题?感觉也没问题啊

连续调用这个函数EPwmSetup();可能会有问题
比如函数中一直从头执行   或者怎么处理    无法让波形连续

shukeli 发表于 2016-12-5 18:08

zhangmangui 发表于 2016-12-4 22:53
连续调用这个函数EPwmSetup();可能会有问题
比如函数中一直从头执行   或者怎么处理    无法让波形连续 ...

对,我把这儿setup放到for外面的话,根本无法封锁脉冲,一直显示脉冲,可能程序写这么简单有问题,估计有哪些没考虑到

zhangmangui 发表于 2016-12-5 22:20

多试试    解决了分享一把
页: [1]
查看完整版本: 求助:用拨动开关控制发脉冲,编程遇到问题,得不到想...