Status: Assigned
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 170 by [email protected]: 16f33 HiRes ADC
http://code.google.com/p/jallib/issues/detail?id=170

I have a problem trying to read the highest 2 bits of the ADC.

The following program will reproduce the problem


---------------------------------------------------------------------
include 16f1933                    -- target PICmicro
--
pragma target clock 16_000_000    -- oscillator frequency
pragma target OSC INTOSC_NOCLKOUT   --
pragma target PLLEN  P1           -- PLL off
--
OSCCON_SPLLEN = 0                 -- PLL off
OSCCON_IRCF   = 0b1111            -- 16 MHz
OSCCON_SCS    = 0b00              -- fuses determine clock source
--
pragma target WDT      disabled   -- no watchdog
pragma target DEBUG    disabled   -- no debugging
pragma target LVP      disabled   -- no Low Voltage Programming
pragma target MCLR external       -- reset externally
--
enable_digital_io()                -- make all pins digital I/O
-- ---------------
-- configure ADC
-- ---------------
const bit ADC_HIGH_RESOLUTION = true
const byte ADC_NVREF = ADC_NO_EXT_VREF
include adc
adc_init()
set_analog_pin(10)
set_analog_pin(12)
-- ---------------
-- setup i2c slave
-- ---------------
const byte I2C_BUFFER_SIZE = 5
include i2c_hw_slave_msg

const byte SLAVE_ADDRESS = 0x5C
i2c_hw_slave_init(SLAVE_ADDRESS)

-- ------------------------------------------------
-- i2c_process_message - User code for i2c slave
procedure i2c_process_message(byte in byte_count) is
   var byte mHi
   var byte mLo
   if (i2c_buffer[0] == 0x20) then
      if (byte_count == 2) then
         if (i2c_buffer[1] == 0) then
            adc_read_bytes(10,mLo,mHi)
            i2c_buffer[0] = mHi
            i2c_buffer[1] = mLo
         end if
      end if
   end if
end procedure

var word measureHiRes
measureHiRes = adc_read(12)

forever loop

end loop

---------------------------------------------------------------------

What is the expected output? What do you see instead?


If I remove the "measureHiRes = adc_read(12)" before the forever loop
I will get the expected output when I poll the value via I2C (all 10 bits)

adding the "measureHiRes = adc_read(12)" to read an ADC channel outside the ISR will corrupt the higher 2 bits returning, in this case, 0x78 instead.

If I change things to only do 8 bit resolution the program works as expected


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