A funny compile thingy

besupreme

New Member
Hi,

I'm trying to help a friend, he is building LED lights for his aquarium. The lights will, if we get it working, be controlled by 3 pwm's with a 20M2. There is a DS1302 clock, which is a 'more pessimum' ;) option, compared to an i2c chip. I've found a programming example for the 1302 (If I'd only remember, where. Well at my age...) and adapted it to the 20M2.

Now when I open the .bas file on my computer and do a syntax check, it says "OK, 288 bytes used." As I don't have the clock here, I try a simulation and that runs as expected.

I've just been told that on the other computer, the compiler complains about every GOSUB and the syntax check always fails.

To verify, I open the programming editor and paste the code I had e-mailed into a new window. Now, the syntax check says "OK, 455 bytes used." -- Now what's happening here..?!? I see that the compiler sometimes produces 288 bytes, and sometimes 455 bytes of code on my computer. And on the other one, which is near the system to be programmed, it doesn't compile at all...??

The Programming editor is V5.5.5 and it says DLL 262144.

We should get it working soon, because there is already fish in the aquarium. Any help appreciated :)
 

Buzby

Senior Member
Hi Besupreme,

Welcome to the Forum.

Please post your code, then we might have some idea what's going on !.

Cheers,

Buzby
 

besupreme

New Member
Well I hope I don't upset anyone because part of the code has been 'found somewhere'...
Comments are german, mostly. More about the project (in german, too) is found at http://f3.webmart.de/f.cfm?id=3542059&r=threadview&t=3972591
Code:
; *******************************
; Filename:           AQUAPWM.BAS
; Version:                   0.03
; Author:    die Strippenstrolche
; Date:          03.04.2013 11:15
; Target PICAXE:             20M2
; Function:    Aquarium PWM Licht
; *******************************
; PICAXE 20M2 Alle Pin Funktionen
;                             +---v---+   
;                         Vdd | 1   20| Vss
;                         RxD | 2   19| TxD/DAC
;           Touch/ADC/O/I C.7 | 3   18| B.0 I/O/ADC/Touch/SRI
;                       I C.6 | 4   17| B.1 I/O/ADC/Touch/SRQ/PWM
;           hpwmA/pwm/O/I C.5 | 5   16| B.2 I/O/ADC/Touch
;               hpwmB/O/I C.4 | 6   15| B.3 I/O/ADC/Touch
; hpwmC/pwm/Touch/ADC/O/I C.3 | 7   14| B.4 I/O/ADC/Touch/hpwmD
; kbclk/pwm/touch/ADC/O/I C.2 | 8   13| B.5 I/O/ADC/Touch/hi2c sda
;    kbdata/Touch/ADC/O/I C.1 | 9   12| B.6 I/O/ADC/Touch/hserin
;             hserout/O/I C.0 |10   11| B.7 I/O/ADC/hi2c scl
;                             +-------+

; PICAXE 20M2 Belegung hier
;                             +---v---+   
;                         Vdd | 1   20| Vss
;                         RxD | 2   19| TxD
; später  irgendwas (?) I C.7 | 3   18| B.0 O LCD D4        später
; später Futtertaste(?) I C.6 | 4   17| B.1 O PWM1         Reserve
; PWM4 "Weiss"          O C.5 | 5   16| B.2 O LCD D5        später
; später         LCD WR O C.4 | 6   15| B.3 O LCD D6        später
; PWM3 "Tagblau"        O C.3 | 7   14| B.4 O LCD D7        später
; PWM2 "Nachtblau"      O C.2 | 8   13| B.5 I/O Uhr SDA     später
; später      LED 2 (?) O C.1 | 9   12| B.6 O Uhr CS        später
; später      LED 1 (?) O C.0 |10   11| B.7 O Uhr SCL       später
;                             +-------+

