Revision: 1780
Author: sebastien.lelong
Date: Sun Mar 14 01:20:38 2010
Log: unittest for 16f887 and vref- only selection
http://code.google.com/p/jallib/source/detail?r=1780

Added:
 /trunk/test/unittest/16f887_adc.jalt

=======================================
--- /dev/null
+++ /trunk/test/unittest/16f887_adc.jalt        Sun Mar 14 01:20:38 2010
@@ -0,0 +1,251 @@
+-- Title: unittest to check ADC libs for 16F887
+-- Author: Sebastien Lelong, Copyright (c) 2008-2009, all rights reserved.
+-- Adapted-by:
+-- Compiler: >=2.4k
+--
+-- This file is part of jallib (http://jallib.googlecode.com)
+-- Released under the BSD license (http://www.opensource.org/licenses/bsd-license.php)
+--
+-- Description: this describes multiple unittests (a testcase), to test the
+-- many different combination while setting up ADC.
+--
+-- Notes: see jallib wiki page about unit testing to learn how to use this file
+--
+
+
+-- These are the different PIC configuration, with different clock
+-- speed. Clock speed can have impacts on acquisition delay computation,
+;@jallib section pic_20MHz
+include 16f887   ;@no_debug
+pragma target OSC HS
+pragma target clock 20_000_000
+pragma target WDT  disabled
+enable_digital_io()
+
+;@jallib section pic_10MHz
+include 16f887   ;@no_debug
+pragma target OSC HS
+pragma target clock 10_000_000
+pragma target WDT  disabled
+enable_digital_io()
+
+;@jallib section pic_8MHz
+include 16f887   ;@no_debug
+pragma target OSC HS
+pragma target clock 8_000_000
+pragma target WDT  disabled
+enable_digital_io()
+
+;@jallib section pic_4MHz
+include 16f887   ;@no_debug
+pragma target OSC HS
+pragma target clock 4_000_000
+pragma target WDT  disabled
+enable_digital_io()
+
+;@jallib section pic_1MHz
+include 16f887   ;@no_debug
+pragma target OSC HS
+pragma target clock 1_000_000
+pragma target WDT  disabled
+enable_digital_io()
+
+
+-- This unittest is a "self test". It should always be run and
+-- give a success. It not, current PIC is probably not supported
+-- by PICShell.
+;@jallib section self_test
+include unittest
+var byte a = 120
+test_byte(a)            ;@assertEquals 120 test_test
+
+
+
+;@jallib testcase test_1vref_low_rsource
+;@jallib use pic_20MHz
+;@jallib use self_test
+const byte ADC_NVREF = 1
+const bit ADC_HIGH_RESOLUTION = true
+const word ADC_RSOURCE = 2_500
+include adc
+adc_init()
+
+test_byte(adc_conversion_delay)         ;@assertEquals 14 test_compute_delay
+set_analog_pin(0)
+
+var byte adcon0_temp = ADCON0 & 0b_1100_0000
+test_byte(adcon0_temp) ;@assertEquals 128 test_compute_tad_adcs
+
+
+;@jallib testcase test_1vref_max_rsource
+;@jallib use pic_10MHz
+;@jallib use self_test
+const byte ADC_NVREF = 1
+const bit ADC_HIGH_RESOLUTION = true
+const word ADC_RSOURCE = 10_000
+include adc
+adc_init()
+
+test_byte(adc_conversion_delay)         ;@assertEquals 21 test_compute_delay
+set_analog_pin(0)
+var byte adcon1_vcfg_tmp = ADCON1 & 0b_0011_0000
+test_byte(adcon1_vcfg_tmp) ;@assertEquals 16 test_vcfg
+--                       XYY
+-- adcs =? 0b_010
+var byte adcon0_temp = ADCON0 & 0b_1100_0000
+test_byte(adcon0_temp) ;@assertEquals 128 test_compute_tad_adcs
+
+
+;@jallib testcase test_0vref_8MHz
+;@jallib use pic_8MHz
+;@jallib use self_test
+const byte ADC_NVREF = 0
+const bit ADC_HIGH_RESOLUTION = true
+const word ADC_RSOURCE = 10_000
+include adc
+adc_init()
+test_byte(adc_conversion_delay)         ;@assertEquals 21 test_compute_delay
+set_analog_pin(0)
+--                       XYY
+-- adcs =? 0b_010
+var byte adcon0_temp = ADCON0 & 0b_1100_0000
+test_byte(adcon0_temp) ;@assertEquals 128 test_compute_tad_adcs
+
+
+;@jallib testcase test_0vref_4MHz
+;@jallib use pic_4MHz
+;@jallib use self_test
+const byte ADC_NVREF = 0
+const bit ADC_HIGH_RESOLUTION = true
+const word ADC_RSOURCE = 10_000
+include adc
+adc_init()
+set_analog_pin(0)
+--                       XYY
+-- adcs =? 0b_101
+var byte adcon0_temp = ADCON0 & 0b_1100_0000
+test_byte(adcon0_temp) ;@assertEquals 64 test_compute_tad_adcs
+
+
+;@jallib testcase test_0vref_1MHz
+;@jallib use pic_1MHz
+;@jallib use self_test
+const byte ADC_NVREF = 0
+const bit ADC_HIGH_RESOLUTION = true
+const word ADC_RSOURCE = 10_000
+include adc
+adc_init()
+set_analog_pin(0)
+--                       XYY
+-- adcs =? 0b_101
+var byte adcon0_temp = ADCON0 & 0b_1100_0000
+test_byte(adcon0_temp) ;@assertEquals 0 test_compute_tad_adcs
+
+;@jallib testcase test_2vref
+;@jallib use pic_8MHz
+;@jallib use self_test
+const byte ADC_NVREF = 2
+const bit ADC_HIGH_RESOLUTION = true
+const word ADC_RSOURCE = 10_000
+include adc
+adc_init()
+var byte adcon1_vcfg_tmp = ADCON1 & 0b_0011_0000
+test_byte(adcon1_vcfg_tmp) ;@assertEquals 48 test_vcfg
+
+;@jallib testcase test_vref_neg_only
+;@jallib use pic_8MHz
+;@jallib use self_test
+const byte ADC_NVREF = 3    -- not user-friendly
+const bit ADC_HIGH_RESOLUTION = true
+const word ADC_RSOURCE = 10_000
+include adc
+adc_init()
+var byte adcon1_vcfg_tmp = ADCON1 & 0b_0011_0000
+test_byte(adcon1_vcfg_tmp) ;@assertEquals 32 test_vcfg
+
+;@jallib testcase test_all_analog_pins
+;@jallib use pic_8MHz
+;@jallib use self_test
+const byte ADC_NVREF = 0
+const bit ADC_HIGH_RESOLUTION = true
+const word ADC_RSOURCE = 2_500
+porta_direction = all_output
+portb_direction = all_output
+porte_direction = all_output
+
+
+include adc
+adc_init()
+
+set_analog_pin(0)
+-- check pin on PORTA configured as inputs (1 is 0b0000_0001 => RA0)
+test_byte(TRISA)  ;@assertEquals 1 test_porta_pin_an0_input
+test_byte(TRISB)  ;@assertEquals 0 test_portb_pin_an0_input
+test_byte(TRISE)  ;@assertEquals 0 test_porte_pin_an0_input
+
+set_analog_pin(1)
+test_byte(TRISA)  ;@assertEquals 3 test_porta_pin_an01_input
+test_byte(TRISB)  ;@assertEquals 0 test_portb_pin_an01_input
+test_byte(TRISE)  ;@assertEquals 0 test_porte_pin_an01_input
+
+set_analog_pin(2)
+test_byte(TRISA)  ;@assertEquals 7 test_porta_pin_an012_input
+test_byte(TRISB)  ;@assertEquals 0 test_portb_pin_an012_input
+test_byte(TRISE)  ;@assertEquals 0 test_porte_pin_an012_input
+
+set_analog_pin(3)
+test_byte(TRISA)  ;@assertEquals 15 test_porta_pin_an0123_input
+test_byte(TRISB)  ;@assertEquals 0 test_portb_pin_an0123_input
+test_byte(TRISE)  ;@assertEquals 0 test_porte_pin_an0123_input
+
+set_analog_pin(4)
+test_byte(TRISA)  ;@assertEquals 47 test_porta_pin_an01234_input
+test_byte(TRISB)  ;@assertEquals 0 test_portb_pin_an01234_input
+test_byte(TRISE)  ;@assertEquals 0 test_porte_pin_an01234_input
+
+set_analog_pin(5)
+test_byte(TRISA)  ;@assertEquals 47 test_porta_pin_an012345_input
+test_byte(TRISB)  ;@assertEquals 0 test_portb_pin_an012345_input
+test_byte(TRISE)  ;@assertEquals 1 test_porte_pin_an012345_input
+
+set_analog_pin(6)
+test_byte(TRISA)  ;@assertEquals 47 test_porta_pin_an0123456_input
+test_byte(TRISB)  ;@assertEquals 0 test_portb_pin_an0123456_input
+test_byte(TRISE)  ;@assertEquals 3 test_porte_pin_an0123456_input
+
+set_analog_pin(7)
+test_byte(TRISA)  ;@assertEquals 47 test_porta_pin_an01234567_input
+test_byte(TRISB)  ;@assertEquals 0 test_portb_pin_an01234567_input
+test_byte(TRISE)  ;@assertEquals 7 test_porte_pin_an01234567_input
+
+set_analog_pin(8)
+test_byte(TRISA)  ;@assertEquals 47 test_porta_pin_an012345678_input
+test_byte(TRISB)  ;@assertEquals 4 test_portb_pin_an012345678_input
+test_byte(TRISE)  ;@assertEquals 7 test_porte_pin_an012345678_input
+
+set_analog_pin(9)
+test_byte(TRISA)  ;@assertEquals 47 test_porta_pin_an0123456789_input
+test_byte(TRISB)  ;@assertEquals 12 test_portb_pin_an0123456789_input
+test_byte(TRISE)  ;@assertEquals 7 test_porte_pin_an0123456789_input
+
+set_analog_pin(10)
+test_byte(TRISA)  ;@assertEquals 47 test_porta_pin_an012345678910_input
+test_byte(TRISB)  ;@assertEquals 14 test_portb_pin_an012345678910_input
+test_byte(TRISE)  ;@assertEquals 7 test_porte_pin_an012345678910_input
+
+set_analog_pin(11)
+test_byte(TRISA)  ;@assertEquals 47 test_porta_pin_an01234567891011_input
+test_byte(TRISB)  ;@assertEquals 30 test_portb_pin_an01234567891011_input
+test_byte(TRISE)  ;@assertEquals 7 test_porte_pin_an01234567891011_input
+
+set_analog_pin(12)
+test_byte(TRISA)  ;@assertEquals 47 test_porta_pin_an0123456789101112_input
+test_byte(TRISB)  ;@assertEquals 31 test_portb_pin_an0123456789101112_input
+test_byte(TRISE)  ;@assertEquals 7 test_porte_pin_an0123456789101112_input
+
+set_analog_pin(13)
+test_byte(TRISA) ;@assertEquals 47 test_porta_pin_an012345678910111213_input +test_byte(TRISB) ;@assertEquals 63 test_portb_pin_an012345678910111213_input +test_byte(TRISE) ;@assertEquals 7 test_porte_pin_an012345678910111213_input
+
+

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