Author: sebastien.lelong
Date: Sun Jun  7 10:36:05 2009
New Revision: 1036

Modified:
    trunk/include/peripheral/adc/adc.jal
    trunk/include/peripheral/adc/adc_clock.jal
    trunk/sample/16f88_adc_lowres.jal

Log:
fix 2*tad delay, convert test

Modified: trunk/include/peripheral/adc/adc.jal
==============================================================================
--- trunk/include/peripheral/adc/adc.jal        (original)
+++ trunk/include/peripheral/adc/adc.jal        Sun Jun  7 10:36:05 2009
@@ -58,14 +58,10 @@
  -- Does an AD conversion with low resolution (8 bit) on the selected  
channel
  procedure _adc_read_low_res(byte in adc_chan, byte out adc_byte) is

-   if target_chip == PIC_12F675 then
-      ADCON0 = _adcon0_shadow | ((adc_chan & 0x03) << 2) -- setup  
multiplexer
-   else
-      ADCON0 = _adcon0_shadow | ((adc_chan & 0x07) << 3) -- setup  
multiplexer
-   end if
+   ADCON0_CHS = adc_chan
     delay_10us(adc_conversion_delay)  -- wait acquisition time
-   ADCON0_GO = true                          -- start conversion
-   while ADCON0_GO loop end loop             -- wait till conversion  
finished
+   ADCON0_GO = true                  -- start conversion
+   while ADCON0_GO loop end loop     -- wait till conversion finished
     -- 2 cases:
     --   - PIC has 10-bits ADC: since low resoltion if left
     --     justified, need to read ADRESH
@@ -77,11 +73,14 @@
     else
        adc_byte = ADRES
     end if
-   if target_clock <= (5_000_000 / 16)  then
-      delay_10us(1)                    -- to satisfy 2*Tad for next  
conversion
+   -- Honor 2*Tad time
+   -- tad_value comes from adc_clock
+   -- we won't be that accurate here (mostly because there's no  
delay_usec(byte in x) procedure)
+   if tad_value >= (ADC_MAX_TAD + ADC_MIN_TAD) / 2 then
+         _usec_delay(2 * ADC_MAX_TAD)
+   else
+         _usec_delay(2 * ADC_MIN_TAD)
     end if
-   -- Seb: but what if target_clock is, say 8MHz ? There's no 2*Tad delay.  
Is it because
-   -- was "too" generous when computing _adc_acquisition_time ?
  end procedure


@@ -93,10 +92,10 @@
     var byte ax[2] at ad_value

     if ADC_HIGH_RESOLUTION then
-      _adc_read_low_res (adc_chan,ax[1])   -- do conversion and get high  
byte
+      _adc_read_low_res(adc_chan,ax[1])   -- do conversion and get high  
byte
        ax[0] = ADRESL                       -- get low byte
     else
-      _adc_read_low_res (adc_chan,ax[0])   -- do conversion and get low  
byte
+      _adc_read_low_res(adc_chan,ax[0])   -- do conversion and get low byte
        ax[1] = 0                            -- clear high byte
        -- shift 2 highest order bits form low byte to high byte,
        -- to get a 10-bit result
@@ -113,7 +112,7 @@
  procedure adc_read_bytes(byte in adc_chan, byte out adc_hbyte, byte out  
adc_lbyte) is
     var word ad_value
     var byte ax[2] at ad_value
-   ad_value = adc_read (adc_chan)
+   ad_value = adc_read(adc_chan)
     adc_hbyte = ax[1]
     adc_lbyte = ax[0]
  end procedure
@@ -130,10 +129,14 @@
        _adc_read_low_res(adc_chan,adc_hbyte)
        adc_value = ADRESL
        -- shift the 2 highest order bits form high byte to low byte
-      asm  rrf   adc_hbyte,f
-      asm  rrf   adc_value,f
-      asm  rrf   adc_hbyte,f
-      asm  rrf   adc_value,f
+         adc_hbyte = adc_hbyte >> 1
+         adc_value = adc_value >> 1
+         adc_hbyte = adc_hbyte >> 1
+         adc_value = adc_value >> 1
+      ;;asm  rrf   adc_hbyte,f
+      ;;asm  rrf   adc_value,f
+      ;;asm  rrf   adc_hbyte,f
+      ;;asm  rrf   adc_value,f
     end if
     return adc_value
  end function

Modified: trunk/include/peripheral/adc/adc_clock.jal
==============================================================================
--- trunk/include/peripheral/adc/adc_clock.jal  (original)
+++ trunk/include/peripheral/adc/adc_clock.jal  Sun Jun  7 10:36:05 2009
@@ -15,6 +15,8 @@
  -- See adc_init for details


+var byte tad_value
+
  if defined(ADC_MIN_TAD) == false then
     -- So this is 1.6usecs
     const byte ADC_MIN_TAD = 16
@@ -36,10 +38,8 @@
     -- So, byte * 10 will give a byte. Ex: 32 * 10 = 64 ...
     -- That's we use a word, so the result can fit in a word (320)

-   var word tad_value = 0
     var bit tad_ok = false
-   tad_value = (factor * 10) / (target_clock / 1_000_000)
-   test_word(tad_value)
+   tad_value = byte((factor * 10) / (target_clock / 1_000_000))
     if tad_value >= ADC_MIN_TAD & tad_value < ADC_MAX_TAD then
          tad_ok = true
     end if

Modified: trunk/sample/16f88_adc_lowres.jal
==============================================================================
--- trunk/sample/16f88_adc_lowres.jal   (original)
+++ trunk/sample/16f88_adc_lowres.jal   Sun Jun  7 10:36:05 2009
@@ -58,21 +58,21 @@
  serial_hw_write("!")

  -- Configure ADC
--- We just need only one ADC channel
-const adc_hardware_nchan = 1
  -- We won't use any external VRef, so measures are done
  -- according to PIC powering voltage
-const adc_hardware_nvref = 0
+const byte ADC_NVREF = 0
  -- The maximum resistance while measuring ADC is... (unit: ohms)
  -- Being accurate helps speeding up ADC acquisition
-const adc_hardware_rsource = 2_000
+const word ADC_RSOURCE = 2_000
  -- In this example, we'll perform low resolution ADC: results are
  -- coded on 8bits
-const adc_hardware_high_resolution = false
+const bit ADC_HIGH_RESOLUTION = false
  -- Now include the famous library
-include adc_hardware
+include adc
  -- And initialize the whole with our parameters
  adc_init()
+-- We just need only one ADC channel
+set_analog_pin(0) -- make RA0/AN0 analog


  -- will periodically send those chars

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jallib?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to