Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Measuring the time of the zero crossings

Status
Not open for further replies.
Hi,

Since CCP1 represents a 16 bit value I recommend to use uint16.
For sure you may use a nother variable: new_ccp (just local in ISR)
And you need the variable: delta_t (global)

Then (pseudo code)
Code:
* New_ccp = ccp1h, ccp1l
* Delta_t = new_ccp - t0
* t0 = new_ccp

No need for a loop

Klaus

I don't know to store timer value (CCPR1H CCPR1L)

I think We can store value like

Code:
void interrupt CCP1_ISP()
{
   // CCP1 Interrupt
   if(CCP1IF == 1)            // if CCP1 Interrupt flag is set
   { 
       uint8_t New_ccp, Delta_t, t0;
      
       New_ccp = CCPR1H + CCPR1L;  
       
       Delta_t = New_ccp - t0;
        
       t0 = New_ccp;
   }   
   
}
 

Hi,

Lucky you live in year 2018. There is internet --> so use it.

Klaus

Yes I used internet and I found the way that I mention in precious post

I have doubt here

Code:
New_ccp = CCPR1H + CCPR1L;

can we store like this Will it store first time period
 

Hi,

Please post the document or internet site where this information is from.

Klaus
 

Hi,

Please post the document or internet site where this information is from.

Klaus

No I didn't mean that .

Generally we declare variable then we assign value to variable

For Example int number, value = 20;
number = value // number = 20

I said I don't understand how to load timer register value in New_ccp variable
 

Hi,

I must assume you dind´t put much effort in finding the solution on your own.
I´m not "C" specialist, thus I can´t give you a perfect answer. But your solution of post#23 is obviously wrong.

If you follow the internet search of post#22 you will find many suitable soultions.
It really takes less than a minute ... I wonder why you didn´t do this on your own.

There are even video tutorials in the first hits of the internet search.
Additionally MPLAB comes with documentation: Is it asking to much to read this documentation?
--> "MPLAB ® XC8 C Compiler User’s Guide", Chapter 5.3.6.2

Klaus
 

Hi,

I must assume you dind´t put much effort in finding the solution on your own.
I´m not "C" specialist, thus I can´t give you a perfect answer. But your solution of post#23 is obviously wrong.

If you follow the internet search of post#22 you will find many suitable soultions.
It really takes less than a minute ... I wonder why you didn´t do this on your own.

There are even video tutorials in the first hits of the internet search.
Additionally MPLAB comes with documentation: Is it asking to much to read this documentation?
--> "MPLAB ® XC8 C Compiler User’s Guide", Chapter 5.3.6.2

Klaus

I am trying best
Does it make sense?

Code:
void interrupt CCP1_ISP()
{
   // CCP1 Interrupt
   if(CCP1IF == 1)            // if CCP1 Interrupt flag is set
   { 
       uint8_t new_ccp, Delta_t, t0;
      
       new_ccp = CCPR1H - CCPR1L;  
       
       Delta_t = new_ccp - t0;
        
       t0 = new_ccp;
   }   
   
}
 

Hi,

In chapter 5.3.6.2 there are only two lines of code. Did you read them?
You may even "copy and paste" them ..and then modify the variable_names to your need. That´s it.
I won´t do this for you.

There are million of example codes, documents and video tutorials.

Klaus
 

CCPR1H and CCPR1L are the high and low bytes of a 16 bit register. They need to be combined respectively. I can hardly imagine that have never seen similar constructs in a C programming tutorial or text book.

Code:
New_ccp = (int)CCPR1H << 8 | CCPR1L;

- - - Updated - - -

As far as I'm aware of, the PIC special register issue (specific read order required) discussed in 5.3.6.2 doesn't apply to CCPR1 register. But it doesn't hurt to use the specified method. In any case <<8 shift of high byte or equivalent operation is required.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top