the frequency in the Oscilloscope? in C program

Discussion in 'Programmer's Corner' started by dun5599, Apr 12, 2011.

  1. dun5599

    Thread Starter New Member

    Oct 15, 2010
    3
    0
    hi everyone,
    i have a problem about my project. my project is about enter the frequency and duty cycle then test the output signal in Oscilloscope.
    i got the good result of my duty cycle but i cant get the correct frequency and i always get the low frequency even i enter 8khz and i just got >30hz.
    can someone tell how to fix it and i got the code in below.
    I used 68hc11 microcontoller .

    Code ( (Unknown Language)):
    1. #define DDRA *(unsigned char *) 0X1026
    2. #define PORTA *(unsigned char *) 0X1000
    3. #define TCTL1 *(unsigned char *) 0X1020
    4. #define TOC2 *(unsigned char *) 0X1018
    5. #define TCNT *(unsigned char *) 0X100E
    6. #define TFLG1 *(unsigned char *) 0X1023
    7. #define SCCR2 *(unsigned char *) 0X102D
    8. #define SCDR *(unsigned char *) 0X102F
    9. #define SCSR *(unsigned char *) 0X102E
    10. #pragma interrupt_handler SCI_ISR()d
    11. #include <stdio.h>
    12. //#include <ctype.h>
    13.  
    14. void SCI_ISR();
    15. int t,x,a,n1,n2;
    16. float t1,t2;
    17. void loop(int, int);
    18.  
    19. main()
    20. {
    21.      
    22.       printf("\n Enter the frquency 1 to 10:  ");
    23.       scanf("%d", &t);
    24.       printf("%d",t);
    25.       t=(1000/t);
    26.       printf("\n Enter the duty cycle 10 to 90:");
    27.       scanf("%d",&x);
    28.       printf("%d",x);
    29.       t1=(x*t)/100;
    30.       t2=(t-t1);
    31.       n1=t1/1;
    32.       n2=t2/1;
    33.       printf("\n Enter C or c to change and esc to exit");  
    34.        
    35.       *(unsigned char*) 0x00C4 = 0x7E;
    36.     *(void(**)()) 0x00C5 = SCI_ISR;
    37.         SCCR2 |= 0x24;    
    38.       asm("cli");
    39.       asm("TPA");
    40.       asm("ANDA #$AF");
    41.       asm("TAP");
    42.       loop(n1, n2);
    43.      // value:
    44.          //{
    45.     // printf("Thank You");
    46.       // }
    47.       return 0;
    48. }
    49.  
    50. void SCI_ISR()
    51. {
    52.               // a = getchar;
    53.     scanf("%c",&a);
    54.          a = SCDR;
    55.      if(a=='C'||'c')
    56.          {
    57.           main();
    58.       }
    59.    else if(a==0x1b)
    60.     {
    61.      exit();
    62.      }
    63.      else
    64.      {  
    65.     loop(n1,n2);
    66.     }
    67.  }
    68.  
    69. void loop(int n1, int n2)
    70.  {  
    71.   PORTA |= 0x40;
    72.  TCTL1 = 0x40;
    73.   TFLG1 = 0x40;
    74.    while(1)
    75. {
    76.         TFLG1 = 0x40;
    77.         TOC2 = (TCNT + n1);
    78.         while (!(TFLG1 & 0X40));
    79.            TFLG1 = 0x40;
    80.            TOC2 = (TOC2 + n2);
    81.             while (!(TFLG1 & 0X40));
    82. }
    83.    
    84.  
    85. }
    86.  
     
Loading...