Trying to find the "End" expected faults

Discuss the Firewing language

Trying to find the "End" expected faults

Postby Timbo » Fri May 15, 2015 7:25 pm

Hi,

So I added a few more lines extra to my code and since then the compiler is complaining with 2 ERROR "END" expected faults

I have been staring at this for an hour and cannot see the issue.

It seem to have come on when I added a nested Select statement but removing it now did fix it.

If anyone with a clear head can see I would appreciate it.

It should not need any special modules. Its really just one big subroutine.

Code: Select all
'*****************************************************************************
'*  Name    : UNTITLED.1                                                     *
'*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
'*  Notice  : Copyright (c) 2015 [select VIEW...EDITOR OPTIONS]              *
'*          : All Rights Reserved                                            *
'*  Date    : 10/05/2015                                                     *
'*  Version : 1.0                                                            *
'*  Notes   :                                                                *
'*          :                                                                *
'*****************************************************************************

' Imports section...

'imports Tick

// A/D port defs
Dim WLevel as A0
DIm WCPress as A1
Dim WLLow as A2
Dim WLHigh as A3
Dim BSen as A4
Dim TempSensor as A5

// Water detection levels

Const WaterTransitionLevel = 600   // Level that trips between a seeinf water and no water


// Pressure sensor inputs
Dim WLevelRaw as Ushort
Dim PreCapPressureRaw as Ushort


// Optical Sensors and levels
Dim LowWLevelSense as Ushort
Dim HighWLevelSense as Ushort
Dim BubbleRaw as Ushort
Dim WaterOptoTransitionLevel as Ushort  = 600 /// temp setting <<<<<<<<<<<<<<<<<

// Boolean status of the water seen across sensor
Dim WaterLevelHigh as Boolean   = False
dim WaterLevelLow as Boolean    = False
Dim BubbleSeen as Boolean       = False

// Temperature Sensor
Dim TempSensorRaw as Ushort


// Solinods
Dim InletSolinoid as D0
Dim DrainSolinoid As D1


// Dims for the Raw Level values

   Dim SampleLevelToBuffer as bit
   Dim RawUpperBufferCounter as byte          // The element in the array pointer
   Const RawUpperBufferNo = 4                  // We are only going to sample 4 to make the maths easier to divide
   Dim RawUpperLevelArray(RawUpperBufferNo) as Ushort         // The Array used
   Dim LowLevelFlag as bit                      // Flag used to watch for an up ward going water level to save the raw


   // Volume and flow level D
   Dim RawLevelStart as Ushort
   Dim RawLevelTop as Ushort
   Dim RawVolumeRange as Ushort
   
   Dim AverageTopSensor as ushort               // Holds the current esimated top value so it can be used for the maths
     
   
   // Subs and Functions
   
   
     
   
   
   Inline Sub OpenDrain()                                                       // Valve control subs
      High(DrainSolinoid)
   end sub
   
   Inline Sub CloseDrain()
      Low(DrainSolinoid)
   End Sub
   
   Inline Sub OpenInlet()
      High(InletSolinoid)
   End Sub
   
   Inline Sub CloseInlet()
      Low(InletSolinoid)
   End Sub                 
   
   Inline Function IsThereWater(InputSensor as ushort) as boolean
      If InputSensor < WaterOptoTransitionLevel then
         Return True
      Else
         Return False
      End if
   End Function
   
 
   
   

