Menu

ReadAD10 speed

Help
2008-02-27
2013-05-30
  • Nobody/Anonymous

    How many clock cycles does the ReadAD10 command take?
    Craig

     
    • Hugh Considine

      Hugh Considine - 2008-02-28

      It's really difficult to say!

      There is a 20 us acquisition delay, the time for the A/D converter to perform the conversion, the time taken to select the pin, and the time to enable and disable the A/D module. Add in the fact that the ReadAD routine is filled with #IFDEF statements which add and remove sections of code based on which registers are present, and the possibility of bank selection code being added automatically, and it all ends up totally confusing. Some PICs are faster than others, some pins can be selected faster than others!

      The best way to get an idea of how long the conversion takes is to use a timer. If the PIC you are using has Timer 1 and EEPROM, try this code:

      InitTimer1 Osc, PS1_1/1
      ClearTimer 1
      StartTimer 1
      Test = ReadAD(AN0)
      StopTimer 1
      EPWrite 0, TMR1H
      EPWrite 1, TMR1L

      This sets the timer to increment every clock cycle, starts it, performs an A/D conversion, then stops the timer and records the current value in the EEPROM. You should then be able to read the EEPROM back with your programmer.

      It might be good to try different values for the timer 1 prescaler, as otherwise the timer might overflow and you'd have no way of knowing (without using Interrupts, but that's just getting even more complicated). Perhaps try having it increment only every 2 clock cycles. This line would then be used to set up the timer:
      InitTimer1 Osc, PS1_1/2

      Note that there are only a few possible prescaler values - 1/1, 1/2, 1/4 and 1/8.

      Using EEPROM to record the value isn't essential - anything that will show you the timer value will also work fine.

       
    • Nobody/Anonymous

      Thats perfect, I need to time some other setions of code so I can just use this.
      Thank you
      Craig

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.