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.

  • to try and fine-tune my process
    it would be easy to comment if you would show your code

    Erik

  • This is the pulse width part of the code

    int count;
    
    TMOD = (TMOD & 0xF0) | 0x05; //setup counter
    
    
      TL0 = 0; // Clear the timer low registers (freq to fast, TH0 not used)
      count = 0; //clear the count
      TR0 = 1; // start the counter.
    
      while (!INT0)
      while (INT0)
    
      TR0 = 0; // stop the counter.
    
      count =  TL0; //copy TL0 to count
    

  • two solutions
    a) increase your xtal freq (make sure the chip can handle it)
    b) use a derivative with a PCA

    Erik

  • 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.

  • I would be interested in knowing the part number of a processor that can increment a count when a pin is held low at or as close to once per clock cycle.

  • I would be interested in knowing the part number of a processor that can increment a count when a pin is held low at or as close to once per clock cycle.
    Any processor with a PCA e.g. hilips P89C66x and P89C51Rx2 and even, the lowly <$1 P89LPC932 where a similar is called a CCA.

    Erik