This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Assembler and pulse width

I need to measure a pulse with that is almost faster then C can process with the hardware I'm using, so I think. I'm only getting a count of 26 on a pulse width, Witch has been good for the last four years. Now I need a count of at least 50 to try and fine-tune my process. My problem might be in the way I've been measuring the pulse width, which is based off of the Keil example using P3.4. Witch if I read the Atmel data sheet right takes 24 cycles to increment the count. Anyone know if Keil has an Assembler example for measuring a pulse with? I'm not asking anyone to write code for me, I only need direction help. If Assembler will give me what I need, I'll force myself to learn Assembler.

Parents
  • I think if you take a look at the generated code, you'll see there is very little overhead for that particular sequence of C.

    Note that the timer count is all performed in hardware. No matter what language you use, you won't see more counts between timer start and stop. For that matter, if C were slowing you down, you would possibly get more counts due to a delay in disabling the timer after detecting the final edge. Switching to assembler would reduce the count.

    You don't mention your particular variant, but a lot of 8051 variants these days operate with less than 12 clocks/instruction, and usually have some extra bits somewhere to control a prescalar for the timers. You might be able to program your timer to increment more frequently than once every 12 clocks. Check the data sheet description of your timer hardware carefully.

    If not, the other solution is what Eric suggested: a faster XTAL frequency will make the timer count faster (among other things) and produce a larger count for the same amount of time. Or find a variant with more sophisticated edge- and pulse- timing hardware built in.

Reply
  • I think if you take a look at the generated code, you'll see there is very little overhead for that particular sequence of C.

    Note that the timer count is all performed in hardware. No matter what language you use, you won't see more counts between timer start and stop. For that matter, if C were slowing you down, you would possibly get more counts due to a delay in disabling the timer after detecting the final edge. Switching to assembler would reduce the count.

    You don't mention your particular variant, but a lot of 8051 variants these days operate with less than 12 clocks/instruction, and usually have some extra bits somewhere to control a prescalar for the timers. You might be able to program your timer to increment more frequently than once every 12 clocks. Check the data sheet description of your timer hardware carefully.

    If not, the other solution is what Eric suggested: a faster XTAL frequency will make the timer count faster (among other things) and produce a larger count for the same amount of time. Or find a variant with more sophisticated edge- and pulse- timing hardware built in.

Children