Claudia Ruch wrote:
> Hi Jan,
>  
> I write to you because I have a problem with the sdcc adc.h library. I
> am new to microcontroller programming and I am working at my diploma
> thesis at the University of Munich at the moment . I saw that there is a
> bug in this file because of the new adcon2 register. I use the pic
> 18f2550 and tried to correct the adc_open command but I did not
> succeed. Can you send me your improved files for ad conversion? Do you
> thing fosc/16 is okay for a 20MHz oscillator? Which aquisition time do
> you recommend?

My patch is only tested on the pic18fXXXX (pic18f2550 and pic18f4550).
On the pic18f1320 and pic18f1220 the library shipped with sddc did work
as far as i remember.

I'll attach the patch to this mail.

Greetings from Heidelberg

jan
>  
> It would help me a lot if you sent me your files.
>  
> Greetings form Munich
>  
> Claudia

Index: sim/ucsim/libtool
===================================================================
--- sim/ucsim/libtool	(Revision 4631)
+++ sim/ucsim/libtool	(Arbeitskopie)
@@ -35,7 +35,7 @@
 
 # ### BEGIN LIBTOOL CONFIG
 
-# Libtool was configured on host viktoria:
+# Libtool was configured on host castor2:
 
 # Shell to use when invoking shell scripts.
 SHELL="/bin/sh"
Index: device/include/pic16/adc.h
===================================================================
--- device/include/pic16/adc.h	(Revision 4631)
+++ device/include/pic16/adc.h	(Arbeitskopie)
@@ -53,6 +53,22 @@
 
 
 /* channel selection */
+#if defined(pic18f2455) || defined (pic18f2550) \
+    || defined(pic18f4455) || defined (pic18f4550)
+#define ADC_CHN_0               0x00
+#define ADC_CHN_1               0x01
+#define ADC_CHN_2               0x02
+#define ADC_CHN_3               0x03
+#define ADC_CHN_4               0x04
+#define ADC_CHN_5               0x05
+#define ADC_CHN_6               0x06
+#define ADC_CHN_7               0x07
+#define ADC_CHN_8               0x08
+#define ADC_CHN_9               0x09
+#define ADC_CHN_10              0x0a
+#define ADC_CHN_11              0x0b
+#define ADC_CHN_12              0x0c
+#else /* all other devices */
 #define ADC_CHN_1		0x00
 #define ADC_CHN_2		0x01
 #define ADC_CHN_3		0x03
@@ -60,9 +76,53 @@
 #define ADC_CHN_5		0x05
 #define ADC_CHN_6		0x06
 #define ADC_CHN_7		0x07
+#endif
 
 
 /* reference and pin configuration */
+#if defined(pic18f2455) || defined (pic18f2550) \
+    || defined(pic18f4455) || defined (pic18f4550)
+#define ADC_CFG_13A_0R  0x01
+#define ADC_CFG_13A_1R  0x11
+#define ADC_CFG_13A_2R  0x31
+#define ADC_CFG_12A_0R  0x03
+#define ADC_CFG_12A_1R  0x13
+#define ADC_CFG_12A_2R  0x33
+#define ADC_CFG_11A_0R  0x04
+#define ADC_CFG_11A_1R  0x14
+#define ADC_CFG_11A_2R  0x34
+#define ADC_CFG_10A_0R  0x05
+#define ADC_CFG_10A_1R  0x15
+#define ADC_CFG_10A_2R  0x35
+#define ADC_CFG_09A_0R  0x06
+#define ADC_CFG_09A_1R  0x16
+#define ADC_CFG_09A_2R  0x36
+#define ADC_CFG_08A_0R  0x07
+#define ADC_CFG_08A_1R  0x17
+#define ADC_CFG_08A_2R  0x37
+#define ADC_CFG_07A_0R  0x08
+#define ADC_CFG_07A_1R  0x18
+#define ADC_CFG_07A_2R  0x38
+#define ADC_CFG_06A_0R  0x09
+#define ADC_CFG_06A_1R  0x19
+#define ADC_CFG_06A_2R  0x39
+#define ADC_CFG_05A_0R  0x0a
+#define ADC_CFG_05A_1R  0x1a
+#define ADC_CFG_05A_2R  0x3a
+#define ADC_CFG_04A_0R  0x0b
+#define ADC_CFG_04A_1R  0x1b
+#define ADC_CFG_04A_2R  0x3b
+#define ADC_CFG_03A_0R  0x0c
+#define ADC_CFG_03A_1R  0x1c
+#define ADC_CFG_03A_2R  0x3c
+#define ADC_CFG_02A_0R  0x0d
+#define ADC_CFG_02A_1R  0x1d
+#define ADC_CFG_02A_2R  0x3d
+#define ADC_CFG_01A_0R  0x0e
+#define ADC_CFG_01A_1R  0x1e
+#define ADC_CFG_01A_2R  0x3e
+#define ADC_CFG_00A_0R  0x0f
+#else /* all other devices */
 #define ADC_CFG_8A_0R	0x00
 #define ADC_CFG_7A_1R	0x01
 #define ADC_CFG_5A_0R	0x02