sub OnTickEvent()' handles Tick.OnTick
                                                                               
   WLevelRaw = Adc.Read(WLevel)                                                  // Read the Pressure Levels
   PreCapPressureRaw = Adc.Read(WCPress)
   
   
   LowWLevelSense = Adc.Read(WLLow)                                              // Read the Bubble sense inputs
   HighWLevelSense = Adc.Read(WLHigh)                                           
   BubbleRaw = Adc.Read(BSen) 
   
                                                                                 
   TempSensorRaw = Adc.Read(TempSensor)                                          // Read the Temp sensor
                                   
   
   // Process the Bubble Level inputs
   
   
   // Check the Low Level Opto
   If IsThereWater(LowWLevelSense) then                                          // If we see water
      WaterLevelLow = False                                                      // Flag it up to say we have water flag is to say water level is not below sensor 
      If LowLevelFlag = 0  then                                                  // If last time the level was below the sensor
          RawLevelStart = WLevelRaw                                              // Record the level at which we see the water
          LowLevelFlag = 1                                                       // Change the level flag
          // Now work out the raw range for the flow calculations later
          RawVolumeRange = AverageTopSensor - RawLevelStart         
      End if
   Else                                                                          // Otherwise
      WaterLevelLow = True                                                       // Flag to say no water so bottom sensor hit
      SampleLevelToBuffer = 0                                                    // We can set the flag to so we save the top level for the everage next time
      LowLevelFlag = 0                                                           // Set this flag as well so we know to catch the upward movement
   End if                       
       
   
   
   // Check the High Level Opto
   If IsThereWater(HighWLevelSense) then                                         // If the level indicates there is water sensed   
      WaterLevelHigh = True                                                      // Mark it so
      If SampleLevelToBuffer = 0 then                                            // First time we see it go high this time we save the value to the buffer
         SampleLevelToBuffer = 1
         RawUpperLevelArray(RawUpperBufferCounter) = WLevelRaw   
         
         // Inc the counter and roll over if need be
         RawUpperBufferCounter += 1             
         if RawUpperBufferCounter >= RawUpperBufferNo then                       // We take the average off 5 samples taken at the level transisiton
            RawUpperBufferCounter = 0
            // 5 Samples taken so now do the maths to get the average top level
           
            dim i as byte
               for i = 0 to (RawUpperBufferNo -1) 
                  AverageTopSensor = AverageTopSensor + RawUpperLevelArray(i)
               next
               AverageTopSensor = Total >> 4
          End if

      End if
   Else                                                                          // If there is no water then..
     
      WaterLevelHigh = False   
                 
   End if
       
   // Check the Bubble opto
   If IsThereWater(BubbleRaw) then
      BubbleSeen = False
   Else
      BubbleSeen = true
   End if
   
   // State Machines controlling the system
 
   
   Public dim MainState as byte
   Const MStateOff = 0                                                           // This State has the unit in Off mode
   Const MStateStartUp = 1                                                       // Starting up
   Const MStateCycle = 2                                                         // Cycling state
   Const MStateSample = 3                                                        // One Shot sample
   Const MStateShutDown = 4                                                      // Shutting down
   
   public Dim SubStateMCycle as Byte                                             // Sub State machine inside The Main cycleing state
   Const SCFilling = 0                                                           // In filling phase
   Const SCEmptying = 1                                                          // In Emptying Phase
   
 
   
   Select MainState
      Case MStateOff
         CloseDrain()
         CloseDrain()
      case MStateStartUp
         OpenDrain()
         OpenInlet()
         
      Case MStateCycle
     
         Select SubStateMCycle
         
         Case MStateCycle
            if WaterLevelHigh = true then
               SubStateMCycle = SCEmptying
            End if       
            OpenDrain()     
           
         Case SCEmptying
            if WaterLevelLow = True then
               SubStateMCycle = SCFilling
            End if
            CloseDrain()
           
         End select                 
           
             
      Case MStateSample
     
         
      Case MStateShutDown
     
         
   end select
   
 
         
     
   
end sub

 



 Sub InitialiseControlInterrupt()
     
      WaterOptoTransitionLevel = 600        // temp config of water level
      // Read the Stored Value for the current Top water level And load it into the array

         
      FOr RawUpperBufferCounter = 0 to RawUpperBufferNo    // cycle through the whole array
          RawUpperLevelArray(RawUpperBufferCounter) = 1000
      Next
      RawUpperBufferCounter = 0
     
       
     AverageTopSensor = 1000             
     
     // Shut tyhe valves
     OpenDrain
     OpenInlet
     
     MainState = MStateCycle
     SubStateMCycle = SCFilling
     
      // Loads of other code to set up here as well
     
 End Sub
 
 
     

sub Main()

    InitialiseControlInterrupt()

   'loop forever...     
   Dim Temp as Ushort = adc.read(A0)
     
     
   while true
   end while
End Sub
Timbo
 
Posts: 93
Joined: Fri May 03, 2013 7:51 pm

Re: Trying to find the "End" expected faults

Postby Jerry Messina » Fri May 15, 2015 9:54 pm

It doesn't like the state variable declarations inside the sub OnTickEvent()

Move
Code: Select all
   Public dim MainState as byte
   Const MStateOff = 0                                                           // This State has the unit in Off mode
   Const MStateStartUp = 1                                                       // Starting up
   Const MStateCycle = 2                                                         // Cycling state
   Const MStateSample = 3                                                        // One Shot sample
   Const MStateShutDown = 4                                                      // Shutting down
   
   public Dim SubStateMCycle as Byte                                             // Sub State machine inside The Main cycleing state
   Const SCFilling = 0                                                           // In filling phase
   Const SCEmptying = 1                                                          // In Emptying Phase

outside of the sub to the main context so they're visible globally
Jerry Messina
 
Posts: 280
Joined: Thu Feb 14, 2013 10:16 am

Re: Trying to find the "End" expected faults

Postby Timbo » Sat May 16, 2015 8:22 am

Thanks Jerry

I was tearing my hair out over it.

Tim
Timbo
 
Posts: 93
Joined: Fri May 03, 2013 7:51 pm

Re: Trying to find the "End" expected faults

Postby Jerry Messina » Sat May 16, 2015 10:47 am

Tim,

A feature you might be interested in is the Enum type. When you declare a variable of type enum it can only take on those values.
Handy for things like state machines

Code: Select all
public enum MState as byte
  Off = 0                                        // This State has the unit in Off mode
  StartUp                                        // Starting up
  Cycle                                          // Cycling state
  Sample                                         // One Shot sample
  ShutDown                                       // Shutting down
end enum   

public dim MainState as MState

MainState = MState.StartUp      // ok
MainState = 0                    // generates compiler error... not an MState member


It doesn't generate less code or anything, but it can help prevent coding errors
Jerry Messina
 
Posts: 280
Joined: Thu Feb 14, 2013 10:16 am


Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest

cron

x