Device declare Bug

General questions about Firewing...

Device declare Bug

Postby demanik » Sat Aug 17, 2013 6:09 pm

Hi David !
If declere device "DEVICE = 24HJ128GP502" in main module that expression "#if _clock = 80" in module "SDSpi" ceases to work. :?:
Without "DEVICE = 24HJ128GP502" works
Code: Select all
DEVICE = 24HJ128GP502
clock = 80

config FBS = {BWRP_WRPROTECT_OFF, BSS_NO_BOOT_CODE, RBS_NO_BOOT_RAM}
config FSS = {SWRP_WRPROTECT_OFF, SSS_NO_SEC_CODE, RSS_NO_SEC_RAM}
config FGS = {GWRP_OFF, GCP_OFF}
config FOSCSEL = {FNOSC_FRCPLL, IESO_OFF}
config FOSC = {POSCMD_NONE, OSCIOFNC_ON, IOL1WAY_ON, FCKSM_CSDCMD}
config FWDT = {WDTPOST_PS256, WDTPRE_PR128, WINDIS_OFF, FWDTEN_OFF}
config FPOR = {FPWRT_PWR4, ALTI2C_OFF}
config FICD = {ICS_PGD1, JTAGEN_OFF}


Thanks for attention
Image
User avatar
demanik
 
Posts: 56
Joined: Sat Aug 17, 2013 5:53 pm
Location: Ukraine

Re: Device declare Bug

Postby David John Barker » Sat Aug 17, 2013 7:04 pm

Hi

I'm assuming you are using the latest version of the compiler? I have tried this code:

Code: Select all
DEVICE = 24HJ128GP502
clock = 80
imports SD

Sub Main()
   const filename as string = "test.txt"
   dim sdAvailable as boolean = SD.Init() = errOK
   Console.Write("sdAvailable = ", cstr(sdAvailable),13,10)
   if sdAvailable then
      if not SD.FileExists(filename) then
         SD.Create(filename)
         SD.Close()
      end if
      if SD.Append(filename) = errOK then
         SD.Write("Hello world",13,10)
         SD.Close()
      end if   
   end if     
End Sub

and everything works as expected.

Does the above work for you? Can you give more detail of your setup? Can you post a small, working program that shows your error?
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: Device declare Bug

Postby demanik » Sat Aug 17, 2013 7:20 pm

David John Barker wrote:I'm assuming you are using the latest version of the compiler?

My version: 1.0.0.2

Code: Select all
DEVICE = 24HJ128GP502
clock = 80

config FBS = {BWRP_WRPROTECT_OFF, BSS_NO_BOOT_CODE, RBS_NO_BOOT_RAM}
config FSS = {SWRP_WRPROTECT_OFF, SSS_NO_SEC_CODE, RSS_NO_SEC_RAM}
config FGS = {GWRP_OFF, GCP_OFF}
config FOSCSEL = {FNOSC_FRCPLL, IESO_OFF}
config FOSC = {POSCMD_NONE, OSCIOFNC_ON, IOL1WAY_ON, FCKSM_CSDCMD}
config FWDT = {WDTPOST_PS256, WDTPRE_PR128, WINDIS_OFF, FWDTEN_OFF}
config FPOR = {FPWRT_PWR4, ALTI2C_OFF}
config FICD = {ICS_PGD1, JTAGEN_OFF}

#option LCD_INTERFACE = 4           ' can be 4 or 8 bit interface
#option LCD_COMMAND_US = 2000       ' command delay in micro seconds
#option LCD_DATA_US = 50            ' data delays in micro seconds
#option LCD_INIT_DELAY = 100        ' module startup delay in milliseconds
#option LCD_RS = PORTB.3
#option LCD_EN = PORTB.5
#option LCD_D0 = PORTB.6
#option LCD_D1 = PORTB.7
#option LCD_D2 = PORTB.8
#option LCD_D3 = PORTB.9

' Imports section...
imports LCD
imports Convert

' Declarations...
Sub Main()
    OSCTUN = &B0000000000000010'7.43MHz
    const sysClock = _clock
    LCD.Clear