; Connections

  symbol Reserve= pinC.7 ;Reserve   (ADC?)      später
  symbol Futter = pinC.6 ;Futtertaste (?)       später
  symbol PWM4   = C.5    ;PWM Kanal 4 "Weiss"
  symbol LCDWR  = C.4    ;LCD /WR               später
  symbol PWM3   = C.3    ;PWM Kanal 3 "Tagblau"
  symbol PWM2   = C.2    ;PWM Kanal 2 "Nachtblau"
  symbol LED2   = C.1    ;LED 2                 später
  symbol LED1   = C.0    ;LED 1                 später
  symbol DS_CLK = B.7    ;Uhr SCL
  symbol DS_SEL = B.6    ;Uhr CS
  symbol DS_SDA = B.5    ;Uhr SDA
  symbol RE_SDA = pinB.5 ;Uhr SDA IN
  symbol LCDD7  = B.4    ;LCD Bit 7             später
  symbol LCDD6  = B.3    ;LCD Bit 6             später
  symbol LCDD5  = B.2    ;LCD Bit 5             später
  symbol PWM1   = B.1    ;PWM Kanal 1          Reserve
  symbol LCDD4  = B.0    ;LCD Bit 4             später

; Register

  symbol Hours     = b0  ; Stunde
  symbol Mins      = b1  ; Minute
  symbol Secs      = b2  ; Sekunde
  symbol PrevSecs  = b3  ; Sekunde letzte Auswertung
  symbol Command   = b4  ; Kommandobyte an die Uhr
  symbol UhrData   = b5  ; Datenbyte von / an Uhr
  symbol ShiftData = b6  ; 1302 Schieberegister
  symbol HourH     = b7  ; ASCII Stunde Zehner
  symbol HourL     = b8  ; ASCII Stunde Einer
  symbol MinH      = b9  ; ASCII Minute Zehner
  symbol MinL      = b10 ; ASCII Minute Einer
  symbol SecH      = b11 ; ASCII Sekunde Zehner
  symbol SecL      = b12 ; ASCII Minute Einer
  symbol Pointer   = b13 ; Pointer
  symbol Temp      = b14 ; Zwischenspeicher
  symbol PWM1val   = w10 ; Word PWM - Wert Reserve
  symbol PWM2val   = w11 ; Word PWM - Wert Nachtblau
  symbol PWM3val   = w12 ; Word PWM - Wert Tagblau
  symbol PWM4val   = w13 ; Word PWM - Wert Weiss

; I/O Directions

  symbol TXM    = %11111111 ;DIRSB Modebyte für Sende an Uhr
  symbol RXM    = %11011111 ;DIRSB Modebyte für Hole aus Uhr
  symbol PCM    = %00111111 ;DIRSC Modebyte für Port C - I/O

; DS1302 Opcodes

  symbol WriteCtrl     = %10001110
  symbol ReadSecs      = %10000001
  symbol WriteSecs     = %10000000
  symbol ReadMins      = %10000011
  symbol WriteMins     = %10000010
  symbol ReadHrs       = %10000101
  symbol WriteHrs      = %10000100
  symbol WriteTrickle  = %10010000
  symbol TrickleSet    = %10100101 

;Directives   

    #terminal 4800
    #picaxe 20m2

Main:
  setfreq m4
  DIRSC=PCM ; E/A Richtungen Port C schreiben
  low DS_CLK ; Taktleitung initialisieren
  pwmout pwmdiv4, PWM2, 250, PWM2Val ; PWMs initialisieren
  pwmout pwmdiv4, PWM3, 250, PWM3Val
  pwmout pwmdiv4, PWM4, 250, PWM4Val
 
; Hier die aktuelle Uhrzeit reinschreiben

  Hours = $19
  Mins  = $31
  Secs  = $05

  PrevSecs = 0
 
  ; Init 1302
  Command = WriteCtrl       ; write protect ausschalten
  UhrData = 0
  gosub Send1302Cmd
  Hours = Hours & %00111111 ; 24h Format
  Command = WriteHrs        ; Stunden schreiben
  UhrData = Hours
  gosub Send1302Cmd
  Mins = Mins & %01111111
  Command = WriteMins       ; Minuten schreiben
  UhrData = Mins
  gosub Send1302Cmd
  Secs = Secs & %01111111
  Command = WriteSecs       ; Sekunden schreiben
  UhrData = Secs
  gosub Send1302Cmd

  do
    Command = ReadSecs      ; Sekunden holen
    gosub Get1302Data
    if UhrData <> PrevSecs then ; warte bis Sekunden sich ändern
      Secs = UhrData
      PrevSecs = Secs
      gosub GetTime ; Zeit aus der Uhr holen
      gosub RechnePWM ; PWM - Werte berechnen
      gosub SendTerminal ; Zeit formatiert an PG schicken
      gosub SetzePWM ; PWM - Werte aktivieren
    endif
  loop
