CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Output Pulse moving

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
prayami



Joined: 22 Dec 2004
Posts: 78

View user's profile Send private message

Output Pulse moving
PostPosted: Wed Sep 07, 2005 8:31 pm     Reply with quote

Hi..I am using PIC18F4525. I am reading a input signal and calculating
input frequency. And generate the output pulses at desire frequency.
The frequency of the output pulse in correct. But the problem is the
output pulse is not steady at any place. It is actually moving on right
side.

Is this mean that it is not generating at exact time?

What can be the problem?

Thanks in advance.......
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Sep 07, 2005 8:37 pm     Reply with quote

Hard to say without any code.
prayami



Joined: 22 Dec 2004
Posts: 78

View user's profile Send private message

PostPosted: Wed Sep 07, 2005 9:45 pm     Reply with quote

Hi...Here with I am sending code that I have used. I have tried to keep
less code in the interrupt. And tried to do more generic way because
I am going to add three more interrupts in this program. And input
pulses can ce of any duty cycle and upto from 1Hz to 200Hz.

I have generated output on PIN_E2. If you will see both the input and
output pulses on the scope then. Input and output will look same but
the problem is input is steady. But output is moving on right side slowly.

This is not allowed because I am going to add phase shift in the next step
of the project.

Code:



#CASE
#include <18F4525.h>
#fuses H4,NOWDT,NOLVP,NOBROWNOUT,NOPBADEN,PUT,NOXINST,NOMCLR,
NOLPT1OSC,PROTECT,CPD,NOWRT,NOWRTD,EBTR,NOCPB,EBTRB,NOWRTC,NOWRTB
#use delay(clock=40000000)
 
int1 RPMOutStatus=0,isCCP1=0;   
int1 GetOutTimer=1;

unsigned int16  temptimer1,tempcount1,temptimer1_1,tempcount1_1;
unsigned int16  mytimerL0,mycountL0,mytimerH0,mycountH0;

int1 HighPulse,ChangePulse,ChangeStatus;
unsigned int16 counttimer1;
unsigned int32 TimerCycle,Timer0CyH,Timer0CyL;
unsigned int8 IntTimer0;



#int_ccp1
void isr()
{      
   
    if(RPMOutStatus==0)
   {
         setup_ccp1(CCP_CAPTURE_FE);   
      RPMOutStatus=1;


         temptimer1 = get_timer1();
         tempcount1 = counttimer1;   
         
         set_timer1(0);
            
       counttimer1=0;
   
       isCCP1=1;
   }
   else
   {

         temptimer1_1 = get_timer1();
         tempcount1_1 = counttimer1;
         
         setup_ccp1(CCP_CAPTURE_RE);   
      RPMOutStatus=0;

   }//if(RPMOutStatus==0)

   
}//#int_ccp1   
 
#INT_TIMER1                       
void timer1_isr() {               
                                   
  if(counttimer1<65534)                                     
  counttimer1++;         
 
}

#INT_RTCC   // fast                 
void timer0_isr() {                                                                                                       

                  
      if(ChangeStatus==1)
      {
         if(HighPulse==0)
         {
            output_high(PIN_E2);         
            HighPulse=1;            
         }
         else
         {
            output_low(PIN_E2);                     
            HighPulse=0;
         }//if(HighPulse==1)
         
         ChangeStatus=0;
      }//if(ChangeStatus==1)

 IntTimer0++;

   if(HighPulse==1)
   {
      if(IntTimer0>mycountH0)
      {
         set_timer0(65535-mytimerH0);
         IntTimer0=0;


         ChangeStatus=1;      
                                 
      }//if(IntTimer0>mycountH0)

   }
   else
   {
      if(IntTimer0>mycountL0)
      {
         set_timer0(65535-mytimerL0);
         IntTimer0=0;      

         ChangeStatus=1;      

         GetOutTimer=1;
                                 
      }//if(IntTimer0>mycountH0)

   }//if(HighPulse==1)                     

}//timer0_isr


