Measure Pulse Width

basically miscellaneous, if it doesn't fit another sub-forum enter it here, we might even promote it to its own sub-forum
danlee58
Posts: 210
Joined: Thu Jan 17, 2013 2:29 am

Measure Pulse Width

Post by danlee58 » Tue Dec 01, 2015 4:15 pm

I am using a SuperPro to measure the pulse width of a signal. I use Timer1 to measure the time between T1.CR1 and T1.CR0. The program is written in C.

T1_CCR = 0x15;

The signal is connected to pin P1.18. Do I have to jumper it to P1.19?

T1 Capture 1 records the leading edge of the pulse ( falling edge), and T1 Capture 0 records the rising edge of the pulse, and generates an interrupt. The interrupt procedure must subtract T1_CR1 from T1_CR0 to determine the pulse width.

I would rather reset T1_TC on T1 Capture 1, so that T1 Capture 0 records the pulse width directly, and eliminate the subtraction. Is this possible?



basicchip
Posts: 944
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: Measure Pulse Width

Post by basicchip » Wed Dec 02, 2015 10:15 pm

If you want to have separate captures, yes you will need to hook the pins together.

How fast is the signal? If less than 100 KHz you could just change the capture edge in the interrupt. Probably even if it is 1 MHz. I don't know offhand what the interrupt response would be.

danlee58
Posts: 210
Joined: Thu Jan 17, 2013 2:29 am

Re: Measure Pulse Width

Post by danlee58 » Thu Dec 03, 2015 1:29 am

The pulse is between 1msec & 15msec duration. I'll try to change the capture edge of the interrupt.

danlee58
Posts: 210
Joined: Thu Jan 17, 2013 2:29 am

Re: Measure Pulse Width

Post by danlee58 » Thu Dec 03, 2015 3:06 am

Can I set T1_CCR = 0X35? It should interrupt on both edges. I only need to know which edge caused the interrupt. I could poll the pin, or examine a register(?).

basicchip
Posts: 944
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: Measure Pulse Width

Post by basicchip » Thu Dec 03, 2015 2:51 pm

As I read the user manual, it looks like if you use CAP0

TxCCR = 0x7 // will interrupt on both edges.

You can always read the state of the pin when it is configured as some other digital function (not so when configured for analog)

danlee58
Posts: 210
Joined: Thu Jan 17, 2013 2:29 am

Re: Measure Pulse Width

Post by danlee58 » Thu Dec 03, 2015 3:45 pm

I'll use T1_Cap0 set to 0x07, and poll P1.19, since I have the signal jumpered to that pin, to determine the level of the signal.

danlee58
Posts: 210
Joined: Thu Jan 17, 2013 2:29 am

Re: Measure Pulse Width

Post by danlee58 » Thu Dec 03, 2015 7:32 pm

I get an error when my interrupt file compiles. The error relates to the IN1(19) instruction. I need this to determine if the signal is High or Low.

basicchip
Posts: 944
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: Measure Pulse Width

Post by basicchip » Thu Dec 03, 2015 10:37 pm

I think you want IN(whatever) not IN1

IN is a rather complex #define, that isolates the user from the actual hardware. You might want to just read the proper FIOxPIN register

danlee58
Posts: 210
Joined: Thu Jan 17, 2013 2:29 am

Re: Measure Pulse Width

Post by danlee58 » Fri Dec 04, 2015 3:36 pm

I changed my pin read from IN1(19) to ((FIO1PIN2 & 0x08) == 0x08). That compiles OK. The strange thing is that I use IN1(18) in the Main program, and it compiles & works correctly.

My next problem is that my Interrupt procedure never runs. I know that the signal is going Low & High, because my Main program monitors it.

I find this statement in UM10360 confusing
T1_TCR
Bit 0 Counter Enable
When one, the Timer Counter and Prescale Counter are enabled for counting. When 1,
the counters are disabled.

basicchip
Posts: 944
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: Measure Pulse Width

Post by basicchip » Fri Dec 04, 2015 8:29 pm

You might want to update the user manual from the NXP website, in the April 2014 version it is correct, 0 is disabled, 1 is enabled

Post Reply