end

Send1302Cmd: ; Wert an die Uhr schicken
  high DS_SEL         ;Chip select an
  ShiftData = Command ; Kommando
  gosub Sende         ; schicken
  ShiftData = UhrData ; Wert
  gosub Sende         ; schicken
  low DS_SEL          ;Chip select aus
return

Get1302Data: ;Wert von der Uhr holen
  high DS_SEL         ;Chip select an
  ShiftData = Command ; Kommando
  gosub Sende         ; schicken
  gosub Hole          ; Ergebnis holen
  low DS_SEL          ;Chip select aus
return     
 
Sende: ; An die Uhr senden, LSB zuerst
  DIRSB=TXM ; DIRSB auf Senden stellen
  for pointer = 1 to 8 ; 8 bits
    Temp = ShiftData % 2 ;bit in Temp
    if temp = 1 then
      high DS_SDA
    else
      low DS_SDA
    endif
    high DS_CLK
    pause 1
    low DS_CLK
    pause 1
    ShiftData = ShiftData / 2 ;naechstes Bit
  next
return


Hole: ; Ein Byte abholen
  DIRSB=RXM ; DIRSB auf Hoeren stellen
  for pointer = 1 to 7
    temp = RE_SDA * 128
    UhrData = UhrData + temp
    UhrData = UhrData / 2
    high DS_CLK
    pause 1
    low DS_CLK
    pause 1
  next
return

GetTime: ;Zeit holen und als BCD in Hours, Mins, Secs speichern
  Command = ReadHrs
  gosub Get1302Data ; Stunden abholen
  Hours = UhrData & %00111111
  Command = ReadMins
  gosub Get1302Data ;Minuten abholen
  Mins = UhrData & %01111111
  Command = ReadSecs
  gosub Get1302Data ; Sekunden abholen
  Secs = UhrData & %01111111
return

SendTerminal: ;Zeit in ASCII wandeln und erst mal auf Terminal anzeigen
  bcdtoascii Hours,HourH,HourL ; Stunde in ASCII
  bcdtoascii Mins,MinH,MinL    ; Minute in ASCII
  bcdtoascii Secs,SecH,SecL    ; Sekunde in ASCII
  sertxd(13,10,"ZEIT:",HourH,HourL,":",MinH,MinL,":",SecH,SecL) ;zack!
  sertxd(13,10,"PWM:",#PWM2Val,",",#PWM3Val,",",#PWM4Val) ;zack!
return

RechnePWM: ; Hier PWM berechnen
  PWM2Val=100 ;erstmal standardwert. Ersetzen durch Berechnung!!
  PWM3Val=100
  PWM4Val=100
return

SetzePWM: ; Hier PWM schreiben
  pwmduty PWM2,PWM2Val
  pwmduty PWM3,PWM3Val
  pwmduty PWM4,PWM4Val
return
 

Buzby

Senior Member
Compiles OK for me, 455 bytes.

Are you sure the 'other PC' is running PE 5.5.5 ?
 

besupreme

New Member
I'm not *absolutely* sure because it's about 600km away.. but it should be the most recent editor.

Now when I close and reopen the editor with the stored program, it sometimes compiles the 288 bytes length. But sometimes also there is a 455 bytes length??
 

Buzby

Senior Member
I've repeatedly opened and closed the file, stopped and started PE, renamed the file, and always get 455.

What OS are you using ?
 

besupreme

New Member
I'm running XP. Does that make any difference to the compiler? I don't know about the other system.

Good to know that it compiles OK on 5.4.0, too!

*edit*

The other PC has been rebooted and after that it compiled OK. And the 20M2 talks to the 1302 :) Yeah.
 
Top