#if _clock = 80
    Writeat(1,1,"80")
#elseif _clock = 64
    Writeat(1,1,"64")
#else
    Writeat(1,1,"32")
#endif
    writeat(2,1,str(sysclock))
    while true
        toggle(portb.2)
        delayms(500)
    end while
End Sub

at me in the first line prints "32" in the second "80"
Image
User avatar
demanik
 
Posts: 56
Joined: Sat Aug 17, 2013 5:53 pm
Location: Ukraine

Re: Device declare Bug

Postby David John Barker » Sun Aug 18, 2013 8:48 am

I understand now. That is the correct behavior, _clock is only available to the preprocessor. To use in you main code, assign to a constant (like you have done). If you look at the 24HJ128GP502 device file, you will see that its "main" sub does exactly this:

Code: Select all
   const sysClock = _clock
   if sysClock = 80 then
   WREG4 = CLKDIV and &HFF3F
   CLKDIV = WREG4
   PLLFBD = 41               
   elseif sysClock = 64 then   
   ...

I guess you could say that _clock should generate an error if used in the main program, I'll look at that. However, assigning to a constant is the correct way to get this value into your main program.
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: Пристрій оголосити Помилка

Postby demanik » Sun Aug 18, 2013 9:11 am

Code: Select all
device = 24FJ64GA002
clock = 80

config CONFIG2 = {POSCMOD_NONE, I2C1SEL_PRI, IOL1WAY_ON, OSCIOFNC_ON, FCKSM_CSDCMD, FNOSC_FRCPLL, SOSCSEL_SOSC, WUTSEL_LEG, IESO_OFF}
config CONFIG1 = {WDTPS_PS512, FWPSA_PR32, WINDIS_ON, FWDTEN_OFF, ICS_PGx1, COE_OFF, BKBUG_OFF, GWRP_OFF, GCP_OFF, JTAGEN_OFF}

' Imports section...
imports SDSpi
imports Convert

' Declarations...
Sub Main()
    spi.start
    spi.fast
    while true
        spi.writebyte(210)
        delayms(5)
    end while
End Sub


in the register "SPICON1Bits.Value" it is entered "&B0000000100111011" instead of "&B0000000100111010"
Code: Select all
module Spi

#if _clock = 80
const SPI_CON = &B0000000100111010
#elseif _clock = 64
const SPI_CON = &B0000000100111110
#else
const SPI_CON = &B0000000100111011
#endif
public sub Start()
   PPS.EnableSpi()                 
   SPICON1Bits.Value = SPI_CON
   SPISTATBits.SPIEN = 1 ' enable SPI 
end sub

SPI works at frequency 20MHz instead of 5MHz :?:
if to comment out "device = 24FJ64GA002" that works at frequency "5MHz"
Image
User avatar
demanik
 
Posts: 56
Joined: Sat Aug 17, 2013 5:53 pm
Location: Ukraine

Re: Device declare Bug

Postby David John Barker » Sun Aug 18, 2013 12:54 pm

You are right, that doesn't look right at all. It seems I introduced an error into the SD library when adding support for the upcoming Firewing 32 bit compiler. Apologies for that. I have uploaded a new BETA which you should download and try out:

http://www.firewing.info/pmwiki.php?n=Firewing.Download

Let me know if this fixes the problem for you. I have also removed "_clock" during the compiler pass (it will now throw an error if used). Assign to a constant, as previously discussed.
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: Пристрій оголосити Помилка

Postby demanik » Sun Aug 18, 2013 1:14 pm

OK
I will try
Image
User avatar
demanik
 
Posts: 56
Joined: Sat Aug 17, 2013 5:53 pm
Location: Ukraine

Re: Device declare Bug

Postby demanik » Sun Aug 18, 2013 1:39 pm

works correctly :D
Image
User avatar
demanik
 
Posts: 56
Joined: Sat Aug 17, 2013 5:53 pm
Location: Ukraine


Return to Questions

Who is online

Users browsing this forum: No registered users and 0 guests

x