the frequency in the Oscilloscope? in C program

Thread Starter

dun5599

Joined Oct 15, 2010
3
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 .

Rich (BB code):
#define DDRA *(unsigned char *) 0X1026
#define PORTA *(unsigned char *) 0X1000
#define TCTL1 *(unsigned char *) 0X1020
#define TOC2 *(unsigned char *) 0X1018
#define TCNT *(unsigned char *) 0X100E
#define TFLG1 *(unsigned char *) 0X1023
#define SCCR2 *(unsigned char *) 0X102D
#define SCDR *(unsigned char *) 0X102F
#define SCSR *(unsigned char *) 0X102E
#pragma interrupt_handler SCI_ISR()d
#include <stdio.h>
//#include <ctype.h>

void SCI_ISR();
int t,x,a,n1,n2;
float t1,t2;
void loop(int, int);

main()
{
      
      printf("\n Enter the frquency 1 to 10:  ");
      scanf("%d", &t);
      printf("%d",t);
      t=(1000/t);
      printf("\n Enter the duty cycle 10 to 90:");
      scanf("%d",&x);
      printf("%d",x);
      t1=(x*t)/100;
      t2=(t-t1);
      n1=t1/1;
      n2=t2/1;
      printf("\n Enter C or c to change and esc to exit");   
       
      *(unsigned char*) 0x00C4 = 0x7E;
    *(void(**)()) 0x00C5 = SCI_ISR;
        SCCR2 |= 0x24;    
      asm("cli");
      asm("TPA");
      asm("ANDA #$AF");
      asm("TAP");
      loop(n1, n2);
     // value: 
         //{
    // printf("Thank You");
      // }
      return 0;
}

void SCI_ISR()
{
              // a = getchar;
    scanf("%c",&a);
         a = SCDR;
     if(a=='C'||'c')
         {
          main(); 
      }
   else if(a==0x1b)
    {
     exit();
     }
     else 
     {  
    loop(n1,n2);
    }
 }
 
void loop(int n1, int n2)
 {  
  PORTA |= 0x40;
 TCTL1 = 0x40;
  TFLG1 = 0x40;
   while(1)
{
        TFLG1 = 0x40;
        TOC2 = (TCNT + n1);
        while (!(TFLG1 & 0X40));
           TFLG1 = 0x40;
           TOC2 = (TOC2 + n2);
            while (!(TFLG1 & 0X40));
}
   
  
}
 
Top