SCTimer in LPC11U68

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SCTimer in LPC11U68

1,244 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mattiad on Thu Dec 11 01:33:07 MST 2014
Dear All,


I would like to use my micro LPC11u68, 100 pins configuration, in order to  check the speed of a quadrature ecoder.
Essentially I need to count the rising and falling edges of two separate signals A & B, typical of the encoder.
One solution is to generate and interrupt every edge and increase a counter, but these implies that every XX us I have to occupy some resources to the micro.
The ideal solution is to have a register which increases stand alone once an event  (rising and falling edges) occours. This would be perfect for me because every 100ms I'd check the value of the register, whitout "stressing" the micro too much.
It seems that with SCTimer (chapter 18 of UM10732) it is possible but, since I'm an inexperienced beginner I don't understand exactly how to make it possible.

Has someone already tried this?

Do you have any suggestion?

Thank you in advance
Labels (1)
0 Kudos
Reply
8 Replies

1,053 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by The Dude on Wed Dec 17 08:37:21 MST 2014
Using a part like the LPC15xx is likely the best solution to your problem.
0 Kudos
Reply

1,053 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Sat Dec 13 19:23:15 MST 2014

Quote: mattiad
I would like to use my micro LPC11u68, 100 pins configuration, in order to  check the speed of a quadrature ecoder.
...
Do you have any suggestion?



Yes, use a LPC15xx with QEI  :)

0 Kudos
Reply

1,053 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mattiad on Fri Dec 12 05:46:21 MST 2014
Hi R2D2,

sorry but I'm new with micro programming and I don't understand  your explaination.
Maybe do you have a portion of the code to take as an example.


Quote:
Then you get a complete A cycle capture time and a B capture time within this cycle (to get the direction).



In this case I check the direction just one time on a number of cycle. If, unluckly, in that moment I have some virations on the structure in which my encoder is inserted, I could find an inverted direction and consider it valid for the cycle.

Increasing or decreasing a register every rising edge allows me to ""filter"" this problemi dued to vibrations.

Best Regards
0 Kudos
Reply

1,053 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Fri Dec 12 04:24:20 MST 2014

Quote: mattiad
I want to read the counter register becauser I count the number of rising edges every 100ms and with this value I calculate the angular speed.
Do you have a better idea to realize this?




Didn't I describe it?

Just capture both signals. Set your SCT event to reset counter after very A cycle.

Then you get a complete A cycle capture time and a B capture time within this cycle (to get the direction).

No interrupt required...
0 Kudos
Reply

1,053 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mattiad on Fri Dec 12 04:11:45 MST 2014
Hi R2D2 and thank you for your answer and suggestion!

I want to read the counter register becauser I count the number of rising edges every 100ms and with this value I calculate the angular speed.
Do you have a better idea to realize this?

The second step that I need to do is, as you say, calculating the direction.
Since I have this kind of input (fig1) my idea is:

- at rising edge of A I check the status of B: if B=0 I increase the counter register else i decrease the counter register. In this case I know the speed and also the direction.

Do you have alternative suggestions which allows me to obtain this datas without using the CPU every rising edge?

Best Regards!!!!

Mattia
0 Kudos
Reply

1,053 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Fri Dec 12 03:28:22 MST 2014

Quote: mattiad
My idea would be: every 100ms my timer gives me an interrupt. During this interrupt I read values contained in the counter registesr...



:quest:

Why do you count?

SCT is able to do a lot of useful things for. If you capture A with SCT0 this cycle time is useful to calculate the speed.
If you use another SCT0 capture input for B you get the direction (< (cycle time)/2 or >(cycle time)/2)  :)

0 Kudos
Reply

1,053 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mattiad on Fri Dec 12 01:15:29 MST 2014
Thank you very much for your clear answer!

I just have a doubt: is it necessary to do steps 4 and five?

My idea would be: every 100ms my timer gives me an interrupt. During this interrupt I read values contained in the counter registesr and then I clear these registers (page 343 of 609).

Best Regards
0 Kudos
Reply

1,053 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by The Dude on Thu Dec 11 12:25:00 MST 2014
I don't know of any examples but maybe this will help you out. Please note that I just
dreamed this up so it is up to you to verify whether it meets your exact needs.

This idea is based on the SCTs being able to be clocked on the positive or negative
of inputs to the SCTs not on both edges. I chose positive edges but you could probably
do one on the positive and one on the negative if there was an advantage in that.
Since the A and B inputs should be 90 degrees out of phase you might be able to use
that to your advantage in calculating the speed and only clocking on one edge.

If this works out it would be great if you could post the code on a BLOG.

Good luck
The Dude

Configuration ================

1. Set SCT0 to be clocked off of your input A (positive edge). See page 338 of 608.
    CLKMODE = 0x02

2. Set SCT1 to be clocked off of your input B (positive edge). See page 338 of 608.
    CLKMODE = 0x02

3. Configure another timer to interrupt and output a pulse every 100 ms.

4. Connect this timer output to an input to SCT0 and SCT1. I think you
    will have to do this externally on your PCB.

5. Configure the SCT0 and SCT1 counter to capture the count values
    when the timer output/SCT inputs go high and reload the counters to 0. You should
    probably sync this input to the respective SCT clock.

6. Create an ISR that reads the SCT0 and SCT1 timer capture registers when the timer interrupt occurs
     and writes these values to a couple variables.

Operation  ================

1. When you receive the timer interrupt you have the two values.
0 Kudos
Reply