void main() {

#PRIORITY RTCC 
    
     HighPulse=0;
   ChangePulse=1;
   ChangeStatus=1;   
         
   set_tris_e(0x00); //All output        

     setup_adc(ADC_OFF);
       
     setup_ccp1(CCP_CAPTURE_RE);   
     
     setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);   
     set_timer1(0);
                
   setup_timer_0(RTCC_INTERNAL | RTCC_DIV_2);
   set_timer0(0);   
 

   enable_interrupts(INT_RTCC);             
     enable_interrupts(INT_TIMER1);
     enable_interrupts(INT_CCP1);   
     enable_interrupts(GLOBAL);
              

            
  while(TRUE) {

//-----Start RPM 1 calculation-----------------------------
   if(isCCP1==1)
   {
   
   TimerCycle = make32(tempcount1,temptimer1);

   isCCP1=0;
   
   }//if(isCCP1==1)

//-----End RPM 1 calculation-----------------------------

//---Start RPM Output Pulse--------------------------
   if(GetOutTimer==1)
   {

      mytimerH0=temptimer1_1;
      mycountH0=tempcount1_1;

      Timer0CyL = (unsigned int32)((make32(tempcount1,temptimer1) - make32(tempcount1_1,temptimer1_1))/2);

      Timer0CyH = (unsigned int32)(make32(tempcount1_1,temptimer1_1)/2);      

      mycountH0=0;
         
      while(Timer0CyH>65535)
      {
         Timer0CyH = Timer0CyH - 65536;
         mycountH0++;
      }
      
      mytimerH0 = (unsigned int16)Timer0CyH;   
   //---------------------
      mycountL0=0;
         
      while(Timer0CyL>65535)
      {
         Timer0CyL = Timer0CyL - 65536;
         mycountL0++;
      }
      
      mytimerL0 = (unsigned int16)Timer0CyL;   

      GetOutTimer=0;

   }//if(GetOutTimer==1)
//---End RPM Output Pulse----------------------------


                     
  }//while(TRUE)
 
}//main





Last edited by prayami on Wed Sep 07, 2005 10:26 pm; edited 2 times in total
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Sep 07, 2005 10:02 pm     Reply with quote

you used the "quote button" instead of the "code button" If you edit you listing it will be able to make it easier to read.

You did not mention how you are triggering the scope. Are you using a daul trace cro and looking at both traces simultaneously? If so what event are you triggering on?
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
prayami



Joined: 22 Dec 2004
Posts: 78

View user's profile Send private message

PostPosted: Wed Sep 07, 2005 10:30 pm     Reply with quote

I am using Digital Scope from PICO Technology Ltd.
On channel one: Frequency Input
On Channel two: Frequency Output

I am Triggering channel A on rising edge.
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Wed Sep 07, 2005 11:15 pm     Reply with quote

prayami wrote:

And generate the output pulses at desire frequency.
I am using Digital Scope from PICO Technology Ltd.


Looked up PICO scopes and their software on the web. It looks like one of the functions the software provides is the spectrum analyzer. You have probably tried this already, but if you look at your output pulse with a spectrul analyzer you should see the primary frequency and it's harmonics. If your output squarewave frequency is steady, it's primary and harmonics will not be shifting on the analyzer (regardless of what your trigger your data acquisition on).
sseidman



Joined: 14 Mar 2005
Posts: 159

View user's profile Send private message

Re: Output Pulse moving
PostPosted: Thu Sep 08, 2005 6:36 am     Reply with quote

prayami wrote:
Hi..I am using PIC18F4525. I am reading a input signal and calculating
input frequency. And generate the output pulses at desire frequency.
The frequency of the output pulse in correct. But the problem is the
output pulse is not steady at any place. It is actually moving on right
side.

Is this mean that it is not generating at exact time?

What can be the problem?

Thanks in advance.......


If you have one pulse on your oscilloscope screen, and it is "moving on the right side", and steady on the left, it means that your pulse width is not constant, and it doesn't say anything at all about your pulse rate.

If you have more than one pulse on the screen, and the pulses after the pulse that triggers the sweep don't seem steady in time, then you are likely having pulse rate problems, and possibly pulse width as well.

Make sure your scope is triggering off the waveform, and not in any "autotrigger" mode.
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Thu Sep 08, 2005 8:17 am     Reply with quote

If the left side of your pulse is steady but the 'width' of the pulse varies(the right side moves) this is most likely caused by your ISR's. An interrupt will happen at any time during your code. Say, the left side of the signal goes High and everything excecutes just fine. The next time the pulse goes High your Timer1 ISR is called(the interrupt is flagged). The processor will execute this code and then return to the normal code. This has, in effect, lengthened your pulse width.

Ronald
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group