@@ -78,8 +138,8 @@
 #define ADC_CFG_2A_2R	0x0d
 #define ADC_CFG_1A_0R	0x0e
 #define ADC_CFG_1A_2R	0x0f
+#endif
 
-
 /* initialize AD module */
 void adc_open(unsigned char channel, unsigned char fosc, unsigned char pcfg, unsigned char config);
 
Index: device/lib/pic16/libio/adc/adcsetch.c
===================================================================
--- device/lib/pic16/libio/adc/adcsetch.c	(Revision 4631)
+++ device/lib/pic16/libio/adc/adcsetch.c	(Arbeitskopie)
@@ -35,18 +35,33 @@
 void adc_setchannel(unsigned char channel) __naked
 {
 #if 0
+#if defined(pic18f2455) || defined (pic18f2550) \
+    || defined(pic18f4455) || defined (pic18f4550)
+  ADCON0 &= ~(0xf << 2);
+  ADCON0 |= channel << 2;
+#else /* all other devices */
   ADCON0 &= ~(0x7 << 3);
   ADCON0 |= channel << 3;
+#endif
 #else
   channel;
   __asm
+#if defined(pic18f2455) || defined (pic18f2550) \
+    || defined(pic18f4455) || defined (pic18f4550)
+    movlw       0xc3
+#else /* all other devices */
     movlw       0xc7
+#endif
     andwf       _ADCON0, f
     
     movlw       0x01
     movf        _PLUSW1, w
-    
+#if defined(pic18f2455) || defined (pic18f2550) \
+    || defined(pic18f4455) || defined (pic18f4550)
+
+#else /* all other devices */
     rlcf        _WREG, w
+#endif
     rlcf        _WREG, w
     rlcf        _WREG, w
 
Index: device/lib/pic16/libio/adc/adcopen.c
===================================================================
--- device/lib/pic16/libio/adc/adcopen.c	(Revision 4631)
+++ device/lib/pic16/libio/adc/adcopen.c	(Arbeitskopie)
@@ -45,16 +45,36 @@
   ADCON1 = 0;
 
   /* setup channel */
+#if defined(pic18f2455) || defined (pic18f2550) \
+    || defined(pic18f4455) || defined (pic18f4550)
+  ADCON0 |= (channel & 0x07) << 2;
+#else
   ADCON0 |= (channel & 0x07) << 3;
+#endif
 
   /* setup fosc */
+#if defined(pic18f2455) || defined (pic18f2550) \
+    || defined(pic18f4455) || defined (pic18f4550)
+  ADCON2 |= (fosc & 0x03);
+#else /* all other devices */  
   ADCON0 |= (fosc & 0x03) << 6;
   ADCON1 |= (fosc & 0x04) << 4;
+#endif
   
   /* setup reference and pins */
+#if defined(pic18f2455) || defined (pic18f2550) \
+    || defined(pic18f4455) || defined (pic18f4550)
+  ADCON1 |= pcfg & 0x3f;
+#else
   ADCON1 |= pcfg & 0x0f;
-  
+#endif  
+
+#if defined(pic18f2455) || defined (pic18f2550) \
+    || defined(pic18f4455) || defined (pic18f4550)
+  ADCON2 |= (config & ADC_FRM_RJUST);
+#else
   ADCON1 |= (config & ADC_FRM_RJUST);
+#endif
   
   if(config & ADC_INT_ON) {
     PIR1bits.ADIF = 0;
Index: device/lib/pic16/libio/adc/adcbusy.c
===================================================================
--- device/lib/pic16/libio/adc/adcbusy.c	(Revision 4631)
+++ device/lib/pic16/libio/adc/adcbusy.c	(Arbeitskopie)
@@ -11,7 +11,12 @@
 #else
   __asm
     movlw       0x00
+#if defined(pic18f2455) || defined (pic18f2550) \
+    || defined(pic18f4455) || defined (pic18f4550)
+    btfsc       _ADCON0bits, 0
+#else /* all other devices */
     btfsc       _ADCON0bits, 2
+#endif
     addlw       0x01
     return
   __endasm;
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to