[讨论] 关于28335Control Suite的External Interrupt的问题

LZt   2016-8-26 09:11 楼主
我在阅读control suite中28335例程(v141)时对下面这个input qualification的delay_us函数产生了疑惑:

1. 为什么设置等待qual周期的时间是35.700us?我跟据reference guide中算出来的,最多只是5*tw(sp)+tw(sp)+Tsysclkout=6*2*255*6.667ns+6.667ns=20.41us?

2. 为什么等待qualification要设置在GPIO31触发GPIO1之前?例程中不是设置GPIO1为滤波采样,所以应该在GPIO31触发GPIO1之后设置延时函数。

  1. #include "DSP28x_Project.h"     // Device Headerfile and Examples Include File

  2. // Prototype statements for functions found within this file.
  3. __interrupt void xint1_isr(void);
  4. __interrupt void xint2_isr(void);

  5. // Global variables for this example
  6. volatile Uint32 Xint1Count; //volatile 关键字告诉编译器该变量是随时可能发生变化的,每次使用它的时候必须从内存
  7.                              //中取出他的值,因而编译器生成的汇编代码会从原内存地址中读取数据使用。
  8. volatile Uint32 Xint2Count;
  9. Uint32 LoopCount;

  10. #define DELAY 35.700L //数字+L代表这是一个long double类型的数值。

  11. void main(void)
  12. {
  13.    Uint32 TempX1Count;
  14.    Uint32 TempX2Count;

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

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

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

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

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

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

  41. // Interrupts that are used in this example are re-mapped to
  42. // ISR functions found within this file.
  43.    EALLOW;        // This is needed to write to EALLOW protected registers
  44.    PieVectTable.XINT1 = &xint1_isr;
  45.    PieVectTable.XINT2 = &xint2_isr;
  46.    EDIS;   // This is needed to disable write to EALLOW protected registers

  47. // Step 4. Initialize all the Device Peripherals:
  48. // This function is found in DSP2833x_InitPeripherals.c
  49. // InitPeripherals(); // Not required for this example

  50. // Step 5. User specific code, enable interrupts:

  51. // Clear the counters
  52.    Xint1Count = 0; // Count Xint1 interrupts
  53.    Xint2Count = 0; // Count XINT2 interrupts
  54.    LoopCount = 0;  // Count times through idle loop

  55. // Enable Xint1 and XINT2 in the PIE: Group 1 interrupt 4 & 5
  56. // Enable int1 which is connected to WAKEINT:
  57.    PieCtrlRegs.PIECTRL.bit.ENPIE = 1;          // Enable the PIE block
  58.    PieCtrlRegs.PIEIER1.bit.INTx4 = 1;          // Enable PIE Gropu 1 INT4
  59.    PieCtrlRegs.PIEIER1.bit.INTx5 = 1;          // Enable PIE Gropu 1 INT5
  60.    IER |= M_INT1;                              // Enable CPU int1
  61.    EINT;                                       // Enable Global Interrupts

  62. // GPIO30 & GPIO31 are outputs, start GPIO30 high and GPIO31 low
  63.    EALLOW;
  64.    GpioDataRegs.GPASET.bit.GPIO30 = 1;         // Load the output latch
  65.    GpioCtrlRegs.GPAMUX2.bit.GPIO30 = 0;        // GPIO
  66.    GpioCtrlRegs.GPADIR.bit.GPIO30 = 1;         // output

  67.    GpioDataRegs.GPACLEAR.bit.GPIO31 = 1;       // Load the output latch
  68.    GpioCtrlRegs.GPAMUX2.bit.GPIO31 = 0;        // GPIO
  69.    GpioCtrlRegs.GPADIR.bit.GPIO31 = 1;         // output
  70.    EDIS;

  71. // GPIO0 and GPIO1 are inputs
  72.    EALLOW;
  73.    GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0;         // GPIO
  74.    GpioCtrlRegs.GPADIR.bit.GPIO0 = 0;          // input
  75.    GpioCtrlRegs.GPAQSEL1.bit.GPIO0 = 0;        // Xint1 Synch to SYSCLKOUT only

  76.    GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 0;         // GPIO
  77.    GpioCtrlRegs.GPADIR.bit.GPIO1 = 0;          // input
  78.    GpioCtrlRegs.GPAQSEL1.bit.GPIO1 = 2;        // XINT2 Qual using 6 samples

  79.    GpioCtrlRegs.GPACTRL.bit.QUALPRD0 = 0xFF;   // Each sampling window is 510*SYSCLKOUT
  80.    EDIS;

  81. // GPIO0 is XINT1, GPIO1 is XINT2
  82.    EALLOW;
  83.    GpioIntRegs.GPIOXINT1SEL.bit.GPIOSEL = 0;   // Xint1 is GPIO0
  84.    GpioIntRegs.GPIOXINT2SEL.bit.GPIOSEL = 1;   // XINT2 is GPIO1
  85.    EDIS;

  86. // Configure XINT1
  87.    XIntruptRegs.XINT1CR.bit.POLARITY = 0;      // Falling edge interrupt
  88.    XIntruptRegs.XINT2CR.bit.POLARITY = 1;      // Rising edge interrupt

  89. // Enable XINT1 and XINT2
  90.    XIntruptRegs.XINT1CR.bit.ENABLE = 1;        // Enable Xint1
  91.    XIntruptRegs.XINT2CR.bit.ENABLE = 1;        // Enable XINT2


  92. // GPIO34 will go low inside each interrupt.  Monitor this on a scope
  93.    EALLOW;
  94.    GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0;        // GPIO
  95.    GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1;         // output
  96.    EDIS;

  97. // Step 6. IDLE loop:
  98.    for(;;)
  99.    {
  100.       TempX1Count = Xint1Count;
  101.       TempX2Count = Xint2Count;

  102.       // Trigger both XINT1
  103.       GpioDataRegs.GPBSET.bit.GPIO34 = 1;   // GPIO34 is high
  104.       GpioDataRegs.GPACLEAR.bit.GPIO30 = 1; // Lower GPIO30, trigger Xint1
  105.       while(Xint1Count == TempX1Count) {}

  106.       // Trigger both XINT2

  107.       GpioDataRegs.GPBSET.bit.GPIO34 = 1;   // GPIO34 is high
  108.       DELAY_US(DELAY);                      // Wait for Qual period
  109.       GpioDataRegs.GPASET.bit.GPIO31 = 1;   // Raise GPIO31, trigger XINT2
  110.       while(Xint2Count == TempX2Count) {}

  111.       // Check that the counts were incremented properly and get ready
  112.       // to start over.
  113.       if(Xint1Count == TempX1Count+1 && Xint2Count == TempX2Count+1)
  114.       {
  115.           LoopCount++;
  116.           GpioDataRegs.GPASET.bit.GPIO30 = 1;   // raise GPIO30
  117.           GpioDataRegs.GPACLEAR.bit.GPIO31 = 1; // lower GPIO31
  118.       }
  119.       else
  120.       {
  121.           __asm("      ESTOP0"); // stop here 注释见文档下方
  122.       }
  123.    }
  124. }


  125. // Step 7. Insert all local Interrupt Service Routines (ISRs) and functions here:
  126.         // If local ISRs are used, reassign vector addresses in vector table as
  127.     // shown in Step 5

  128. __interrupt void xint1_isr(void)
  129. {
  130.         GpioDataRegs.GPBCLEAR.all = 0x4;   // GPIO34 is low
  131.         Xint1Count++;

  132.         // Acknowledge this interrupt to get more from group 1
  133.         PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
  134. }

  135. __interrupt void xint2_isr(void)
  136. {
  137.         GpioDataRegs.GPBCLEAR.all = 0x4;   // GPIO34 is low
  138.         Xint2Count++;

  139.         // Acknowledge this interrupt to get more from group 1
  140.         PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
  141. }


  142. //===========================================================================
  143. // No more.
  144. //===========================================================================


回复评论

暂无评论,赶紧抢沙发吧
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复