Issue with system file for the 18F4550 - Using ADC

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
bitfogav
Registered User
Registered User
Posts: 167
Joined: Sat Oct 09, 2010 1:39 pm
Location: United Kingdom

Issue with system file for the 18F4550 - Using ADC

Post by bitfogav » Sat Sep 29, 2012 10:47 am

The code below used to work fine but with the latest version 2.2.1.4 of the Compiler it doesn't.

All the code is doing is reading the AN0 pin and setting the delay for flashing a led.

Code: Select all

Device = 18F4550  
Clock = 20
    
Include "ADC.bas"

Dim STATUS_LED As PORTD.3

Function Get_ADC_Sample() As Word 
   result = ADC.Read(0) 
   result = result * 2 
End Function

While true
   High(STATUS_LED) 
   DelayMS(100 + Get_ADC_Sample) 
   Low(STATUS_LED) 
   DelayMS(100 + Get_ADC_Sample) 
Wend
Ive found that ive had to change the system file for the 18F4550 as Jerry pointed out in this topic http://www.sfcompiler.co.uk/forum/viewt ... 8f4550+adc

Change the line

Code: Select all

#const _adc = $05                      // 5 ADC channels available 
to

Code: Select all

#const _adc = 12                       // 12 ADC channels available 
and save the file.

This fixes the issue that ive got reading the ADC pin, so I guess the system file for the 18F4550 was updated in the latest version of the Compiler.
But what I would like to know is, if I need to change anything else in the system file or whether this change to the system file will affect anything else please?.

CharlieM
Registered User
Registered User
Posts: 199
Joined: Wed Oct 10, 2007 12:05 am

Post by CharlieM » Sun Sep 30, 2012 12:31 am

bitfogav are you sure your version is 2.2.1.4?

I see on the website that the last release is 2.2.1.3 and this is the latest version I have.
Running version 2.2.1.9
Regards CharlieM

bitfogav
Registered User
Registered User
Posts: 167
Joined: Sat Oct 09, 2010 1:39 pm
Location: United Kingdom

Post by bitfogav » Sun Sep 30, 2012 7:52 am

Yes im sure it is 2.2.1.4, I see that the last update by David on the website is 2.2.1.3.

As this forum doesn't support uploading images here is an image taken from my SF help -> about tab. shows version 2.2.1.4
http://www.freeimagehosting.net/cngun

This version was the Electronic download version from Mecanique.

Edited* The image above may no longer work so you can find the latest version of the compiler here:
http://www.sfcompiler.co.uk/wiki/pmwiki ... ionHistory
Last edited by bitfogav on Sun Oct 07, 2012 2:31 pm, edited 2 times in total.

bitfogav
Registered User
Registered User
Posts: 167
Joined: Sat Oct 09, 2010 1:39 pm
Location: United Kingdom

Post by bitfogav » Sun Sep 30, 2012 8:37 am

This is the Old system file for the 18F4550:

Code: Select all

{
****************************************************************
*  Name    : 18F4550                                           *
*  Author  : David John Barker                                 *
*  Notice  : Copyright (c) 2006 Mecanique                      *
*          : All Rights Reserved                               *
*  Date    : 17/11/2006                                        *
****************************************************************
}

module SystemTypes

// system header...
#const _core = $0012                   // processor core
#const _ram_banks = $08                // 8 RAM bank(s) used
#variable _maxaccess = $60             // access ram is 96 bytes
#variable _maxram = $0800              // 2048 bytes of user RAM
#variable _maxrom = $008000            // 32 KB of program ROM
#const _eeprom = $0100                 // 256 bytes of EEPROM
#const _eeprom_start = $F00000         // EEPROM start address
#const _ports = $05                    // 5 available ports
#const _ccp = $01                      // 1 CCP module(s) available
#const _eccp = $01                     // 1 ECCP module(s) available
#const _mssp = $01                     // 1 MSSP module(s) available
#const _usart = $01                    // 1 USART(s) available
#const _adc = $0D                      // 13 ADC channels available
#const _adres = $0A                    // 10 bit ADC resolution
#const _comparator = $02               // 2 comparator(s) available
#const _psp = $00                      // Parallel Slave Port (PSP) is NOT supported
#const _can = $00                      // onboard CAN is NOT supported
#const _usb = $01                      // onboard USB available
#const _ethernet = $00                 // onboard Ethernet is NOT supported
#const _flash_write = $01              // FLASH has write capability
And here is the new system file:

Code: Select all

{
****************************************************************
*  Name    : 18F4550                                           *
*  Author  : David John Barker                                 *
*  Notice  : Copyright (c) 2011 Mecanique                      *
*          : All Rights Reserved                               *
*  Date    : 10/08/2011                                        *
****************************************************************
}

Module SystemTypes

// system header...
#const _core = $0012                   // processor core
#const _ram_banks = $08                // 8 RAM bank(s) used
#variable _maxaccess = $60             // access ram is 96 bytes
#variable _maxram = $0800              // 2048 bytes of user RAM
#variable _maxrom = $008000            // 32 KB of program ROM
#const _eeprom = $0100                 // 256 bytes of EEPROM
#const _eeprom_start = $F00000         // EEPROM start address
#const _ports = $05                    // 5 available ports
#const _ccp = $01                      // 1 CCP module(s) available
#const _eccp = $01                     // 1 ECCP module(s) available
#const _mssp = $01                     // 1 MSSP module(s) available
#const _usart = $01                    // 1 USART(s) available
#const _adc = $05                      // 5 ADC channels available
#const _adres = $0A                    // 10 bit ADC resolution
#const _comparator = $02               // 2 comparator(s) available
#const _psp = $00                      // Parallel Slave Port (PSP) is NOT supported
#const _can = $00                      // onboard CAN is NOT supported
#const _usb = $01                      // onboard USB available
#const _ethernet = $00                 // onboard Ethernet is NOT supported
#const _flash_write = $01              // FLASH has write capability
The old version actually states 13 ADC channels and the new one states 5 ADC channels.

Jerry Messina
Swordfish Developer
Posts: 1246
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Sun Sep 30, 2012 10:58 am

But what I would like to know is, if I need to change anything else in the system file or whether this change to the system file will affect anything else please?
I think you're good to go. When the system files are generated, that '_adc' entry is one of the settings that has to be done manually.

Because the ADC has changed so much over time, it's always a good idea to compare the settings in ADC.bas to the datasheet for your chip.

bitfogav
Registered User
Registered User
Posts: 167
Joined: Sat Oct 09, 2010 1:39 pm
Location: United Kingdom

Post by bitfogav » Sun Sep 30, 2012 11:18 am

Thanks for clearing this up Jerry, I always enjoy debuggin code.

I hope this helps someone else :)

Post Reply