Home
CUBLOC Manual - Comfile Technology
Contents
1. NIC vec LX LY LX LY Buffered Bus LDA or LCL sx P82B715 sY SX SY 12C Bus SDA or SCL GND N C Extend to almost 3 4 of a mile using the P82B715 SDA SCL P82B715 CUBLOC P82B715 12C DEVICE By using the P82B96 ground and power can be isolated on each end SDA p W e spa gt 1X RX SCL La RX P82B96 TX RY SCL gt TY GND TY Lg ft RY P82B96 12V 12V na LONG CABLE T I SDA gt A gt k SDA SCL gt gt gt P82B96 P82B96 SCL Please refer to Phillips website for more information on the specific chips discussed here http www standardics nxp com 319 If you are using 12C within 12 feet we recommend using the following protection circuit If the 12C devices are connected with no buffers electrical interference can cause damage either the Cubloc or the 12C slave device By using diodes as shown below you can protect against most of the electrical interference If the devices are in a heavy industrial environment we recommend using P82B96 chips as buffers ao 7 wee a O id 241032 C soL CABLE a2 O gt SCL GND SDA lt _ gt SDA CUBLOC 320 Chapter 9 MODBUS About Modbus Modbus is a protocol developed by Modicon as an interface to their PLCs It is usually used with d
2. Each menu button s position and style can be changed using the MenuSet command Up to 100 buttons can be displayed on a single screen Each button can be assigned a different function on a different screen resulting in virtually unlimited menus and buttons 450 MenuSet MenuSet index style x1 y1 x2 y2 index Menu index number style Button style O none 1 box 2 box with shadow x1 y1 x2 y2 Menu button position The index value must be a number from O through 99 style is the shape of the button where 0 is for no box 1 is for a box and 2 is for a shadowed box 0 1 2 x1 yl x2 y2 are the x and y axis positions of the left upper and lower right corners When this command is executed the set part of the screen becomes part of the button s area MenurTitle MenuTitle index x y string index Menu index number x y Title location based on left upper corner of button string Name of the menu MenuSet only draws the box itself Use the MenuTitle command to set the name of the menu like shown here MenuTitle 0 13 13 Gas Left MenuTitle 1 16 13 Initialize MenuTitle 2 13 13 Total Cost Gas left Initialize Total cost 451 MenuCheck gt variable MenuCheck index touchX touchX variable Variable to store results 1 if selected O if unselected index Menu index number touchX x coordinate of the touch touchY y coordinate of the touch Use th
3. End If Return Start End Restart 456 Cutouch Sample Programs SAMPLE 1 Let s make a simple counter that will print to the screen The source files used here are in the Cubloc Studio installation directory Usually C Program Files Comfile Tools CublocStudio 3241 lt Filename CTOO1 CUL gt Const Device Ct1720 Dim i As Integer Contrast 550 LCD CONTRAST SETTING Do Locate 15 6 print DECS a Inor i Delay 200 Loop Please adjust the screen s contrast accordingly using the Contrast command Depending on the model the contrast may be able to be adjusted using a knob on the back of the Cutouch providing the ability to change the contrast manually 457 SAMPLE 2 The following sample program will display a RESET button and will increment the number displayed on the screen every time the button is pressed 3241 RESET lt Filename CTOO2 CUL gt Const Device Ct1720 Dim i As Integer Dim TX1 As Integer TY1 As Integer Contrast 550 Set Pad 0 4 5 On Pad GoSub GETTOUCH Menuset 0 2 120 155 1957200 MenuTitle 0 20 14 RESET Do Locate 15 6 Print DECS i acia i Delay 200 Loop GETTOUCH TX1 GetPad 2 TY1 GetPad 2 If MenuCheck 0 TX1 TY1 1 Then Pulsout 18 300 I 0 End If Return The SET PAD command activates touch input The ON PAD command jumps to a label when touch input is received The MENUSET command sets the desired touch input area and the ME
4. Debug Terminal Baud Rate Parity Data Bits ax H Port COMI v 115200 vw None 8 7 RK I Fis Right Side 121 Dec Converts an integer variable to a string representation of a decimal 10 bit Dec8 means to convert to 8 decimal places 1 to 11 can be used for decimal places Debug Dec A TE A is 1234 1234 is printed Debug Dec10 A If A is 1234 bbbbbb1234 is printed b is a blank space in this case IE A is 1234 234 1s printed les E character is cut Debug Dec3 A S CUBLOC studio d cubloc_test format cul File Edit Device Run Setup Help Esa Ba lA l gt mar El _Ocbue Terminal Baud Rate Parity Data Bits y TK Port FI BASIC F2 LADDER Ladder Mnemonic cow E COM w ris200 none e v arx Const Device CB280 Dim A As Long A 523478 Debug Dec A Cr Debug DEC10 A Cr Debug DEC3 A Cr Debug Dec A Cr Fix Right Side Include the name of the variable by using question mark This question mark can only be used with HEX or DEC Debug Dec A Debug Hex A Debug Hex B If A is 1234 A 1234 will be printed If A is amp HABCD A ABCD will be printed If B is a variable within a subroutine for example subroutine CONV with a value of amp HABCD B CONV ABCD will be printed 122 Float Use Float to convert floating point values to String Const Device cb280 Dim F1 As Single Fl 3 14 Debug Float El cr rs
5. 4 CuNET Jumper Bread Board DC 9V INPUT RS232 CHANNEL 1 POWER S W When 9V is supplied the 5V voltage regulator inside the Study Board will provide 5V to the main module and all peripherals DC adapter polarity can be used either way For normal operation please use a 9V adapter with at least 200mA of current 312 Cubloc Study Board Schematic t RESET GND VSS IT 5V VDD DOWNLOAD 01234567 ponnonnnnnnnnnnnnin CB280 01234567 TIIT wer ee CB280 1 To use RS 232 channel 1 please connect wires to the appropriate pins on the interface labeled RS 232C in the upper right hand corner 2 For the CB280 connect RS 232 channel 1 as shown below Tx RX rx Rx 3 When using CuNET all jumpers must be shorted If using pin 8 and 9 for general I O all jumpers should be left open 313 About I2C The Cubloc provides an easy set of commands to communicate using the I2C protocol 12C communication is a widely used protocol primarily for communicating with ADC EEPRO
6. Debug Dec DATA1 3 Cr Debug Dec DATA1 6 Cr Debug Dec DATA1 1 Cr e SEDE Terminal Baud Rate Parity Data Bits comi v 15200 None aj T Fix Right Side 101 Operators When evaluating expressions in a programming language it is important to understand the order of operations also know as operator precedence The following table describes Cubloc BASIC s operator precedence Precendence MOD______ Multiply Divide MOD Math Add Subtract Math Left Shift Right Shift Logic Less than Larger than Comparison Less or Equal to Larger or A Equal to Same Different Comparison AND XOR OR Boolean AND XOR OR amp Logic Last NOT NOT Within each row in the table above the operators are evaluated from left to right Operators can be used in conditional statement as show below IF A 1 10 THEN GOTO ABC 1 I gt 12 2 gt 5 3 4 3 4 2 6 344 gt 2 6 3 4 Use parenthesis to explicitly control the order of operations in an expression When multiple operators are used the expression will be evaluated in the following order 1 Operator s inside parenthesis 2 Negative Sign 3 Exponent 4 Multiplication Division Remainder MOD 5 Addition Subtraction 6 Bit wise Left Shift Bit wise Right Shift lt lt gt gt 102 5 3 4 5 3 4 1 d A B C D E X G H Operators used in Cubloc B
7. Close I Fix Right Side 230 Set OnPad Set OnPad On Off At power on Set OnPad is On by default This command turns on or off the ability to receive On Pad interrupts When Set OnPad is On the interrupt service routine ISR set using the On Pad command will be executed when the corresponding interrupt occurs If Set OnPad is Off then the ISR will not be executed when the interrupt occurs See also the Set Pad and On Pad commands 231 Set OnRecv Set OnRecvO On Off Set OnRecv1 On Off Set OnRecv2 On Off Set OnRecv2 On Off At power on Set OnRecv is On by default This command turns on or off the ability to receive On Recv interrupts An On Recv interrupt occurs after data is received on the serial port AND stored in serial port s the receive buffer When Set OnRecv is On the interrupt service routine ISR set using the On Recv command will be executed when the corresponding interrupt occurs If Set OnRecv is Off then the ISR will not be executed when the interrupt occurs See also the On Recv command Set OnRecvl On Set OnRecvl Off 232 Set OnTimer Set OnTimer On Off At power on Set OnTimer is On by default This command turns on or off the ability to receive On Timer interrupts An interrupt occurs at every time interval set by the On Timer command When Set OnTimer is On the interrupt service routine ISR set using the On Timer command will be executed when the corresponding interrupt occur
8. 131 Chapter 6 Cubloc BASIC Statements Library AdIn variable Adin channel variable Variable to store results No String or Single channel AD Channel Number not I O Pin Number Cubloc has several 10bit Analog to Digital Converters ADCs and 16bit Pulse Width Modulators PWMs The user can use an ADC to convert analog signals to digital or use a PWM to convert digital signals to analog The ADin command reads the analog signal s amplitude and stores the result in a variable Depending on the model the number of ADC ports may vary For the CB280 there are 8 AD ports P24 to P31 An ADC port must be set to input before use When a voltage between O and AVREF is applied that voltage is converted to a value from O to 1023 AVREF can accept voltages from 2V to 5V The default reference is 5V If an AVREF of 3V is used voltages from O and 3V are converted to a value from 0 to 1023 Note CB220 AVREF is fixed to 5V Return value 1023 0 ov 5y Input voltage Dim A As Integer Input 24 Set port 24 to input A AdIn 0 Do a A D conversion on channel 0 and store result in A 133 The CB220 and CB280 ADC ports are AD INPUT PORT SOUT SIN ATN vss Po P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 Pa shown below CB280 TTLTX1 TTLRX1 AVREF P48 P31 P30 AD INPUT P29 ER PORT P32 P33 P34 P35 P36 P37 P38 P39 Please refer to the following table for ADC chan
9. CUBLOC studio d cubloc_test functest cul fille Edit Device Run Setup Help Bong B8B A gt at Bo FI BASIC F2 LADDER Ladder Mnemonic Const Device CB280 Dim A As Byte A 0 Do Delay 100 Debug Dec A Cr A ADD_VALUE A Loop End Close I Fix Fight Side Function ADD_VALUE B As Byte As Byte ADD_VALUE B 1 Function End 81 Global and Local Variables When you declare variables inside a subroutine or a function it is considered a Local variable Local variables are created when the subroutine or function is called and removed when the subroutine or function exits This means that local variables will temporarily allocate data memory for the duration of the call Local variables may only be referred to or used inside the subroutine or function in which they were declared On the other hand global variables may be used anywhere in your program Main Program Global Variable Sub ProgramA Sub Program B Local Variable Local Variable Dim A As Integer Declare A as Global Variable LOOP1 A A3 1 Debug Dp A CR Display A on Debug screen DELAYTIME Call Sub DELAYTIME GoTo LOOP1 End End of Main Program Sub DELAYTIME Dim K As Integer Declare K as Local Variable For K 0 To 10 Next End Sub In the program above A is declared as a global variable and K is declared as a local variable A can be used anywhere in the program but k ca
10. 474 CB405RT Related Commands CB405RT related commands can be used on in Cubloc Studio V2 6 B or in later versions First the RTC related commands RTCRead variable RTCRead address If you see the address table of RTC chip DS3231 below you will notice that the time data are stored from addresses O through 6 The rest of the variable variable to store the result Byte type address RTC s address addresses are related to the alarm and RTC chipsetting thus recommend those interested to refer to the DS3231 databook RTCRead command literally reads data from the RTC chip BIT7 BITO ADDRESS MSB BIT6 BITS BIT4 BIT3 BIT2 BIT1 LSB FUNCTION RANGE 00h 0 10 Seconds Seconds Seconds 00 59 01h e 10 Minutes Minutes Minutes 00 59 02h 0 12 24 BMPM 10 Hour Hour Hours UNAARNE 10 Hour 00 23 03h 0 o 0 0 0 Day Day 1 7 04h 0 0 10 Date Date Date 01 31 05h Century o 0 10 Month Month Monit Um es Century Century 06h 10 Year Year Year 00 99 07h A1M1 10 Seconds Seconds Alarm 1 Seconds 00 59 08h A1M2 10 Minutes Minutes Alarm 1 Minutes 00 59 09h AtM3 12 24 EMI 10 Hour Hour Alarm 1 Hours 1 12 AM PM 10 Hour 00 23 D Alarm 1D 1 7 oAh AM4 DYT 10 Date ey arm Leay Date Alarm 1 Date 1 31 OBh A2M2 10 Minutes Minutes Alarm 2 Minutes 00 59 AM OCh A2M3 12 24 suen 10 Hour Hour Alarm 2 Hours i ee oDh A2M4
11. ees PulsOut 18 300 Elseif MenuCheck 3 TX1 TY1 Then lt lt 4 4 PulsOut 18 300 Elseif MenuCheck 4 TX1 TY1 Then lt lt 4 el a PulsOut 18 300 Elseif MenuCheck 5 TX1 TY1 Then lt lt 4 K PulsOut 18 300 Elseif MenuCheck 6 TX1 TY1 Then lt lt 4 7 PulsOut 18 300 Elseif MenuCheck 7 TX1 TY1 Then lt lt 4 E arte He PulsOut 18 300 Elseif MenuCheck 8 TX1 TY1 Then lt lt 4 se 9 PulsOut 18 300 Elseif MenuCheck 9 TX1 TY1 Then lt lt 4 PulsOut 18 300 Elseif MenuCheck 10 TX1 TY1 1 Then PulsOut 18 300 Enda If Locate 3 3 Print HEX4 I Return The final value I is stored in BCD format The Bcd2Bin command can be used to convert it back to a binary number 461 SAMPLE 5 This sample uses CUCANVAS to make some menus To create the virtual keypad shown in the previous page it would take a long time to manually code it and place buttons CUCANVAS can save time Run CUCANVAS and press the Add Form button in the upper right hand corner Enter a desired name for the new form NumKey is used in this example v ASS CuCANVAS File Edit Generate Tools View Help Dee S a Numkey Add Form Use tab key to select neighbor ones 1 Numkey a O o A a a 116 25 On the left side of CUCANVAS there a toolbar with an arrow box filled box circle filled circle line text and
12. 188 KeyInH variable KeyInH port debouncingTime variable Variable to store results No String or Single port Input port 0 to 255 deboucingTime Debouncing time 0 to 65535 KeyInH is for active high inputs For active low inputs the KeyIn command should be used When a button press is detected KeyInH will return 1 otherwise it will return 0 A KeyInH 1 100 Read from port 1 after waiting 100ms for debouncing 189 Keypad variable Keypad portBlock variable Variable to store results Returns Byte No String or Single portBlock Port block 0 to 15 Use this command to read input from a matrix keypad One port block can be used to read a 4 by 4 keypad input The keypad rows should be connected to the lower 4 bits of the Port Block and the keypad columns should be connected to upper 4 bits of the port block Pullup resistors 2 2K to 10K should be connected to the lower 4 bits of the port block A resistor should be connected even if a row is not being used Please refer to the diagram below gA AYA 9 1 5 031491827 2712 A A A yA i 121821921 2413 234 02037 W414 i 4 4 3 3 7 121037 2 15 4 5 6 7 A Keypad 0 Read the status of keypad connected to Port Block 0 If no keys are pressed 255 will be returned Otherwise the pressed key s scan code will be returned 190 Low Low port port I O port number 0 to 255 Thi
13. 98 Constants Constants can be used to declare a constant value a value that cannot be changed within the program This essentially allows a number to be assigned a name often improving readability and debugging of the source code The const statement can be used to declare constants in Cubloc BASIC Const PI As Single 3 14159 Const WRITIME As Byte 10 Const MSG1 As String ACCESS PORT When the constant is not given a type the compiler will find an appropriate type for it as shown below Const PI 3 14159 Declare as SINGLE Const WRTTIME 10 Declare as Byte Const MYROOM 310 Declare as Integer since it s over 255 Const MSG1 ACCESS PORT Declare as String Con Another CONST method The Con statement can be also used to declare constants as shown below PT Con 3 14159 Declare as Single WRTTIME Con 10 Declare as Byte MYROOM Con 310 Declare as Integer MSG1 Con ACCESS PORT Declare as String 99 Constant Arrays In constant arrays the user is able to store a list of values before the program begins A program requiring a large number of constant values can be simplified as shown below Const Byte DATA 31 25 102 34 1 0 0 0 0 0 65 64 34 I 0 A DATA1 1 Store 31 in A a oD tae A DATA1 I U Store 25 in A Const Byte DATA1 CUBLOC SYSTEMS String data can be stored in Byte constant arrays Each Byte contains the ASCII code of each character in the String
14. Debug September Case 9 Debug November Case 10 Debug December End Select i Time 3 Debug Hex2 i Print date Debug i Time 4 Select Case i Case 0 Debug Sunday Case 1 Debug Monday Case 2 Debug Tuesday Case 3 Debug Wednesday Case 4 Debug Thursday Case 5 Debug Friday Case 6 Debug Saturday End Select Debug Cr i Time 2 Debug Hex2 i i Time 1 Debug Hex2 i i Time 0 Debug Hex i Cr Delay 1000 ES ena Terminal Baud Rate Parity Data Bits E De En y 115200 None Friday Friday Friday 257 UDelay UDelay time time Interval 1 to 65535 UDelay is a more precise delay The delay is initialized to about 70 micro seconds Every unit added to it will add 14 to 18 micro seconds For example UDelay O would be about 70 micro seconds UDelay 1 would be about 82 to 84 micro seconds UDelay 100 Delay about 1630 micro seconds When an interrupt occurs or Ladder Logic code is being executed at the same time this delay function might be affected During this delay BASIC interrupts are enabled and could cause further delay when using this command To prevent interference from Ladder Logic or BASIC interrupts consider stopping Ladder Logic and all interrupts before using this command 258 UsePin UsePin port In Out aliasName port I O port number 0 to 255 In Out In or Out aliasName Alias for the port Optional Thi
15. Line 9 Program 57488 204 In previous versions of Cubloc Studio output symbols had to be put at the far right of the rung but starting with Cubloc Studio 3 4 1 output symbols can be put elsewhere as well Po P1 B F64 it 11 4 INPUTTESTKIN BOARD_LED Ma B DO c The number of ladder columns has been reduced from 16 to 8 27 Cubloc Studio d WtestWmsb764testl cul File Edit Device Run Setup Help DSHS Sea O 0er a BASIC LADDER Ladder Monitor SM ole WE lt TITEI T LZ te pare FS FS F6 F7 F9 F11_ F12 NOT END pare Delete ESA 1 BOARDED Modified Program 57488 2048 However files created in previous versions of Cubloc Studio will still display 16 columns 7 Cubloc Studio d WtestWmsb764testl cul Fle Edit Device Run Setup Help DSB Sage O arta BASIC LADDER A o lale Bie X 15 Y 308 Modified Table of Contents CHAPTER 1 GETTING STARTED sescsesesssesosssesescsosesosesososesososesosososososocososososseosossesessessosse 19 What is CUDIOC 2 cinc isipen seb E aE a maa Aa Eai 20 CUbIOG SPeCifiCALIONS s mir 21 Eadder Logic nd BASIC A a 25 Multi tasking of Ladder Logic and BASTC ocococcnccncononnncnnnnnnancnnnnnos 28 Advantages of an On Chip PLC Embedded Computer ccccccccncnccnconos 30 Development EnViroOnMenNt amecioon sonoros 32 Hints for Traditional PLC USeFS ocococcncncncoconnnnncncnnonenanancnnnnancnnna
16. P46 P62 P10 P26 SBVOOTL OM NROr OH P45 P61 PWM6 P11 P27 PWM3 5322400000000 P44 P60 PWM7 P12 P28 PWM4 INTO ao wmoroooran T1X1 P43 P59 PWM8 P13 18 38 P29 PWM5 INT1 9 o VP D99 RX1 P42 8 P58 P14 19 39 P30 INT2 eo 00 SDA P41 P57 1X3 P15 20 40 P31 INT3 eo eco 00 SCL P40 60 80 P56 RX3 wo ora mo an ooo oo 88 gt gt po CB400 CB405 64 64 CSS 7K 110K BASIC 6K LADDER 1K BASIC 51K LADDER 4K HEAP 55K FLASH __ 200KB S O 200KB R5232 4 CH A D 16 CH PwM 12 CH Name Pins 1 0 Explanation sour 1 our DOWNLOAD SERIAL OUTPUT sin 2 In_ DOWNLOAD SERIAL INPUT ATN 3 mn DOWNLOAD SERIAL INPUT 22 64 OWER GROUND 21 44 OWER 4 5V to 5 5V Power Supply 1 OU 2 IN 3 IN 4 P IN P IN ADC Reference Voltage Battery Backup Can t be used IN N RESET pin OU N OU RS232 Input 12V pour pour T T 3 3 1 2 1 2 The following I O ports are described in blocks yo spPiss 1 0 1 O SPI SS NEP O ASA 1 0 PwmcHanNeto yo PWM CHANNEL1 O IS TTLRX channel 2 PWM CHANNEL 2 TTLRX channel 2 vo fT 1 0 PWMCHANNEL6 1 0 PWM CHANNEL 1 0 PWMCHANNELS Po 1 0 Pp Po vo AAN vo l P17 26 yo aADcHanNeLi P18 27 o aADcHanNeL2 P19 28 yo ADCHANNEL3 P20 29 yo ADCHANNEL4 P21 3o yo aADcHanNeLs P22 31 yo ADCHAN
17. Set Ladder On 445 Cutouch Output ports CT1721C has 32 NPN TR output ports Sink DC output A N Ooh Vid QD od e RSS DECEPLEPL PB Bh a ooh gh ot om ass rom LOAD LOAD P25 446 Cutouch Input ports CT1721C has 32 opto isolated DC input AS PPPS PANDA DAV OD CEEL ELIEL ES PLES ERE ES DC24V INPUT Cutouch A D and TTL I O Ports CT1721C has 8 A D ports A DINPUT SLLLN OFF 0to 5V ON 0to 10V on enre CT1721C has 16 TTL I O ports and 2 High speed Counter X LELETEI 448 Cutouch jumper connector Batt Backup This battery supports Data Sram memory only Rs485 Rs485 Signal Ground RS232 CH1 Download DC9 24V 449 Menu System Library The Cutouch supports extra commands easily create and manipulate menus With the menu system library a menu system as shown below can be made in less than 5 minutes Comfile Automobile gas pressurizer Select gas Gas pressure Auto type Gas left Initialize Total cost MENU Commands The Cutouch has enough memory to support approximately 100 menu buttons The MenuSet command is used to set the x and y coordinates as well as the style of the menu The MenuTitle command can be used to name the menu When touch input is received the MenuCheck command can be used to determine which menu button was pressed 0 99
18. that are sensitive to resets turn this option off In the Help menu Cubloc Studio upgrade and version information can be found LADDER size adjust LADDER line space adjust LADDER background color LADDER monitorring speed setting Auto run when download 373 PLC Setup Wizard To use Ladder Logic in Cubloc you must create some minimal BASIC code Although very simple this can be hard for first timers You can use the PLC Setup Wizard and setup the I Os you will be using and create the BASIC source automatically PLC SETUP WIZARD Fl BAS F2 LALDER gle 0 dl MR el E e Mn 4 Fo Fi Tt ee 5 PLC Setup Wizard Ladder environment edit Output BASIC code review Device Select 1 0 maps A D convertor CB220 X W AD channel 0 gt D10 awon e rors F AD channel 1 gt D11 I AD channel 2 gt D12 I AD channel 3 gt D13 I AD channel 4 gt D14 F AD channel 5 gt D15 F AD channel 6 gt D16 F AD channel 7 gt DI I High Count gt D39 High Count0 gt D38 Out GiRelayout Out lsoloutt Alias Nick Name Out GiMotort Out el Pa P15 out out el Out el C PWM 0 1 2 lt D26 z Example x MO SubRelay M PWM 3 4 5 lt D29 arman ABCD CUBLOC REL K M0 MASELAN u M3 out e Si Out E Out El use MODBUS on CHI CEDERESE REESE 115200 None 8 1 I Use Fast Scantime Load Save As Replace Basic Code Canc
19. 17 MEMO Chapter 1 Getting Started What is Cubloc Cubloc is different from the traditional PLCs that you may have encountered Traditional PLCs are built into cases and have hardwired connections but Cubloc is an On Chip PLC Industrial Controller meaning you have more freedom and flexibility in the final product size and design Cubloc Modules are similar to traditional PLCs in that Ladder Logic can be used but the small size allows developers to design custom PCBs for any application Traditional PLC There are different models each with a unique program memory size and number of I O ports Please make a selection based on your product s requirement 20 Cubloc Specifications ty p soke soke soke Memory Data 2KB BASIC 2KB BASIC 2KB BASIC 24KB BASIC Memory 1KB Ladder Logic 1KB Ladder Logic 1KB Ladder Logic 4KB Ladder Logic EEPROM 4KB EEPROM 4KB EEPROM 4KB EEPROM 4KB EEPROM Program 36 00 sec 36 000 inst sec 36 000 inst sec 36 000 inst sec Speed 16 1 O lines 5V TTL 91 1 0 lines 5V TTL General 20 1 0 lines 5V TTL input output 49 I O lines SV TTL 33 input only 32 Purpose i configurable input output output only 26 1 0 i Spare I O 6 5V configurable input output 2 serial ports 2 serial ports 2 serial ports Channel 0 RS232C Channel 0 RS232C Channel 0 RS232C 12V Channel 1 TTL 12V Channel 1 12V Channel 1 RS232C 5V Configurable RS232C 12V amp TTL 12V amp
20. 335 Modbus ASCII Slave Slave Source Const Device cb280 OpenCom 1 115200 3 80 80 Set Modbus 0 3 UsePin 2 Out UsePin 3 Out UsePin 4 Out Set Ladder On Master Slave RX AA RS232 P2 CH1 pg P4 GND CB280 When the slave finishes processing the data sent by the master the return packet from the slave will cause a jump to the label GETMODBUS The Set Until command is used to check for the ending code LF 10 The GetStr command is used to store all received data in RDATA The data in RDATA can be analyzed for any communication errors If the slave is not connected the program will never jump to GETMODBUS 336 Chapter 10 Application Notes NOTE 1 Switch Input Let s say you are developing some kind of machine controlled by a Cubloc The first thing you need is a user interface Our task today is to build a machine that will receive input from a switch and process it to perform a task We will make a start and stop button that will turn a lamp on and off START el STOP KEY La 10Kohm As you can see above ports PO and P4 will be connected to a pull down resistor resistor attached to ground The CB220 will read these switches as logic low or off when the switch is not pressed To find out if these switches are pressed or unpressed we can use Cubloc BASIC command In lt Filename startstopkey cul gt Const Device cb220 Dim a As Byte Do If In 0 1 Then a 1 If
21. 377 CB290 and CB405 Registers The following is a chart showing the registers for the CB290 and CB405 The CB290 and CB405 have more M C T and D registers than the CB220 and CB280 Register P External devices M2047 Special Register F FO to F127 System Status Timer T TO to T255 16 bit 1 For Timers Word Counter C CO to C255 16 bit 1 For Counters Word Step Enable S SO to S15 256 steps For Step Enabling 1 Byte Data Memory D DO to 511 16 bit 1 For Storing Data Word P M and F Registers are in bit units whereas T C and D are in word units To access P M and F registers in word units use WP WM and WF respectively Register Range Name WPO to 7 16 bit 1 Word Register P Word Access WM WMO to WM63 16 bit 1 Word Register M Word Access WFO to WF7 16 bit 1 Word Register F Word Access WPO contains PO through P15 PO is the least significant bit of WPO and P15 is the most significant bit These registers are often used with commands like wMov WPO es Po WP1 fesi pro WP2 ea ps WP3 ros pss 378 379 Ladder Symbols Contact A Contact B Contact A is Normally Open and closes when a signal is received On the other hand Contact B is Normally Closed and opens when a signal is received ee ele Je A Normal Open B Normal Close Input Output Register Symbol Input Output registers are the most basic
22. 56 P28 pa 9 25 P20 P47 41 57 P32 Ps 100 26 P21 PAG 420 058 P33 Pe 110 27 P22 P45 48 59 Pad P7 12 28 P23 5 P44 440 60 P35 4 pa 130 O 29 P15 P43 45 61 P36 Po 140 30 P14 P42 460 62 P37 1 P10 150 O 31 P13 Bats 47 0 0 63 Pas P11 160 32 P12 P40 480 64 P39 142 ByteOut ByteOut portBlock value portBlock I O Port Block Number 0 to 15 value Value to be output 0 to 255 ByteOut outputs a value to a port block a group of 8 I O ports Refer to ByteIn When using this command all I O ports within the specified port block are set to output ByteOut 1 255 v Output 255 te Port Block 1 Ports 8 through 15 are set to HIGH NOTE I O Port 1 only supports input Therefore ByteOut 0 will not set Port 1 to Output 143 CheckBf variable CheckBf channel variable Variable to store results No String or Single channel RS232 Channel 0 to 3 The command CheckBf can be used to check the current data in the receive buffer without modification Unlike Get it will not erase the data after reading Only 1 byte can be read at a time A CheckBf 1 Check current data in the receive buffer 144 Compare Compare channel target port targetState channel High speed counter channel target Target of pulses CHO 0 to 65535 CH1 0 to 255 port Output port DO NOT USE input only ports targetState Target output port state When the
23. Cls IAIN Endif End Sub Sub ProcessSubMenu4 If Menucheck 0 TX1 TY1 FlashMenu 0 Beeper 4 al Elseif Menucheck 1 TX1 TY1 FlashMenu 1 CurrentScreen Grs IAIN Endif End Sub _MAINMENU Sub Beeper Num As Byte Dim i As Byte For i 1 To Num High 18 Delay 100 Low 18 Delay 200 Next Then 1 then _MATNMENU Then 1 Then _MATNMENU Then 1 Then 469 End Sub Sub FlashMenu Num As Byte Menureverse Num Delay 150 Menureverse Num End Sub Sub DisplayTime Glocate 16 220 Font 0 0 Dprint Dai MAA IL AAR DS ASS Al pp E Dp Btd2bin Ti me 0 2 1 End Sub include CT1721treemenu inc Use CuCanvas to Generate your menus lt Filename CT1721treemenu inc gt SUB MAIN FONT 6 STYLE 0 0 0 GLOCATE 96 24 PRINT Main Menu ONT 0 ENUSET 0 2 40 96 144 128 ENUTITLE 0 20 8 Submenu 1 ENUSET 1 2 168 96 280 128 ENUTITLE 1 24 8 Submenu 2 ENUSET 2 2 40 152 144 184 ENUTITLE 2 20 8 Submenu 3 ENUSET 3 2 168 152 280 184 MENUTITLE 3 24 8 Submenu 4 LINESTYLE 0 DOTSIZE 0 0 COLOR BOX 80 16 232 56 FONT 4 0 END SUB SS SS SS SHAM SUB SUBMENU1 FONT 6 1 STYLE 0 0 0 GLOCATE 96 24 GPRINT Submenu 1 LINESTYLE 0 DOTSIZE 0 0 470 COLOR 1 BOX 80 16 232 56 FONT 2 1 MENUSET 0 2 88 88 224 120 MENUTITLE 0 22 8 Beep 1 time MENUSET 1 2 0 208 72 239 MENUTITLE 1 10 7 lt BACK FONT 4 0 END SUB SUB SUBMENU2 FONT 6 STYLE 0 0 0 GLOCATE 96 24 GPRINT
24. DY DT 10 Date Dey Alam 2 Day ee Date Alarm 2 Date 1 31 OEh EOSC BBSQW CONV Rs2 RS1 INTCN A2lE A1IE Control OFh OSF o e 0 EN32kHz BSY A2F A1F Control Status 10h SIGN DATA DATA DATA DATA DATA DATA DATA Aging Offset 11h SIGN DATA DATA DATA DATA DATA DATA DATA MSB of Temp 12h DATA DATA 0 0 0 0 0 0 LSB of Temp 475 CAUTION To use CB405RT in the beginning of the program one must replace Const Device tinclude Dim i As Wait 100 RTCwrite RTCwrite RTCwrite RTCwrite RTCwrite RTCwrite RTCwrite Do i RTCread 0 Wait 500 Loop 476 Debug Goxy i RTCread 1 Debug Goxy i RTCread 3 Debug Goxy 1 i RTCread 6 CB405 with Include CB405RT CB405RT Use include instead of the Const Device statement Integer 0 amp h20 Ses 1 amp h59 E MIN EA NENE Hour 24h 3 8h7 day 1 7 1 Sun 2 Mon 3 Tue 4 Wed 5 Thu 6 FRI 7 SAT 4 amp h31 Date 5 amp h12 Month 6 amp h08 Year ea i sieve Debug Goxy 1 2 Hex2 i Min i RTCread 2 And amp h3f 3 Hex2 i Hour Debug Goxy 1 4 Hex2 i Day i RTCread 4 Debug Goxy 1 5 Hex2 i Date i RTCread 5 Gliese ip Y Merida Debug Goxy 1 7 Hex2 i Year When the above example program is executed the following debug window will appear e Terminal Baud Rate Parity en An u zz y 115200 y tone x l Close I Fi
25. In contrast some languages allow values to be passed by reference in which the actual memory address is passed to the subroutine Cubloc BASIC only supports passing by value Too many characters in one line If you run out of room you can use an underscore character _ to go to the next line as shown here ST COMFILE TECHNOLOGY ST COMFILE are TECHNOLOGY Comments Use an apostrophe single quote to add comments Comments are discarded during at compile time and will not consume any program memory ADD AVAL UE SS et eel Add 1 to B Comment Nested Subroutines Nested subroutines are supported in Cubloc A Floor SQR F Pe Dew ELSOK on Ser E Colons Colons cannot be used to append commands in Cubloc BASIC as is possible in some other languages A 1 B 1 C 1 INCOFreGt Correct 87 Variables There are 5 types of variables in Cubloc BASIC OByte 8 bit positive number O to 255 Integer 16 bit positive number O to 65535 Long 32 bit positive negative number 2147483648 to 2147483647 OSingle 32 bit floating point number 3 402823E 38 to 3 402823E 38 OString character string O TO 127 bytes BYTE For storing negative numbers please use LONG or SINGLE Use the Dim statement for declaring variables as shown below Dim A As Byte Dim B As Integer C As Byte Dim STL As String 12 Dim ST2 As String Dim AR 10 As Byte Dim AK 10 20 As Integer Dim ST 10 As Strigg i0 Dec
26. P50 P51 P52 P53 P54 P55 P56 P57 P58 P59 P61 50 66 Output 68 Output 69 Output 60 Output 80 Output CUNET SCL CUNET SDA INT Channel 2 INT Channel 3 High speed Counter Channel 0 High speed Counter Channel 1 381 P70 39 Imput P71 m o pk P77 102 nput ejeje ojojo AIWIN P85 P86 107 Input 0 87 8 P80 P81 P82 P83 Block 10 P84 0 P88 N C Do not use this I O P89 PWM Channel 3 Block 11 3 2 3 2 3 P87 PWM Channel 4 INT Channel 0 P91 95 yo PWM Channel 5 INT Channel 1 VDD VSS 24 IN AavoD 43 ea 6 AVREF Power 4 5V to 5 5V GROUND RESET Input LOW signal resets Normally HIGH or OPEN P64 P65 P67 Bloces P68 3 39 I 4 1 i 2 24 3 Po 5 A 6 Po 7 ee 8 Po Po Se P72 87 Imput fe P73 EAS P74 89 Input Po P75 90 Input ____ Block 9 Po P76 101 Imput Po Po P78 103 Imput Po P79 104 Input Po 1 SS Po Po Po 7 AAA 8 AA 1 1 1 C N N N N RS232 Channel 1 12V Data Output c f a il po fF RS232 Channel 1 12V Data Input ADC Power Data Output Data Input ADC Reference Voltage ive ive LTX1 51 The CB290 s output only pins P24 to P55 are in a high impedance state High Z at power ON You must use Set OutOnly On to enable the pins if you wish to use them Set Outonly On This
27. Pt P17 o pao P2 P18 o pen P3 P19 o Rag P4 p20 INTO e P32 P5 p21 lt INT1 bd Pa Po p22 INT2 e Ba o e Oo o o 225 Set Ladder Set Ladder On Off Ladder is set to off by default Use this command to turn enable Ladder Logic The following is an example of a simple BASIC program for starting Ladder logic Const Device CB280 Device Declaration UsePin 0 In START Port Declaration UsePin 1 In RESETKEY UsePin 2 In BKEY UsePin 3 0ut MOTOR Alias MO RELAYSTATE Aliases Alias M1 MAINSTATE Set Ladder On Start Ladder Do Loop BASIC program will run in infinite loop 226 Set Modbus Set Modbus mode slaveAddress returnInterval mode 0 ASCII 1 RTU slaveAddress Slave address 1 to 254 returninterval Return interval 1 to 255 Cubloc supports the Modbus protocol in combination with Ladder Logic functions Modbus can be used on RS 232 channel 1 only To enable Modbus slave mode use the Set Modbus command This command will enable the Modbus slave It must come after an OpenCom command to set up RS 232 communication on RS 232 channel 1 The baud rate stop bit and parity settings can be set with OpenCom OpenCom 1 115200 3 80 380 Please set receive buffer ie ene Teast 50 Set Modbus 0 1 100 ASCII mode Slave address 1 After this command Cubloc responds automatically Cubloc supports Modbus commands 1 2 3 4 5 6 15 and 16 06 1 Word Write Multiple Bit
28. Submenu 2 LINESTYLE 0 DOTSIZE 0 0 COLOR 1 BOX 80 16 232 56 FONT 2 MENUSET 0 2 88 88 224 120 MENUTITLE 0 16 8 Beep 2 times MENUSET 1 2 0 208 72 239 MENUTITLE 1 10 7 lt BACK FONT 4 0 END SUB SUB SUBMENU3 FONT 6 STYLE 0 0 0 GLOCATE 96 24 GPRINT Submenu 3 LINESTYLE 0 DOTSIZE 0 0 COLOR 1 BOX 80 16 232 56 FONT 2 MENUSET 0 2 88 88 224 120 MENUTITLE 0 16 8 Beep 3 times MENUSE TAZAS 2259 MENUTITLE 1 10 7 lt BACK FONT 4 0 END SUB SUB SUBMENU4 FONT 6 1 STALE 0 1010 GLOCATE 96 24 GPRINT Submenu 4 LINESTYLE 0 471 472 Chapter 13 CB405RT CB405RT CB405 core module equipped with a built in accurate RTC DS3231 equipped with a built in 16 bit A D converter 8 channels The CB405RT is a product which adds an RTC and a 16 bit ADC to the original CB405 The external dimensions and pinout are the same as the CB405 with the exception that ports P32 to P37 are used for the 16 bit ADC and therefore cannot be used The CB405RT has a built in realtime clock DS3231 which automatically compensates for clock errors due to temperature changes sporting improved accuracy over the existing RTC When a supercapacitor is connected to VBB data memory is preserved even when the power supply is interrupted Since the supercapacitor is charged automatically when the device is powered the supercapacitor can compensate for the power supply if interrupted eliminating the need for batteries
29. TTL 5V Ports Baud rates 2400bps 5V Configurable Configurable Baud to 230 400 bps Baud rates 2400bps rates 2400bps to to 230 400 bps 230 400 bps Analog A 8 Channel 10 bit 8 Channel 10 bit z 6 Channel 10 bit ADCs ADCs ApoE 8 channel 10 bit ADCs 3 Channel 16 bit 3 Channel 16 bit 6 Channel 16 bit 6 Channel 16 bit Analog PWMs DACs PWMs DACs PWMs DACs PWMs DACs Outputs Frequency 35hz to Frequency 35hz to Frequency 35hz to Frequency 35hz to 1 5Mhz 1 5Mhz 1 5Mhz 1 5Mhz External 4 channels in spare 4 Channels 4 Channel Interrupts 1 0 i 2 Channel 32 bit 2 Channel 32 bit a eo Speed Counters up to Counters up to Cuter api ne ounters 2Mhz 2Mhz R DC 9V to 12V 100mA 5 to 12V 40mA 5V 40mA ports 5V 70mA ports lor From USB ports unloaded unloaded unloaded ME icles Operating 40 C to 120 C 40 C to 120 C 40 C to 120 C 40 C to 120 C Temp I O Board 24 pin DIP 600mil 64 pin Module 108 pin Module 2 9 L x 2 0 W x 0 4 H ae a WX TA F A 2 4 L x 1 9 W x 0 5 H 75x 53x12mm 39 x 15 3x11mm 35x 25 4x 11 mm 9 4 47 8 x 13 mm Serial 21 200KB 200KB 200KB 200KB Memory Data neon 6KB BASIC 51KB BASIC 4KB Lad 6KB BASIC Memory Logic 4 1KB Ladder Logic der Logic 55KB Heap 1KB Ladder Logic 4KB EEPROM 4KB EEPROM 4KB EEPROM 4KB EEPROM Program 6 000 36 000 inst sec 36 000 inst sec 36 000 inst sec Speed sec 16 I O lines 5V General PEE m 49 I O lines 5V TT
30. This is a conditional statement you can put right after the On Recv command Normally the On Recv interrupt is generated when a single byte is received via the specified serial port Set Until can be used to only generate an interrupt when either packetLength bytes are received or stopChar is detected packetLength is used to interrupt stopChar never arrives To interrupt only on packetLength set charCheck to 1 You MUST use this command with the On Recv command The following is an example Dim A 5 As Byte OpenCom 1 19200 0 100 50 On Recvl DATARECV_RTN Set Until 1 99 s As you can see above the packet size is 99 bytes In other words if character S is not received within 99 bytes an interrupt will occur The stop character may also be written in decimal form as shown below set Until 1 100 4 In the following example an interrupt be generated only when the packet length is greater than or equal to 5 charCheck is 1 so stopChar is ignored Sere umeli 1 501 242 243 ShiftIn variable ShiftIn clock data mode bitLength variable Variable to store results No String or Single clock Clock port 0 to 255 data Data port 0 to 255 mode 0 LSB first Least Significant Bit first after rising edge 1 MSB first Most Significant Bit first after rising edge 2 LSB first Least Significant Bit first after falling edge 3 MSB first Most Significant Bit first after falling edge 4
31. iO ito TS Wizard F3 F4 F5 Fe lei Fe F9 Fil F12 NOT END Insert Delete Undo Copy P62 P63 P86 MO P72 P31 EIT O P31 Y P80 Pal P82 P83 P84 P85 MO HHHH HH P31 MI WORK_ON TOGLE MI M2 WORK_OFF TOGLE M2 P2 MPG ON INPUT M3 HER 0 M3 P40 P62 MPG ON OFF TOGLE M5 AHIHI O TH M4 M5 MPG ON LED Pap HH gt z Modified Program 154 Bytes Data 1001 The red box shown above is the Ladder Logic cursor You may use the keyboard s up down left and right keys or the mouse to control the red box After moving to the desired position you can use the keys F3 through F12 to place the desired symbol You can also enter text for each symbol 364 1 Press F3 to make a contact cl ls al ir H lt 3 1 1 10 T L 4 F3 ES EN A E ES AA neal Gang OUI BEND 1 2 2 Type START and press ENTER ari ES as aleta ar E aa F3 F4 F5 F6 Fr Fe F9 Fil Fl2 NOT END FAL 2 3 Press F5 couple times and you will see that it creates a line dk ER I a T 11C T L F3 F5 F6 Fe F9 Fil Fl2 NOT END START C 1 2 4 Press F7 t pe RELAY and press ENTER alla Ye 7 HACI T T Y Hed lt 3 gt lt gt F3 F5 Fs Fe F9 Fil F12 NOT END Insert Delete Undo START ET 1H 5 Go to the next rung line and press END sel Sie poe Ul paca ECU AA ke 2 E CO ECO OO F3
32. include and define can be used to include files and process code before compiling include filename Reuse code by including source files For files in the same directory as the current source file you can write the following include MYLIB cub For files in other directories you will need to include the full path name as shown here include c mysource CUBLOC lib mylib cub Using include files you can store all of your common subroutines in a separate file In this case please make sure to include the subroutine file at the very end of your program after the End statement define name constants By using define you can assign names to values before compiling define motorport 4 Low motorport In the example above motorport will be compiled as 4 You can also use CONST for similar tasks However CONST will use data memory define will only use program memory CONST motorport 4 Low motorport 106 The following example uses define for replacing a line of code define FLAGREG1 2 define f led FLAGREG1 BITO define calc 4 i 256 ye lee al Set FLAGREG S bit zero to 1 Lt r legc 1 them fled Make if easier to read j calc Calculations can be simplified The name argument in a define statement is not case sensitive For example define ALPHA 0 and define alpha 0 do not define different constants They both define the same constant DEMO PROGRAM a Terminal 2 CUBLOC st
33. port s send buffer Afterward the Cubloc BASIC interpreter takes care of the actual sending Use the Brree command to prevent overloading the send buffer 213 Pwm Pwm channel duty period channel PWM channel 0 to 15 duty Duty cycle must be less than the period period Maximum of 65535 Outputs a pulse waveform whose shape is determined by the values of duty and period Be aware that the PWM channel is different from the I O port number For the CB280 ports 5 6 and 7 are used for PWM O 1 and 2 Before using Pwm make sure to set the ports I O mode to output and set their output to a known state logic low or logic high Depending on the value of period a PWM signal of up to 16 bit precision is generated A period of 1024 is a 10 bit pulse and a period of 65535 is a 16 bit pulse The pulse s actual frequency in Hz can be computed with the following formula Frequency 2 304 000 period duty must to be less than period The pulse s output will remain active for a fraction of the period given by duty period Pwm is independently hardware driven within the Cubloc Once the Pwm command is executed it will keep running until the Pwmoff command is called 200 1024 Low 5 Set port 5 output and output LOW signal Pwm 0 200 1024 Output 10 bit pulse with duty of 200 and width of 1024 IMPORTANT PWM channels 0 1 and 2 must use the same value for period since they share the same
34. words use wP and wD For example _wP 0 represents PO through P15 The following is an example program IDO 1234 paa 3456 _D 2 100 For 11 10 o SE _M 1 0 Next aa Jesh il GA l Accessing BASIC variables from Ladder Logic is not possible but you can use Ladder interrupts to request a BASIC routine to change a Ladder Logic variable 116 Use Ladder Logic pins in BASIC using the Alias Command The Alias command can be used to set aliases for Ladder Logic registers except the D register Aliases although declared in BASIC can only be used in Ladder Logic UsePin 0 In START UsePin 1 0ut RELAY Alias MO MOTORSTATE Alias M1 RELAY1STATE Alias T1 SUBTIMER 117 Chapter 5 Cubloc BASIC Functions Math Functions Sin Cos Tan Return sine cos ine and tangent values Cubloc uses radians as units Use a Single for most precise results A Sin B Return the sine of B A Cos B Return the cosine of B A Tan B Return the tangent of B ASin ACos ATan Return arc sine arc cosine and arc tangent values Cubloc uses radians as units Use a Single for the most precise results A ASin B Return the arc sine of B A ACos B Return the arc cosine of B A ATan B Return the arc tangent of B Sinh Cosh Tanh Return Hyperbolic Sine Hyperbolic Cosine and Hyperbolic Tangent values A Sinh B Return the hyperbolic sine of B A Cosh B Return the hyperbolic cosine of B A Tanh B Retu
35. 1 to 32 This command sends and receives data simultaneously In contrast the ShiftOut and ShiftIn commands only support either sending data ShiftOut or receiving data ShiftIn but not both The Spi command can be used on any I O port The Set Spi command must be used prior to the Spi command to ensure the I O ports are defined prior to sending or receiving data 246 StepAccel StepAccel channel port freqBase freq Top FreqAccel qty channel StepPulse channel StepAccel supports only 0 port Output port freqBase The starting stepper frequency Up to FreqTop freqTop The frequency after acceleration is finished Up to 3 3KHz freqAccel The acceleration in steps per second qty of pulses to output up to 2147483647 Frequency Top Frequency Base Frequency Accel gt Number of Pulses This command outputs a set number of pulses at a set frequency up to 3 3kHz with acceleration The StepAccel command supports only 1 channel so O must be used for the channel parameter You can use any of the available I O ports on the Cubloc When the StepAccel command is executed the specified port s I O mode is automatically set to output Even after the command has finished generating pulses the port s I O mode remains output The output frequency can be set from 1hz to 3 3KHz This command will run in the background independently so system resources can be used for other tasks 247 StepPulse S
36. 109 AA A suaesecbbsdays ia alaaa dda LOT a EIda 110 Er AUR ONU a AE S EEA A ES S TAT os ee ar 106 492
37. 128 lt 2 CUBLOC studio d cubloc_test unary cul File Edit Device Run Setup Help Bam g 28 A mar FI BASIC F2 LADDER Ladder winem Baud Rate Parity Data Bits grx Const Device CB280 E 115200 gt rore 7 e gt RK Dim A As Long A 10 Debug Dec A Cr amp a Terminal A Not 1 Debug Dec A Cr A Ned 4 Debug Dec A Cr A Ded 15 Debug Dec A Cr Close I Fix Right Side 193 Nop Nop This command does nothing but consumes one command cycle It is useful for tuning small intervals Low 8 Nop High 8 Output very short pulse to port 8 About 50 micro Sec Nop Low 8 194 On Int On IntO GoSub label On Int GoSub label On Int2 GoSub label On Int3 GoSub label This command must be called before accepting external interrupts Cubloc has 4 external interrupt ports The interrupt ports can be set to sense input on the rising edge falling edge or both Set OnIntx command must be used with this command in order for the interrupt to work CB220 has no external interrupt inputs Rising Edge Falling Edge Dim A As Integer On Int0 GoSub GETINTO Sea ONO Falling Edge Input Do Loop GETINTO A A 1 Record number of interrupts Return 195 On LadderInt GoSub On LadderInt GoSub label If Register F40 turns on in Ladder Logic and the On LadderInt GoSub command is used then the processor will jump to the routine label specified by On LadderIn
38. 2500 32768 When the code above is executed a 1ms pulse will be generated from I O port P5 and the RC servo motor will position itself to 45 degrees Const Device CB280 Low 5 Pwm 0 4000 32768 When the code above is executed a 1 5ms pulse will be generated from I O port P5 and the RC servo will position itself to O degrees By simply changing the duty value of PWM command the RC servo can easily be controlled For the CB220 3 RC servos can be controlled simultaneously while the CB280 and CB290 can control up to 6 RC servos The CB400 CB405 can control up to 12 servos Warning When the RC servo is in operation it will need about 500mA of current Please make sure to use a power supply of at least 500mA 352 NOTE 6 Digital Thermometer The DS1620 is a digital thermometer The chip has an internal temperature conversion table so the user does not have to make a separate table Temperatures between 55 and 125 degrees Celsius can be measured by the DS1620 in units of 0 5 degrees cik T HI 1 RsT T LO mogero T com DS1620 Const Device CB220 Const iorst Const ioclk Const iodg 5 Dim i As Integer Delay 100 High iorst u init ds1620 Snifrrt ut ioclk atole 0 1278 Ste OO Ik LeCle 0 3 8 Low iorst High iorst 6 ShiftOut ioclk iodq 0 shEE 8 Low iorst Do High iorst ShiftOut ioclk iodq 0 haa 8 i ShiftIn ioclk iodq 4 9 i i debug dec i cr Low iorst Dela
39. 4 6 16 Area of the Cubloc to be addressed the HMI SCADA software area DO D511 area TO T255 area C 0 C255 42001 42256 M area WMO WM255 43001 43256 Bit Region Coil Input Status Relevant Function Codes 1 2 4 15 Address to be entered in the addressed HMI SCADA software P area PO P127 E 128 or 10001 10128 M area MO M2047 097 6144 or 14097 16144 333 Modbus ASCII Master There are no special commands needed to set the Cubloc as a Modbus master One simply needs to use Cubloc s RS 232 commands like Get and Put The following is an example illustrating the Cubloc running as a Modbus ASCII master Master Source Const Device p230 Dim RDATA As String 80 Dim a As Byte ct As Byte Dim lo As String I7 Dim Port As Integer OpenCom 1 115200 3 80 80 On Recvl Gosub GETMODBUS Set Until 1 60 10 Do Loop GETMODBUS For Port 2 To 4 BitWrite Port Delay 100 Next For Port 2 To 4 BitWrite Port Delay 100 Next If BLen 1 0 gt 0 Then End If Return End A BLen 1 0 Debug GOT RESPONSE B GetStr 1 A Debug B Sub BitWrite K As Integer 334 Dim LRC As Integer Putote Al 0305r r D Data Receive Interrupt routine When Ending Code 10 on Channel 1 is discovered create an interrupt T Turn POPI P2 ON 0 Turn P0 P1 P2 OFF If buffer empty then Store the buffer length in A Store received data in B As Integer
40. A Aa lie aaa en 88 MA A e Habana 90 About Variable Memory SPACe ococcccccncoconononnnnenononornnnananenararanana nos 94 ACAYS i eina ana ar nie aE teat veeadug ndaicean ea DE Taj dto sidad iaa Dalia 95 Bit and Byte ModifierS oooomoccncccnnoncnnnnnnnncncnenonnonnncnennanrnrnannn nana 96 CONSTANTS in A aia 99 C nstant Arrays e o i ec 100 Operators 5 presona na aa cok cates a a A E a aa aara 102 Expressing UMD FS ei nia 105 The BASIC Preprocessor pine sanee semen eens 106 Conditional DiFettiVeS iiina aa sea telrode eee eek cove seat 108 To Use Only Ladder Logic 111 To Use ON BASICiutaia lianas 111 Inter ria int aa eee te eA a a aa e aaa a Er enact 112 More about Interrupts kisesi inisee nrinn eee eee iini daak n Teana 113 Pointers using Peek Poke and MeMAdrF ooccccnccnconcnncnnnncnnnnnnncnnnos 115 Sharing Data ice la roda 116 CHAPTER 5 CUBLOC BASIC FUNCTIONG i sssssssssssssssssssssssessesscsessesessessesessessesesseeseees 118 Math iRUNCHOMS id aa 119 TYPE Conversio ieies da 121 String FUNCHONS ia 124 CHAPTER 6 CUBLOC BASIC STATEMENTS LIBRARY cccssssssssssssssesssssssssssseseees 132 AGIA RT 133 AMS iaa aia 135 BA aa 136 BCIE Ss inoa aaen atril 137 BCD as E A T 138 O O T E T T 139 BILBAO ii A AA iaa a i eii 140 ET A A E 141 BEI A ti ai 142 Bd ade cau senuneranages 143 ChECKBEC vis teaseeetiued aaa aaia stbesteaceseetssueesessteceevecd 054 144 COM Pareciincucinceee ce A tee 145 CAU o ees 146 COURSE
41. BASIC language but its use should be limited in an effort to adopt a structural programming paradigm Be especially careful when using GoTo within a GoSub or subroutine since improperly terminating a subroutine can have undesired effects If I 2 Then Goto LAB1 End If LAB1 TRES About Labels A label can be set with a colon to specify a point for GoTo or GoSub to begin execution ADD_VALUE LINKPOINT Labels cannot use reserved keywords numbers or include blank spaces The following labels are not permitted Ladder Reserved keyword 123 Number About 10 Blank space 174 Heap Memory Access Heap memory access is a special feature only available on the CB405 module The user may use 55KB of heap memory from address O through 56831 amp H0000 through amp HDDFF The heap can be used to store large data for graphics temperature tables etc With a backup battery the heap can be used for data logging and other persistent uses 55K bytes 0000 4K bytes 0000 amp HDDFF amp HFFF Heap Memory EEPROM Memory There are five heap related functions Erase the entire heap HRead variable HRead address Read the designated length number of bytes set by length from heap address address and store into variable HWrite HWrite address variable Store length number of _ length bytes of variable to the heap address address HeapW HeapW address variable Store one byte IN variable to th
42. CYCLH pila M2 M1 PIERCE1 EXT P33 4 7 gt LOOP1 EXT P32 CUTOFF1 RET ua uo DIED E1 EYT DAR Image of Cubloc Studio is shown above 23 There are other PLCs on the current market that support both Ladder Logic and BASIC However these PLCs do not multi task Because BASIC is part of their Ladder Logic it does not run independently like Cubloc or Cutouch This can prove to be costly since BASIC is not real time oriented and can delay the Ladder Logic scans possible causing missed inputs or other undesired behavior Cubloc on the other hand doesn t suffer from these weaknesses because it multitasks guaranteeing accuracy and precise timing SINGLE TASK MULTI TASK LADDER BASIC LADDER BASIC LADDER BASIC Cubloc is a brand new type of industrial controller By being able to do things that traditional PLCs can t we have expanded the horizons of both PLCs and BASIC micro computers Cubloc is fully backed by many Plug N Play peripherals such as our CUBASE industrial I O Boards and Plug N Play Relay8 Boards With these peripherals controlling DC AC devices is easy With 32 bit IEEE floating point math support and MODBUS ASCII RTU support the user will find that Cubloc and Cutouch are among the most versatile BASIC PLC hybrid chips on the market today 24 Ladder Logic and BASIC Ladder Logic s greatest advantage is that all circuits are laid out
43. Const Device CB280 Dim stl As String 12 Dim i As Integer stl 123 i Val stil Debug Dec i Cr Dim fl As Single ati 3 14 fl Valeng stl Debug Float f1 Cr ValHex String variable Parses a given String in hexadecimal format into its numeric equivalent Dim STI AS String 12 Dim i AS Long ST1 ABCD123 i ValHex ST1 SHABCD123 is stored in variable I 130 Chr asciiCode Return the character represented by the given ASCII code Dim SIL INS Seta I2 ST1 Chr amp H41 Debug ST1 Print A amp H41 is the ASCII code for character A ASC stringValue Return ASCII code of the first character in the given String Dim STI AS String I2 Dim i AS Integer STI 123 i Asc ST1 H31 is stored in variable I ASCII code of 1 Eis SES 03I Caution A variable must be used when using string functions Debug Left INTEGER 4 A String constant cannot be used ST1 INTEGER Debug Left ST1 4 The String must be stored as a variable first a Terminal Baud Rate Parity Data Bits DTE CUBLOC i she c_testichr c E CUBOS Studie dy ubloc_test chr cul comi 15000 none y b zl a File Edit Device Run Setup Help Bang 22 a gt ma Bl FI BASIC F2 LADDER Ladder Mnemonic Search Const Device CBZ80 Dim stl As String 12 stl Chr s2h41 Debug stl Cr sti 123 Debug Hex Asec stl Cr Close F Fis Right Side
44. DI i Si 973 970 968 965 963 960 957 954 951 948 346 945 942 938 935 931 927 923 919 915 911 907 902 898 893 888 883 878 873 868 862 857 851 845 839 833 827 821 815 808 802 795 788 181 774 7167 160 753 746 738 731 723 716 708 700 692 684 677 669 661 652 644 636 628 620 612 604 596 587 579 571 563 595 547 538 530 522 514 506 498 491 483 475 467 460 452 445 437 430 422 415 Dim a As Integer b As Integer Do b Tadin 0 If b gt 990 Or b lt 400 Then Debug Out of Range Check short or open th End If For a 0 To 100 If b gt TH TABLE a Then Exit For Next Debug Dec a cr Delay 500 Loop lt Filename ntcth cul gt By using the TADIn command for AD conversion the Cubloc will automatically calculate the average of 10 A D conversion reads for more precise results The sample program shown here will be able to sense between O and 100 degrees A minor modification to the code would allow a larger temperature range The formula for acquiring the A D conversion value from the R T table is as follows V xTHR 1000 THR THR is the resistance value 1000 is for a 1K Ohm resistor and 5 is for 5 volts The 10 bit A D converter of the Cubloc will return a value between 0 and 1024 Therefore to get the A D value you must multiply the result V by 204 8 A chart can be made by plotting this formula in a spreadsheet 347 NOTE 4 Sound Bytes This applica
45. Didean sa 249 A es cictheel leah ost nek eee ane Pattee 249 SVS sta tevece ciate varesvec cts Vocee a ees terete 252 TADO Oise a ada Ad Aei 253 O a ea aaa ache netenus ace cece ee A EAA 254 A ied ee ee ea eh ee dee 256 UD Gla ts sine eds E ddane ah ondaeivene sey ven eees rome T 258 Us iNadiciatcc ii A A EA des ARA A A ets 259 UTM A eee a setae 260 Wal dt nick nda 261 WAEIT x eset A a A a ELAN 262 CHAPTER 7 CUBLOC DISPLAY LIBRARY ssscssssssssscsscsscsscsscssscsesssasssscscssscsscsscssssceees 263 CLEDD Module a a a aa daada me a asddeatabedeeeamabdehe sescheaeanee 267 GHLCD Graphic LCD GHB3224C 0000ccccnncnnoncnnncnnannnnnnnnnnnannnnnnnnns 270 Us A E A A cadeses 273 CIGAR iian A adaa ibadan aea ves see a ad a a a ia 273 ORO a ETE A E AATE TEA O 273 O O ON 273 E a CN 273 Pl deis 274 CREDO UE e dabas 275 Layer ino lapso coria caca pira TET tia tai aE E a STAD O E E 276 GAY iniy in t a aaa etapa aged an AEA EA a EAA 277 Overlay vise sete I NE a e aea O TED ts 277 oTo n E E Re EEEE A A TEETE 278 IG Mtycts ire A NA 278 A A A a a A EE an gu duced aia 278 FO M ETTE ON 279 Uli A O E TETTE OT ATT 280 OMO de aa os a ESA 280 LMG danes e a tales ute ed a i aa daa aa a a a 281 LUNETO raian A A Aa 281 BOX A A NT 282 BOX A a tes bees ean a A 282 A A A A A 282 A A a RT 283 Circle A AET ode A esca 283 A TN 284 ELO A A Sales 285 A A A wesc 285 DP A cio 286 a A A 287 Pi A E A A EAT 288 Cold A ETT 288 AS ETELE Sadat ee aoa
46. E A A ies 397 TMON TAMO Nicosia odes gee cdeledi waa a 398 TON TAON ad ac aan ac 400 MORF TAO RE o A EEA 401 ETA ia a S nah tea 403 CTO A od ad EN 403 UP DOWN COUNTER hirae aiian a ninaa eaa a e Eai ipi aE aena 404 LE D EETA cs bla 405 Comparison LO Eo aio 406 Storing Words and Double WordS ococcccccocococonononnnnncnronononnnnnananos 407 Binary Decimal HexadeciMal ooccccocccccnnonconancnccnnnancnnnnnnnnnnnnnnnes 408 WBClD a A eae 409 WBIN wicsiccecc ces ci AA edad 410 WBENT DWBENT 0000 Ae 411 WMOV DWMOVe sonreir iaa 412 WXCEHG DWXCEA Gi eneeed iets eel este A aA A 413 FMOV AP nn coed a a scctaanaaseapaatyrena ete es 414 GMO fiver ARO 415 WEMP DWEMP i a raro savas 416 WINC DWINC WDEC DWDEC coccccncncococcnnncncnncnnnancnroncnanananreness 417 WADD DWAD D aeaaaioii dan 418 WSUB DWSUB Sa A dio 418 WMUL Tocata tario ads Dalila 419 WDIV DWDIV ciciooiocciciiic A 420 WOR DWOR a a eraa a iaaa ian daa 421 WOR DWXOR 000 a ieu aa 422 WAND DWA N Di ramaan n a TAS 423 WROL DWROL succi n Eear aeia a Eata 424 WROR IDWROR Seasann o ia 425 WRCELDWREL ae nd ali 426 WRER IDWRER a O 427 WINV DO WIN Viatri era hates NESNE 428 WNEG DWNEG fii 0 A e as 429 GOTO LABEL nr reali ted 430 CALLS SBRT RE Tiida A e 431 INTO Ni A 432 TND A A seme 433 Special REIS Si cereeseween e a aaa A E 434 CHAPTER 112 CUT OU C Hitiviveseces covcssccsccsceccensdtgescet dd 437 Whatiis Gutouch ics acer seis soon esnegetosacetaney ds 439 Cutouc
47. GPop x y layer logic logic 0 OR logic 1 AND logic 2 XOR logic 3 Clear screen then pop This command pops a screen from stack and displays it on the specified layer at coordinates x y The logic parameter specifies how the popped screen should be combined with the data currently displayed on the specified layer eee 120 20 2 y 0 293 294 GPaste GPaste x y layer logic logic 0 OR logic 1 AND logic 2 XOR logic 3 Clear screen then pop This command pastes a screen from the stack and displays it on the specified layer at coordinates x y The logic parameter specifies how the popped screen should be combined with the data currently displayed on the specified layer This command is identical to GPop except it will not remove the screen from stack Therefore you can use this command if the current item in the stack must be used again 295 HPush HPush x1 y1 x2 y2 layer The HPush HPop and HPaste commands are similar to GPush GPop and GPaste except the x coordinate in multiples of 8 as shown below The 320 pixels is divided into 40 columns each 8 pixels wide 111111111122222222223333333333 0123456789012345678901234567890123456789 239 HPush 6 20 12 1100 2 HPop HPop x y layer This command is the same as GPop except the x coordinate must be from 0 to 39 HPop 10 20 2 0 HPaste HPaste x y layer This command is the same as GPaste except the x coordinate must
48. Get 1 1 Read 1 Byte A 3 Get 1 1 Read 1 Byte A 4 Get 1 1 Read 1 Byte EnA TE Return End of interrupt routine IMPORTANT When a Recv interrupt service routine ISR is being executed subsequent Recv interrupts will not be received After the ISR is finished executing if there is still data being received another Recv interrupt will be generated and the ISR will execute again 199 On Timer On Timer interval GoSub label interval Interrupt interval 1 10ms 2 20ms 65535 655350ms 1 to 65535 can be used On Timer can be used to repeatedly execute an interrupt routine on a specified interval Set the desired interval in increments of 10 milliseconds and a label to jump to when interrupt occurs On Timer 100 GoSub TIMERTN Dim i As Integer Loop TIMERTN Toer ab i is incremented by 1 every second Return IMPORTANT Be aware that ithe interrupt service routine ISR must require less time to execute than the interval itself If the interval is set to 10ms the ISR must execute within 10 ms otherwise collisions can occur 200 OpenCom OpenCom channel baudRate protocol recvSize sendSize channel RS232 Channel 0 to 3 baudRate BaudRate Do not use a variable protocol Protocol Do not use a variable recvSize Receive buffer size Max 1024 Do not use a variable sendSize Send buffer size Max 1024 Do not use a variable This command must be used to enabl
49. HAA Print Chr amp HDB30 Bmp Bmp x y fileNumber layer x y Coordinates where bitmap should display fileNumber Bitmap File number layer Layer on which to display the bitmap The GHB3224 has flash memory for storing bitmap files The BMP Downloader is used to download bitmaps to the LCD Once the bitmaps files are stored in flash memory this command can be used to display them on the LCD The GHB3224 has 102 400 bytes of flash memory for storing bitmap files which can store approximately 10 320x240 full screen images 291 Graphic Data Push and Pop Commands The GHB3224 has a separate stack for storing graphic data The current screen can be pushed and popped on and off the stack By saving and restoring the screen to the stack copy cut and paste features can be implemented The GPush and GPop can be used for precise cutting of the current screen while HPush and HPop can be used for higher speed operations with less precision The stack is LIFO last in first out so it will pop the last screen that was pushed onto the stack There is approximately 32KB of stack memory on the GHB3224 which can store approximately 3 to 4 full screens Please refer to the picture below for a depiction of how the stack works Li P 292 GPush GPush x1 y1 x2 y2 layer Push the rectangular area with upper left coordinates x1 y1 and lower right coordinates x2 y2 onto the stack GPush 10 20 200 100 2 GPop
50. IMPORTANT The device being used must be declared before using BASIC or Ladder Logic Below is an example of declaring the Cubloc CB220 module Const Device CB220 Use CB220 This should be the first line of a program When this command is not used the CB220 model will be assumed Const Device CT1720 Use CT1721 Const Device CB280 Use CB280 78 Cubloc BASIC Features Cubloc BASIC supports functions and subroutines The user is able to create subroutines and functions to organize their programs Using subroutines and functions allows the user to reuse code and organize programs for better readability Function SUM A As Integer B As Integer As Integer Dim RES As Integer RES A B SUM RES End Function Calculations can be done within conditional statements such as If While etc If A 1 100 Then GoTo ABC If A 1 100 And B 100 20 OR C 3 Then GoTo ABC Hardware RS 232 Communication Cubloc uses a hardware RS 232 UART instead of software RS 232 UART allowing real time processing to continue during RS 232 operations A graphic LCD library is provided Cubloc provides a complete graphic LCD library for the Comfile GHLCD product Boxes lines circles and other graphics commands are easily implemented in a few lines of code Various Communication Protocols are supported CUNET Display peripherals such as character LCDs RS232 up to 4 channels MODBUS built in slave functio
51. In the example above If DATA1 0 is read the ASCII code of C is returned Likewise if DATA1 1 is read ASCII code of U is returned Integer and floating point Single numbers can also be stored in arrays as shown below Const Integer DATA 6000 3000 65500 0 3200 Const Long DATA2 12345678 356789 165500 0 0 Const Single DATA3 3 14 0 12345 1 5443 0 0 32 0 For multiple line constant arrays end each line with a comma or an underscore character as shown 1 Const Byte DATA 31 25 102 34 1 0 0 0 0 0 65 64 34 12 123 94 200 0 123 44 39 120 239 132 13 34 20 101 123 44 39 12 39 2 Const Byte DATAZ Sil 25 02 sa il W 6S Gf si _ z TOL 1237 447 397 L27 29 String constant arrays are deprecated 100 Please make note of the following differences between arrays and constant arrays Po Array Constant Arra Storage Location Data Memory SRAM Program Memory FLASH When Allocated During Download Can be Changed__ Yes __ mno Purpose Store changing values Store constant values When Powered Lost Retained off DEMO PROGRAM CUBLOC studio d cubloc_test constarray cul File Edit Device Run Setup Help 376806 44 gt BA FI BASIC F2 LADDER Ladder Mnemonic Const Device CB280 Const Byte DATA 31 25 102 34 1 0 0 0 0 0 65 64 34 12 123 94 200 0 123 44 39 120 239 132 13 34 20 101 123 44 39 12 39
52. Ladderint Dec i End If If _D 0 2 Then Locate 0 0 Print TEST PROGRAM Dec i End If Return For a short version of the ladder above the user can use an INTON command which accomplishes both WMOV and SETOUT in one command The following is an equivalent shortened version of the ladder above INTON 3 D0 PO 1 1 PI INTON 2 D0 1 C l 197 On Pad On Pad GoSub label The On Pad interrupt will jump to the specified label when the keypad touchpad port receives a packet packets sizes are assigned by the Set Pad command Please be sure to use a Return command after the label Const Device Ct1720 Dim TX1 As Integer TY1 As Integer Contrast 450 Set Pad 0 4 5 On Pad GoSub GETTOUCH Do Loop GETTOUCH TX1 GetPad 2 TY1 GetPad 2 Circ PulsOut 18 300 Return 198 On Recv On Recv0 GoSub label On Recv1 GoSub label On Recv2 GoSub label On Recv3 GoSub label When data is received on one of Cubloc s RS 232 channels this command will jump to the specified label Recvo for channel 0 Recv1 for channel 1 etc The processor will automatically check for received data and trigger interrupts when this command is used Dim A 5 As Byte OpenCom 1 19200 0 100 50 On Recvl DATARECV_RTN Jump to DATARECV_RTN when RS232 channel 1 receives any data Do Loop Infinite Loop DATARECV_RTN If Blen 1 0 gt 4 Then A 0 Get 1 1 Read 1 Byte A 1 Get 1 1 Read 1 Byte A 2
53. O The Cutouch combines a traditional PLC with a touchscreen graphical LCD By integrating user input display output and control developers can now use one device as a complete control system TOUCH PANEL PLC N ge e ii aia CUTOUCH 439 Cutouch Specifications Cutouch CT1721 Dual Core Atmega128 O 18 432Mhz Program Memory 80KB Flash EEPROM 4KBEEPROM 2 High speed hardware independent serial Serial Ports for ports Communication Configurable Baud rates 2400bps to 230 400 bps Configurable Voltage 0 to 5V OR O to 10V 6 Channel 16 bit PWMs DACs Analog Outputs Output Voltage Range O to 5V Configurable Frequencies 35hz to 1 5Mhz External Interrupts 4 Channels High Speed Counters 2 Channel 16 bit Counters Required Power 24V DC Current Consumption w ports unloaded 24V w Backlight ON 170mA 24V w Backlight OFF 70mA 12V w Backlight ON 340mA 12V w Backlight OFF 130mA _RTC Real Time Clock _ RTC Real Time Clock y 1 User Configurable Timer Configurable Interval Units 10ms Yes a 1 Farad rechargeable Super REC Back up Capacitor is included DataMemoryBack up Noo Operating Temperature 0 C to 70 C Package Integrated Touch screen Panel w 2mm 9 Headers and 2 5mm RCABLE Headers 440 Hardware Requirements The Cubloc Studio software used to develop programs for the Cutouch will run on a computer with Windows 7 Vi
54. P46 P62 P45 P61 P27 PWM3 P44 P60 P28 PWM4 INTO TX1 P43 P59 P29 PWMS5 INT 1 RX1 P42 P30 INT2 SDA P41 P31 INT3 SCL P40 POW www wwNWNWYWNNNNNNNNN SOBUVAHRONASGHIDARON gt 203 Out Out port value port I O port number 0 to 255 value Value to output to the specified I O port 1 or 0 This command outputs a 1 logic high or a O logic low to the specified Port When you execute this command the Cubloc will automatically set the port s I O mode to output If using the out command it is not necessary to use the Output command to set the port beforehand OUE El a Output a logic high signal on port 8 This is same as using command High 8 Ome 8 0 Output a Iogic low signal on port 8 This is same as using Low 8 204 Output Output port port I O port number 0 to 255 Set the port s I O mode to output All Cubloc module s I O ports are set to High Z input by default at power on Output 8 Set port 8 s I O mode to output You can also use the High or Low commands to set a port s I O mode to output When using the Output command the port s output logic high or logic low is not clearly defined Therefore it recommended to use the High or Low commands to set a port s I O mode so the port s output is properly initialized Low 8 Set port 8 s I O mode to output and output a logic low 205 OutStat variable OutState port variable Variable to store results No String or Single por
55. Reverse Step STEPSET is used for Normal Step STEPSET PO STEPSET S0 1 c 1 PI STEPSET S0 2 c 1 P2 STEPSET S0 0 STEPSET turns ON the current step but only if the previous step is ON STEPSET is processed one step at a time in sequence according to the step number For example in the ladder above when P1 turns ON SO 2 is turned ON but only if SO 1 is ON After SO 2 turns ON SO 1 is turns OFF When P2 turns ON S0 0 is turned ON and all other steps are turned OFF S0 0 or step 0 is used to reset All other steps are processed in order 396 STEPOUT STEPOUT differs from STEPSET in two ways First it is not evaluated in sequence and second when a step is turned ON it remains in that state regardless of its input condition When using STEP OUT and a step is turned ON all other steps are turned OFF so only one step is ON at any given time PO STEPOUT S0 1 1 Pl STEPOUT S0 2 c 1 P2 STEPOUT 50 0 H tH2 r 1 In the ladder above when P1 turns ON S0 2 will turn ON When PO turns on S0 1 turns ON and S0 2 turns OFF and S0 1 turns ON When PO turns OFF S0 1 is unchanged as each step when turned ON remains ON regardless of its input condition Finally when P2 turns ON S0 0 turns ON and S0 1 turns OFF po M a En gt pe FA 0 0 S0 1 0 2 397 TMON TAMON TMON arg timeout TAMON arg timeout Cubloc Studio 3 3 1 and later Impl
56. S SSE a A O a 293 FADING A O 479 HADIN2 Tic A A A AAA 480 A A O NO 177 A A a a 177 ESA Wisin AI EA cido 177 O A chase E E E E E E EE T EEA A ulet ethamebactes 121 Oia ATEA E T TT 179 FAP apee a ii 125 PAS ia A A AA A AAA AA 296 FIP OPs ieee Seta ras Pandillas cares ccncers E TAT 296 UR US Ser a Sa 296 HIRGAG A A E 176 Wen A A Aaa eke 176 T2G REA Astr a e aean taaa Aa Ardin a AEA aa a oa A an DA GN 181 T2CReadN Acida A A 182 A A i E aeae ua aaa aaa E pean ts hah tean neh a i ea alaa a ia a aAA 180 T2ACSCOP iiia E E a y whee nde aed A E E 180 TZ Write as 2 aa ea aa Ne Aana a a da 183 Tf Then Elseif c ElSe End fics is ieh en aeta na ee eae ee a 184 MS A A nia 185 INC iii da DARA AAA 186 INP nO A A Aa 187 INTON EEEE eet ee eta E ah oo ae ees 432 KCMD elector A ds 405 KOU sites ad A A a A E IA casos 405 KIA a on 188 A A O ON 189 Ki A a a catisiaeat pe 190 Label ia bi tada 174 LABEL A A a DE 430 Ciria Ae dt daaustecPadeduies ricos i aa a 276 Mco A dere A A AT 127 Na TE ii aaa 128 Oi A r a th sti aie 278 LIM EE EE steak eu nna a vacates 281 LINCS le ieee tehid ia 288 LIN GTO iia A ini Pia faba UEAN coke cauieaa tbe A 281 OA hs Gc twetegs Beh A bate tone fakes cacveteefaed tas 388 LOAD Nica a A ee Sosa eee eee ea 388 LOCA iee Yad daueavea ders ia Preswatede does se heii ices aatesh na aa SEEN ads A ENDE ies 273 LOOP A dank ales elas As thee etek 393 A te Maksn ndash onc eact hentaaed ad aoe ichait E can doe aeh as Ohaus t
57. SDA and SCL to start mode After this command SDA and SCL go low N SCL AN START 12CStop 12CStop Set I2C SDA and SCL to stop mode After this command SDA and SCL go high 180 I2CRead variable 12CRead dummy variable Variable to store results No String or Single dummy Dummy value Read a byte from the I2C ports set by SET 12C command Use any value for the dummy value A I2CRead 0 SCL SDA This command will send an ACK signal back to the slave 12C device After reading a byte an SCL pulse will be sent while SDA is kept low 181 12CReadNA Variable 12CReadNA dummy variable Variable to store results No String or Single dummy Dummy value Normally 0 Functions the same as the 12CRead command but without acknowledgment A I2CReadNA 0 SCL SDA 182 12CWrite variable 12CWrite data variable Acknowledge 0O Acknowledgment 1 No Acknowledgment data data to send Byte value 0 to 255 Sends one byte of data through I2C This command creates an ACK pulse and returns O if there is an acknowledgment and 1 if there isn t No acknowledgment indicates that there was a communication error possibly due to incorrect wiring The following is an example illustrating how this can be used to trigger an error processing function If I2CWrite DATA 1 Then GoTo ERR PROC If you don t need to check for an ACK you can just use any variable to rece
58. Segment or LCD and process users input is a difficult task for standard Ladder Logic But these things are rarely a problem for programming languages such as BASIC BASIC is able to process floating point numbers data communications and other things beyond the scope of what Ladder Logic can do alone Another advantage is that its syntax is very similar to the English language IF GOTO etc allowing both beginners and experienced developers to learn in matter of hours instead of months BASIC is a very common programming language and many developers may be able to start programming a Cubloc with only a few glances at hardware specific commands Ladder Logic Programming Languages BASIC C ASM Device PLC PC or Micro Computer Application Automation Machine General Computing Control Advantages Sequencer Bit Logic Complex Math Timers Counters Data Communication Data Collection amp Process Analysis Graphic Interface Basic Parallel Sequential Mechanism Ladder Logic s parallelism and BASIC s sequential language both have advantages Ladder Logic makes controlling unrelated parallel tasks easy which can be difficult with BASIC On the other hand BASIC can easily process complex sequential tasks and has a wider range of commands and interface abilities That is why we created Cubloc where the user is free to use both Ladder Logic and or BASIC based on the application being created After under
59. and other wiring requirements This is usually fine for one or two applications but doesn t lend itself easily to larger scale production Cubloc modules can be easily integrated into a custom product providing all the features of a PLC yet the professional appearance and lower manufacturing cost of a custom design CUBLOC CORE MODULE 30 Cubloc is an On Chip PLC allowing an easy fit on a PCB You may use the PLC almost like an MCU You can design a customized PCB for your desired product reducing its cost and size and most importantly making your product one of a kind The following table shows a few differences between a traditional PLC and On Chip PLC Micro computer Cubloc Traditional PLC Din Rail Attachment a Labor Costs High Low Productian MICA Final Size Compact If you are currently distributing a system using a traditional PLC please review our products and consider the reduction in cost if you were to use Cubloc instead We believe that you will end up with a more superior product at a fraction of the cost 31 Development Environment Cubloc Studio can be installed on a Windows 7 Vista XP 2000 or 98 operating system equipped computer If you would like to use it in a Linux Unix Macintosh environment you will need to install a virtual machine such as VMware that allows your computer to run the Windows operating system An RS 232 port is also required or you may use a USB t
60. be controlled by going to Setup gt Ladder Logic Environment Options and adjusting the Monitoring Speed slider If the monitoring speed is too fast it can negatively affect Cubloc s communications as monitoring consumes Cubloc s resources We recommend a monitoring speed of 5 CUBLOC studio c Weubloc_testWu3 1018 cul J File Edit Device Run Setup Help Bodo se A gt att Bie FI BASIC F2 LADDER Ladder Mnemonic E EE tear a i o 4HO a O Monitoring Stop M300 TO M301 A H pul TON 70 50 c wgl M3 M301 Hat M301 a JOG HI SPEED PULS M3 F2 2 SPEED LOW END TIME TON T1 20 HH 4414 c moog J zi X11 Y 97 Modified Program 9602 Bytes Data 101 NOTE Please be sure to stop monitoring before editing or downloading 370 Time Chart Monitoring C lic k He re Bon g ABE gt wit e With Time Chart Monitoring Ladder Logic contacts can be analyzed in a time chart The minimum width of the time chart is 40ms The Zoom control can be used to measure the width of each pulse after stopping Up to 8 Registers can be monitored at one time Device Select Com Port Select Start Stop Sampling Time _ Cursor Move ramen fa control icon Zoom control 7 Relay select Use Unuse Time interval display X position To use the Time Chart Monitor you must turn Debug off in BASIC To do this simply add th
61. be from 0 and 39 296 GHB3224C DIP Switch Settings On the back of the GHB3224B there are DIP switches to set the RS232 baud rate and I2C slave address GHB3224 DIP Switch number 4 is not used DIP Switch RS232 Baud Rate 12C Slave Address Only one communication method either CUNET or RS232 can be used at a time 297 Seven Segment Display CSG A seven segment display can be used to display numbers Eight LEDs are used for most seven segment displays as shown below allowing decimal points to be displayed as well Using a seven segment display requires specialized circuits to control and refresh the segment matrix This increases in complexity with each digit added In the interest of convenience and simplicity we have developed an easy to use seven segment display called the CSG module Mn ml cl J 71 EJ tC As you can see above the front has a 4 digit seven segment display and the back has two I2C connections After connecting the CSG to a Cubloc you can use the commands in the following table to easily and quickly display the numbers you want gto e5v scx Son CSG 4S COMFILE Digit Data 8 CSGXPut SlaveAdr Control digit places and output CSGXPut 0 0 Digit Data data as binary number 9 298 CSGDec The CSGDec command is used to print decimal values to the display Const Device CB280 Set I2c 9 8 must be used before
62. chart shows several example freqValues and their corresponding frequencies The highest possible frequency can be achieved by setting freqvalue to 1 and the lowest possible can be achieved by setting freqValue to 65535 A freqValue of O does not produce any output FreqValue Frequenc FreqValue Frequenc 5 384 KHZ 100 22 83 KHz 65535 35 16 Hz You can calculate freqValue using the following formula freqValue 2 304 000 Desired Frequency Before using this command please set the specified PWM port to output mode and set to a logic high or logic low state To stop the output use the PWMOff command The following is an example Const Device CB280 Dim i As Integer Low 5 SS Port 5 to low and output i l Ereq0ut 0 10 Produce a 209 3Khz wave Do Infinite loop Loop 164 Since FreqOut uses the same resources as the PWM there are some restrictions to consider PWM channels 0 1 and 2 use the same timer If PWM channel 0 is used for a FreqOut command PWM channels 0 1 and 2 cannot be used for a PWM command Likewise PWM Channels 3 4 and 5 are linked If Freqout is used on PWM channel 3 PWM Channels 3 4 and 5 cannot be used for a PWM command You can produce different frequencies on PWM channels O and 3 To summarize two different frequencies can be produced at one time and when using the Freqout command a PWM command cannot be used on the same channel The following is a chart that correlates f
63. colon to mark the start of a start of a frame and ends the frame with a Carriage Return CR or a Line Feed LF START SLAVE FUNCTION DATA ADR COLON 2 Bytes 2 Bytes n Bytes 2 Bytes CR LF RTU requires no special characters to mark the start and end of a frame It uses 4 bytes of silence a delay to indicate the start and finish START SLAVE FUNCTION DATA ADR T1 72 13 74 1 Byte 1 Byte N Bytes 2 Byte T1 T2 T3 T4 Cubloc support NOTE Starting with Cubloc Studio v3 3 1 the CB400 CB405 and CB405RT no longer support Modbus ASCII However Modbus RTU is still supported so please use Modbus RTU instead Cubloc supports Modbus functions 1 2 3 4 5 6 15 and 16 Function Code 01 02 Bit Read 03 04 Word Write 0 06 1WordWrite In Modbus there are addresses that correspond to Cubloc registers Cubloc s registers P M F C T and D can be accessed using the addresses in the following table Bit Units Word Units Address egister 2000H 3000H Po OOOH TT po OOOH je pl poo fro p___ o OHHH wR 323 gt 9000 A oo 324 Function Code 01 Read Coil Status Function Code 02 Read Input Status These functions are used to read the bit status of a PLC s Register The following is an example that reads registers P20 through P56 from slave address of 3 Quer Field RTU Bytes ASCIT Bytes Header colon 1 Slave Address 0X03 1 03 2 Function Code 0x01 1 01 2 Start Address HI 0x0
64. inverse O Normal 1 Inverse underline O Normal 1 Underline This command is used to add bold inverse or underline decorations to your pami BOLD fonts WAX ma INVERSE i AX UNDERLINE CMode CMode value value 0 Box type 1 Underline type This command sets the type of cursor to use The default is the underline type Mi 0 BOX Type 1 Under Line Type 280 Line Line x1 y1 x2 y2 This command draws a line from x1 y1 to x2 lt lt Line 10 20 100 120 Draw a line LineTo LineTo x y This command draws a line from the last point to x y i LineTo 200 50 Continue drawing a line from the last point 281 Box Box x1 y1 x2 y2 This command draws a rectangle with the upper left coordinates of x1 yl and the bottom right coordinates of x2 y2 Box 10720200 100 Draw a box BoxClear BoxClear x1 y1 x2 y2 This command clears a rectangle with upper left coordinates of x1 y1 and bottom right coordinates of x2 y2 Box llear 10 201 200 100 Clear box BoxFill BoxFill x1 y1 x2 y2 logic logicOperator O0 OR 1 AND 2 XOR This command draws a rectangle with upper left coordinates of x1 y1 and bottom right coordinates of x2 y2 and fill by logically combining with other BoxFill areas O OR will display BoxFill areas that overlap and BoxFill areas that don t overlap 1 AND will display only the BoxFi11 areas that overlap 2 XOR will display
65. iorst Shiftout ioclk iodio 0 o e s amp co o co Shiftout ioclk iodio Low iorst o o Delay 1 High iorst Shiftout ioclk iodio 0 amp h80 8 Shiftout ioclk iodio 0 amp H50 8 Low iorst Do High iorst adr amp h81 Shiftout ioclk iodio 0 adr 8 I Shiftin ioclk iodio 4 8 Debug Hex I Cr f Low iorst Delay 1000 Loop Line 15 Modified Shortcut Explanation CTRL Z UNDO CTRL O OPEN CTRL S SAVE CTRL C COPY CTRL X CUT CTRL V PASTE CTRL F FIND CTRL HOME Go to the very beginning CTRL END Go to the very end CTRL Y REDO 72 Debugging r Cubloc Studio c program files x86 comfiletools cublocstudio samples ds1302 cul Cc la File Edit Device Run Setup Help DSBS G e anem eo BASIC LADDER Const Device CB280 2 Delay 10 r aia i 3 Debug He11o lt Debug Terminal i x Port gt Baud Rate Parity Data Bits o comz y 115200 y None ls y ps a A l Close E Fix Right Side As shown in the screenshot above the Debug statement can be used to monitor your BASIC program while it s running Be aware that you cannot debug and monitor Ladder Logic simultaneously You must remove all Debug statements or comment them out with an apostrophe before attempting to use Ladder Logic monitoring Another option is to use the command Set Debug Off which will automatically ignore any Debug state
66. ladder scans will be performed Set Ladder On Declaring the Device to Use The type of device being used must be declared in BASIC at the beginning of every program using the Const Device command The following are examples illustrate this for the CB220 and the CB280 Const Device CB220 Use the CB220 or Const Device CB280 Use the CB280 384 Using Ladder Logic Only If only using Ladder Logic a minimal amount of BASIC code is required The BASIC code must contain at a minimum a device declaration the Set Ladder On command and a Do Loop to keep the program executing Port declarations and aliases must also be declared in BASIC The following example illustrates such a program Const Device CB280 Device Declaration UsePin 0 In START Port Declaration UsePin 1 In RESETKEY UsePin 2 In BKEY UsePin 3 0ut MOTOR Alias MO RELAYSTATE Aliases Alias M1 MAINSTATE Set Ladder On Start Ladder Do Loop BASIC program will run in infinite loop 385 Ladder Logic Commands Low Level Commands Symbol Contact A Open by default LOADN Contact B Closed by default HENE STEPSET NOT Invert the result Step Controller Output Step Set STEPOUT Step Controller Output Step Out E Master Control Start MCSCLR Master Control Stop DIFU Set ON for 1 scan time when a logic high signal is received DIFD Set ON for 1 scan time when logic low signal is received SETOUT Set and Hold Output ON RSTOUT Set and Hold
67. often ePlease check www comfiletech com to download the latest version of Cubloc Studio ePlease run Setup gt Firmware Download after installing a new version of Cubloc Studio as the newest firmware is distributed with Cubloc Studio ePlease check www comfiletech com for latest User s Manual Please be sure to insert the Cubloc module correctly as inserting it improperly can damage the module Please be aware that our 1 Year Warranty only covers defective items Changes in v3 4 1 After compiling and downloading a program to the Cubloc source code navigation dropdown lists will appear This drop down lists provide the ability to navigate to any function subroutine or label in a source file at an instance This is particularly useful for long source files with many lines of code lt Cubloc Studio d WtestWmasterWmasterWdomomaster_yv4r9s1 cul J File Edit Device Run Setup Help DBE Sartre Q OA m a BASIC LADDER Function Sub Label Finestrone PORTONE sUsepin 21 In REED1_PORTONE Usepin 22 In SENS_Fumo Usepin 11 In SENS_Metano Usepin 12 In Tamper_Ext 1 Blocco COM 0 GND i Usepin 13 In Riserva Usepin 14 In Riserva Usepin 5 In Riserva Usepin 6 In Riserva s Usepin 7 In Riserva Usepin 10 In Riserva Output a tax Blocco COM 9 Vec Usepin 63 Out NO_Sirena_Ext i Usepin 62 Out Sirena_Int 12 Usepin 61 Out Buzzer_Imp Usepin 60 Out Buzzer_Cont 4 6
68. only the BoxFill areas that don t overlap BoxFill 10 20 200 100 0 Draw and fill 282 box Circle Circle x y r This command draws a circle with center coordinates of x y and radius r Circle 200 100 50 Draw circle CircleFill CircleFill x y r Draw and fill a circle with x y as the center and with r as the radius Cirelerill 200 100 50 Draw and fill circle 283 Ellipse Ellipse x y r1 r2 This command draws an ellipse with center x y horizontal radius r1 and vertical radius r2 Ellipse 200 100 100 50 Draw ellipse EIFill EIFill x y r1 r2 This command draws and fills an ellipse with center x y horizontal radius r1 and vertical radius r2 BIFill 2001100 0 0 510 Draw and fill ellipse 284 GLocate GLocate x y This command specifies the graphical text position on the current graphic layer GLocate 128 32 locate new position GPrint CUTOUCHS GPrint GPrint string This command prints a string on the graphic layer You have more freedom printing text in the graphic layer as you can use GLocate to specify the exact position Then you can use the GPrint command to print a string at the specified location GPrint CUBLOC IS FASTER CR Print String and go to next line CR CUTOUCH CUBLOC IS FASTER 285 DPrint DPrint string DPrint is similar to GPrint except it over writes the current graphics DPRint WE LOVE CUBLOC
69. point By using Debug commands you will be able to detect the location of bugs in your program and monitor variables changes in real time You can send data to the download port of Cubloc by entering text in the upper text box of the debug terminal This is useful for interactive communication with the Cubloc Warning The Debug command may not be used while monitoring in Ladder Logic Likewise Ladder Logic monitoring can not be used while debugging using Debug statements The following is a chart of commands that can be used with the Debug command You can control the debug terminal s output like an output screen or LCD cLR O Clear Debug screen Debug CLR HOME Move cursor to the upper left corner of Debug HOME the Debug screen csLE 3 Move cursor one to the left csRI__ 4 Moveccursoronetotheright Y pesup__ 5 Movecursoroneuyp____________ ___________ cson_ 6 Movecursoronedown__________ _ Make beeping sound PT BKSP_ 8 BACK SPACE Debug ABC LF ee a ci cursor to the end of line E e a cursor 13 10 Carriage Return go to next line Debug ABC CR You must use above commands within a Debug statement Debug Goxy 5 5 Dec I Debug Clr TEST PROGRAM 152 Decr Decr variable variable Variable to decrement No String or Single Decrements variable by 1 Decr A Decrement A by 1 153 Delay Delay time time Time interval variable or constant up to L
70. read multiple bytes from the EEPROM If we don t send a STOP command we can keep reading from the EEPROM since it automatically increments its address In this way we can set the starting address only once and then read the rest of the data much faster Set IZC 3 9 2CStart f I2CWrite amp b10100000 1 Then ERR PROC Chip address A0 E I2CWrite adr Bytel 1 Then ERR PROC Write address to read from f I2CWrite adr LowByte 1 Then ERR PROE 2C5tart Repeat start f I2CWrite amp b10100001 1 Then ERR_PROC Read command For i 0 To 10 adata i I2CRead 0 Read 10 bytes continuously adata is an array Next 2CSEOP 316 12C example The following example shows a CB280 and 24LC32 EEPROM connected A value will be written to a specified address of the EEPROM and then read back to display on the DEBUG window of Cubloc Studio Const Device cb280 Dim adr As Integer Dim data As Byte Dim a As Byte data hal adr amp h3 pet 120 372 Do Write 1 Byte 2CStart f I2CWrite b10100000 1 Then Goto err proc a I2CWrite adr bytel a I2CWrite adr lowbyte a I2CWrite data ZESTOD Delay 1000 Read 1 Byte 2CStart a I2CWrite b10100000 a I2CWrite adr Bytel a 12CWrite adr LowByte ZES tant a I2Cwrite b10100001 a 12CRead 0 2CStOP Print Results 24LC32 68280 Debug Hex a cr Delay 500 AO an an Loop A1 7 A2 SDA P3 err _joieteres zr Debug Error I Do Loop 317 More
71. resources but their duty cycles can be different PWM channels 3 4 and 5 also must use the same value for period but again their duty cycles can be different 214 PwmOff PwmOff channel channel PWM channel 0 to 15 Stops the PWM output on the specified PWM channel The following illustrates the PWM channels available on each module sourgi Y 24h vin SIN 2 231 vss ATN 3 221 RES vss 4 211 voo Po gs 201 P15 Pi ge 191 P14 P2 o7 18h P13 Pa ga 17 P12 Pa g9 16H P11 PWMO P5 010 15F P10 PWM1 lt megn 141 P9 PWM2 lt p7 Q 12 13b Ps For CB220 3 PWM channels are provided on ports P5 P6 and P7 TTLTXA TTLRXA 1 AVREF 2 pas Pat P30 P29 P28 P32 P33 P34 P18 p19 gt PWM3 P20 gt PWM4 P21 gt PWM5 p12 P40 48 64 P39 Please refer to the table below for PWM channels and their corresponding I O ports CB220 CB280 CB290 CT17X0 CB400 CB405 PWMO 1 0 5 PWM1 1 0 6 PWM2 1 0 7 PWM3 1 0 27 PWM4 1 0 28 PWM5 1 0 29 PWM6 y oe I O 12 I O 13 A SS gt gt gt gt gt gt gt pros gt gt gt gt ee ee PWM8 PWM9 PWM10 PWM11 I O 52 I O 53 po po po Pwm7 po po po 215 RamClear RamClear Clear Cubloc BASIC s RAM BASIC s data memory can hold garbage values at power on RamClear can be used to initialize all data memory to zero There are Cubloc modu
72. show 3 00000 instead of 3 14 The reason is that the EEWrite statement automatically converts floating point values to whole numbers In order to store floating point values we can use Peek and Poke to read the data directly Const Device CB280 Dim F1 As Single F2 As Single F1 3 14 EEWrite 10 Peek MemAdr F1 4 4 Poke MemAdr F2 EERead 10 4 4 Debug Float F2 CR The debug window will now show 3 14 We use MemAdr F1 to find the memory address of Fi and then use the Peek statement to directly access the memory and write 4 bytes We store that value in the EEPROM Next we use MemAdr F2 and Poke to read 4 bytes directly Warning Please use caution when using these command as incorrectly manipulating memory can affect the entire program Peek and Poke may only access data memory 115 Sharing Data The Cubloc has separate BASIC and Ladder Logic data memory areas BASIC DATA MEMORY LADDER DATA MEMORY Variable Variable ML Variable Variable cL Ladder Logic data memory can be accessed from BASIC easily by using system variables Using these system variables data can be easily read from or written to Ladder Logic data memory Gr Access units Ter toate Resistor JP Bits P 0 to P 127 P Register t _D_ Words _D 0 to _D 99 D Register Data Registers P and M can be accessed in units of bits and registers C T and D can be accessed in units of words To access P and M registers in units of
73. subroutine s starting point and RET marks the subroutine end See ee Se ee ee ee i o o o Main Program oo I i START CALLS CHK ATN I i Hi 1 I I RET i e A E TE l 1 there are sub routines SBAT CHK ATN gt gt gt st tof sub ro tine l t i 4 BKEY TON TO 100 IHI 1 i A A I RET End ofsub routine r HL 1 l ee ee eR ee ee ee ee ee ee ee ee ee ee d END e 1 End ofladder Please be aware that when adding sub routines to your program RET must be appended to the end of main program before the first subroutine END must be placed at the very end of the main program after the last subroutine 431 INTON INTON s d INTON is the same as the WMOV command except it triggers an interrupt in BASIC Usually Constants egisters s Source _ aen oo E eo E PO INTON 3 D0 J PI INTON 2 00 F 432 TND TND is a conditional exit command TND is typically used to abort a ladder scan F29 P2 1 HI 0 PO TND 2 HH 1 F30 P4 3 HI CJ END 4 l In the ladder above when PO turns ON the ladder scan will be aborted SBAT CHK RTN l PO M2 PI TND H 1 P2 M3 RET e l It can also be used to exit from subroutines when a certain condition is met In the ladder above when P1 turns ON the subroutine will be aborted but the ladder scan will continue 433 Special Registers Cubloc contains a set of special registers that ca
74. the CSGDec command Dim b As Integer b 8 Do CSGDec 0 b CSGDec command Delay 100 b bot 1 If b 0 Then b 200 Loop To use CSG commands the Set 12c command must be used beforehand Slave Address The I2C slave address can be set using the DIP switches on the back of the CSG module A total of 4 addresses can be set per I2C line pair CSG DIP Switch Address 123 ON A E 123 oN EE E 123 ON E 123 ON E nn 299 To display more than 4 digits use 2 CSG modules as shown below and set different slave addresses for each hn ml ood m od 1 01 01 01 107 Z 1 EL CSGNPut CSGNPut slaveAddress digit data slaveAddress CSG module 12C slave address digit Digit position O to 3 data Data amp H30 to amp H39 amp H41 to amp H46 This command displays the desired digit on the specified CSG module The most significant bit of the data parameter controls the decimal point You can use amp H30 through 39 and amp H41 through amp H46 only amp H30 displays 0 amp H31 displays 1 amp H39 displays 9 amp H41 displays A amp H42 displays b amp H46 displays F 300 CSGXPut CSGXPut slaveAddress digit data slaveAddress CSG module 12C slave address digit Digit 0 through 3 data Bit array with each position corresponding to an LED segment This command turns on the LED at the specified position When displaying anything other tha
75. to 255 The Cubloc has a dedicated port for keypad touchpad inputs similar to a PC s keyboard or mouse port This port can be used with the Set Pad command to create interrupts when input is received on a keypad touchpad etc This port is as an SPI slave To use pad communication you must use a Set Pad command at the beginning of your program Pad communication uses 4 wires SCK is used as the clock signal SS as the slave select MOSI as the master out slave in and MISO as master in slave out MISO MISO avd HONOL v o A v oO A TOUCH PAD CONTROLLER SOBRES I O ports PO through P3 can be used for pad communication 235 TTLTX1 TTLRX1 AVREF P48 P31 P30 P29 P28 P32 P33 P34 P35 P36 The packetSize parameter sets the packet size need to cause an interrupt For example the Cutouch panel requires 4 bytes to be received before an interrupt is generated The bufferSize parameter is the total size of the receive buffer The buffer size must be at least 1 more than the packet size A larger buffer will essentially give you more time to process the interrupt service routine The buffer size is usually set to 5 or 10 times the packet size The mode parameter will set the receiving mode of the received data Please refer to the following table Mode Value Bit Pattern Diagram LSB First amp H20 0010 xxxx Po EEE First atte 0000 xxxx O A Low Edge XXXX a Triggered SCK H
76. turned on off Quer Field RTU Bytes ASCII Bytes Header colon 1 Slave Address 0X03 1 03 2 Function Code OXOF 1 OF 2 Start Address HI 0x00 1 00 2 Start Address LO 0x14 1 14 2 Length HI 0X00 1 00 2 Length LO 0X0B 1 OB 2 Byte Count 0X02 1 02 2 Data 1 OxD1 1 D1 2 Data 2 0X05 1 05 2 Error Check CRC 2 LRC 2 Ending Code CR LF 2 The following table shows how Data in the above query is divided P20 corresponds to the least significant bit of the first byte sent and P27 corresponds to the most significant bit There will be a total of 2 bytes sent in this manner Unused bits can be set to zero A Poa leu eee Ul to h 1 Response Field RTU Bytes ASCII Bytes Header colon 1 Slave Address 0X03 1 03 2 Function Code OXOF 1 OF 2 Start Address HI 0X00 1 00 2 Start Address LO 0X14 1 14 2 Length HI 0X00 1 00 2 Length LO OX0B 1 OB 2 Error Check CRC 2 LRC 2 Ending Code CR LF 2 330 Function Code 16 Preset Multiple Registers PLC s can remotely control the status of registers in units of multiple words through this function code The following is an example showing slave address 3 s DO through D2 being written Quer Field RTU Bytes ASCII Bytes Header colon 1 Slave Address 0X03 1 03 2 Function Code 0X10 1 10 2 Start Address HI 0X70 1 70 2 Start Address LO 0X00 1 00 2 Length HI 0X00 1 00 2 Length LO 0X03 1 03 2 Byte Count 0X06 1 06 2 Data 1 HI OxD1 1 D1 2 Data 1 LO 0X03 1 03 2 Data 2 HI OXO0A 1 OA 2 Data 2 LO 0x
77. with Firmware download View Relay Usage View Watch window Check Syntax Setup Menu PLC Setup Wizard PC interface setup Editor environment setup Open BASIC Debug Terminal Window This window opens automatically when there s a Debug statement in the source code Clear Cubloc s Flash Memory This will turn off the download function for a Cubloc Core module to protect against noisy environments where the flash memory can be affected Once you choose this menu you will be unable to download new programs to your Cubloc module You will be able to download again after a Firmware Download View relays in use by Ladder Logic after compilation See at a glance the status of relays in a separate window See at a glance the status of relays in a separate window Check the source code s syntax Ladder Logic Environment Options Use English menu Firmware download Menu PLC Setup Wizard PC Interface Setup Editor Environment Setup Ladder Logic Environment Options Use English menu Firmware Download 76 Explanation Wizard to automatically generate BASIC code Setup the RS232 COM PORT for Download Monitor Select COM1 through COM4 Configuration options for the BASIC editor Configuration options for Ladder Logic Change the language of the menus to English Download Firmware to Cubloc Please use this to download firmware to Cubloc manually MEMO 77 Chapter 4 Cubloc BASIC Language
78. 0 Delay 200 Loop I Fix Right Side 221 If the program is being reset the Reset line will be printed more than once 2 How to check if a particular point of the program is being executed Simply insert a Debug command at the point in question as shown below A de Terminal Const Device CB280 Baud Rate Parity Data Bis gry 6 u els En y 115200 None fs y arx High 0 Delay 200 Low 0 Delay 200 Loop eee a T Fix Right Side The debug statement above will never execute as the program will execute the Do Loop indefinitely 222 3 How to simulate an LCD You can simulate an LCD using the Debug terminal Simply use Goxy XX yy to access a particular location on the terminal as shown below CUBLOC studio d cubloc_test debuscreen cul Ele Edt Device Run Setup Help a adi XATA at Ria FI BASIC F2 LADDER Ladder Mnemonic Dim A As Integer Debug CLR Debug Goxy 1 1 Debug POWER METER SYSTEM MONITOR SCREEN Debug Goxy 2 3 Debug Input status Debug Goxy 2 5 Debug Output Status Debug Goxy 2 7 Debug AC current Debug Goxy 2 9 Debug DC current Debug Goxy 16 3 Debug Debug Debug Debug G Debug 1 7A Debug Debug Debug Debug Do Debug Goxy 30 5 Debug Counter Dec5 A Incr A Loop bsos Tecna Ed Use the command Baud Rate Data Bits ait Debug Clr to clear z z 115200 y m Ae z the debug w
79. 0 1 00 2 Start Address LO 0x14 1 14 2 Length HI 0X00 1 00 2 Length LO 0X25 1 25 2 Error Check CRC 2 LRC 2 Ending Code CR LF 2 For Modbus ASCII the LRC is the 2 s complement of the 8 bit sum of all packet values except the colon CR and LF For the table above 0x03 0x01 0x13 0x25 0x3C To find the 2 s complement of 0x3C we can write it in binary first 0011 1100 Then invert the bits 1100 0011 Then add one 1100 0011 0000 0001 1100 0100 0xC4 The LRC is therefore 0xC4 The table below illustrates this frame in Modbus ASCII 325 The response frame to the query above would be Response Field RTU Byte ASCII Byte s s Header i 1 colon Slave 0x0 1 03 2 Address 3 Function 0x0 1 0i 2 Code 1 Byte Count 0x0 1 05 2 5 Data 1 0X5 1 53 2 3 Data 2 0X6 1 6B 2 B Data 3 0x0 1 01 2 1 Data 4 OXF4 1 F4 2 Data 5 0X1 1 1B 2 B Error Check CRC 2 LRC 2 Ending Code CR LF 2 If you look at the response to the query you can see that bits 20 through 27 make up one byte Data 1 s least significant bit corresponds to P20 and Data 1 s most significant bit corresponds to P27 Likewise Data 2 corresponds to P28 through P35 Data 3 to P36 through P43 Data 4 to P44 through 51 and Data 5 to P52 through P59 We don t need P57 through P59 so the most significant 3 bits of Data 5 can be disregarded 326 Function Code 03 Read Holding Registers Function Code 04 Read Input Registers These functions can read
80. 09 iois po 522883 4 90617073 toos Fs w9s49 7 4 901087406 io04 Eo 44540 6 s 8go207868 1002 344 pa woo91 5 878320427 99 995 992 989 987 985 983 981 979 977 o 975 1 973 2 970 3 968 4 965 5 963 6 7 957 8 954 9 951 o 948 1 945 2 942 3 938 4 935 5 931 6 927 7 923 8 87783 4 488663246___ 919 9 915 o 911 1 907 2 902 3 898 4 893 5 888 6 883 7 878 345 s2 risio9 27084025 555 3 fiiwsas 668747011 547 4 iioo 0 2 629210536 538 5 ovas 2589812422 530 1041 3 2 550571543 522 1009 2 2 511506263 514 978 3 2 472634416 506 pa8 5 2 433973277 498 919 8 _ 2 395539544 491 gozo 2 357349316 483 865 3 2 319418079 475 839 4 2 281760687 467 814 5 2 244301354 460 790 4 2 207323646 452 767 1 2 170570465 445 794 7 2134144055 437 723 0 2 098055989 430 702 0 2 062317177 422 100 lesisg_ 2 026937858 415 101 662 2 1 99192761 08 102 643 3 1 957295352__ 401 103 625 0 1 92304935_ 394 104 607 3 1 889197225 387 105_ 590 2 1855745964 380 106 573 7 1822701928 373 107 557 7 1790070865 367 108 5422 1757857926 360 109 527 2 1726067674 353 39 x 33 40 33 41 x 32 42 i 32 43 s15 0152586936 31 44 fio o 150270604 31 245 30 246 30 247 29 248 29 250 28 2 0 137234968 28 y NTC THERMISTOR READ TABLE 10K DIODE TYPE Const Device cb280 Const Iitegsr IH TABLE M992 920198097 Sis ISI Psp ek
81. 1 word 16 bits and is usually used for counters timers and data registers The following shows an example that reads slave address 3 s registers DO through D2 Quer Field RTU Bytes ASCIT Bytes Header colon 1 Slave Address 0X03 1 03 2 Function Code 0X03 1 03 2 Start Address HI 0X70 1 70 2 Start Address LO 0X00 1 00 2 Length HI 0X00 1 00 2 Length LO 0X03 1 03 2 Error Check CRC 2 LRC 2 Ending Code CR LF 2 The query above asked for a length of 3 And since 1 word is 2 bytes we will get 6 bytes total in the response Response Field RTU Bytes ASCIT Bytes Header colon 1 Slave Address 0X03 1 03 2 Function Code 0X03 1 03 2 Byte Count 0X06 1 06 2 Data 1 LO 0X03 1 03 2 Data 1 HI OXE8 1 E8 2 Data 2 LO 0X01 1 01 2 Data 2 HI OXF4 1 F4 2 Data 3 LO 0X05 1 05 2 Data 3 HI 0X33 1 33 2 Length LO 0X03 1 03 2 Error Check CRC 2 LRC 2 Ending Code CR LF 2 327 Function Code 05 Force Single Coil This function can be used to remotely set a register s value in units of bits To turn on a bit register OXFFOO must be set To turn off a bit register 0x0000 must be sent Any other values will be ignored The following is an example showing slave address 3 s P1 register being turned on Quer Field RTU Bytes ASCII Bytes Header colon 1 Slave Address 0X03 1 03 2 Function Code 0X05 1 05 2 Start Address HI 0x01 1 01 2 Start Address LO 0X00 1 00 2 Length HI OXFF 1 FF 2 Length LO 0X00 1 00 2 Error Check CRC 2 LRC 2 Ending Code C
82. 12 1 12 2 Data 3 HI 0x04 1 04 2 Data 3 LO 0X05 1 05 2 Error Check CRC 2 LRC 2 Ending Code CR LF 2 Response Field RTU Bytes ASCII Bytes Header colon 1 Slave Address 0X03 1 03 2 Function Code 0X10 1 10 2 Start Address HI 0X70 1 70 2 Start Address LO 0X00 1 00 2 Length HI 0X00 1 00 2 Length LO 0X03 1 03 2 Error Check CRC 2 LRC 2 Ending Code CR LF 2 331 Error Check If there is an error in the data from the master the slave will send back an error code Field Hex ASCIT Bytes Header colon 1 Slave Address 0X03 03 2 Function Code 0X81 81 2 Error Code 0X09 09 2 Error Check LRC 2 Ending Code CR LF 2 The list of possible error codes is as follows Explanation 0i ILLEGAL FUNCTION When a non supported function code received ILLEGAL DATA ADDRESS When an incorrect address is received ILLEGAL DATA VALUE When bad data is received 09 LRC UNMATCH When LRC is incorrect The error check is only for MODBUS ASCII there is no error check in RTU Modbus RTU uses a CRC to check for errors in transmission 332 Using Modbus with HMI SCADA Addresses The following describes the address mechanism to be used from HMI SCADA software Data Type 999 nput Status 0001 19999 nput Register 0001 39999 olding Register 0001 49999 To determine the appropriate address to use from HMI SCADA software refer to the following table Word Region Holding Input Registers Relevant Function Codes 3
83. 128 LTrim stringValue Removes all blank spaces from the left side of the given String Dim STI AS String 12 STI COMFILE ST1 Ltrim St1 Debug AAA ST1 AAACOMFILE is printed RTrim stringValue Removes all blank spaces from the right side of the given String Dim SHEL AS String 12 ST1 COMPILE ST1 RTrim ST1 Debug ST1 TECH COMFILETECH is printed Blank spaces on the right are removed oe Terminal Baud Rate Parity Data Bts g em CUBLOC studio d cubloc_test stringfunc cul ey ris200 none la rx File Edit Device Run Setup Help Bon g tia a gt m m E FI BASIC F2 LADDER Ladder Mnemonic Const Device CB280 Dim stl As String 12 stl CUBLOC A Debug Ltrim stl Core Cr Debug Rtrim stl Core Cr 129 Val stringValue Parses a given String into its equivalent decimal value Dim STI AS String E 12 Dim i As Integer STI MAS i Val ST1 123 is stored in variable I as a number ValSng stringValue Parses a given String into its equivalent floating point value Dim SHEL AS String 12 Dim F As Single SRE TAn F ValSng ST1 3 14 is stored in variable F as a floating point number Debug Terminal Baud Rate Parity Data Bits Port lt 7 CUBLOC studio d cubloc_test stringfunc cul com riszoo none la Eile Edit Device Run Setup Help FERRERO E Fi BASIC F2 LADDER Ladder Mnemonic
84. 136 Bla A DA es 137 Derrida a TARA DA TAE ada tenner cudnt aida 138 BM ii ee 139 BIN2 BCC sis sedvtes sted arica a arataa teste AAAA EA 140 Bitiscieseassacteeis sedia ay cebu A DA Ed Aa 96 BLOWN toitn A E TEAT 141 DOUE vader naa inate aE 291 BOX ccs ece eave E A EET 282 Box Cleats osesea cies ieee toe Uno aes a ae 282 Box ri dida Dates aba ceh a ecards 282 ESAE A AAA AA a AA AAA 97 A A O 142 BUE a e ld 143 CAES A On Ed eos 431 CHECK Bie iia a nada 144 E i EEE aoa casasdesiee sete Hie cae inca eda aceasta 131 A O Ee ele ee tenes 283 Circle Fille a ins 283 CEC DOUC AAEE EE EE AE T O EE TE eae laaeievetaancnes 275 S F EEA PE A 273 CIS arera a a a acid sate ATu 273 EMO it a E 280 lA A A 288 A AT 145 COMA A A a S dez 99 Constant ArTaYSicsiti a occ 100 Costas AD a 99 Contrasta aaa A di oe 278 CU E smencemes 146 EOUMTROS O tismrracaci tard A tdci 148 SEDE EA A A a da 301 ESC dicas 301 CSGAPUG tati iaa TEN 301 AO ain tial es cath ti ea leaning a ta vadeuaeetve coer even A A EEA 273 CSO Marsa A NO AN 273 GT D sere ehoisaska in iid ee ee E ae pied ial yaork eae 403 AT RO 403 DORiii ta e eve vinds ae aa a iadaaa ress 149 Del iii E OET 150 DEE E E EEO E AE EE E ET 122 A E EA E AA ET 153 Dei ias 291 DEFCON na cia bcerehbaree ent lhe civ E E EAT 391 Dedica 154 DIED A A A is 392 DU talon aa ee sitatmcnadetePclncsucadaanmunieet ire sa 392 DO LOOP iii ad a A AT 155 DOUSIZO 2 E a ne chdedea saad eramemnae danke gi sweat oath 288 DP
85. 2 bits BKEY WRCR D1 HA J Usable Constants Registers fo fo Example MSB DB The BEFORE e gt LL Le E Er Shiftto the right gt CARRY F72 MSB LSB AFTER ofsfo sfo s sfoj gt Shiftto the right CARRY F72 least significant bit is moved to the carry flag while the most significant bit is populated with a 0 427 WINV DWINV WINV arg DWINV arg Cubloc Studio 3 3 1 and later Toggles inverts each bit in arg making each 1 a 0 and each O ail WINV operates words 16 bits and DWINV operates on double word 32 bits F3 WMOYW ei F_POR WINY DO Usable Constants E lag Jo fo 428 WNEG DWNEG WNEG arg DWNEG arg Cubloc Studio 3 3 1 and later Toggles the sign of arg WNEG operates words 16 bits and DWNEG operates on double word 32 bits F2 DWMO Y OFDODOH DO J F_init DWNEG DO Usable S C T Constants El isters o Jo jojo 429 GOTO LABEL GOTO label LABEL label The GOTO command causes a jump to label The LABEL command is used to name a position in the program to jump to START GOTO SK_1 l BEKY TON T0 100 1 LABEL SK_1 J In the ladder above when START turns ON the program will jump to label SK_1 In the ladder below when DO equals CO the program will jump to SK_1 ere GOTO SKI l 430 CALLS SBRT RET CALLS label SBRT label The CALLS command calls a subroutine with the specified label SBRT marks the
86. 21 If a 5V regulated power source is already available the user may simply connect it to pin 21 If an application requires more than the 100mA of current a separate power supply should be used Method 1 DC5 5 12V m Method 2 DC5V 45 CB280 CB380 The CB280 and CB380 are packages of 64 pins of which 49 can be used for I O The CB280 and CB380 do not have an 5V regulator internal you must supply a 5V regulated power source ww SOUT vob TXI 33 49 TTLTXI SIN vss RX1 3449 50 TTLRX1 ATN RES AVDD 350 51 AVREF vss N C N C 360 052 P48 SS_PO P16 ADCO_P24 37 53 P31_ADC7 Input_only SCK_P1 P17 ADC1_P25 38 e 54 P30_ADC6 Mosi_P2 P18 ADC2_P26 39 55 P29 ADC5 MISO_P3 P19_PWMS ADC3_P27 40 56 P28_ADC4 P4 P20_PW4_INTO P47 410 057 P32 PWMO_P5 P21_PWM5_INT1 P46 42 58 P33 PWM _P6 P22_INT2 P45 430 59 P34 PWM2_P7 P23_INT3 P44 44 60 P35 CUNET SCL_P8 P15_HCNT1 P43 45 061 P36 CUNET SDA_P9 P14_HCNTO P42 46 62 P37 P10 P13 P41 470 063 P38 P1 P12 P40 48 64 P39 Block Block 0 DOO PWM Channel 0 PWM Channel 1 PWM Channel 2 CuNET SCL CuNET SDA PO Blockt fe PO PO High speed Counter Channel 0 High speed Counter Channel 1 PO PO PO Block 2 PWM Channel 3 PWM Channel 4 INT Channel 0 PWM Channel 5 INT Channel 1 INT Channel 2 P23 28 I O INT Channel 3 P26 P27 P28 56 yo P29 P24 37 1 0 ADCO AD Channel 0 P25 38 1 0 ADC1 AD Chann
87. 3 C 8 17 P12 PIO PwN3 ADC4_P4 9 m 16 P11_TX1 Paowa ina PWMO_ADC5_P5 10 e e 15 P10_RX1 NE PWM1_ADC6_P6 11 ETS 14 P9_SDA CUNET PWM2_ADC7_P7 12 13 P8_SCL CUNET Port Block Explanation Block 0 Block 1 O e A High speed Counter channel 0 High speed Counter channel 1 PWM3 po SvOutput Imput RESET Input LOW signal resets PoP GROUND IN 5 5V to 12V_ Input Power Block 2 43 SIN SOUT ATN are RS 232 communication pins used to interface with a PC for downloading debugging monitoring and serial communication All Cubloc models have SOUT SIN ATN pins and are connected to a DE 9 connector PC serial port as shown below VIN vss RES VDD P15 P14 P13 P12 P11 P10 P9 P8 Other pins are mostly I O ports The user may select which ports pins to use as INPUT or OUTPUT When set to INPUT the pin enters a high impedance state when set to OUTPUT the pin either outputs logic low or logic high The maximum current source sink available from the output ports is 25mA The user is free to choose which I O ports he she will use for which purpose such as ADC PWM etc 44 Supplying power to the CB220 CB320 The CB220 and CB320 have an internal 5V power regulator that accepts a DC input between 5 5V and 12V It will produce a stable 5V at 100mA When using the internal regulator the supply voltage can be applied to pin 24 and 5V will appear on pin
88. 404 KCTU This command is exactly same as the CTU command except this command will be able to remember its count when the module is powered off By comparison the CTU command will lose its count when the module is powered off This command can only be used with modules that support battery backup such as the CB290 CB405 and CuTouch Pl KCTU C0 100 l c P2 l R 100 pulse PO P1 ve Use RESET to set the counter to 0 at the Power off amp on beginning When using this command for the very first time use the RESET signal to initialize the counter Otherwise the counter could start at some random value KCTD This command is exactly same as the CTD command except this command will be able to remember its count when the module is powered off By comparison the CTD command will lose its count when the module is powered off This command can only be used with modules that support battery backup such as the CB290 CB405 and CuTouch 405 Comparison Logic Compare 2 word 16 bit or 2 double word 32 bit values and turn on an output when the conditions are satisfied Command DO T1 MO 1 0 You can mix comparison logic as shown below DO T1 gt CO 99 MO lt D1 100 When either DO T1 or D1 lt 100 and if CO gt 99 MO will turn ON In other words either DO has to equal to value of T1 or D1 has to be less than 100 while CO must be greater than or equal to 99 406 Storing Word
89. 5 MENUTITLE 3 9 4 4 MENUSET 4 2 225 100 250 125 MENUTITLE 4 9 4 5 MENUSET 5 2 260 100 285 125 MENUTITLE 5 9 4 6 MENUSET 6 2 190 135 215 160 MENUTITLE 6 9 4 7 MENUSET 7 2 225 135 250 160 MENUTITLE 7 9 4 8 MENUSET 8 2 260 135 285 160 MENUTITLE 8 9 4 9 MENUSET 9 2 190 170 215 195 MENUTITLE 9 9 4 0 MENUSET 10 2 225 170 285 195 MENUTITLE 10 12 4 ENTER FONT 4 0 To Cipboara Save to File Instead of copying and pasting repetitive menu creations include files can be used Click the Save to File button and save the code as an include inc file Save Your Design To BASIC Code EIES AE sa E APPNOTE 7 c CT005 INC 464 Include files make it easy to change the interface of a program without a lot of cut and paste operations within the main code The following program is exactly same as SAMPLE 4 except an include file is used for the virtual keypad lt Filename CTOO5 CUL gt Const Device Ct1720 Dim TX1 As Integer TY1 As Integer Dim I As Integer COMETAS TADO Set Pad 0 4 5 On Pad GoSub GETTOUCH NUMKE Y Execute the Sub routine in INCLUDE file I 0 Do Loop GETTOUCH TX1 GetPad 2 TY1 GetPad 2 If MenuCheck 0 TX1 TY1 1 Then lt lt 4 PulsOut 18 300 Elseif MenuCheck 1 TX1 TY1 Then lt lt 4 2 PulsOut 18 300 Elseif MenuCheck 2 TX1 TY1 Then lt lt 4 SS PulsOut 18 300 Elseif MenuCheck 3 TX1 TY1 Then lt lt 4 4 PulsOut 18 300 Elseif M
90. ASIC may differ slightly from common mathematical operators Please refer to the table below Subtract J 103 63B E A Al To the power of 102 mod 3 1234 3 3843 A 503 A 2 When numbers of different types are mixed in an expression the final result is cast to the type of the assigned variable Dim F1 As Single Dim A As Long F1 1 1234 A F 3 14 A gets 3 even though result is 3 525456 Please be sure to include a decimal point when using floating point numbers even if your computer s language setting uses a different character for its decimal separator Fl 3 0 4 0 Write 3 4 as 3 0 4 0 for floating values FI 200 0 FIoor A 12 0 ES ES 05 200 as ZOO 0 12 as LO The And Xor and Or operators are used for both logical and bit wise operations If A 1 And B 1 Then C 1 if A 1 and B 1 Logical Operation If A 1 Or B 1 Then C 1 if A 1 or B 1 Logical Operation 103 D I B And amp HF Set the upper 4 bits to zero Bit wise Operation B Xor amp HF Invert the lower 4 bits Bit wise Operation A B Or amp HF Set the lower 4 bits to 1 Bit wise Operation D I Strings can be compared with the operator Dim STI AS String 12 Dim ST2 AS String 12 ST1 COMFILE ST2 CUBLOC I ST1 ST2 Then ST2 ORK Check if STI is same as ST2 When comparing Strings Cubloc BASIC compares the ASCII value of each character in the String Therefore String compariso
91. About 12C Advanced 12C is a common protocol used by many devices today Cubloc uses 12C as one of its primary communication protocols CuNET is built upon the 12C protocol The main advantage of CuNET is that it s hardware controlled for LCDs Not CSG modules or I O ports 12 commands such as I2CWrite and I2CRead are software commands An advantage of I C is that it does not require receive interrupts like serial communications the clock line is controlled by the master device This allows the Cubloc to multi task not creating any situations where the processor can freeze indefinitely while attempting to communicate The Cubloc can simply request data when it wants to it does not have to wait for the 12C slave device to respond As a result a Cubloc CB280 module can interface with up to 24 separate 12C buses That s buses you can add multiple 12C devices per 12C bus The Cubloc simulates a master 12C device Therefore all other connected 12C devices must operate as slaves Note The I O port used for I2C communication must be an Input Output port not Input Only or Output Only 5V 5V SCL SDA Slave Address Even though the maximum range for a typical I2C bus is around 12 feet a long distance extender chip such as the P82B715 can be used to extend the bus to almost 34 of a mile A P82B96 can also be used as a buffer to protect the I2C devices from electrical surges and interference 318
92. As Integer Dim K As Integer Dim M As Integer K 0 Const Byte KEYTABLE 1 4 7 10 2 5 8 0 3 6 9 11 12 13 14 15 Do i Keypad 0 IE ak lt ANG Then i KEYTABLE i 1 a lt lt NO Masa K K lt lt 4 RERI Csghex 0 K Eme WAIT UNTIL KEY DEPRESS 341 Do While KeyPad 0 lt 255 Loop M BCD2Bin K Debug Dec M CR End If Loop When there is no input the returned scan code is 255 Using the statment Do While keypad 0 lt 255 we wait until a key is released which will return a scan code of 255 This is to allow the processor to stop reading input while a key is being pressed Otherwise the processor might receive multiple key inputs since the Cubloc s execution speed is very fast Using _D 0 M you can pass the scan code to Ladder Logic s DO register If you need to use a keypad in Ladder Logic you can make minor modifications to this code to quickly get your results 342 NOTE 3 Temperature Sensor There are many uses for devices that sense temperature Refrigerators heaters air conditioners automobiles etc all make use of devices that sense temperature There are several different kinds of temperatures sensors There are PT100 NTC and PTC thermistors and other chip type sensors such as the DS1620 We will take a look at the NTC thermistor and interface it with the Cubloc The NTC thermistor is a temperature sensitive resistor Depending on the temperature the value of resistance will
93. B vl u a lu lt z lt lt aj ia Jo Measure frequency from pulse output PWM 0 channel Const Device CB280 Dim A as Integer Input 15 Low 5 Freqout 0 2000 Low 0 On Timer 100 Gosub GetFreq Do Loop GetFreq A Count 1 Debug goxy 10 2 Debug dec5 A Countreset 1 Reverse 0 Return 147 CountReset CountReset channel channel Counter channel 0 to 1 Resets the specified counter to 0 CountReset 0 Clear Channel 0 CountReset 1 Clear channel 1 148 Dcd variable Dcd source variable Variable to store results No String or Single source source value Ded is the opposite of Ncd It returns the bit position counting from one of the most significant bit that is a 1 I ped iS Result is 4 since 15 0b00001111 lt CUBLOC studio d cubloc_test unary cul File Edit Device Run Setup Help Bang mA A gt FI BASIC F2 LADDER Ladder mnemp Port Baud Rete Party Debug Terminal Dim A As Long A 10 Debug Dec A Cr A Not 1 Debug Dec A Cr A Ned 4 Debug Dec A Cr A Ded 15 Debug Dec A Cr Close I Fix Right Side Data Bits BTX Const Device CBZ80 com 115200 gt Mone 7 f T RK 149 Debug Debug data data data to send to PC Cubloc supports RS 232 debugging with the Debug command The user can insert Debug commands as desired within a program The result of the Debug command is di
94. CR Print String and go to next line 0 319 WE LOVE CUBLOC This command prints faster than GPrint since it simply overwrites the background When trying to display animations or numbers that change rapidly such as a moving ball or the current time DPrint will allow smoother transitions DPrint can only be used with X Axis values that are a multiple of 8 For example you can use GLocate 8 2 or GLocate 16 101 but not Glocate 10 30 286 Offset Offset x y This command offsets printed characters on the graphic layer x is the spacing between characters and y is the spacing between lines The default value is O Both x and y can be set independently Offset 0 0 Default offset CUBLOC IS FUN COMFILE TECHNOLOGY 239 Offset 3 3 1 Set x and y offset to 3 0 CUBLOC IS FUN 319 COMFILE TECHNOLOGY 239 287 Pset PSet x y This command draws a dot at coordinates x y Pset 200 100 Draws a Goe Color Color value value 0 white 1 black This command sets the current drawing color The default value is 0 white Color 0 Set color to white LineStyle LineStyle value This command sets the line style used when drawing lines and shapes You can make dotted lines by increasing value The default value is O a solid line Linestyle 1 Use dotted lines DotSize DotSize value style value the size of the dot style the style of the dot 0 rectangular 1 circular
95. CUBLOC Studio D CUBLOC_Test SELECT cul com 115200 none fo Ele Edit Device Run Setup Help 289734504 atte FI BASIC F2 LADDER Ladder Mnemoniq Const Device CB280 Dim A As Integer A 4 Do While A lt 10 Debug Dec A Cr Incr A Loop T Fis Right Side Debug Terminal joe Port Baud Rate Parity Data Bits CUBLOC Studio D CUBLOC_Test SELECT cul com risaoo y ene gt fe gt Ele Edit Device Run Setup Help Bag g xA M gt mar FI BASIC F2 LADDER Ladder Mnemonic Const Device CB280 Dim A As Integer A 4 Do Debug Dec A Cr Incr A Loop Until A gt 9 I Fix Right Side 156 DTZero DTZero variable variable Variable for decrement No String or Single DTZero decrement variable by 1 as long is variable is greater than O If variable is O DTZero does nothing This differs from the Decr command which will underflow the variable and wrap around to the type s highest value DTZero A Decrement A by 1 unless A is 0 157 EERead variable EERead Address ByteLength variable Variable to store result No String or Single address 0 to 4095 byteLength Number of bytes to read 1 to 4 Read data from the specified address in the EEPROM Dim A As Integer Dim B As Integer A 100 EEWrite 0 A 2 Store 2 bytes of A in Address 0 B EEReed 0 2 Read 2 bytes from Address 0 and store in B 158 EEWrite EEWrite address
96. Cr T Fix Right Side 91 Concatenate Multiple Strings To concatenate multiple strings together use the operator as shown below Dim al As String 30 Dim a2 As String 30 al Comfile a2 Technology eu cul al ae Ma Debug al cx The above program will show Comfile Technology Inc on the debug screen DEMO PROGRAM Debug Terminal Port Baud Rate Parity Data Bits are Ay tl lt CUBLOC studio d cubloc_test string cul comi 115200 Nene 8 Y Ele Edit Device Aun Setup Help ara 2am RAA p ait Ba FIT BASIC F2 LADDER Ladder Mnemonic Const Device CBzZ80 Dim al As String 30 Dim a2 As string 30 al Comfile a2 Technology al al ad Inc Debug al E Fix Right Side 92 How to Access Individual Characters within a String You can treat strings as a Byte array Simply append _A after the name of your string variable as shown below Dim 511 As String 12 STl A Array 1s creeted at the same time Suma ML Sit sT1_A 0 ASC A Ue Store Ain the rirse character ot STIE When you declare Dim Stl as String 12 St1_A 12 is also declared automatically by the Real Time Operating System RTOS The string and the array use the same memory space Whether you use the string or the array you are still accessing same memory location The example below shows how to convert blank characters to z Debug Terminal DER Fort Baud Rate P
97. DIDAAON 10 11 VIN vss RES VDD P15 P14 P13 pig CHANNEL 1 P11 TX P10 lt RX P9 P8 ES OOODOOOOOOOOO For the CB280 module there are dedicated RS 232 ports For channel 1 there are 2 types of outputs 12V and TTL 5 0V Please make sure to use only one of them at a time 12V 12V 12V 12V RES Nic P16 2 PIT P18 P19 P20 P21 P22 P23 P15 P14 P13 P12 TTLTX1 5V TTLRXI 4 AVREF GND Pas Par P30 p29 P28 P32 P33 P34 Pas P36 P37 Pas we 64 P39 If necessary the Set RS232 command can reset the RS 232 channel s configuration during program execution 202 CB400 CB405 RS232 How to The following is a table of the 5V TTL signal pins for the CB405 1 0 Port 5V TTL The CB400 CB405 has an internal MAX232 that can be used to convert any of the 5V TTL signals to 12V level signals The following is an example for connecting channel 3 This allows any 12V RS232 device to connect to TXE and RXE Sout TtUTXE Sin TtRXE Atn AVdd 4 AVref Vss Vdd Vss PO AD8 P32 P48 Input SCK P1 AD9 P33 P49 any MOSI P2 AD10 P34 P50 MISO P3 AD11 P35 P51 PWM9 P4 PWMO P5 PWM1 P6 PWM2 P7 RX2 P8 TX2 P9 P10 PWM6 P11 PWM7 P12 PWM8 P13 P14 P15 AD12 P36 P52 PWM10 AD13 P37 P53 PWM11 AD14 P38 P54 AD15 P39 P55 HCNT1 P47 P63 HCNTO
98. E zo of 32 EE z ce z Sout 1 DE 110061 TITXE Sin 2 62 E CB405 Vss 4 ss PO 5 Ma ss gt ony T MOSLP2 7 L_ MISO_P3 8 P4 9 PVvO_P5 10 PWM1_P6 11 ADC14_ P38 PW2_P7 1 ADC15_ P39 RX2_P8 1 HCNT1_ P47 T2_P9 1 HCNTO_ P46 P10 1 P45 PWW6_P11 1 P44 PWM7_P12 1 P28 PWM INTO Ti P Pame 1 Pao NTS NT CUNET DA Pa P15 2 EUN NSCL P40 Input Oniy P1 PWM6 P11 PWM7 P12 PWM8 P13 Vdd GNI CB400 VBB P16 ADO P17 AD1 P18 AD2 AD10 P34 PSO P19 AD3 AD11 P35 P51 PWM9 P20 AD4 AD12 P36 4 P52 PWM10 30 P21 AD5 AD13 P37 P53 PWM11 P22 AD6 AD14 P38 P54 P23 AD7 AD15 P39 P55 P24 HCNT1 P47 P63 P25 HCNTO P46 P62 P26 DEUVOUFLLNDROTOS P45 Pet P27 PWM3 352206000000 P44 P60 P28 PWM4 INTO aueo woroporan TX1 P43 P59 P29 PWM5 INT1 26043030000 RX1 P42 P58 P30 INTZ 0 SDA P41 59 P57 TX3 P31 1NT3 SCL P40 P56 RX3 VIN 5 5V 12Vinput vss RES VDD P15_HCNT1 P14_HCNTO P13 P12 P11_TX1 P10_RX1 P9_SDA CUNET P8_SCL CUNET Warranty Comfile Technology provides a one year warranty on its products against defects in materials and workmanship If you discover a defect Comfile Technology will at its option repair the product replace the product or refund the purchase price Simply return the product with a description of the problem and a copy of your invoice if you do not have your invoice please include your name and telephone number This warrant
99. ECT anything to these pins 48 CB290 The CB290 is a package of 108 pins of which 91 can be used as I O ports It has a battery backup capable 28KB of memory and an RTC The CB290 does not have an internal 5V regulator Of the 91 I O ports 32 ports are output only 32 ports are input only and rest can be set as output or input as desired by the user program ww Sout 10621 vdd TX1 410061 THTx1 i 2 Rx1 TURX1 CB290 iii Vdd Vss P24 P32 P25 P33 P26 P34 ec P27 P35 lo Eu P28 P36 Zz P29 P37 P30 P38 Ss 2320 P31 P39 Serb So555 P40 P48 ee P41 P49 QoS Se RR AS Hees e zaidii AA P43 P51 eecoccooocoocoe P46 P54 F63 2006 40 P71 cc ce s P47 600 080 P55 1MDO0DO N MTO oro gt gt 2 RRE 222 OCT MOR ooro Or DANNNAREREDDDD adaoaboaaaaead 1 11 2 EE 66 pS fa EE Port Pin 1 0 Port Block Explanation SOUT DOWNLOAD SERIAL OUTPUT eee DOWNLOAD SERIAL INPUT __ DOWNLOAD SERIAL INPUT GROUND Po EA SCK a MOSI Block 0 A MISO a aaa 0 P6 11 vo PWM Channeli PWM Channel Ae ADC3 AD Channel3 ADC4 AD Channel4 NS ADC5 AD Channel5 ADC6 ADChannel6 ADC7 AD Channel 7 Ps 25 vo ADCO_ AD Channel 0 P9 26 yo ADC1 AD Channel1__ A ai 1 LADC2_ ADChannel2_ Block 1 49 P23 P24 P25 P26 P27 P28 P29 P30 P31 P32 P33 P34 P35 P36 P37 P38 P39 P40 P41 P42 P43 P44 P45 P46 P47 P48 P49
100. EL3 P20 29 yo ADCHANNEL4 P21 3o yo aADcHanNeLs P22 31 yo ADCHANNEL6 AD CHANNEL 7 Po P27 36 yo Pwm3 P28 37 yo PwM4 iNTO P29 38 yo PwMs inti Of P30 39 10 02 A P31 40 yo ints Communication line for connecting to the coprocessor Please try to save these pins for future coprocessor communication ports 58 i ee La lr RN Pes He o ab channets P34 47 mo AD CHAaNNEL10 P35 48 yo ADCHANNEL 11 P36 49 yo aADcHanNeLi2 P37 5o yo ADCHANNEL 13 P38 __ 5i yo ADcHanNeLia P39 52 1 0 AD CHANNEL 15 Es CUNET clock pin P44 56 vo ES E P45 55 vo __ E P48 65s vo i T Ef P49 66s vo P50 _ 67 vo A fh P51 68 yo PwmcHanNet9 pps2 69 yo PwmchHanNetio0 P53 70 yo PWM CHANNEL 11 P54 71 vo 1 f e55 72 vo gt gt A P56 80 yo RX3 TIiRXchamei3 P58 _ 78 _ vo A P59 77 P O Peo _ 76 vo S Ef P61 75 vo e E P62 _ 74 vo e63 73 vo Eh 59 CB405RT CB405 core module equipped with a built in accurate RTC DS3231 equipped with a built in 16 bit A D converter 8 channels The CB405RT is a product which adds an RTC and a 16 bit ADC to the original CB405 The external dimensions and pinout are the same as the CB405 with the exception that ports P32 to P37 are used for the 16 bit ADC and therefore cannot b
101. F4 FS Fe F Fe F9 Fil F12 NOT END Insert Delete Undo START RELAY 1HI C 2 El At the very end of the Ladder Logic program you must always put an END command 365 Editing Ladder Logic Text Editing Text To edit existing text place the cursor in the desired location and press ENTER A text box will appear for editing the text START TON 11 100 1 HH Erasing a Cell To erase a cell select it with the cursor and START Pi 1 HH press the SPACE key START E 1H Erasing a Rung one line A rung is a row in Ladder START RELAY 1H N2 HO OUT 2H END 3 c 1 You can press CTRL D to erase a rung This actually moves the rung to a buffer START RELAY A END 2 1 366 Rung Recovery To recover an erased rung recall it from the buffer press CTRL U START RELAY 1HI N2 ouT2 2H END 3 c 1 Cell Insert and Delete Select an empty cell on a rung START C TON T0 100 1H l If you press the DEL key the cell is erased and items on the right are pulled one cell to the left START J TON To 100 1 il E l If you press the INS key a blank cell is inserted and items on the right are moved one cell to the right START TON T0100 1 1 Rung Copy When the same style of rung is needed you can press CTRL A and it will copy the rung above and pasted it one rung below START TON TO 100 1 k E 1
102. GA ASA WF m E El El P9 PO of 42 182 2 1 pi 131571987 ARE p3 221 027087 na P3 231131137 Zis P4 P5 P6 P7 The CSG module is a 4 digit seven segment LED module that can be connected via CUNET or the I2C interface to display numbers and custom characters oo m n J 21 ES El a GND re SCL SDA cs 4s 6 COMFILE lt Filename csgprint cul gt Const Device CB280 Set I2c 9 8 Dim i As Byte Do CsgDec 0 1 ak cet oak ae al Loop 340 If you connect the CSG to the CuNet connector and execute the program above the CSG module will show incrementing numbers The key matrix can be easily read using the KeyPad command If you look carefully at the keypad you will see that the scan code does not match the actual key pressed In order to read the correct key we will use a Byte array KEYTABLE to map the scan codes to the appropriate key Const Device CB280 Set I2c 9 8 Dim i As Integer Dim K As Integer CONSE BYES RATTA BLE O Sits Oa Sh Gy io al ALa Do i Keypad 0 IEG ANG Then i KEYTABLE i Csgdec 0 i ERA IE Loop And now we will make a simple program that receives input When a number key input is received it is displayed to the CSG module as a 4 digit number The number is stored int the variable k which is in BCD format We then use the BCD2Bin command to convert the BCD value back into binary Const Device CB280 Sot T20 978 Dim i
103. GOTDATA A Get 1 1 Debug A Return 166 GetA GetA channel arrayName byteLength channel RS 232 Channel 0 to 3 arrayName Array to store received data Byte type only byteLength Number of bytes to store 1 to 65535 The command GetA can be used to store received RS 232 data in a Byte array Data will be stored starting from the first element of the array Check the receive buffer with BLen before reading to avoid overflowing the buffer Const Device CB280 Dim A 10 As Byte Opencom 1 115200 3 501 10 Set Until 1 8 10 10 is a required dummy value it will be ignored On Recvl Gosub GOTDATA Do Do While In 0 0 Loop Wait until press button Connect PO Futster 1 IO CE Do While In 0 1 Loop Loop GOTDATA GetA 1 A 8 Debug A 0 A 1 A 2 A 3 A 4 A 5 A 6 A 7 Return In order to run the program above please connect Rx to Tx as shown below 167 GetA2 GetA2 channel arrayName byteLength stopChar channel RS 232 Channel 0 to 3 arrayName Array to store received data Byte type only byteLength Number of Bytes to store 1 to 65535 stopChar Stop character ASCII code GetA2 is the same as Geta except it will stop reading data at the when it encounters stopChar even if the data received is less than byteLength If stopChar is not found then it will operate just like GetA stopChar is included in the received data You can use the sys 1 command to check the number of bytes re
104. HAD_Vref can be applied to HAD_CHO through HAD_CH7 TXE 4108 RXE 4208 HAD_Vref 43080 Vdd 4408 HAD_CHO 45080 HAD_CH1 46080 HAD_CH2 4708 HAD_CH3 4808 HAD_CH4 4900 HAD_CH5 5008 HAD_CH6 P38 51080 HAD_CH7 P39 5208 The 16 bit ADC gives a result ranging from OV to Vref expressed as one of the 65536 equally divided intervals It is capable of much more accurate measurement compared to a 10 bit ADC 479 HADIn2 variable HADIn2 channel combination variable Variable to store the result Integer or Long type channel Combination AD channel combination code This command is for a differential A D input Two channels are paired up and the A D converter converts the difference between the two voltages Channel combination code Input Input 0 CHO CH1 1 CH2 CH3 2 CH4 CH5 3 CH6 CH7 4 CH1 CHO 5 CH3 CH2 6 CH5 CH4 7 CH7 CH6 include CB405RT Do Debug Goxy 1 1 Dec5 Hadin2 0 Wait 500 Loop TXE 4104 RXE 4204 HAD_Vref 4304 Vdd 4404 HAD_CHO 4504 HAD_CH1 4604 HAD_CH2 4704 HAD_CH3 4804 HAD_CH4 4904 HAD_CH5 5004 HAD_CH6 P38 5104 HAD_CH7 P39 5204 TIP For a more accurate measurement one should start with a reliable power source A Linear power source e g using 7805 etc is better for A D input than a switching power source circuit e g using LM2576 Also when the A D input pins are extended and exposed outside the board a protection circuit where additional chip
105. ILE TECHNOLOGY in a 14 byte string the last 4 characters bytes will be truncated Dim ST As String 14 ST COMFILE TECHNOLOGY LOGY is not stored COMFILE TECHNOLOGY LOGY does not fit In Cubloc BASIC only the double quote character can be used for String constants must be used for String An single quote characters may not be used ST COMPILE TECHNOLOGY cannot be used inside the String ST COMFILE TECHNOLOGY cannot be used inside the String ST COMFILE TECHNOLOGY cannot be used inside the String Furthermore Cubloc BASIC does not support character escape sequences Use CHR amp H22 to include a double quote character in a String Commas and single quotes also cannot be directly declared in a String Use CHR amp H27 to included a single quote character and CHR sH2C to included a comma 90 Example for printing to an LCD Print Chr amp H22 COMFILE TECHNOLOGY Chr amp H22 oat Print Chr amp H27 COMFILE TECHNOLOGY Chr amp H27 Apostrophe DEMO PROGRAM Debug Terminal Port Baud Rate Parity Data Bits Cara sit i SE CUBLOC studio d cubloc_test string cul com v 15200 none 8 erx Ele Edit Device Run Setup Help BEME ES ELE BE FI BASIC F2 LADDER Ladder Mnemonic Const Device CB280 Dim 1 As String Dim 2 As String 10 61 COMFILE TECHNOLOGY 82 KOREA SOCCER Debug 81 Cr Debug 82
106. In 4 1 Then a 0 Out 14 a Loop When the switch is pressed a bouncing effect occurs from the switch s mechanical spring 338 The above picture shows how bouncing can confuse Cubloc controller with alternating high and low signal levels To get rid of this bouncing effect a capacitor and resistor can be added to filter it out A simpler method is to use the KeyInH command instead of In which will remove the bouncing effect through software Const Device cb220 Dim a As Byte Do If KeyInH 0 20 1 Then a 1 If KeyInH 4 20 1 Then a 0 Out 14 a Loop The 2 parameter of KeyInH 0 20 a delay before reading the input so the signal bounce has time to settle This delay is called the debouncing time The software will wait for 20ms before reading the input In industrial environments there can be a lot of electromagnetic noise which can affect switch signals To prevent this noise from affecting the circuit a circuit diagram similar to one shown below can be used Using a photocoupler the user is able to raise the voltage and minimize the effect the noise has on the switch input DC24V DC5V oe 2 2Kohm _i e o Xk il o CUBLOC I O PC 18T1 10Kohm ae ZIT 339 NOTE 2 Keypad Input This application demonstrates interfacing to a 4x4 keypad and displaying the results on a 4 digit seven segment module CSG module CB280 P8 YA I
107. L 64 1 0 lines 5V TTL Purpose P P input output input output 1 0 coe ee configurable configurable 5V TTL 2 serial ports 2 serial ports 4 serial ports 4 serial ports Channel 0 RS Channel 0 RS232C Channel 0 RS232C Channel 0 RS232C 12V 232C 12V 12V Channel 1 12V Channel 1 to 3 Channel 1 to 3 RS232C TTL Channel 1 TTL RS232C 12V amp TTL RS232C TTL 5V 5V Configurable Baud 5V 5V Configurable Configurable Baud rates 2400bps to 230 400 Configurable Baud rates 2400bps Jrates 2400bps to bps Baud rates to 230 400 bps 230 400 bps 2400bps to 230 400 bps Analog 8 Channel 10 8 Channel 10 bit J E bit ADCs ADCs 16 channel 10 bit ADCs 16 Channel 10 bit ADCs 6 Channel 16 6 Channel 16 bit 12 Channel 16 bit 12 Channel 16 bit PWMs Analog bit PWMs PWMs DACs PWMs DACs DACs DACs Frequency 35hz to Frequency 35hz to Frequency 35hz to 1 5Mhz Outputs Frequency 1 5Mhz 1 5Mhz 35hz to 1 5Mhz 83 I O lines 5V TTL input output configurable External 4 Channels in Interrupts Spare 1 0 4 Channels 4 Channels 4 Channels High 2 Channel 32 2 Channel 32 bit Speed bit Counters Counters up to as up to 2Mhz 2Mhz 5 to 12V 40mA ports iad ports eee 5V 40mA ports unloaded unloaded E B Data Memory None None Optional Backup Operating 40 C to 120 40 C to 120 C 40 C to 120 C 40 C to 120 C Temp c aera 64 pin Module 80 pin Module 108 pin Module 1 2
108. L x 0 6 W x aei 0 4 H IPEX I Woe 2 4 L x 1 9 W x 0 5 H 2 4 L x 1 9 W x 0 5 H 30x15 3x11 35 ag mm 59 4 x 47 8 x 13 mm 59 4 x 47 8 x 13 mm mm 2 Channel 32 bit 2 Channel 32 bit Counters Counters up to 2Mhz up to 2Mhz Size 22 The main advantage of Cubloc is that it fills Ladder Logic s weaknesses with the BASIC language Ladder Logic is good enough to replace sequence diagrams but to collect data print graphics and process complex tasks is asking a little bit too much That is why we added the BASIC language You can now run both Ladder Logic and or BASIC DIM A AS INTEGER H IF IN 0 0 THEN OUT 2 A LADDER LOGIC File Edit Device Run Setup Help DSHS 8ee Q oe eo Basic Const Device Const iorst Const iodio 6 Const ioclk 5 Dim I As Integer Dim adr As Byte High iorst Shiftout ioclk il Shiftout ioclk il Low iorst Delay 1 High iorst Shiftout ioclk ilj Shiftout ioclk ij Low iorst dit Device Run Setup Help D6B 183098 10 1024 2 a BASIC LADDER Q ye Ola 12 0 Search F3 F4 FS F6 F7 Fe F9 Fa F12 NOT END iK Insert 10 Delete MCS 0 MASTER START STOP MASTER START STOP Maso pag LOOP1 EXT P32 Do M250 High iorst adr amp h81 Shiftout iocl I Shiftin il Debug Hex I C Low iorst Delay 1000 Loop START
109. LOW ADDRESS and DATA can be sent When all data is sent the Stop command can be transmitted It takes about 5ms for each EEPROM write The following is an EEPROM write sequence in Cubloc s BASIC code Set I2C 9 8 n Set P9 as SDA P8 as SCL I2CStart If I2CWrite b10100000 1 Then ERR PROC Chip Address A0 If I2CWrite adr Bytel 1 Then ERR_PROC Weite address to write to If I2CWrite adr LowByte 1 Then ERR_PROC If I2CWrite data 1 Then ERR_PROC Write byte I2CStop Delay 5 Wait for the write operation to finish Next we will look at how to read 1 byte from the EEPROM Although it might look more complex than writing 1 byte we will soon find out that they are very similar 315 R W Repeated Start R W NoAck M M M y S CONTROLBYTE OJA HIGHADDRESS A LOWADDRESS A S CONTROLBYTE 1 A DATA X P S Start we A Acknowledge Read Point P Stop Read Point is where the actual data will be read from the EERPOM The first part of the command is for setting the address to read data from Set I2C 9 8 I2CStart If I12CWrite amp b10100000 1 Then ERR PROC Chip Address AO If I2CWrite adr Bytel 1 Then ERR_PROC Write address to read from If I2CWrite adr LowByte 1 Then ERR PROC HAS paa te Repeat start If I2CWrite s b10100001 1 Then ERR PROC Read command Data I2CRead 0 1 Store res lt to data I2CStop And now we will look at how to
110. LSB first Least Significant Bit first before rising edge 5 MSB first Most Significant Bit first before fising edge bitLength Length of bits 1 to 16 The ShiftIn command receives a shift input It uses 2 ports CLOCK and DATA to communicate The ShiftIn and ShiftOut commands can be used to communicate with SPI Microwire and similar communication protocols When using EEPROM ADC or DAC devices that require SPI communication this command can be used After Rising After Falling Edge Edge ox JEU Before Rising Edge Dim A AS Byte A ShiftIn 3 4 078 1 Port 3 is CLOCK port 4 is DATA mode is 0 bits to be received a MNA DATA 244 ShiftOut ShiftOut clock data mode variable bitLength clock Clock port 0 to 255 data Data port 0 to 255 mode 0 LSB first Least Significant Bit first 1 MSB first Most Significant Bit first 2 MSB first Most Significant Bit first create ACK For 12C variable Variable to store data up to 65535 bitLength Bit length 1 to 16 This command performs a shift output There are 3 modes Mode 2 is for the I2C protocol In I2C communication an ACK signal is required for every 8 bits ShiftOut SHO els Y Port 3 Clock Port 4 Data Mode 0 send 0x55 8 bits to be sent ex JUVUJUUUL A E IA 1 0 1 00 1 0 41 0 55H LSB MSB 245 Spi InData Spi OutData Bits InData Input data OutData Input data Bits Number of bits
111. Locate 0 0 Print COMPILE Locate 1 3 Brine SON BLOC V5 DS cl Delay 100 Loop The slave address specified in the Set Display command should match that of the CLCD 269 GHLCD Graphic LCD GHB3224C The GHLCD is an LCD that features the ability to display characters and graphics on three different layers Unlike the CLCD the GHLCD supports many different commands for easily drawing lines circles and boxes There are also commands to copy cut and paste graphics and a BMP downloader for downloading images to the GHLCD The GHB3224C model is a blue and white STN type LCD with a display area of 320 by 240 pixels There are 3 layers The first layer is for text and the other 2 layers can be used for graphics GHB3224C Library is 99 compatible with Cutouch modules Layer1 270 The text layer is a 40x15 grid as illustrated below Each character size is 8 by 16 pixels The GHLCD series features a 320 by 240 pixels for graphics 0 319 239 Please note that graphics or characters will appear randomly when trying to print outside the specified range of pixels shown here 271 GHB3224C supports CuNET The GHB3224C model supports CuNET When using Cubloc with the GHCLD using CuNET instead of serial communications will free up the serial port for other uses GHB3224C CuNET settings Set Display 1 0 1 50 GHLED CUNET Set Address to 1 Send buffer to 50 Warning The CuNET slave address and display
112. M DAC and external I O chips I2C uses two lines SDA and SCL and devices must operate in either master or slave mode The Cubloc can only be used as a master Be sure to configure I2C using the Set 12C command before using any other I2C commands I2C s START STOP When SCL Clock and SDA Data are logic high 12C is in an idle state Ifa START command is executed during the idle state 12C begins When SCL and SDA are both logic low I2C is in a busy state If a STOP command is executed during the busy state I2C stops There is also a Repeated Start in 12C If a START command is executed during a busy state 12C restarts lt lt Repe ted STOP Start a gt a si n 4 O TU 314 Using an EEPROM through 12C We will go through an example showing 12C communication between a Cubloc and a 24LC32 EEPROM The following is a diagram from the EEPROM s data sheet It shows how to send data to the EEPROM R W y S CONTROLBYTE OJA HIGHADDRESS A LOWADDRESS A DATA AJP S Start A Acknowledge P Stop The first bit is for the Start command The 4 upper bits of CONTROL BYTE must be 1010 and the 3 lower bits are for selecting the chip s address The user may change the EEPROM chip s address by configuring the chip For a read 1 can be written into R W and for a write O can be written into R W A is for acknowledgment of the 8 bits 1 byte sent Then HIGH ADDRESS
113. Maid eae 191 O eames te eek acne gee cai Aiea ee Sead Send teeter ae eens ee oa 129 MESA EEN O E EAT 394 MESCLR EEE E E A AE a eo 394 MEMA a a a aa i as 192 MENU DUELONS sseni an e a i a O EE A as 450 MENU a aa 453 MentCheck ui ii a 452 M NURCVEFSC iin ica A A A AAA 452 M NUSEE t iris sais a a A tilo 451 Menu Title ii A a on a ae aa 451 Midori E S E A E T A ETET 127 Ll A NN 370 mM lti tasking aoe ESAE i hea ia cuteaever caret eaten E AE TEOR 28 488 NID BIG vaa ai ala Seren azauh cated 96 NOP yee iii A tee deee av adge a Stsieet 194 NOW rei sree doce A in Duane dad 389 OE A A A A A A 287 MA a dos 195 On LadderInt GoSUb ci sicinncion narnia Inia date 196 OP eds talc E wate aw eee a oan wens eOoase E ae 198 A A i SA eee ee a oa 199 OMSTIMERO EE casera ida 200 OPA COM ira ata da e aaa Tadeo 201 Operators A AE AS AS 102 18 A A E A EOS 389 DUE AA A AE ee a 204 A A A A A EN 388 A AN 205 SS A a eE A needs Eaa i aTa 206 Overa yrei aene s e ania ia a a aa aa a a a 277 Paid A A TOT 290 PU A A A ai 206 PR A e AR 115 207 PEC S tup Wizard rd A nia 374 PORC ia A ap 115 207 A TN 274p Pi AA AA a A DAD 288 PUISOUE a rca da 208 PU o a CRO o o ELO O ett ae 209 PU a dt cia 211 PUTA LA A le tamed seid cea dade AO 212 PUES A ia sata as a 213 PM A eh a aa 214 PIM a ii 215 RamClea rara id t 216 ROS E A E T T Meare Pans Bede Seta A E 217 RETA A AAA A 431 ROVER a a 218 lA a saa caus ogo TARN E AC 127 RAG ooo Uv vda caro Oo ab
114. NEL6 AD CHANNEL 7 Po P27 36 yo Pwm3 P28 37 yo PwM4 iNTO P29 38 yo PwMs inti Of P30 39 10 02 A P31 40 yo ints Communication line for connecting to the coprocessor Please try to save these pins for future coprocessor communication ports 54 P32 45 yo ADCHANNEL8 P33 46 yo ADCHANNELO P34 47 yo ADCHANNEL10 P35 48 yo ADCHANNEL 11 P36 _ 49 yo ADCHANNEL12 P37 50 yo ADCHANNEL13 P38 51 yo ADCHANNEL14 P39 52 yo ADCHANNEL15 P40 60 mo sch CUNET Clock P44 56 yo fT P45 55 yo P47 53 1 O HCNT1 High Speed Counter Ch 1 ee P49 665 vo P50 67 vo T P51 68 mo PwmCchamel9 ______________ P52 69 yo PWMChannel 10 P53 70 mo PwmChameli1 ____________ P54 71 vo gt gt gt P55 72 vo 0 S N Ii P56 so yo RX3 TTLRX Channel3 P58 78 _ vo S P59 77 vo S o Peo 76 yo S P61 75 yo o E i DO ss yo ss yvo 87 vo ss yvo 89 vo 90 yo 91 vo 92 vo a DO E Po Po P66 _ Po Po Po P69 Po _ Po 55 p72 99 yo fT P73 100 yo lo p74 101 yo p75 102 yo i o p76 103 yo o P77 104 yo p78 105 yo fT P79 106 vo A A Ps0 93 vo T pat 94 vo g
115. NOTE Step 2 CHAR Asc Mid NOTE PL 1 amp H41 FreqOut CH PLAYTABLE CHAR CHAR Asc Mid NOTE PL 1 1 amp H30 Delay CHAR 100 Next PwmOff CH End Sub When using the PWM port for other purposes the FreqOut command cannot be used To get around this limitation any regular I O port can be used to create sound The following example shows how to make an alert sound with I O port P4 This program uses the Reverse and UDelay commands to alternate the I O port between logic high and logic low 349 350 NOTE 5 RC Servo Motor RC servo motors or servos for short are used by many hobbyists to make remote control cars planes etc In recent years they have been used for robot arms legs and wheels With the Cubloc s PWM outputs a servo can be easily added to any project A servo typically has three wires The black wire is ground and red wire is for power The other yellow wire is for receiving a PWM signal A typical pulse rate is approximately 60 pulses per second Red 5V Black GND CB220 The servo will move to a location set by the PWM s pulse and duty cycle and will hold its position 1mS 1 5mS 2mS gt gt De rN FA w w w 45 0 45 351 Every RC servo motor is different but as an example pulses of ims 1 5ms and 2ms might stop a RC servo motor to 45 degrees 0 degrees and 45 degrees respectively Const Device CB280 Low 5 Pwm 0
116. NUTITLE command sets the name of the button itself PulsOut outputs a BEEP sound to the piezo speaker 458 SAMPLE 3 This sample draws a circle wherever the screen is touched lt Filename CT003 CUL gt Const Device Ct1720 Dim TX1 As Integer TY1 As Integer Contrast 550 Set Pad 0 4 5 On Pad Gosub GETTOUCH Do Loop GETTOUCH TX1 Getpad 2 TY1 Getpad 2 CiliaenluesiLil TXI al 10 Pulsout 18 300 Return 459 SAMPLE 4 This sample make a virtual keypad that accept numerical input lt Filename CT004 CUL gt Const Device Ct1720 Dim TX1 As Integer TY1 As Integer Dim I As Integer Contrast DU Set Pad 0 4 5 MenuSet MenuSet 0 2 165 50 195 75 MenuTitle 0 11 4 17 Menuset 1 2 205 50 235 75 MenuTitle 1 TATAN Menuset 2 27245790 27519 MenuTitle 2 11 4 3 MenuSet 3 2 165 85 195 110 MenuTitle 3 aaa MenuSet 4 2 205 85 235 110 MenuTitle 4 11 4 5 MenuSet 5 2 245 85 275 110 MenuTitle 5 11 4 6 MenuSet 6 2 165 120 195 145 MenuTitle 6 11 4 7 Menus 7 2 205 120 235 145 MenuTitle 7 ESAS MenuSet 8 2 245 120 275 145 MenuTitle 8 11 4 9 Menuset 9 2 165 155 195 180 MenuTitle 9 O MenuSet 10 2 205 155 275 180 MenuTitle 10 17 4 ENTER 1 0 Do Loop GETTOUCH TX1 GetPad 2 460 TY1 GetPad 2 If MenuCheck 0 TX1 TY1 1 Then Src g S Top PulsOut 18 300 Elseif MenuCheck 1 TX1 TY1 Then lt lt 4 a PulsOut 18 300 Elseif MenuCheck 2 TX1 TY1 Then lt lt 4
117. O P6 11 1 O PWM CHANNEL 1 P7 12 1 O PWM CHANNEL 2 P8 13 1 O TTL232 RX2 P9 14 1 O TTL232 TX2 P10 15 1 O 1 Pil 16 I O PWM CHANNEL 6 P12 17 I O PWM CHANNEL 7 P13 18 1 O PWM CHANNEL 8 P14 19 1 O P15 20 I O P16 25 I O AD CHANNEL 0 P17 26 I O AD CHANNEL 1 P18 27 I O AD CHANNEL 2 2 P19 28 1 O AD CHANNEL 3 P20 29 I O AD CHANNEL 4 P21 30 I O AD CHANNEL 5 P22 31 1 O AD CHANNEL 6 P23 32 I O AD CHANNEL 7 P24 33 I O P25 34 I O P26 35 I O 3 P27 36 I O PWM3 P28 37 I O PWM4 INTO P29 38 I O PWM5 INT1 P30 39 I O INT2 P31 40 I O INT3 61 This part has been changed from original CB405 Block Name Pin I O Special Description No Function HADCHO 45 INPUT 16bit AD CHANNEL 0 HADCH1 46 INPUT 16bit AD Belongs CHANNEL 1 to no HADCH2 47 INPUT 16bit AD block CHANNEL 2 HADCH3 48 INPUT 16bit AD CHANNEL 3 HADCH4 49 INPUT 16bit AD CHANNEL 4 HADCH5 50 INPUT 16bit AD CHANNEL 5 HADCH6 51 1 0 16bit AD P38 usable P38 CHANNEL 6 HADCH7 52 1 O 16bit AD P39 usable P39 CHANNEL 7 Note Since ports P32 to P37 are internally connected to the RTC and the 16 bit ADC if a program uses these ports the RTC and ADC chip will not function properly Also if ports P38 and P39 are used for output HADCH6 and HADCH7 cannot be used respectively P40 60 I O SCL CUNET clock P41 59 I O SDA CUNET da
118. O Off 1 On This command is used to turn the backlight on and off The default is on WMode WMode value value O Fast 1 Slow This command is used to select the method for refreshing the screen To draw graphics or text data must be written to memory Slow mode only writes to memory between screen refreshes so the screen redraws at a slower rate but produces no imperfections in the display Fast mode writes to memory at any time so the screen refreshes at a faster rate but can cause imperfections in the display such as flickering and noise 278 Font Font fontSize eFontWidth fontSize O to 8 Font Selection eFontWidth O fixed width 1 variable width This command sets the size and with of the font used to print characters The GHB3224 LCD has 4 different font sizes and 2 different widths Font Size Font o1 10x 16 2345 16x16 6 7 24x 24 ss 48 x48 Const Device CB290 Cis Delay 100 Font 0 0 Glocate 10 10 GPrint FONT 0 0 ABCDEFGHIJKLMN Fonte 2 0 Glocate 10 30 GPrint FONT 2 0 ABCDEFGHIJKLMN Font 6 0 Glocate 10 50 GPrint FONT 6 0 ABCDEFGHIJKLMN Font 8 0 Glocate 10 72 GPrint FONT 8 0 Glocate 10 120 GPrint FONT 0 1 ABCDEFGHIJKLMN Font 2 Glocate 10 140 GPrint FONT 2 1 ABCDEFGHIJKLMN E G G F G Locate 10 160 Print FONT 6 1 ABCDEFGHIJ 279 GPrint TFONT B1 7 Style Style bold inverse underline bold O Normal 2 or 3 Bold
119. Output OFF ee al End of Ladder Logic GOTO Jump to the Specified Label LABEL Label Declaration CALLS Call a Subroutine SBRT rear ae ke ae es ls el A LATT SS LIN hi hal hal hal hol hold Ly had hd hd Declare a Subroutine End Subroutine Conditional Exit Command 386 High Level Commands Data Commands s d s d s d s d s d n s d n Move Word Move Double Word Swap Word Swap Double Word Move Data Multiple Times Fill Data Move a Group of Data Increment Decrement Commands WMUL Word Multiplication WDIV DWSUB Double Word Subtract DWDIV Double Word Division Logical Commands WAND DWAND WXOR DWXOR s1 s2 d s1 s2 d s1 s2 d s1 s2 d s1 s2 d s1 s2 d Word XOR Double Word XOR Bit Shift Commands 387 LOAD LOADN OUT LOAD is for contacts that are open by default and LOADN is for contacts that are closed by default LOAD OUT Registers that can be used LOAD LOADN 388 NOT AND OR NOT Symbol PO P5 0 PO Pl Po FJ 0 PO P5 0 4 A AND OR NOT inverts the results On the first rung in the example above if PO is ON then P5 will be OFF AND is performed on two registers when they are placed horizontally beside each other on the same rung On the second rung in the example above both registers PO and P1 must be ON in order for P5 to be ON An OR operation is performed when two registers are placed vertically beside
120. PLC Embedded computer UBLOC User Manual Last Updated 2015 11 20 Everything for Embedded Control COMFILE TECHNOLOGY Comfile Technology Inc www comfiletech com Copyright 1996 2015 Comfile Technology Blank Page 24 23 22 21 20 19 18 17 16 15 w ji SOUT 1 17 VDD TXI 330 49 TTLTX1 sn 20 e1s vss CB280 exi 340 050 TLRXI sour 7 v ATN RES CB380 2D 250 051 AVREF CB220 2 az VSS N C N C P48 ATN 3 ss_PO P16 ADCO_P24 P31_ADC7 CB320 Ves CA Input_only SCK_P1 P17 ADC1_P25 P30_ADC6 sapero del TM MOSI_P2 P18 ADC2_P26 P29_ADC5 MSO P3 P19 PNB ADC3_P27 p2a_apca _ Inputonly SCK_ADC1_P1 6 P4 P20_PWM4_INTO P47 P32 MOSI_ADC2_P2 7 E PWMO_P5 P21_PWM5_INT1 P46 P33 F SEARE 1 0 MISO_ADC3_P3 7 8 PWM1_P6 P22_INT2 P45 P34 p19 pwm3 ADC4_P4 19 es PWM2_P7 P23_INT3 P44 P35 Bat owm inti PWMO_ADC5_P5 10 e CUNET SCL_P8 P15_HCNT1 P43 Pao MEA PYWM1_ADOS_PS 1111 yT CUNET SDA_P9 P14_HCNTO P42 P37 PWM2_ADC7_P7 12 P10 150 31 P13 P4 P38 Pit 100 32 P12 P40 P39 w Sout sin amp CB290 Vss SS PO P8_ADCO Input only SCK P1 P9 ADC1 MOSI _P2 P10 ADC2 MSO P3 P11_ADC3 ce Pa P12_ADC4 bo PWW0_P5 P13 ADC5 zz PUMI_P6 PI4ZADOS 33 PAM2 P7 P15_ADC7 Sloe P56 Soar P57 P58 oaeNadnetworam P59 Zzhidaipboooooe P60 eNO THOR MDDOr AOD P61 SSS 332358295983 P62 P63 e c 0 0 Re Ora Do NATO LR BE BE Or O N MOR oaro On DONNA SRR RR OO OO PRAKS RRR ERTS S
121. R LF 2 The response is typically an echo of the request indicating that the operation was successful Response Field RTU Bytes ASCII Bytes Header colon 1 Slave Address 0X03 1 03 2 Function Code 0X05 1 05 2 Start Address HI 0x01 1 01 2 Start Address LO 0x00 1 00 2 Length HI OXFF 1 FF 2 Length LO 0x00 1 00 2 Error Check CRC 2 LRC 2 Ending Code CR LF 2 328 Function Code 06 Preset Single Registers PLC s can remotely control the status of its registers in word 2 bytes units through this function code The following is an example showing slave address 3 s D1 being written Quer Field RTU Bytes ASCII Bytes Header 1 colon 1 Slave Address 0X03 2 03 2 Function Code 0X06 2 06 2 Start Address HI 0X70 2 07 2 Start Address LO 0x01 2 01 2 Length HI 0X12 2 12 2 Length LO 0X34 2 34 2 Error Check CRC 2 LRC 2 Ending Code 2 CR LF 2 The response is typically an echo of the request indicating that the operation was successful Response Field RTU Bytes ASCII Bytes Header colon 1 Slave Address 0X03 1 03 2 Function Code 0X06 1 06 2 Start Address HI 0X70 1 01 2 Start Address LO 0x01 1 70 2 Length HI 0X12 1 12 2 Length LO 0X34 1 34 2 Error Check CRC 2 LRC 2 Ending Code CR LF 2 329 Function Code 15 Force Multiple Coils PLC s can remotely control the status of its registers in units of multiple bits through this function code The following is an example showing slave address 3 s P20 through P30 being
122. TE A ts T234 Y 1234 will be displayed notice the 6 blank spaces Debug DP A 10 1 If A is 1234 0000001234 will be displayed it Terminal Baud Rate Parity Data Bits aT TA CUBLOC Studio D CUBLOC_Test FORMAT cul COn riszo0 one y fs lan File Edit Device Run Setup Help Band xBa A mu a FI BASIC F2 LADDER Ladder Mnemonic Const Device CB280 Dim A As Integer A 1234 Debug Dp A 8 Cr Debug Dp A 10 1 T Fix Right Side 124 HP value numberOfDigits zeroPrint HP converts a variable into a hexadecimal string representation If ZeroPrint is set to 1 zeroes are substituted for blank spaces Debug HP A 4 0 Convert A into HEX String representation Set display decimal places to 4 If A is ABC bABC will be displayed b stand for blank spaces Debug HP A 4 1 If A is ABC OABC will be displayed ee Terminal lt CUBLOC Studio D CUBLOC_Test FORMAT cul Aa Ra 7 a Dl 7 5 y aui e arity a Bts File Edt Device Run Setup Help 7 pa Com gt 1115200 Mone X Band 5608 4 al El frene fe FI BASIC F2 LADDER Ladder Mnemonic Const Device C 200 Dim A As Integer A habl2 Debug Hpf A 6 Cr Debug Hp A 8 1 Fix Right Side 125 FP value wholeNumberDigits fractionalNumberDigits FP converts floating point variables into a formatted string with user defined whole and fractional number of dig
123. This command sets the dot size used when drawing lines and shapes Value sets the size of the dot and style makes the dot either rectangular 0 or circular 1 DotSize 1 1 Set dot size to l and dot style to circular 288 289 Paint Paint x y This command fills the area enclosing x y Paint 100 100 Fill the area enclosing 100 100 Arc Arc x y r start end This command draws an arc x y specifies the arc s center r specifies the car s radius start specifies the angle at which to start drawing and end specifies the angle at which to stop drawing Are TSO L507 100 200 290 Draw an arce from 200 to 290 degrees 290 239 DefChr DefChr code data code Custom character code amp hDB30 to amp hDBFF data 32byte bitmap data This command creates custom characters A character of size 16x16 pixels can be created and stored in the LCD memory Then the character can be used just like any other regular character using the Print or GPrint and DPrint A total of 207 custom characters can be stored in the memory The characters are not preserved when powered off DefChr amp HDB30 amp HAA amp HAA amp HAA amp HAA amp HAA amp HAA amp HAA amp HAA _ amp HAA amp HAA amp HAA amp H55 amp HAA amp HAA amp HAA amp HAA _ amp HAA amp HAA amp HAA amp HAA amp HAA amp HAA HAA amp HAA _ amp HAA amp HAA amp HAA amp HAA amp HAA amp HAA amp HAA amp
124. V and 12V RS 232 signals O max232 116 O 15 1 2 3 1 14 Rs232c output 4 43 RS232C INPUT 5 vor 12 TIL OUTPUT 6 11 TTL INPUT RS232C OUTPUT 7 J 10 TTL NPUT RS232C INPUT 8 1 9 Ttrourrur 309 CUNET CUNET is a communication protocol for Cubloc peripherals such as the CLCD GHLCD CSG modules With just 2 pins SCL and SDA up to 127 devices can be communicated with simultaneously CUNET uses Cubloc s 12C protocol to perform the communication To use CUNET please be sure to add pull up resistors 4 7K each to the SCL and SDA lines SCL and SDA pins are in an open collector configuration protecting against outside noise It automatically removes pulses less than 50ns SOUT SIN ATN VSS VIN VSS RES VDD PO P15 GND P1 P14 5V RESET P2 P13 SCL P3 P12 SDA P4 P5 P6 P7 P11 P10 P9 P8 4 7Kohm x 2 When using CUNET the connector s pin 1 must be connected to ground pin 2 to 5V or RESET pin 3 to SCL and pin 4 to SDA This 4 pin configuration is standard for all CUNET interfaces When using CUNET the Cubloc core module will act as the master and the connected device will act as as the slave All CUNET devices will respond to the Cubloc while in an idle state CUNET is a master slave protocol Slaves cannot initiate communication with the master For externally initiated communication you must use PAD communication PAD can receive inputs from other external devices without the need for th
125. WE 14000 Dim SF As Sering 15 ST Float F1 0 First store in a SEring ST Left ST 3 Convert to 3 decimal places Debug ST Ur Shale lt CUBLOC studio d cubloc_test format cul File Edit Device Run Setup Help 8509480 4 gt umma Ba FI BASIC F2 LADDER Ladder Mnemonic Port Baud Rate Parity Data bts ax i i Const Device CB280 com 115200 y none Y fs v arx Dim F1 As Single Fl 3 14 l Debug Float F1 3 140000 Close I Fix Right Side You can also store a value in string before printing with Debug statements or displaying to the LCD as shown below lt 2 CUBLOC studio d cubloc_test format cul File Edit Device Run Setup Help 89374850 A miS FI BASIC F2 LADDER Ladder Mnemoni Const Device CEZ00 Dim F1 As Single Dim 1 As String 12 Fl 3 14 sl Float Fl Debug 51 A Terminal e ES Baud Rate Parity Data Bits TX 1a ll z s200 None le RK 3 140000 Close I Fix Right Side 123 String Functions String functions are provided to assist the user in accessing and modifying data within a String DP value numberOfDigits zeroPrint DP converts a variable into a decimal string representation If ZeroPrint is set to 1 zeros are printed instead of blank spaces Dim A as Integer Debug DP A 10 0 Convert A into decimal String representation Set display decimalPlaces to 10
126. Write Please refer to Chapter 9 for detailed description of Modbus with ASCII and RTU examples The return interval is Cubloc s delay time for responding to the master Modbus device If the return interval is set to be too fast the master device might not be able to receive all data The default setting is 1 which is about 200 micro seconds A value of 100 is about 4 5ms and a value of 255 is about 11ms 227 Set OnGlobal Set OnGlobal On OFF OnGlobal is On by default This command turns on or off the ability to process ALL interrupts When OnGlobal is set to off and then set to On all interrupt settings in effect before OnGlobal was set to off will be still be in effect Set OnGlobal Off Turn ALL interrupts OFF If you don t use any interrupts you can turn off all interrupts using Set OnGlobal Off to increase Cubloc s execution speed 228 Set OnInt Set OnIntx On Off x 0 to 3 External interrupt channel At power on Set OnIntx is On by default This command turns on or off the ability to receive individual external interrupts x corresponds to the interrupt number supported by the device For example OnInt1 is used for interrupt 1 When Set OnIntx is On for a specific interrupt the interrupt service routine ISR set using the On Intx command will be executed when the corresponding interrupt occurs If Set OnIntx is off then the ISR will not be executed when the corresponding external interrupt occurs See
127. a Look in Am Documents y e e Fa My Pictures History Desktop A My Computer My Network lide Files of type CUBLOC Source file cul hd Cancel mm SS ree When opening a file you will only see CUL files CUB files are not displayed but they are in the same folder When you open a CUL file Cubloc Studio automatically opens CUB file The source code can only be saved on the PC Source code downloaded to the Cubloc module can not be uploaded back to the PC When you press the RUN button or IMPORTANT CTRL R Save Compile Download and Execute are all automatically processed Ladder Logic and BASIC both are compiled with one RUN button If an error is found during compilation the cursor will relocate to the error position All Cubloc modules implement code obfuscation By obfuscating the downloaded program data the code is safe from any attempt to read part of the chip s memory and copy the source code 71 Creating BASIC Code You can create BASIC code as shown below Cubloc Studio s text editor is similar to most text editors and performs syntax highlighting of certain commands m R Cubloc Studio c program files x86 comfiletools cublocstudio samples ds1302 cul File Edit Device Run Setup Help DBAS Gee Q oet ao BASIC LADDER I Const Device CB280 Const iorst 7 Const iodio 6 Const ioclk 5 Dim I As Integer Dim adr As Byte High
128. a 219 RSTOU Tian td ads 390 ARTERIA A E ta 475 RTEWiite dass td aa od Such a dates a lin 478 SB Tal al nadaa 431 IO A a aa aa betwee aaah Bay 220 SODIO Fes f ined a dessin adea ia 221 Set DISPARES a 265 A O 224 Set ON aed 225 SEMA di is 226 Set iMOdbUSs A dd 227 Set Onil A E A a 228 SetOn Mt da a Aa decays 229 Set Onladderintiict 0e Ss ae elas ee A ENa i 230 Set OnPad d 231 SENOR Mii AAA ia A eee ia we eee ales 232 SEDO TIMED si A ee cite bes i Sete bh oda Badan Sak Siena coded oe te ets 233 Secta a o deen leds 234 Set Passe itive cia e toch sheila dia o la Tan casa 235 SER ici da eta 238 SERA ii a ican sie 239 SS A A A deve vdeddces Seceu ety cddetuseaeaesaceadeas ty 241 SU di 242 A coved cdedccntteas sausteaecbastssevauwecbescwevsaduceuusedeegerend Dears 390 SHIN a 244 A A O E T 245 Pi A A E A A A td 128 Special iRegisterS stos aio was rata oa ee weg dde tan 434 483 SM a soa desa 246 StEPACCEs weil aid ratas E a A a E AAEE Eds 247 STEPOU Mb a AA EAE 397 SEP ica eas s hese a eas detedade aar O seek wee deuce genase 248 STEPS Ed tia sats EEEE A cc eae elt heed 396 StepStat ec ccsccs tensa A a A A AETA 249 StCPStOPiwencccee seve terme A teenies seeertennie 249 SERING EET cs cece sk elaaus vas seemed ge ot edaa tenacndeldautiwdey ve pane Consens Gare Caceres 90 STRING CA A A O ees as 128 SURING a A A a 128 A EEA E A E E E che aseeehaiceuvenate 280 O A EE E cach T A ANN 252 TADIN an aae lt a a aea E Eaa a EOE S th
129. ad Dim A 10 As Byte Opencom 1 19200 0750 10 GetA2 1 A 20 10 Read until stop character ASCII code 10 is found or 20 bytes have been read 168 GetCrc GetCrc variable arrayName byteLength variable String variable to store results Integer type arrayName Array with data Must be a Byte array byteLength number of bytes to calculate CRC GetCrc calculates a Circular Redundancy Check CRC when using MODBUS RTU Master Mode GetCre will return a 16 bit integer CRC value of the specified array arrayName You can set the number of bytes to use for the CRC calculation from the the array starting at 0 Const Device CB280 OpenCom 17115200737 807 20 Set Modbus 1 9 Dim A 20 As Byte Dim B As Integer RamClear UsePin 0 Out UsePin 9 Out Set Ladder On i NFP OWN 0 ES GetCre B A 6 Store in variable B the CRC for 6 bytes of array A Debug Hex B Cr NOTE Please use byte arrays when using this function 169 GetPad variable GetPad length variable Variable to store results length Length of data to receive Reads length bytes from the pad buffer allocated with Set Pad Const Device CB280 Dim X As Integer Dim Y As Integer Set Pad 0 4 20 Mode 0 Packet size 4 bytes Buffer 20 bytes On Pad GoSub ABC Define ABC as interrupt service routine Do Run forever Loop ABC X GetPad 2 First 2 bytes is the x coordinate Y GetPad 2 Second 2 bytes is y coordinate Debug Dec X Cr Print x c
130. add 124 DP teueeeeeie nat hone aanl eae ende dade ge geemne coe aeaese 286 DUZG rO cet cik i osa dd 157 DWADD odia 418 DWANDoiescccvutenectre tet A A ras 423 DWBENTE A Aa 411 O AE A TATT 416 DW DEC Shi A ide 417 DAA DI AY A EE EEE EE dardo 420 DMN G e a cdas 417 DWINV S a a EE T a aea a A E nE 428 DIM OM A A LEETS 412 DWNEG lt a aia 429 DIOR A A ode Dd 421 DIR Cl aa 426 DIWRER id id 427 BAWA LO EAEE ass 424 DWROR A A a a aE 425 DWSUB wiitccceuentaeliitienesen ioe A da 418 DANDA E m EE E AEE E T E TOTE T 413 DWXOR ca T 422 EEPROM to ia ccd AE E aa aca 159 EERCAG 3 fees cine erir A E 158 EE WRLC lt a ii AT ea etme ela 159 486 Ella a a 284 Ellipse nera a A A 284 FlO Ste te mae A 123 EMOS A e 414 O O ON 279 A enaa ceded i adoted dea thneataaas eens aad iaaa teed 161 E A ea 126 A katel cate ane tele Awl i a a a a belie eS beeea laada tala ua at 163 BRC QO Utes incur A A as 164 Get disacsansncseatece ca versweeeedaledeaars ide 166 CAMA A Be ace the an natn al a 167 A O tients ES a aa E E tases an aE aaa 168 CEAMSE 169 GotPad ui ta e amas 170 A O EEA A E A E EEE E S A 171 Eea A OCAT TTEA A E TAT A AE TEN 172 A A E GE Aa 277 E oTr IA ss EEEE E A EA AT da 285 GMO V aa a as a els 415 LEOR oS L TE a E E T A E 173 GOTO honasan EAE a A AE a A wees E E adian 430 EEEE E E A A S 174 E EI EEEE EEA TE E TAEA A TT AT 295 GPOD merren raer e a ee e a a a A e aN 293 LE d ET aN EEEE EAE A AE T Chute race E T TEATE E 285 ERE KE a PE
131. alibration for CT1721C Store Current Time to CT1820 RTC Last 4 Files Edited Exit Device Menu Download Bitmap to CT1721C Calibrate CT1721C s Touch screen Download Bitmap to CT1820 Calibrate CT1820 s Touch screen Synchronize this PC s current time with the CT1820 s RTC View last 4 files edited Exit Cubloc Studio If a Const Device statement does not exist in your source code you can use the Device menu can create a Const Device statement at the very beginning of your source code If a Const Device statement already exists using the Device menu will simply replace the Const Device statement Run Menu Download amp Run Ladder Logic Run Ladder Logic Stop Reset Ladder Monitor on BASIC Debug Terminal clear CUBLOC flash memory Write enable fuse off Run with Firmware download View Relay Usage View Watch window Check Syntax Menu Download amp Run Ladder Logic Run Ladder Logic Stop Reset Ladder Monitor on Ctrl R F2 Ctrl Fl Explanation Compile BASIC and Ladder Logic download to Cubloc module if there are no errors and restart the program automatically To disable automatic restart please go to Setup gt Studio Option to change Continue execution of Ladder Logic while monitoring Stop execution of Ladder Logic while monitoring Reset the Cubloc module Start Ladder Logic monitoring 75 BASIC Debug Terminal Clear Cubloc s Flash Memory Write enable fuse off Run
132. also the Set Intx command which controls external interrupts Set OnInt0 On Set OnIntl On set Onintl Off Set OnInt2 Off set Onints On 229 Set OnLadderInt Set OnLadderInt On Off At power on Set OnLadderint is On by default This command turns on or off the ability to receive Ladder Logic interrupts When Set OnLadderInt is On the interrupt service routine ISR set using the On LadderInt command will be executed when the corresponding interrupt occurs If Set OnGlobal is off then the ISR will not be executed when the Ladder Logic interrupt occurs See also the On LadderInt command EY CUBLOC studio d WAZ cul Wladderlab4_t cul 1 MEE BEE CwWIAD se EBO rH BSo 6 288 a gt mm ME FI BASIC F2 LADDER Ladder Mnemonic pic 4H al 1 41 491 E Tl Z_ too 10 Wizard ES F4 F5 F6 T FB F9 Fl F12 NOT END Copy F30 INTON 3 00 ae G 2 1 FO Insert 4EO 10 Delete Undo 3 XAT VA Modified Program 1452 Bytes Data 1 y 7 CUBLOC studio d WAZH n2w cubloc 22 0Aaddedabs M ES TRE MAE CHOI SWA SAS TSEHH Badi 8Q A4A n m ME FI BASIC F2 LADDER Ladder Mnemonic Const Device CB280 a Dim A As Integer panc Lear e Debug Terminal oxi Set Ladder On Baud Rate Party DataBits q Port On Ladderint Gosub FROMLADDER com z fris200 z none gt fe zla Do Loop FROMLADDER Debug Dec A CR 0 1 Incr A Return
133. alue B 3 Case Ts lt 1 1 Use lt for logical operations B 3 Case Else se Else for all other cases B 4 End Select Select Case K Case Is lt 10 I less than 10 R 0 Case Is lt 40 CTE less than 40 R 1 Case Is lt 80 R 2 Case Is lt 100 R 3 Case Else R 4 End select 220 Set Debug Set Debug On Off Set Debug is set to On by default You can use this command to control debugging functions in BASIC When you don t need any debugging features you can use this command to turn off all Debug commands instead of modifying every instance of of the Debug command When this command is used no Debug command will be compiled they are simply discarded from the program Debug Command How to When used correctly the Debug command can help the user identify and fix bugs in a program During a program s execution variables can be monitored and verified an LCD can be simulated and do other tasks can be performed to increase development productivity 1 How to Check if program is being reset Sometimes do to programming errors a program can be automatically reset This condition can be verified using Debug Simply put a Debug statement at the beginning of your program such as Debug Reset as shown below Const Device CB280 Debug Terminal Debug Reset Baud Rate _ Parity Dao te ex E COM1 v 115200 yw None vj 8 v RK Do High 0 Delay 200 Low
134. alues are undefined 252 TADIN variable TADIn Channel variable Variable to store results No String or Single channel AD channel number Not Port number 0 to 15 This command is similar to ADIn but returns the average of 10 values read with the ADIn command When working under noisy environments using TADIn could help in obtaining more precise results TADIn is a pre made function Function TADIn num As Byte As Integer Dim ii As Integer ta As Long ta 0 For ir 0 To 9 ta ta ADIn num Next TADIn ta 10 End Function 253 Time variable Time address variable Variable to store results No String or Single address Address of time value 0 to 6 The CT1721C CB290 has an internal Real Time Clock RTC chip You can use the Time and Timeset commands to write and read time values to and from the RTC Time information such as the current time of day day of the week and year can be written to the RTC and read from it in real time If a backup battery is used time is kept current even when the module powers off The following is a chart showing the addresses of the RTC and its corresponding values You cannot use these commands for the CB220 nor CB280 since they do not have an RTC po Second o0tos9 2 digit place i Minute 0to59 2 digit place 1 digit place pa Hour j oOto23 2 digit place 3 Date oto31 2 digit place 1 digit place el p
135. an interrupt service routine ISR The On cosub statement can be used to tell a program to listen for an interrupt and execute an ISR When the interrupt occurs the main program stops execution and jumps to the ISR designated by the ON cosuB statement Once the ISR is finished the Return statement is used to return execution back to the main program INTERRUPT ROUTINE MAIN PROGRAM External key input can occur at any time and data can be received via RS 232 at any time Since the main program cannot wait forever to receive these inputs we need interrupts If a key is pressed or serial data is received while the main program is running an interrupt occurs and the main program jumps to the appropriate ISR While an ISR is running subsequent interrupts of the same type are ignored For example if an RS 232 receive interrupt occurs during execution of previous RS 232 receive ISR the new RS 232 receive interrupt will be ignored On the other hand if a timer interrupt occurs See the on Timer statement during execution of an RS 232 receive ISR it will immediately interrupt the RS 232 receive ISR execute the timer s ISR and then return to the RS 232 receive ISR Interrupt Type Explanation o O S O Initiates an interrupt on a periodic basis Initiates an interrupt when an external input is received Initiates an interrupt when data is received via RS 232 On LadderInt Initiates an interrupt when Ladder Logic requests an interr
136. arity Data Bits CUBLOC studio d cubloc_test string cul I g cul com v i1s200 one fe File Edit Device Run Setup Help Sa SABE 4 gt at Bo F1 BASIC F2 LADDER Ladder Mnemonic Const Device CB280 Dim A As Integer Dim st As String 30 st COMFILE Debug st Cr For A 0 To 12 If st_a A Asc Then st_a A Asc z End If Next Debug st Cr Fix Right Side This feature cannot be used with String arrays 93 About Variable Memory Space In the CB220 and CB280 2KB 2048 bytes of data memory is available However the memory is not dedicated entirely to variables Some data memory is reserved for use by peripherals like the DISPLAY and the RS232 buffers An additional 80 bytes are used for the Debug statement Subroutines functions and interrupt routines when executing also consume data memory especially if they declare local variables Of the available 2048 bytes about 1800 bytes can be used for global variables Space must be reserved for subroutines which may reduce the memory available for global variables However this can often save memory as the local variables will be destroyed after the subroutine completes releasing the memory to be used again When the user creates buffers with SET DISPLAY or OPENCOM data memory will be consumed to allocate buffers Initializing Memory In Cubloc BASIC data memory is not cleared when powered on The user sho
137. ast significant bit to most significant bit Bits on the far left are appended on the far right WROL operates on word values and DWROL operates on double word values Registers that Constants E be used les BKEY WROL DO jp 3 If DO has 8421H the following results Do 0843H al y 424 WROR DWROR WROR d DWROR d This commands rotates the bits in d 1 bit to the right most significant bit to least significant bit Bits on the far right are appended on the far left WROR operates on word values and DWROR operates on double word values Registers that Constants A be used E d BKEY WROR D1 A 1 If D1 has 8421H the following results DoJ A D1 0C210H 425 WRCL DWRCL WRCL arg DWRCL arg Cubloc Studio 3 3 1 and later Shifts arg one bit to the left and fills the carry bit F72 WRCL operates on words 16 bits and DWRCL operates on double words 32 bits BKEY WRCL D1 HA J Usable Constants Registers EE gt Jo jo Example The BEFORE lt poooaona aa CARRY F72 Shift to the left AFTER EEE lt A CARRY F72 f Shiftto the left most significant bit is moved to the carry flag while the least significant bit is populated with a 0 426 WRCR DWRCR WRCR arg DWRCR arg Cubloc Studio 3 3 1 and later Shifts arg one bit to the right and fills the carry bit F72 WRCR operates on words 16 bits and DWRCR operates on double words 3
138. been developing PLC and BASIC controllers since 1997 Leveraging previous experience we are providing a unique product that is powerful flexible and has the best features of both BASIC controllers and PLCs Programmable Logic Controllers Ladder Logic which is a traditional way of programming PLCs for its outstanding reliability and straightforward design cannot easily cope with graphic interfaces and other functions that require complex code In these situations the BASIC programming approach greatly simplifies the work required to implement many complex features Cubloc is able to execute BASIC and Ladder Logic simultaneously through on chip multitasking By sharing data in common memory users are able to integrate both BASIC and Ladder Logic to efficiently take advantage of both programming approaches Cubloc was created for beginners and advanced users alike Its simplified commands and programming tools are an easy way to get started with microcontrollers yet the device is powerful enough to handle serious automation applications with minimal time spent in the programming phase With our Plug N Play displays development boards and relay boards you will be able to put an application together in matter or hours instead of months Comfile Technology Inc Notice The Start Kit or Industrial Kit comes with the latest version of Cubloc Studio at the time the CD was created Please be aware that the software may be upgraded
139. ber If Device 220 Debug CB220 module used endif The above example illustrates how depending on the type of Cubloc Cutouch declared you can decide to include a command in the final compilation of your program Using conditional directives you will be able to write applications for different Cubloc Cutouch modules with just one source file 108 Using the preprocessor directive telseif or else you can create more complex if endif expressions Const Device CB220 Delay 500 Device only returns the decimal number If Device 220 Debug CB220 module used elseif device 280 Debug CB280 module used elseif device 290 Debug CB290 module used elseif device 1720 Debug CT1720 module used endif else may only be used ONCE in an if expression Also you can only compare constants declared with the CONST statement in a if directive ifdef name tendif You can use ifdef to check if a constant was previously defined with a define directive or CONST statment If the constant has been previously defined the statements inside the if endif block will be compiled otherwise they will be discarded define LOWMODEL 0 ifdef LOWMODEL Low 0 endif In the above example since LOWMODEL is defined the statement Low 0 is compiled else elseifdef may be used for more complex expressions as shown below ifdef LOWMODEL Low 0 elseifdef HIGHMODEL High 0 else Low 1 109 en
140. bug Goxy 0 1 dec4 Time 13 Delay 100 Close I Fix Right Side Loop Address 13 will increment its value by 1 every second just like address 10 except when it reaches 65 535 it will reset to 0 Addresses 10 through 13 must be used with Cubloc Studio version 2 0 X and above 255 TimeSet TimeSet address value address Address of time value 0 to 6 value Time value 0 to 255 Use the TimeSet command to store new time values Bit Structure po Second 0to59 2 digit place 1 digit p ace 1 Minute otos93 J 2 digit place 1 digit place 2 Hour 0 to 23 2nd digit 1 digit p place Date 01 to 31 2nd digit 1 digit p place 4 Day_ ots T T P 1 digit place 5 Month 1to12 T J10 itdigit place 6 Year_ 00to99 2 digit place The following is an example showing how to set the time a current time to the debug window Const Device CB290 Dim i As Byte TimeSet 0 0 Sec TimeSet 1 amp H32 Min TimeSet 2 amp H11 Hour TimeSet 3 amp H1 Date TimeSet 4 amp H5 Day of the week TimeSet 5 amp H6 Month TimeSet 6 amp H5 Year Do i Time 6 Debug rear VV Hek ak WY i Time 5 Select Case i Case 0 Debug January Case 1 Debug February Case 2 Debug March Case 3 Debug April Case 4 Debug May Case 5 256 ace ace nd output the Loop Debug Terminal Screenshot Debug June Case 6 Debug July Case 7 Debug August Case 8
141. cable Connector The Download Channel is a 4 pin connector and RS 232 Channel 1 is a 3 pin connector They can be connected to a PC as shown below GND DTR TD RD Download Monitoring GND TD RD RS232 Channel 1 PC SIDE 444 Backup Battery The Cutouch will maintain data in its volatile memory when powered off by using a backup battery If backup is not needed the program should clear the memory at the beginning of the program Use RamClear to clear all data memory at the start of your program The Cutouch comes with a self charging 1 0F super capacitor that can last about a day up to 30hrs You can replace it with a 10 0F super capacitor to extend the duration to about 300 hours 12 5 days Adding a battery can provide additional backup time depending on capacity To add a backup battery please connect to the ports labeled External Battery under the super capacitor not visible when the back cover is in place Const Device CT1720 Dim TX1 As Integer TY1 As Integer TX1 0 TYl 0 Clear just this variable RamClear Clear all RAM In Ladder Logic all registers S M C T and D are retained by the backup battery Register P is cleared by default when the device is powered on If you only want to clear parts of a register rather than all registers use the following method Const Device CT1720 Dim i As Integer For i 0 to 32 Clear only Register MO to M32 Ma 0 Next
142. change By reading the value of this resistance we can determine the temperature A common NTC thermistor resembles a diode With this thermistor we can sense temperatures between 30 and 250 degrees Celsius You can acquire an R T Resistance Temperature conversion table from the maker of the thermistor The following is a diode type 10Kohm NTC thermistor R T conversion chart and table Temperature Minimum Average Maximum 343 pi 1628 130687 134969 po 12087 124903 128936 ps 15619 119406 123207 22 ito61o 114182 117764 pp 23 105846 109216 112592 pa 101313 10493 107675 pp 25 9700 0 100000 103000 26 928313 95725 9864 0 For connecting the sensor to the Cubloc please refer to the following circuit diagram To protect against voltage surges a zener diode is recommended especially if the thermistor is attached to a long probe wire 5 1V ZENER DIODE 0 47uF 1Kohm O 1 CUBLOC A D CHANNEL 0 NTC TH As you can see in the circuit diagram we will be using an ADC Analog to Digital converter to read the voltage across the sensor The A D converter will convert the voltage into a value between O and 1024 The most important part of this application note is the following table which converts the temperature and voltage to an A D value between 0 and 1024 Only some of the temperatures are shown pza i22313 4 4 9594529
143. clared as OUT with the UsePin command will have the corresponding P register s value written to the port s output INPUT REFLASH y LADDER SCAN y OUTPUT REFLASH In BASIC the commands In and Out an be used to control I O ports This method directly accesses the 1 0 ports when reading and writing In order to avoid collisions between the two I O ports should be used in either BASIC or Ladder Logic but not both Once a port is declared with the UsePin command it can only be used in Ladder Logic and cannot be directly accessed in BASIC except through the ladder registers UsePin 0 IN START UsePin 1 0UT RELAY Aliases such as START or RELAY as shown above can be assigned using the UsePin command to improve readability 382 Use of Aliases When creating Ladder Logic using Register numbers such as PO P1 and MO aliases can be used to help simplify programs Po P5 P1 STARTKEY MAINMOTOR Swi H In order to use an alias they must be declared in BASIC Alias M0 MAINMOTOR Alias M2 STATUS1 Alias M4 MOTORSTOP Aliases can be declared using either the UsePin or the Alias commands 383 Starting Ladder Logic Cubloc executes BASIC first To enable Ladder Logic use the command Set Ladder On After this command is executed Ladder Logic will begin running and perform ladder scans every 10 milliseconds If the Set Ladder On command is not used Ladder Logic will not run and no
144. command only works with CB290 Rev B The revision number can be found on the bottom side of the CB290 module The Set Outonly command actually toggles virtual Port 88 to enable the output only pins If your program accidentally uses P88 you will see strange behavior on the output only pins Please do not access P88 in your Basic or Ladder Logic programs 1 21 Vdd 41 61 TUTX1 20022 Vss RX1 420062 TURX1 30023 RES 40024 NA A a 50025 Pa 65 P32 e Input oply SCKP1 6 26 P9_ADC1 70027 3 470067 P34 3 80028 i 48 0 068 P35 4 90029 i i nesr i Output Only 10031 H 120032 i 520072 P39 56 130033 P64 d 530073 P48 140034 A 540074 P49 3 550075 P50 560075 P51 570077 P52 580078 P53 590079 P54 60 80 P55 15 35 160036 170037 180038 190039 200040 PWM4_P90 95 81 NIC 2 9 10 Port Blocks 52 CB400 The CB400 is a package of 108 pins of which 80 can be used as I O ports It has more I O ports than the CB405 but less memory Sout Vdd TXE 410061 TUTXE Sin GND RXE 4 62 THRXE Atn RES C B 4 0 0 NIC 063 AVref Vss VBB Vdd 64 Vss PO P16 ADO AD8 P32 45 0 065 P48 input SCK PA P17 AD1 AD9 P33 46 66 P49 onyt MOSI P2 P18 AD2 AD10 P34 47 667 P50 L MISO P3 P19 AD3 AD11 P35 P51 PWM9 P4 P20 AD4 AD12 P36 P52 PWM10 PWMO P5 P21 AD5 AD13 P37 P53 PWM11 PWM1 P6 P22 AD6 AD14 P38 P54 PWM2 P7 P23 AD7 AD15 P39 P55 RX2 P8 P24 HCNT1 P47 P63 TX2 P9 P25 HCNTO
145. d Writing to an EEPROM Typically EEPROMs store between 0 5 to 64KB of data Data is retained even after powering off For example if you wanted to retain a temperature setting for a temperature controller you could simply store the value of the temperature in the EEPROM in case of a power outage The Cubloc has an internal EEPROM of 4KB This EEPROM can be used to store small amounts of data If a larger EEPROM is needed the 24LC512 can be used to store up to 64KB of data The following example will demonstrate how to access the 24LC32 4KB EEPROM using the I2C protocol Serial EEPROMs usually support either SPI or 12C I2C EEPROM part numbers begin with 24XXXX and SPI EEPROM part numbers begin with 93XXX 24LC32 4 7Kohm Const Device CB220 Dim adr As Integer Dim data As Byte Dim a As Byte data amp ha6 adr amp h3 Set WAC 7 6 Do T2CStart If I2CWrite amp b10100000 1 Then Goto err proc a I12CWrite adr bytel a I12CWrite adr lowbyte a I2CWrite data 358 2CStop Delay 1000 2CStart a I2CWrite amp b10100000 a I2CWrite adr bytel a I2CWrite adr lowbyte 2CStart a 12CWrite amp b10100001 a I12CRread 0 2CStop Debug Hex a cr ADR ADR 1 DATA DATA 1 Loop Cra DIsO CR DS TETTO TA Do Loop This example program will write a number to the EEPROM and read it back When this program runs correctly numbers will increment in the debug window This program can be easily modifie
146. d to support other EEPROMs Note Typically EEPROMs need a delay of about 5ms after a write operation 359 MEMO 360 Chapter 11 Ladder Logic WARNING If you do not use the SET LADDER ON command in BASIC Ladder Logic will not be executed 361 Ladder Logic Basics The following is an example of an electrical circuit with one switch and a lamp If you take out the power the following results If you express the above circuit using Ladder Logic the following results H P9 As you can see Ladder Logic is basically an easy way to model electrical circuits in software The switch corresponds to the input port PO and the lamp corresponds to the output port P9 There are many ways to connect other devices such as timers counters etc The following is an example illustrating OR and AND logic using Ladder Logic 362 In this circuit diagram PO and P3 are ORed and that result is ANDed with P2 If you express the circuit diagram above in Ladder Logic it will be as follows PO P2 Pg 1 FAA 0 P3 In Cubloc Studio the right side is not shown In Cubloc Ladder Logic PO Pi P2 are called Registers 363 Creating Ladder Logic Programs The screen below shows you how Ladder Logic programs are created in Cubloc Studio CUBLOC studio c Wcubloc_testWu3 1018 cul File Edit Device Run Setup Help Bad g XAA att Bia FI BASIC F2 LADDER Ladder Mnemonic Pa 4 4 1 lt mE T al io
147. data byteLength address O to 4095 data Data to write to EEPROM up to Long type values byteLength Number of Bytes to write 1 to 4 Store data in the specified address in EEPROM This is very useful for storing configuration or calibration data Dim A As Integer Dim B As Integer A 100 EEWrite 0 A 2 Store A in Address 0 B EERead 0 2 Read from Address 0 and store in B When writing to the EEPROM it takes about 3 to 5 milliseconds When reading from the EEPROM it takes less than 1 millisecond There is a physical limit of around 100 000 writes to each location within the EEPROM If you are using the EEPROM for data acquisition or data that requires a lot of writes we recommend using a module with battery backup memory such as the CB290 or CB405 instead One alternative is an RS 232 Compact Flash CF or Secure Digital SD memory interface module The following table compares SRAM and EEPROM EEPROM General use Store often used variable Important data that needs to information over a power survive even a backup outage Example daily battery failure Example production counter Product Serial Number 159 EKeyPad variable EKeyPad portblockIn portblockOut variable Variable to store results Returns Byte portblockin Port Block to receive input 0 to 15 portblockOut Port Block to output 0 to 15 EKeyPad extends KeyPad to read up to 64 key inputs Two port blocks are used to read a ke
148. day 0 ojoj oj o DAY ADDRESS 6 year ER These addresses can be used to read and write to the DS1302 Please note that the data is in BCD code format 355 NOTE 8 MCP3202 12 Bit A D Conversion The Cubloc has a 10 bit A D converter For greater resolution meaning greater precision you can use a chip like the MCP3202 The MCP3202 is a 12 bit A D converter that supports the SPI protocol Here we will show you how to implement this 12 bit A D converter into your project c U UCOCUOU Low for data communication I O Explanation Direction Clock signal Data Input Data input from MCP3202 Chip Select I DO Data Output Const Device Const iodi 7 Const iodo 6 Const ioclk 5 Const iocs 4 Dim i As Byte Dim ad As Integer Do Low iocs i amp b1011 seh Sic eres soli 0 iA Data output from MCP3202 ad Shiftinlioclk iodo 3 12 High iocs Debug Dec ad cr Delay 100 Loop 356 The MCP3202 will convert voltage coming into CHO and CH1 to a digital value and retain it SPI communication can then be used to read the value from the MCP3202 The voltage measured on the MCP320 CHO and CH1 pins must not be greater than the voltage supplied to the MCP3202 The result of the A D conversion is displayed in the debug window e a Terminal 5 x Baud Rate DataBis an AM Ed y 115200 frre y fe RX Close TP Fix Right Side 357 NOTE 9 Reading from an
149. di EJ 367 Comments You can enter comments by adding an apostrophe THIS IS SAMPLE PROGRAM PO P3 a You can use a semi colon to drop to the next line For example This is Sample Program Date 24 Sep 2007 Comfile Technology THIS IS SAMPLE PROGRAM DATE 24 SEP 2007 COMFILE TECHNOLOGY PO P3 El 0 368 Ladder Logic Block Copy and Paste You can make a block of ladder logic and copy and paste to different parts of the program Y CUBLOC studio c Wcubloc_testYfu3 1018 cul File Edit Device Aun Setup Help a9334X508 4M att Bo FI BASIC F2 LADDER peas pic AF Ve Al te1 i fer Wizard F3 F6 F feo E E F12 or END ee AE P31 MI WORK_ON TOGLE M2 WORK_OFF TOGLE MPG ON INPUT 0 MPG ON OFF TOGLE M5 MPG ON LED P40 z Modified Program 154 Bytes Data 1001 Click and drag the mouse to select the block you wish to copy Press CTRL C to copy and CTRL V to paste Similar to text editing you can press CTRL X and CTRL V to cut and paste also NOTE Please be aware that the Ladder Logic editor does not support undo 369 Monitoring Cubloc Studio supports real time monitoring of Ladder Logic C lick Here Ban SG ABB A gt nar a El Status of contacts that are ON will be displayed in green Timer and counter values will be displayed in decimal The monitoring speed can
150. dif ifndef name endif ifndef is the opposite of the ifdef directive If a constant has not been defined the statements inside a ifndef endif block will be compiled otherwise the statements will be discarded define LOWMODEL 0 ifndef LOWMODEL Low 0 endif telseifndef and else may be used for more complex expressions as shown below ifndef LOWMODEL Low 0 elseifndef HIGHMODEL High 0 else Low 1 endif Finally the directives may be mixed as shown below if MODELNO 0 Low 0 elseifdef HIGHMODEL High 0 else Low 1 endif Nested if directives are not supported if may not be used inside another if 110 To Use Only Ladder Logic If you do not need to use BASIC you can program in Ladder Logic alone But you will need a few lines of BASIC to get started as shown below Const Device CB280 Select device UsePin 0 In START Declare pins to use UsePin 1 0ut RELAY Alias MO MOTORSTATE Set Aliases Alias M1 RELAY1STATE Set Ladder On Start Ladder Device model aliases and pin I O mode must be set in BASIC Ladder Logic must be started in BASIC with the Set Ladder On statement To Use Only BASIC Ladder Logic is off as default Set Ladder On If using only BASIC don t use this statement Ladderscan Or this one 111 Interrupts Interrupts are external events that stop a program s normal flow interrupting the program and immediately execute some other subroutine called
151. e Cubloc to initiate communication Please refer to the on Pad command for more detailed information 310 When the device is to be powered from the CUNET bus pin 2 of the CUNET device should be connected to 5V on the main module Power GND GND SCL SDA SCL SDA eeee a lt MAIN CuNET Module Pin 2 of a CUNET device can be connected to RESET on the main module when a separate power supply is powering the CUNET device Active low to RESET causes the Cubloc to reset Power Power ceno le e GND RESET RESET SCL e e SCL SDA lle e SDA MAIN CuNET Module CUNET cables can be up to 3 feet in length For longer distances up to approximately 1 mile he Phillips 12C long distance interface chip P82B96 or P82B715 can be used 311 Cubloc Study Board Circuit Diagram The Cubloc Study Board is useful for first timers and developers of the Cubloc Simple experiments can be created using switches LED RS 232 communication 12C piezo ADC toggle switches and LCDs 1 RS232 CH1 Contact 2 CB280 TX RX PIEZO Contact Download Port Reset Switch Contact LED S Ws 3 ALCD Connector 1 0 Ports Contact rror lola altea CuNET
152. e RS 232 communication The Cubloc has 2 or 4 channels for RS 232C communication depending on the model Channel 0 is typically used for monitoring and downloading but it can also be used for RS 232 communication if monitoring is not needed Downloading will still work regardless You may use any value between 2400 to 230400 but we are recommed one of the following values 2400 4800 9600 14400 19200 28800 38400 57600 76800 115200 230400 For the protocol parameter please refer to the table below a 0 1 1 0 1 1 The following table shows typical settings based on the previous table Parity Stop Bit_ Value to Use 8 None de 8 Even f1 19 Hex 13 8 ODD 1 27 Hex 1B eee ed NONE 0 1 Stop Bit Reserve 1 2 Stop Bits Even Odd tou dei 7 NONE EA PE ECO 7 obo 1 26 Hex 1A OpenCom 1 19200 3 30 20 Set to 8 N 1 201 The send and receive buffer size can be set with the OpenCom command Each buffer can be as large as 1024 bytes but be aware that the send and receive buffers consume data memory So the larger the buffers the fewer number of variables can be used in the program Receive buffer sizes from 30 to 100 and send buffer sizes from 30 to 50 will suffice for most programs For the CB220 module pins 1 and 2 can be used for channel 0 Ports 10 and 11 can be used for channel 1 CHANNEL O TX SOUT RX gt SIN aaa o
153. e Set Debug Off command at the very beginning of the BASIC program NOTE While using the Time Chart Monitor Ladder Monitoring may not be used 371 Watch Point The Watch Point feature is useful when in a long Ladder Logic program two registers cannot be viewed simultaneously in the same screen due to their location in the ladder Two apostrophes are used to add a watch point Examples PO Pi DO CUBLOC studio c Wcubloc_testWu3 1018 cul Elle Edit Device Run Setup Help aJ GASB A att ee FI Basic F2 LADDER Ladder Mnemonic p 4 I Ol 1 1c I I f i l Monitoring f Stop 73 74 P56 P30 JOG LOW MODI 5 JOG X INPUT M18 JOG Y INPUT M19 O JOG Y INPUT M20 JOG Z INPUT M21 O JOG 2 INPUT M22 76 P30 P56 P30 JOG HI MODE JOG HI MODE lu Maa qn Y Modified Program 9602 Bytes Data 101 NOTE To set a watch point it s two apostrophes not a quotation mark that must be used O HH Xu E 372 Options Window A Options AA Ladder Style a 1 1 eee Line Space p Boarder Color C Black White Monitoring Speed Fast J Slow Auto Excute mode Auto Run when download If you select Auto Run when download the program will automatically This can become a problem for machines To precisely control when to reset a program reset itself after downloading
154. e aaa veeneres oF eevee a che ed ec E TAA A 148 DOO vicidciettusesasecannas ER 149 DAD en 150 DEC A A NN 153 Del A a bea deen Gentle 154 DOMO Patada rada boat veadauednaerse loa 155 10 DTZ O A A E E AA N 157 EERSA Jire iii 158 EEWNCE ici A A des 159 EK Y Pi ni 160 TOEREN A E els E E 161 EAN A duet EE NA EO 163 O aE E E ETE EE 164 Geth TOA 166 E ra E E i 167 A AT 168 GOCE rCiviirea e haa a Aa AEKA EEEn aia 169 GetPad o oinnia td 170 GOtStr O E TE 171 GetStr2 Jorge a a Eeay A AE ESA EE TAE 172 GOSU RETU aan a aa a a aa S SE I a ERE An Re 173 GOO a E aaa on 174 CS Joera eaa eSa O 176 AP A 176 HeapElO ama o daa 177 O A Peteeees i tua a cehcanteteidec uate ube e a a i aE 177 Heap We sisi cn dh aiceis cee A sain vos A AA ogee cn cian ges 177 OO oi ia A A oa a Aua 179 LES da aaa 180 A o PEPE EEEE ATEA A IT 180 AN EJ aea a detest apaa vast A AAA 181 I2EReadNA hacian scaler yea A aE AAEN A 182 IZE WI us A A os 183 If Then ElSelf ENIf ccccccscsceseeseeeeeeeeeeeseseeeeeeeaegenenseseeeeeaeaes 184 O o A 185 OC Sita t oece Seu avatwnadeces cade ce ana tamesanny we 186 TP maS een cetera A A TA TA aca 187 KID A A a IA 188 Key INM enk oiana dr A tenga waned abe 189 O O 190 O A adds 191 MemA dr his ad de 192 A A O NO 193 NMOPrsiiitraa oran damas da Dl DIE Da ae ve 194 ONIL ea iaa acia 195 On LadderInt GOSUbiimaniniii a ica 196 le A his cavadeunth svvesei stank asian vocab aa OER Daai dame da eN 198 12 OM TIME
155. e heap address address Heap variable Heap address Read one byte from the heap address address H and store into variable 175 HRead variable HRead address byteLength variable Variable to store results address Heap address byteLength Number of bytes to read constant or variable 1 to 4 Read the designated number of bytes set by length from heap address address and store into variable HWrite HWrite address data byteLength address Heap address data Constant or variable with data whole numbers only byteLength number of bytes to write Store length number of bytes of variable to the heap address address Dim A As Integer Dim B As Integer A 100 HWrite 0 A 2 Write integer A to address 0 B HRead 0 2 Read from address 0 and store in B EERead and EEWrite have same syntax aS HRead and HWrite Function Memory Feature Type EERead EEPROM Retains data during power cycles without EEWrite a battery The EEWrite command takes about 5ms 4KB of available memor HRead SRAM Retains data during power cycles with a HWrite backup battery Without a backup battery data is lost HWrite command takes about 20 micro seconds to execute much faster compared to EEWrite 55KB of available memor 76 1 HeapClear HeapClear Set all 55KB of the heap to zero Heap variable Heap address variable Variable to store results address Heap address Returns 1 by
156. e of them is processing the other is not The following is the CLCD command table Command Example Byte Execution Explanation hex s Time If ESC C 1B 43 2 15mS Clear screen A 15ms delay must be executed after this command the Cursor On Default LESC s 1B73 2 Cursor Off EsC B 1B42 2 Backlight On Default esco 1B6e2 2 Backlight Off esc H of 1B48 2 Locate 0 0 Change the position of the cursor NES Character codes 8 through 15 are D 8byte 8bytes 8 custom characters that the user is free to create and use Pt OT Move to beginning of row 1 pa o2 1 Move to beginning of row 2 3 o3 J4 Move to beginning of row 3 a 1 Move to beginning of row 4 data received is not a command the CLCD will display it on the screen When using RS 232 the maximum baud rate settings for 12V 4 pin levels is 38400 For TTL 5V levels 3 pin a baud rate up to 115200 can be used The following is an example of code using the CB280 to connect to a CLCD module using the CUNET protocol When you execute this program the CLCD will display incrementing numbers Const Device CB280 Set Display 2 0 1 50 Set the SLAVE ADDRESS to 1 by manipulating the DIP switch Dim i As Integer Delay 100 t Delay for start up ot CLCD Cls Delay 200 Delay for initializing and clearing CLCD Gicoara fasta Locate 5 2 prine MSheewaie Er Delay 500 Cil 268 Delay 100 Do Tack ab
157. e used Refer chapter 13 for more information P10 P26 PWM6 P11 P27 PWM3 PWM7 P12 P28 PWM4 INTO PWM8 P13 P29 PWM5 INT 1 P14 P30 INT2 P15 P31 INT3 The following describes all pins excluding I O ports Name Pin No I O Description SOUT 1 OUT SERIAL OUTPUT for DOWNLOAD SIN 2 IN SERIAL OUTPUT for DOWNLOAD ATN 3 IN SERIAL OUTPUT for DOWNLOAD VSS 4 22 POWER IN GROUND 64 VDD 21 44 POWER IN Supplies 4 5V_ to 5 5V HAD_Vre 43 IN Supplies reference voltage to the16 bit f ADC AVREF 63 IN Supplies reference voltage to the10 bit ADC VBB 24 POWER IN Battery connection pin for battery backup RES 23 IN RESET pin TTLTXE 61 OUT RS232 to TTL232 conversion circuit TX connection terminal TTLRXE 62 IN RS232 to TTL232 conversion circuit RX connection terminal TXE 41 OUT RS232 output terminal connects with 60 external RS232 port RXE 42 IN RS232 external RS232 port input terminal connects with he following describes the I O ports listed by their port blocks Block Name Pin I O Special Description No Function PO 5 1 O SPI s SS P1 6 Input SPI s SCK Input only pin P2 7 Input SPI s MOSI Input only pin 0 P3 8 Input SPI s MISO Input only pin P4 9 1 O P5 10 1 O PWM CHANNEL
158. each other on the same rung On the third rung in the example above when either PO or P1 is ON P5 will be ON When two or more AND or OR operations are used on a single rung as illustrated in the following example it is called a BLOCK AND or a BLOCK OR BLOCK AND PO P2 y P5 H4 I C Po P2 PS HH PI P3 o Fir BLOCK OR 389 SETOUT RSTOUT SETOUT turns a register ON and holds it on even if its input condition changes Contrary to SETOUT RSTOUT turns a register OFF and holds it OFF even if its input condition changes On the first rung in the example below SETOUT will turn P5 ON when PO turns ON and will hold P5 ON even if PO turns OFF In the second rung of the example below RSTOUT will turn P5 OFF when P1 is ON and will hold P5 OFF even when P1 turns OFF PO SETOUT PS C J P1 RSTOUT P5 C J SETOUT RSTOUT Registers that M F S G T Constants can be used o o 390 DEFCON DEFCON name value Cubloc Studio 3 3 1 and later Defines a named constant DEFCON DATA1 456 1 WMOY DATA1 DO e J DEFCON provides a convenient way to reuse a value within a ladder diagram If the value changes only the constant s declaration the DEFCON statement would need to change Please note you cannot use reserved words as constant names For example DEFCON WMOV 100 is not legal since WMOV is a reserved command name 391 DIFU DIFD DIFU turns an output ON for the duration o
159. ecccecseeteeeseeecedieweeseeneeteetenseeees 343 NOTE 4 Sound Bytes caco cion a tdci 348 NOTES RG Sery Moto ie sstccticead cae deerteie von se a agag tere ba 351 NOTE 6 Digital Thermometer psss osrin aaau raaa Ta 353 NOTE DSISO2A RTCiriicia corras 354 NOTE 8 MCP3202 12 Bit A D COnVerSiOn cceseseeseeeeeeeeeeeeeeeeee eens 356 NOTE 9 Reading from and Writing to an EEPROM ococccncncnncnnnnnro 358 CHAPTER 11 LADDER LOGIC cssssssossossssesscsscsecssssscersorsesecsecsessesecsssesseesersesecsecsscsesess 361 Ladder Logic Basi s iii iia 362 Creating Ladder Logic PrOGramMS omccccoconnnnnnnnnnnnonononannnnaronanannrnns 364 Editing Ladder Logic Text ccccieccieerent ii 366 MONItOFINO MEEA EE A ETE T vean 370 Time Chart MOnItOFN Oisein es aera aa Erea ONE 371 Wate Point drsi nal a da A A a E et actin a 372 REGISTE iii din 377 Ladder Symbols iii A ca neiwutecee ANER 380 USING OS iii ci id ad sess dens ones lanes 382 Use of Alas SS oi a ts Pd aA 383 Starting Ladder Log Cetina a a a 384 Declaring the Device tO USC eect teeter erent idien aiaa 384 Using Ladder Logic Only tess ivtsecectstesveviesdteceeneededeedvererssts deteaivens 385 Ladder Logic C MMmaNd Sian rena ds 386 LOAD HOADN OUT a in a 388 NOT SAND OR ci di de A a teat tie Dn 389 SETOUT RS LOU Ft it tia Seamed ccs aca 390 DEFCON ut a 391 DIFUADIFD a a o a ciar 392 LOOP TS rie 393 MES MESCLR o das 394 EPICA ines 396 MEAN a coa 396 STEPOU ira ashy vies E tad
160. ed relatively high The Cutouch is a complete touchscreen controller featuring both a graphical user interface and direct I O reducing complexity and cost The embedded BASIC language can be used to draw graphics and print characters to the LCD and process touchscreen coordinates BASIC makes it easy to interface to various types of sensors read analog values process text perform mathematical operations and perform custom RS 232 communication tasks that are difficult to accomplish with a traditional PLC Ladder Logic is also available and can execute alongside BASIC to perform sequential processing and real time logic as done traditional PLCs The Cutouch has reprogrammable flash memory for BASIC and Ladder Logic programs An RS 232 serial port is used to download and debug code using a Windows PC but once disconnected from the PC the Cutouch will operate as a stand alone device If you are thinking about developing a device that uses a touchscreen consider the Cutouch The integrated approach saves time and lets you concentrate on solutions instead of problems Comfile Technology Inc 438 What is Cutouch The Cutouch is quite different from traditional touchscreens Traditional touchscreens are not a complete integrated product for solution development They are usually only capable of displaying graphics and capturing touch input Most touchscreens require an external controller in order to affect the real world through I
161. ee makweeedee 134 TADI Dia a E E E E E A A T 253 TAMON a maa an o dl da at a nA EE a 398 TAO Nascde ts ick ck stata teda tea satind sian gegavacnged acts teed adbpedadasth ites a e a a naa a 400 WMO C eace asec cree A le an aka teen ei Ree to aaa 254 TIMES Cts Tomra e ta ld ide 256 TMO N A eee Ava ane AL 398 IND hee exe A hie A A et tke od 433 A tava tutvscevinis EEE aE Decvete saaddcasad daaa A a a teva diacia 401 TON EE chi Sik cesta tamethduniaues T 400 A stele ter Pont Seed dace aha tal ce te Pa ae ie pe aie 258 Us PM A A AAA A dd 259 UTMA X i aa a Ai c abate 260 Mii A A AS Ac 130 Vale o a 130 MA ii Ad Dia Sandee sation vadetue ate ae 130 WADD cut iia Diada sceate admis de 418 Wai A A AEA E a ats 261 Walt Draw inc laci n 453 Wa tives ceeded tents io octets AAA AAA RARE cdta 262 WANDA AA io cad et Ne 413 423 WBCDtssvesencducaris et aa aaa dei aieeti is 409 WBGNiT E E E AE NS 411 WBIN otier nere a iia A Taa 410 WEMP is a A e 416 WDE EREET da AT 417 WD A EEA At EA 420 WINCEotiiacintca atada ii dees tact Meant 417 WINM ihe A A ae ee he 428 WMode ita NA asadas 278 WMO Via at A A ea ee ee eee tad cewek 412 WMUL aca A aS ia tee dn een dates 419 N E E EEE E E daa 429 WOR a sane 421 Word discs 97 T ra E EE ia 426 AAE e EE AAA AE EE E EAT E a E E 427 WRO Lo A A A ia a Ea 424 WROR soc it da a da aa Tad adaa 425 WSUB a O ad Aa 418 WKH Ga aos aaa 413 WXOR arree a A a aa A daa e 422 defiNe s aer a ct ld a 106 Al a nt aia 108 A O
162. el As you can see in above screen device name I O mode alias and other features can be set simply by clicking You can set aliases for registers turn Modbus on and set the Modbus baud rate You can always review the current BASIC code generated in real time by navigating to the Output BASIC code review tab 374 E PLC Setup Wizard Ladder environment edit 7 Const Device CB220 Opencam 1 115200 3 80 20 Set Modbus 0 1 in 4 Qut Usepin 5 Qut Relayout Usepin 6 Qut Soloutl Usepin 7 Out Motorl Usepin 14 Qut Usepin 15 Qut Aliason IMO ABCD M1 CUBLOC M2 RELAY1 IM3 KOREA Aliasoff Set Ladder On Set Count On pountraset 0 o Input 0 Bio Adin 0 Input D 11 Adin 1 Input 14 D 38 COUNT 0 Loop Load Save As Replace Basic Code Cancel To get values for A D PWM or COUNT read from the D registers For ADCO the AD value is stored in D 10 Reading from register D 10 will return the AD value for ADCO To output PWM3 simply write to register D 29 For HIGH COUNT1 simply read from register D 39 If necessary the register for storing and writing values can be changed by modifying the BASIC code When finished making changes click the Replace Basic Code button to produce the final BASIC code Please be aware that any existing BASIC code will be overwritten Changes can also be saved to a file by clicking the Save As button Click the Load button to restore
163. el 1 39 40 Block 3 ADC7 AD Channel 7 4 1 0 55 P30 54 10 P31 53 yo P32 57 yo P33 58 vo P34 59 10 so 10 P36 P37 P38 P39 P40 P41 P42 P43 10 P44 P45 P46 P47 P48 N N N 1 0 4 4 4 4 4 TA AAA OOOO A OOOO OOOO OOOO OOOO OOOO gt eS PO PO LE N OOOO OOOO 4 OOOO AAA RESET Input LOW signal resets Normally HIGH or OPEN id RS232 Channel 1 5V TTL level Data O RES AVDD TTLTX1 4 46 45 44 43 42 41 52 17 VSS 18 33 34 35 RS232 Channel 1 5V TTL level Data Input ADC Reference Voltage SL AVREF 51 37 38 39 0 56 55 54 53 57 58 59 1 2 3 4 8 7 6 5 4 3 2 1 52 17 18 19 33 34 35 9 50 51 P24 P25 _ P265 _ E P28 P29 P30 P31 P32 gt P33 P34 P36 paz P38 P39 P40 par P42 P43 P44 pas P46 P47 pag vss AVDD LAVREF 47 How to supply power to the CB280 and CB380 The CB280 and CB380 do not have an internal 5V regulator you must provide your own 5V power as shown below DC5V SOUT o TTLTX1 SIN o TTLRX1 ATN e AVREF VSS P48 PO o P31 P1 o P30 P2 00 P29 P3 o P28 P4 P32 P5 o P33 P6 ee P34 P7 00 P35 P8 o P36 P9 o P37 P10 o P38 P11 ee P39 Pin 20 and 36 are not used please DO NOT CONN
164. ements a timer that turns arg ON when the input turns ON and remains ON until timeout elapses After timeout elapses arg will remain on regardless of the input Type of Time units Maximum Time Timer TMON 655 35 sec TAMON 0 1 sec 6553 5 sec PO TMON T0 10 e 1 PO TAMON 10 100 1 C J Usable Registers P M F Ss c T OT Y AT B Constants lag jofojojloj lo TO 1sec If the input PO turns OFF the output TO still remains ON 398 co MO TO 1sec After the timeout elapses the output TO will turn OFF even if the input PO remains ON co at TO 1sec 1sec If the input PO turns ON after the timeout has elapsed the output TO will turn ON again po M TO 1sec If the input PO turns OFF and then ON before the timeout has elapsed the output TO will still remain ON only for the specified timeout 399 TON TAON TON and TAON provide the capability to delay the effect of an input changing from OFF to ON for a specified amount of time When the input turns ON a timer begins incrementing from its initial value to the specified value When the specified value is reached the output is turned ON TON increments every 0 01 seconds and TAON increments every 0 1 seconds Type of Time units Maximum Time Timer 655 35 sec TAON 6553 5 sec Hr 1 For TON and TAON there are 2 parameters The first parameter can be any value from TO through T99 and the second
165. enuCheck 4 TX1 TY1 Then lt lt 4 I 3 PulsOut 18 300 Elseif MenuCheck 5 TX1 TY1 Then lt lt 4 O PulsOut 18 300 Elseif MenuCheck 6 TX1 TY1 Then lt lt 4 465 PulsOut 18 300 Elseif MenuCheck 7 TX1 TY1 Then lt lt 4 E PulsOut 18 300 Elseif MenuCheck 8 TX1 TY1 Then lt s ul 9 PulsOut 18 300 Elseif MenuCheck 9 TX1 TY1 Then lt lt 4 PulsOut 18 300 Elseif MenuCheck 10 TX1 TY1 1 Then 0 PulsOut 18 300 End If Locate 3 3 Print HEX4 I Return End INCLUDE CTO05 INC We must place the include command at the end of the code as the generated code is in the form of a subroutine which must come after the End statement in the main program CUCANVAS can be downloaded at www cubloc com CUCANVAS is free to use with Cutouch products 466 SAMPLE 6 This sample demonstrates how to set up a paging and menu system Switching between screens is quite simple Maintain a variable that keeps track which screen is currently being displayed While switching to a new screen always update this variable Use the variable to determine which set of Menucheck tests should be run for a particular screen Subroutines are very useful for compartmentalizing the code lt Filename CT1721treemenu cub gt Const Device CT1720 Ramclear Set Pad 0 4 5 On Pad Gosub ProcessTouch Dim TX1 As Integer Dim TY1 As Integer Dim C
166. er Set the graphic layer 0 1 2 There are 3 layers on the GHLCD GHB3224 series Any of the layers may be used as a graphic layer Graphic commands such as Line Circle and Box Can be used to draw on a graphic layer Normally layer 1 is used for text while layer 2 is used for graphics Layers 2 and 3 have slightly different characteristics We recommend layer 2 for graphics that require a lot of erasing Layer 1 can also be used as a graphic layer In this case you can even erase text characters with graphic commands To set Layer 3 to a graphic layer use the command Layer 3 On Overlay Overlay overlayMode overlayMode Logical mode O OR 1 AND 2 XOR This command determines the drawing logic mode between layer 1 and layer 2 Usually layer 1 is for text and layer 2 is for graphics By using this command the user can specify the overlay mode when layer 1 and layer 2 are displaying on the same position The default is xor which will invert when layer 1 and layer 2 print to the same positions oR will allow graphics on both layers to overlap AND will display graphics only where they overlap 277 Contrast Contrast value value Contrast value 1 to 1024 This command controls the contrast of the LCD Use this command with care the contrast setting is sensitive You will most likely need to adjust the contrast wheel on the back of the LCD after using this command Contrast 450 Light Light value value Backlight
167. er interface structure desired PC INTERFACE 33 Hints for Microcontroller Users Microcontrollers MCU such as the PIC AVR and the 8051 are self contained programmable computers For mass production MCUs can cut costs and reduce the overall product size But one disadvantage is that it can be difficult to learn everything necessary to program an unfamiliar controller The hardware commands and even programming tools vary widely between controller families This can be a drawback for low quantity or frequently modified projects Even experienced engineers can feel that MCU programming is time consuming To make a final product it takes many hours of programming and debugging with an MCU Even after development if bugs arise it can be difficult to update the MCU In comparison Comfile s Cubloc can cut the programmer s development time as much as 20 times and provide an MCU like chip that is upgradeable through an RS232 cable or even through the internet by using an XPORT By providing a way to upgrade the final product s value is increased If you have experience programming with MCUs we guarantee you that development of your final product will be much easier with Cubloc You will be able to spend more time designing the features of your final product instead of spending hours relearning register locations and compiler syntax Having Cubloc hardware on hand means that you can respond immediately to any equipment contro
168. et Display command can only be used once at the beginning of the program Method O Use CUNET CUNET is an implemntation of the I2C protocol that is part of the Cubloc For the CB220 use I O port 8 Clock and I O port 9 Data sout 1 2410 VIN SIN O2 230 vss ATN O3 220 RES vss O 4 210 VDD Po Os 200 P15 P1 g6 190 P14 P2 O7 180 P13 P3 O8 170 P12 P4 do 16D P11 Ps QO 10 150 P10 P6 O 11 140 P9 SDA P7 O12 130 P8 SCL CUNET can be used with displays that support it CUNET does not use baud rate settings it uses slave address settings instead Set Display 2 0 1 50 CLCD Slave address of 1 Send buffer of 50 Although multiple devices can be connected via 12C for CUNET displays only ONE device may be attached 266 CLCD Module On the back of the CLCD a control board is attached This control board receives CuNET signals and prints to the CLCD DIP S W CUNET RS232 5V RS232 The CLCD can also communicate using RS 232 There are two RS 232 connectors one for 3 pin 5V level signals and the other for 4 pin 12V level signals o y ase sen CUNET RS232 5V RS232 Use the CLCD DIP switches to set the 12C slave address The 4 DIP switch is not used 267 ON CuNET and RS 232 communication can both be used If both are connected please make sure when on
169. evices like touchscreens HMI devices and SCADA software most of which now support Modbus In Modbus there are master and slave devices The master provides command while the slave receives and responds to commands The slave can only send data to the master when requested it cannot initiate communication on its own Each slave has a unique address called a slave address The master using those slave addresses can talk to one slave at a time For 1 to 1 connections RS 232 can be used For 1 to N connections RS 485 can be used The master sends messages in units of frames Each frame contains the slave address command data and checksum codes The slave receives a trame analyzes it performs the requested function and responds When responding to the master slaves also respond in frames There are two Modbus transmission modes ASCII and RTU RTU is binary and can be implemented in fewer bytes than ASCII making it a little more compact ASCII uses a Longitudinal Redundancy Check LRC for error checking while RTU uses a Cyclic Redundancy Check CRC The table below shows a Modbus frame in both ASCII and RTU Field Hex ASCII RTU Header colon None Slave Address 0X03 03 0X03 Command 0x01 01 0X01 Start Address HI 0X00 00 0X00 Start Address LO 0X13 13 0X13 Length HI 0X00 00 0X00 Length LO 0X25 25 0X25 Error Check LRC 2 Bytes CRC 2 Bytes Ending Code CR LF None Total Bytes 17 Bytes 8 Bytes 322 ASCIT uses a
170. f one ladder scan when the input changes from OFF to ON Conversely DIFD turns an output ON for the duration of one ladder scan when the input changes from ON to OFF PO P5 F C l E Pi PE pi E n P5 Ela ME SCAN P6 gt 1 SCAN 392 LOOP LOOP label register Cubloc Studio 3 3 1 and later Repeatedly jumps to abel until the value in register reaches O register is automatically decremented with each iteration F1 WMOY 5 DO m m F_on Fi WMOY 0 D1 B pons F_on LABEL NT1 J WINC D1 mt m LOOP NT1 D0 ai J In the example above DO is initialized to 5 This will be the number of times to repeat the loop D1 is initialized to 0 This is the number we wish to change D1 is incremented with each iteration and DO is decremented with each iteration Therefore when DO reaches 0 LOOP no longer jumps to NT1 and D1 will contain the value 5 393 MCS MCSCLR MCS and MCSCLR are used to conditionally execute rungs in a ladder Rungs between MCS x and MCSCLR x are executed only when the input to MCS x is ON If the input to MCS x is OFF the rungs between MCS x and MCSCLR x will not be executed Using this command an block of Ladder Logic can be conditionally executed MCS 0 7 MCSCLA 0 1 In the example above when MO turns ON the rungs between MCS O and MCSCLR are executed normally If MO is OFF P5 and P6 will not be processed MCS numbe
171. fa Ct fo fo WSUB DWSUB WSUB s1 s2 d DWSUB si s2 d These commands subtracts s2 from s1 and store the result in d WADD subtracts word values and DWADD subtracts double word values a La a a Registers sto jo fo fo jo s2 Jo fo Jo Jo la fo follo START WMOY 100 DO l ACTION WSUB DO 5 DI c l In the ladder above D1 will get 95 418 WMUL WMUL s1 s2 d These commands multiply s1 and s2 and store the result in a WMUL multiplies word values Usable M F S C T Constants Registers START WMOW 1234H DO c 1 facon WMUL DO 1234H D1 E 1 In the ladder above the result of 1234H 1234H is stored as the double word 14B5A90H in D1 START DWMOY 123456H DO c 1 ACTION DWMUL DO 1234H D2 1 In the ladder above the result of 123456H 1234H is stored as 4B60AD78H in D2 DO 3456H_ pp 0012H D2 OAD78H_ D3 4B60H p4 _ A EE D5 419 WDIV DWDIV WDIV si s2 d DWDIV si s2 d These commands divide s1 and s2 and store the result in d and the remainder in d 1 WDIV divides word values and DWDIV divides double word values Usable M F S C T Constants Registers ACTION WDIW D0 D2 D4 C 1 1234H AA A ink 611H Oo eee dE DWDIV DO D2 D4 1 Ll 5G78H 2384 7 0C335H 299H EE ES a O 420 WOR DWOR WOR si s2 d DWOR si s2 d These commands l
172. from a saved file 375 Usage of Ladder Register With this feature the aliases of all registers can be seen A great deal of time can be saved using this feature while debugging and developing the final product Go to Run gt View Register Usage to open this window Usage of Ladder Relay IA LA P relay usage P P P P P P P P P P P P P NNNNA 376 Registers CB220 CB280 Registers The following is a chart showing the registers for the CB220 and CB280 Register Name Input Output Register P PO to P127 1 E e w External devices Internal Registers M MO to M511 Internal Registers Special Register F FO to F127 System Status TO to T99 16 bit 1 Word CO to C49 16 bit 1Word Step Enable S SO to S15 256 steps For Step Enabling 1 Byte Data Memory D DO to 99 16bit 1 Word For Storing Data P M and F registers are in bit units whereas T C and D are in word units To access P M and F registers in word units use WP WM and WF respectively Register Name ister Name WP nse to 7 is Register P ee Access Word Word Access a hi E lil Word WPO consists of registers PO through P15 PO is the least significant bit of WPO and P15 is the most significant bit These registers are often used with commands like wmov PO MO FO TO co DO c49 T99 S D99 l P127 F127 NY y 16bit 16bit 1bit 1bit M511 SUR 1bit
173. h SpecificatiONS cocococcnccnncnnonennnnncnnnnnnnnananrnncnnnnnnanennnnss 440 Hardware Requirements occcccoconnnncncnonarononnnnnncnnnnroronnnnnnnnnrnnannns 441 Cutouch DIMENSIONS iii a 442 Cutouch I O Posadas adds ia ade 443 Backup Battery aeinn eed ie An e raana aaa vi eN a AEA E a oi 445 Cutouch Output Ports ca o nEaN as 446 16 Cutouch Input prte a o io 447 Cutouch A D and TTL I O Ports c00ccccccccnnnccnnnnnconnnnncnnnnnncnnnannnnnnnn ns 448 Cutouch jumper amp CONNECtOF oo cece eee eee eee 449 Menu System Library ina a amiini 450 MENUSCOMMAanNS ae iania e aaa las 450 M NU SEE a 451 Men Te eane a a tiaa r aera as 451 Menu CHECK ies rrira ass 452 MenuReverSe coc a da a a cod 452 Men Ci tartelnerassdeasiateneve cerca ieecartcmedpamaae AOR 453 Walt DiAWicsicsasaceaoaaivtavascaseaei ne a da iia 453 Touch Pad Input Examples ii de esaa eed vated ees 455 Cutouch Sample PrograMS ocococccnccccononnnnanancnnnoronnanananenonaranannnes 457 CHAPTER 13 CB405SRT icssocsccessctocseassossseceessocestencoseavececsstdvasedeossneensnssoscseegesnocseceesssoscentecteceses 473 CBAOSR Tad diac o a Ai a 474 CB405RT Related COMMANdS ococococonononnncnnononononanancncnnrnnnnnrnnnnns 475 RAKS LT ie aida 475 RTEWIE A a 478 HAD iii A an 479 HADIMN2Z Ti do 480 Appendix A ASCI CODE cita dpi 481 Appendix B Note for BASIC STAMP USOTS oococococononnnnnnncnnannronannns 482 Ladder Logic Special Registers sneren susiranda e pahiya ioniy 483
174. he binary number and an H at the end for hexadecimal numbers To clearly identify that a hexadecimal value is a number we can put a 0 in front of the hexadecimal number E g OABH OA1H OBCDH BASIC is slightly different from Ladder Logic in the way binary and hexadecimal numbers are expressed amp B100010 is used for binary and amp HAB is used for hexadecimal 408 WBCD WBCD s d Cubloc Studio 3 3 1 and later Converts the 16 bit binary value in s to a BCD Binary Coded Decimal value ans stores the result in d F3 WMOV 1234 D0 1 C ma J F_POR F2 WBCD D0 D2 DO D2 Pa C wm 1 moa mam F_init Values shown are in hexadecimal Usable Registers P M F s c T D vY A 6B Constants o o isd f fofo 1234 ee 04D2H 409 WBIN WBIN s d Cubloc Studio 3 3 1 and later Converts the 16 bit BCD value in s to binary and stores the result in d Va F3 WMOY 1234H D2 A eL 1234 J F_POR F2 WBIN D2 D4 D2 Dd m a mwa 1 1234 aD Finit lues shown are in hexadecimal Usable Constants TIME 4660 D2 12344 gt D4 410 WBCNT DWBCNT WBCNT s d DWBCNT s d Cubloc Studio 3 3 1 and later Counts the number of active bits 1s in s in stores the result in d WBCNT operates words 16 bits and DWBCNT operates on double words 32 bits BIT 15 BITO me ee number of bits is 3 F2 WOW DA4H DO ei mg J F_init Fl WBCNT D0 D2 D2 m _C mg J 0002 F_
175. he interrupt service routine ISR It must require less time to execute than the interval itself If interval is set to 10ms the ISR must execute within 10 ms Otherwise collisions can occur It is quite common for a microcontroller to make use of interrupts but with the Cubloc interrupts should be used sparingly 113 The Cubloc does not handle hardware interrupts directly When an interrupt occurs the handler jumps to the BASIC interrupter Because the BASIC interpreter is slower than directly processed machine code extra latency can be added to the interrupt service routine and prevent the main routine from operating smoothly Therefore we recommend using interrupts sparingly with the Cubloc If interrupts are used keep the interrupt service routine very light and fast For example writing to a serial port or using the Delay command is not recommended If you need a device that can handle interrupts with speed and ease please consider the Moacon The Moacon is an ARM based modular industrial controller from Comfile Technology designed for high speed interrupt intensive applications 114 Pointers using Peek Poke and MemAdr The following is an example that uses the EEWrite statement and the EERead statement to read and write floating point data Const Device CB280 Dim 1 As Single 2 As Single f1 3 14 EEWrite 0 f1 4 2 EERead 0 4 Debug Float f2 cr When you run this program the debug window will
176. high speed counter value pu reaches a set target point COMPARE gt target the processor will set an I O Port to logic low or logic high If targetState is set to 1 and the target number of pulses target have been received the output port port will output logic high Likewise if the targetState is set to O and the target number of pulses target have been received the output port port will output logic low WChamel Compare Range HCOUNT Channel 0 0 to 65535 HCOUNT Channel 1 O to 255 The high speed counter itself supports up to 32 bits but the Compare is limited since this command was designed to not affect the overall multitasking of Cubloc s main processor Note For channel 0 please use the Set Count0 On command before using Compare Dim i As Integer Debug Terminal Port Baud Rate Parity DataBits grx 32 u com 115200 y None fje onx Set Count0 On Compare 0 10 61 1 Do i Count 0 Debug Goxy 0 0 dec4 i Cr Delay 100 Loop The above uses high speed counter channel 0 with a target of 10 pulses When the counter value becomes 11 the output port port 61 will output logic high Fix Right Side 145 Count variable Count channel variable Variable to store results No String or Single channel Counter channel number 0 to 1 Return the counted value from the specified counter channel Please set the counter inpu
177. igh Edge el XXXX Dxxx Triggered Sampling after SCK aaa XXXX x1xx Sampling before 8HOO XXXX XOXX SCK 236 The receiving modes can be added together For example for MSB first High Edge Triggered SCK and sampling after SCK 0x00 0x00 0x04 0x04 Here are some common examples sx IJUUUUUUUL_ amp H 0 0 Sample MSB Bit6 BitS Bit4 Bits Bit2 Biti LSB sx JUUUUUUL amp H 0 4 Sample MSB Bit6 BitS Bit4 Bits Bit2 Biti LSB SCK amp H 0 8 Sample MSB Bit6 Bits Bit4 Bits Bit2 Biti LSB SCK amp H 0 C Sample MSB Bit6 Bits Bit4 Bits Bit2 Biti LSB For pad communications you can use Comfile s keypads and touch screens The Set Pad command will automatically set the I O mode of ports PO through P3 the user doesn t have to set them 237 Set RS232 Set RS232 channel baudRate protocol channel RS 232 Channel 0 to 3 baudRate baudRate Do not use a variable protocol Protocol Do not use a variable You can only use the OpenCom command once to open a serial port Set RS232 is used to change the baud rate and or protocol of a serial port at run time For the protocol parameter please refer to the table below A Stop Bit i 0 NONE 0 1 Stop Bit 1 Reserve 1 2 Stop Bits 0 Even 1 Odd The following table shows typical settings based on the previous table Stop Bit Value to Use 8 NONE 8 Eve
178. in parallel they are all processed as fast as the ladder scan time will allow This allows for a more parallel execution path for unrelated functions PO P2 PS A P3 P5 P6 P8 sC HH As you can see above both A and B circuits are in a waiting state ready to turn the output On as soon as input is turned On For example if input P3 turned On P9 would turn On In comparison BASIC processes code in order a type of Sequential Processing Dim AAs Integer Dim BAs Integer A 0 Jump Again For B 0 to 10 Debug DECA CR A A 10 Loop Next Goto Again These 2 types of programming languages have been used in different fields for a long time Ladder Logic is used in automation controllers such as PLCs On the other hand BASIC and other programming languages such as C and Assembly have been used in PCs and MCUs Whether you are an experienced MCU or PLC user you will be able to benefit by integrating both BASIC and Ladder Logic in your designs 25 Another advantage of Ladder Logic is the ability to process input within a guaranteed slot of time No matter how complex the circuit becomes Ladder Logic is always ready to output when it receives input This is the primary reason why it is used for machine control and other automation fields Ladder Logic is more logic oriented It is not a complete programming language To do complex processes it has its limits For example to receive input from a keypad display to 7
179. indow At any time during development you can remove all Debug statements from the program s compilation by using the command Set OUTPUT 0K COUNTER 11417 Debug Off AC CURRENT INPUT C CURRENT COMFILE TECH 223 Set I2C Set 12C dataPort clockPort dataPort SDA data send receive port 0 to 255 clockPort SCL clock send receive port 0 to 255 The Set 12c command sets the data port SDA and clock port SCL for I2C communication Once this command is executed both ports I O modes become output and their outputs become logic high For I2C communication please use ports capable of both input and output and 4 7K resistors as shown below SCL L_ spa I2C communication requires ports capable of both input and output but some ports are only capable of either input or output Please check the port specifications in the data sheet for the model you are using 224 Set Int Set Intx mode x 0 to 3 External interrupt channel mode 0 Falling edge 1 Rising edge 2 Changing edge This command must be used with the on Int command in order to receive external interrupts The mode of interrupt can be set to trigger on either the falling edge rising edge or changing edge Set Int0 0 Set external interrupt 0 to trigger on the falling edge P35 P36 P37 P38 P39 P7 P23 e INT3 P8 P15 P9 P14 P10 P13 Pi P12 SOUT VDD e TTLTX1 SIN v s e TTLRX1 ATN RES e ANREP vss NIC e Pas Po P16 e P31
180. is able to cover the desired range Byte variables can cover 0 to 255 For larger values a variable with a larger range must be chosen Dim K As Byte For K 0 To 255 Debug Dp K CR Next When using a negative Step please choose a Long variable type if the loop will go below 0 Dim LK As Long For LK 255 To 0 Step 1 This will reach 1 as last step Debug Dp LK CR Next 161 DEMO PROGRAM Const Device CB280 Dim A As Integer For A 1 To 9 Debug Y3 x Debug Dec A Debug Debug Dec 3 A Cr Next Const Device CB280 Dim A As Integer B As Integer For A 2 To 9 For B 1 To 9 Debug Dec A Debug Dec B Debug Debug Dec A B Cr Next Debug Cr Next 162 Debug Terminal Port Baud Rate Party D aBis ry a com fi15200 y None je z rx I Fix Right Side e edo Terminal Baud Rate iat Data Bits BT A com v 115200 zj 8 7 Rrx F Fix Right Side FreePin FreePin I O I O I O port number This command will reassign an I O port back to BASIC if it had previously been assigned to Ladder Logic with UsePin 163 FreqOut FreqOut channel freqValue channel PWM channel 0 to 15 freqValue Frequency value between 1 and 65535 Freg0ut output the specified frequency to the specified PWM channel Please make sure to specify the PWM channel not the I O port number For the CB220 and CB280 ports 5 6 and 7 correspond to PWM Channel O 1 and 2 respectively The following
181. is command to determine which menu button has been touched touchX and touchY are the x and y coordinates of where the user touched the screen If the coordinates of the touch match the coordinates of the button 1 is returned otherwise O is returned If MenuCheck 0 TX1 TY1 1 Then MenuReverse 0 Beep 18 180 End If MenuReverse MenuReverse index index Menu index number This command causes the menu button identified by index to have it s colors reversed This is useful to provide visual feedback to a user indicating that a menu button has been touched Initialize Total cost 452 Menu Variable Menu index position variable Variable to store results 1 selected O unselected index Menu index position Position 0 x1 1 y1 2 x2 3 y2 To find the current coordinates of Menu buttons set using the MenuSet command use Menu function to return the current status of the specified menu 0 will read x2 1 will read y1 2 will read x2 and 3 will read y2 If Menu 0 1 lt 100 THEN 1 TE Menu button 0 s YI is less than 100 WaitDraw WaitDraw This command will wait for a drawing command to finish before resuming execution ElFi 11Y 200 100 100 50 Fill an ellipse WaitDraw Wait until drawing is finished This command is especially useful for animations and if graphics are displayed at a high rate The Cutouch has an internal buffer for receiving graphic commands from the internal Cubloc controlle
182. is command will run in the background independently so system resources can be used for other tasks 248 StepStat variable StepStat Channel variable Variable to store results channel StepPulse channel 0 or 1 Stepstat allows you to monitor how many pulses have been generated since the last StepPulse command StepStat will return double the number of pulses remaining to be generated If there are 500 pulses left to output StepStat will return 1000 You can also check the output status of pulses using _F 56 or F56 in Ladder Logic When channel O is generating pulses _F 56 will be logic high 1 When channel 1 is generating pulses _F 57 will be logic high 1 If no pulses are being generated the F registers will be logic low 0 STEPPULSE CHO F56 STEPPULSE CH1 NI F57 Jl StepStop StepStop channel channel StepPulse channel 0 or 1 The StepStop command immediately stops pulse output on the specified channel 249 DEMO PROGRAM Const Device CB280 Do Do While In 0 1 Loop StepPulse 0 5 5000 300 Do While In 0 0 Loop Loop When the port O switch is pressed port 5 will output 300 pulses at the speed of 5kHz The following is a circuit diagram for the code above CB280 sv 5KHz 130 Pulses 15KHz 300 Pulses Ue 250 A stepper motor controller can be created using a stepper motor and stepper motor driver as shown below CONTROLLER DRIVER POWER GROUND
183. is provided on pins 1 and 2 For the CB220 320 a 5V RS 232 interface id provided on pins 10 and 11 12V sourgi YS apv gt sin g2 I 23b vss ATN 3 f 220 RES 12V vss Qa 210 voD Po gs 200 P15 P1 ge 190 P14 P2 07 180 P13 P3 g8 170 P12 5V Pa g9 160 Pu gt Ps 10 15h P10 lt P6 C 11 EN 141 Pa GND P7 Q12 130 P8 For the CB280 380 RS 232 channel 1 can make use of either 5V or 12V signals but the pins are different For a 5V interface use pins 49 and 50 For a 12V interface use pins 33 and 34 12V 12V 12V 5V 12V vss 4 020 nic P4 s 25 P20 Ps 10 26 P21 Pe ne 27 P22 P7 120 28 P23 Pa 130 29 Pis Po 14 30 pis Pio 15 31 P13 Pun iso 32 P12 Downloading programs to the Cubloc is very easy since the PC s RS 232 interface can connect directly to pins 1 and 2 of the Cubloc For RS 422 and RS 485 5V signals are provided on RS 232 channel 1 308 For the CB280 a 12V RS 232 interface is provided in addition to the 5V interface but only one can be used at a time The following shows a simple circuit diagram to convert a 12V RS 232 interface to a 5V RS 232 interface using a MAX232 chip CuBLOC RX CuBLOC TX The MAX232 is a very useful chip for converting between 5
184. its Dim A as Single A 3 14 Debug Float A 323 1400000 Prints all digits Debug FP A 3 2 t 3 14 Print user defined digits With the FP function the user can control the number of digits to be used for string data when using Debug or displaying to an LCD Sead Terminal Baud Rate Parity Data Bits g 9 ll lt Cubloc Studio d cubloc_test fptest cul a File Edt Device Run Setup Help COMA Eg 115200 Fl rone z fe E Bang ABAM p mr Y F1 BASIC F2 LADDER Ladder Mnemo Const Device CB280 Dim A As Single AH 3 da 3 140000 Debug Float A Cr 3 14 Debug FP A 3 2 Cr Close I Fix Right Side Cubloc floating point values are stored in accordance to the IEEE724 format The output of FP and Float may differ but the value stored in the variable will be the same 126 Left stringValue numberOfCharacters Returns a specified number of characters from the left side of a String Dim STI AS String 12 STI CUBLOC Debug Left ST1 4 CUBL is printed Right stringValue numberOfCharacters Returns a specified number of characters from the right side of a String Dim STIL AS String 12 STI CUBLOC Debug Right ST1 4 BLOC is printed Mid stringValue location numberOfCharacters Returns a specified number of characters from a string starting at a specified location Dim SHUI AS String 12 ST1 CUBLOC Debug Mid ST1 2 4 UBLO is printed Debug Terminal ER For
185. ive the ACK status as shown below A 12CWrite DATA One byte of data transfer takes approximately 60 microseconds Please refer to Chapter 8 About I2C for a detailed description of 12C communications 183 1f Then Elself EndIf You can use If Then Elself Else Endif conditional statements to control execution of your program If Conditionl Then Expression1 Expression2 ElseIf Condition2 Then Expression3 Else Expression4 End If Usage 1 If A lt 10 Then B 1 Usage 2 If A lt 10 Then B 1 Else C 1 Usage 3 If A lt 10 Then When using more than 1 line B 1 do not put any Expressions after Then End If Usage 4 If A lt 10 Then B 1 Else Cc 1 End If Usage 5 Usage 6 If A lt 10 Then Bar If A lt 10 Then ElseIf A lt 20 Then B 1 Gat ElseIf A lt 20 Then End If c 1 ElseIf A lt 40 Then C 2 Else D 1 End If 184 In variable In port variable The variable to store result No String or Single port I O port number 0 to 255 Read the current state of the specified port This function reads the state of the I O port and stores it in the specified variable When this command is executed Cubloc will automatically set the port to input and read from the port You do not need to use the Input command to set the port beforehand when using this command Dim A As Byte A In 8 Read the current state of port 8 and store in variable A 0 or 1 TIP By default all I O ports are
186. kets are 4 bytes each x and y coordinates each get 2 bytes Buffer size is 5 one more than the actual packet size 2 On Pad GoSub abc This command is for PAD interrupt declaration When a pad event occurs the program will jump to label abc 3 This is the interrupt service routine When a pad event occurs this part of the code will be executed until Return GetPad will read the data received from touch pad 2 bytes for the x coordinate and 2 bytes for the y coordinate 4 Draw a circle where touch input was received When this program is executed a circle will appear wherever the screen is touched This program can be used as a skeleton for touch programs 455 The following is an example combining menu and pad commands When a menu button is pressed a beep will sound and the menu button will colors reveresed i DEMO FOR Cutouch Const Device CT1720 Dim TX1 As Integer TY1 As Integer Dim k As Long Contrast 550 Set Pad 0 4 5 On Pad GoSub abc MenuSet 0 2 8 16 87 63 MenuTitle 0 13 13 Start Menuset 1 2 90 16 176 63 Menta lei AS Ena MenuSet 2 2 184 16 264 63 MenuTitle 2 13 13 Restart Low 18 Do Loop abc TX1 GetPad 2 TE GetPad 2 Circlerili TXL TY1 10 f MenuCheck 0 TX1 TY1 Then MenuReverse 0 PulsUut 18 300 Send out beep to piezo End If f MenuCheck 1 TX1 TY1 Then MenuReverse 1 PulsOut 18 300 End If f MenuCheck 2 TX1 TY1 Then MenuReverse 2 PulsOut 18 300
187. l needs flash programmer target board target board MCU engineer s desk CUBLOC engineer s desk 34 Cubloc s Internal Structure BASIC processor Ladder processor BASIC Program Memory BASIC LADDER Data Memory Data Memory The BASIC Interpreter controls a Flash storage area for the user s BASIC programs The Ladder Logic processor also has a Flash storage area for the user s Ladder Logic program I O ports are shared between BASIC and Ladder Logic allowing free access to both BASIC data memory can only be accessed by the BASIC Interpreter while Ladder Logic data memory can be accessed by both the BASIC Interpreter and the Ladder Logic Processor BASIC 1 and Ladder Logic 2 share the same Flash memory The total available memory space is 80KB for some models and 200KB for others BASIC and Ladder Logic can both use up to the entire memory area if needed I O ports 5 can be used both by BASIC and Ladder Logic The user must specify I O ports to use in both languages All I O ports can be used in Ladder Logic or BASIC 35 Cubloc Peripherals PROTO BOARD Series Proto boards for Cubloc can be used for testing and debugging your future products before starting PCB artwork or production These proto boards all include basic power and interface circuits BASE BOARD CUSB Series The CUBASE and CUSB series are especially geared for the industrial field applications Simply attach our Plug N P
188. l nibbles to make processing certain data formats easier LOWNIB Variable s NIBBLE O NIBO to 7 Variable s NIBBLE O to 7 A NIB3 7 Store 7 in Nibble 3 of A cono TTT oo SANO OA NIB7 NIB6 NIB1 NIBO LOWNIB 96 Byte To access specific bytes of a variable the following can be used LOWBYTE BYTEO BYTE 0 of Variable BYTE1 BYTE 1 of Variable BYTE2 BYTE 2 of Variable BYTE3 BYTE 3 of Variable A Bytel HAB Store amp HAB in byte 1 of variable A LONG BYTE3 BYTE2 BYTE1 BYTEO LOWBYTE Word To specify a certain Word of a variable the following can be used A Word is 16 bits LOWWORD WORDO Word 0 of variable WORD1 Word 1 of variable A Wordl amp HABCD Store amp HABCD in word 1 of variable A LONG LOWWORD Tip Need to access 5 bits of a variable NewVariable Variable AND 0x1F This will mask the last 5 bits of the variable DEMO PROGRAM MAR MEE Debug Terminal l El Port Baud Rate Parity Data Bis gtx 2 ll com ris200 hone ls PRX S lt CUBLOC studio d cubloc_test longbyte cul Ele Edit Device Run Setup Help Bang JAAM p mm M FI BASIC F2 LADDER Ladder Mnemonic Const Device CB280 Dim A As Long A amp H12345678 Debug Hex A BYTEO Cr Debug Hex A BYTE1 Cr Debug Hex A BYTE2 Cr Debug Hex A BYTE3 Cr A WORD1 hABCD Debug Hex A Cr T Fix Right Side
189. lace 5 Month itoi2 2 digit 1 digit place 6 Year _ 00 to 99 2 digit place 1 digit place Please refer to the chart below for the weekdays corresponding numerical values Sunday o Saturday J6 254 System Real Time Clock RTC This feature will allow you to use the system timer of a Cubloc as an RTC You can use Time and TimeSet commands to access the following addresses Returning Value O to 59 O to 59 0 to 65535 13 Continuous 0 to 65535 Seconds Address 10 will increment its value by 1 every second When its value becomes 60 address 11 will increment its value by 1 When address 11 s value becomes 60 address 12 will increment its value by 1 When address 12 s value becomes 65535 it will reset back to O At power on all addresses are set to 0 The TimeSet command can be used to set the time at the beginning of user s program The system RTC addresses 10 to 13 s values are stored as raw binary values unlike the CB290 s and CB405 s on chip RTC There is no need to convert the values using BCD2Bin and Bin2BCD The system RTC uses the processor s system timer so there can be a slight time difference lt 1 after a 24 hour period Const Device CB405 Debug Terminal DE Port Baud Rate Parity Data Bits Tx n Dim i As Integer com x 115200 None fs z rx Cis Timeset 10 58 Timeset 13 254 Do i Time 10 Debug Goxy 0 0 dec4 i Cr De
190. lare A as Byte Commas may NOT be used Declare a String of 12 bytes String is 64 bytes default Declare AR as a Byte Array Declare AK as a 2 Dimensional Array Declare a String Array 88 DEMO PROGRAM SZ CUBLOC studio d cubloc_test variable cul File Edit Device Run Setup Help IPE o BB a gt ait O Debug Terminal FI BASIC F2 LADDER Ladder Mnemonic Const Device CB280 Dim A As Byte B As Integer Dim C As Long im D Single Port Baud Rate Parity Data Bits com riszo0 None 5 A 123 B 5000 c 32999000 D 3 14 Debug Dec A Cr Debug Dec B Cr Debug Dec C Cr Debug Float D Cr I Fix Right Side Var Statement Same as Dim Var Can be used in the place of Dim to declare variables Below are examples of how to use Var A Var Byte Declare A as BYTE STI Var Stering 12 Declare STI as String of 12 bytes AR Var Byte 10 Declare AR as Byte Array of 10 AK Var Integer 10 20 Declare AK as 2 D Integer Array ar Var String AO Declare String Array 89 String A String can be a maximum of 127 bytes in size When the size is not declared a default size of 64 bytes will be assumed Dim ST As String 14 For maximum usage of 14 bytes Dim ST2 As String Set as 64 byte String variable When declaring a String as 14 bytes an additional byte is allocated by the processor to store a NULL terminating character When storing COMF
191. lay relays to CUBASE output ports for implementing solenoids limit switches etc With 24V input ports and DIN rail mounting brackets the CUBASE and CUSB series integrate quickly into any automation project For even greater integration the CUSB series contains a switching power supply for direct operation from AC power except CUSB 22D requires 24V power The CUSB modules have integrated relays and optoisolated inputs all accessible through screw clamp terminals 36 STUDY BOARD The Study Board is geared for Cubloc first timers Connections for simple experiments including switches LEDs RS232 communication I2C piezo ADC toggle switches and LCDs are included We recommend the Start Kits which include a study board a Cubloc module all necessary cables and a manual LCD DISPLAY Module CLCD GHLCD Series Various LCD displays are provided for use with Cubloc using the CUNET 12C protocol With one line commands PRINT CLS etc you can easily start printing to an LCD without complex commands Ta AA 0 COMF ILE B come meres CUNET is especially engineered for Cubloc displays therefore we recommend using CUNET supported LCDs for quick and easy development Our Graphic Display GHLCD allows you to download black and white bitmap images to the onboard memory and display them on demand 37 Seven Segment Display Modules CSG Series Seven segment display modules can be easily implemented
192. les that support battery backup of the RAM If you don t use the RamClear command in these modules Cubloc will retain the values in RAM between power cycles 216 Reset Reset Restarts the Cubloc BASIC program from the beginning It does not clear the data memory so any variables that have been declared will retain their values RamClear should be used if this behavior is not desirable 217 Reverse Reverse port port I O port number 0 to 255 Reverse the specified port output logic high to logic low or logic low to logic high Output 8 t Set Bore tO output Low 8 Set output to logic low Reverse 8 Reverse from logic low to logic high 218 Rnd variable Rnd 0 The command Rnd returns a random numbers between O and 65535 The number passed to Rnd has no effect but is required Dim A As Integer A Rnd 0 Internally this function is pseudorandom it creates a random number based on previous values When powered off and turned back on again the same pattern of random values is generated Thus this function is not a true random number generator 219 Select Case Select Case variable Case value value Statement 1 Case value value Statement 2 Case Else Statement 3 End Select If variable meets the value or expression following Case the code beneath Case is executed Select Case A Case 1 B 0 Case 2 B 2 Case 3 4 5 6 Use Comma for more than 1 v
193. matically by the Cubloc RTOS NOTE If you are using an RS232 to RS485 converter and it supports automatic mode then you don t need to use this command Set RS485 1 48 Set P48 as the transmit enable pin TTLTX P48 T L When using the Set RS485 command the port chosen may not be used for other purposes son 1 Please refer to the diagram on the left when connecting multiple Cublocs or Cutouchs using RS485 SN75176B Please use a 120 Ohm terminating resistor for the device at the end SN75176B The two 560 Ohm pull up and pull down resistors are required for proper communication SN75176B 240 Set Spi Set Spi clk mosi miso mode clk port for clock output mosi port for data Master output Slave Input miso port for data Master input Slave output mode communication mode bit 3 O MSB start 1 LSB start bit 2 O wait at clock LOW 1 wait at clock HIGH bit 1 Output sampe point O before rising edge 1 after rising edge bit O Input sample point O before rising edge 1 after rising edge Ex Set Spi 9 8 7 0 Const Device CB280 Dim Dtin As Byte Set Spi ti 70 Dtin Spi Dtout 32 241 Set Until Set Until channel packetLength stopChar channel RS232 channel 0 to 3 packetLength Length of packet 0 to 255 stopChar Character to catch charCheck Optional Whether to use stopChar 0 Check Char default 1 Dont Check Char
194. mbines the Locate and Print commands into one statement CLEDOUL 3 2 COMETEER Print Comfile at position 3 2 Using the Locate and Print command separately can occasionally result in characters being printed to the wrong location The CLEDOUt command was created to address this problem Const Device CB280 Dim I As Integer Set Display 2 0 0 80 Do CLCDOUT 1 1 COMFILE Dec I Incr T Delay 200 Loop This command can only be used with CLCD modules manufactured after December 2010 Users of existing CLCD modules manufactured before December 2010 should contact Comfile Technology for an upgrade This command is not supported by the GHLCD devices After executing this command the Print command s behavior is undefined After the first CLCDOut command is executed CLCDOut should be used exclusively instead of Print from that point on 275 Layer Layer layer1Mode layer2Mode layer3Mode Layer1Mode Set layer 1 mode 0 off 1 on 2 flash Layer2Mode Set layer 2 mode 0 off 1 on 2 flash Layer3Mode Set layer 3 mode O 0ff 1 on 2 flash Set the mode of the specified layer The flash mode will flash the layer at 16Hz When the LCD is powered on layer 1 and 2 defaults to on and Layer 3 defaults to off This command can be used to hide the process of drawing lines circles etc Set the layer to off when drawing then set the layer on when drawing is complete 276 GLayer GLayer layerNumber LayerNumb
195. ments Menus Ele Edit Device Run Setup Help File Menu New Open Ladder Import Save Save As Save Object Print Ladder Print BASIC Print Setup Ctri O Ctrl S Download from object file BMP download for CT1721C Touch calibration for CT1721C BMP download for CT1820 Touch calibration for CT1820 Store Current Time to CT1820 RTC C Program Files x86 ComfileT ools CublocStudio samples ct1721_multiscreen cul C Program Files x86 ComfileT ools CublocStudio samples DS1302 cul C Program Files x86 ComfileTools CublocStudio samples CumotionKeypad cul C Program Files x86 ComfileT ools CublocStudio samples RCSERVO cul Exit Menu Explanation New Create new file Open Open file Ladder Import Import Ladder Logic part of a Cubloc program Save Save current file Save As Save current file under a different name Save Object Print Ladder Print BASIC Print Setup Download from Object 74 Save current program as an object file Use this to protect your source code An object file is a strictly binary format file so others cannot easily reverse engineer it You can use Download from Object File to download an object file to Cubloc Print Ladder Logic section only Print BASIC section only Setup printer for printing Ladder Logic editor Download an object file to the Cubloc module file BMP download for CT1721C Touch calibration for CT1721C BMP download for CT1820 Touch c
196. menu box Select the last button menu box and draw a small box on the screen The O on the button means the menu number is O In the actual screen this number will not be displayed Type 1 in the Title field on the top There is now a 1 button 462 Y Numkey cys CUCANVAS File Edit Generate Tools View Help Deegan a Numkey Use tab key to select neighbor ones El o a o o S A o E A keypad like the one shown below can be created in less than 5 minutes by creating each button in the same way the 1 button was made Numkey cys CUCANVAS DER File Edit Generate Tools View Help DEHE a 2 Numkey Use tab key to select neighbor ones 1 Mumkey Bgo gt 00B OD 5 a Enter 11625 frsssr x wm sex 463 Now for the fun part Simply click Generate on the menu bar and click View Basic Code CUCANVAS will generate a subroutine that includes the buttons just created Simply copy Ctrl C and paste CTRL V this code to Cubloc Studio A complete menu has just been created in a matter of minutes The To Clipboard button will also copy the generated code to the clipboard Real Time Code Generation Ex BASIC Code for CUBLOC SUB NUMKEYO FONT 0 0 STYLE 0 0 0 MENUSET 0 2 190 65 215 90 MENUTITLE 0 9 4 1 MENUSET 1 2 225 65 250 90 MENUTITLE 1 9 4 2 MENUSET 2 2 260 65 285 90 MENUTITLE 2 9 4 3 MENUSET 3 2 190 100 215 12
197. n 1 i19 Hex 13 8 ODD 1 27 Hex 1B oe 7 NONE 7 EVEN f1 18 Hex 12 7 om 1 26 Hex 1A OpenCom 1 T9200 3 30 20 Open Rs232 channel 1 Set R5232 1 115200 19 Change the baud rate amp parity 238 Set RS485 Set RS485 channel portNumber channel RS 232 channel 0 to 3 portNumber Transmit enable port number RS485 allows you to link multiple Cublocs up to a distance of 1 2km With RS485 there must be 1 master and the rest must be slave devices You can use a chip such as the SN75176B or use an RS232 to RS485 converter module With RS485 transmitting and receiving data cannot occur simultaneously RS485 is known for being stable under noisy conditions You can refer to the following circuit schematic for connecting TTL signals from a CB280 to the RS485 chip SN75176B gt 5600 CUBLOC CB280 SN75176B 485 gt 560 2 RS485 communication needs a Transmit Enable signal to control when the device is sending or receiving There can only be one device transmitting while all the other devices are in receiving mode Example When the PC is transmitting all the slave devices can only receive data 223050 Slave Adr 01 Slave Adr 02 Slave Adr 03 239 The set Rs485 command allows the Cubloc or Cutouch to control the data line whenever it wants to send or receive data While the data is being sent the transmit enable pin will output active high This will be done auto
198. n be used to obtain the Cubloc s current status or for timing functions and applications Special Explanation Register Always OFF Fi Always ON Always ON Turn on 1 SCAN time at POWER UP Set Ladder On F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15 F16 F17 F18 F19 F20 F21 F22 F23 F24 F25 F26 F27 F28 F29 F30 F31 F32 F34 F36 F37 F38 F39 F40 m ER F4 FS F6 fs ae ee F9 Fio a 2 Fiz F13 Fla Fis Fi6 F17 Fis F19 Po Far F22 F23 __ F24 F25 FP6 275 F28 F29 F30 F31 F3S2 Pas F36 F37 Fas8 Fs9 F40 434 F67 F_ gt gt Result of WCMP DWCMP F_CARRY F_ZERO 435 Turning F40 ON will create a LadderInt in BASIC Please refer to the On LadderInt GoSub command for details Turning F2 ON causes one ladder scan immediately when the Set Ladder On command is executed in BASIC Reserved registers should not be used 436 Chapter 12 Cutouch Preface The Cutouch is a fully integrated graphical touchscreen device containing a Cubloc embedded computer In recent years touchscreens have found increasing use in the field of industrial automation However most touchscreen devices require connection to an external PLC and require learning yet another complex interface description method In addition the cost of touchscreen interfaces has remain
199. n numbers this command can be used to control each LED segment individually Bit 7 6 5 4 3 2 1 0 leo n e lr Je lb Jc fs la To print an L positions D E and F must be turned on corresponding to but positions 3 4 and 5 Therefore the bit value would be 0011 1000 which in hexadecimal is 8 H38 CSGXPut 0 0 H38 Display an L CSGDec CSGDec slaveAddress data slaveAddress CSG 12C slave address data Decimal value This command prints a decimal value to the CSG CSGHex CSGHex slaveAddress data slaveAddress CSG slave address data Hexadecimal value to display This command prints a hexadecimal value to the CSG 301 MEMO 302 Chapter 8 Interfacing Input Output Circuits How to connect LEDs Connect an LED as shown below and output a logic high to the connected I O port to turn the LED ON 330 ohm CuBLOC 1 O Port How to connect push buttons Connect a push button as shown below and set the connected port s I O mode to input When the button is pressed the Cubloc will read logic high otherwise it will read logic low Las CuBlOC 1 0 Port 10Kohm How to connect a potentiometer Connect the potentiometer as shown below to an A D I O port and use the ADIn command to read the position of the potentiometer 10Kohm 4 O CuBLOC I O Port The Cubloc core module uses 5V power When using a larger voltage please use an appropriate voltage converter or regulator 304 How to C
200. n only be used inside the subroutine DELAYTIME Arrays cannot be declared as local variables Arrays must be declared as global variables 82 Calling Subroutines Once the subroutine is created they can be used like any other statement For a subroutine you do not need parenthesis around the parameters Use commas to separate multiple parameters The example below shows how this is done DELAYTIME 100 Call subroutine End Sub DELAYTIME DL As Integer Dim K As Integer Declare K as Local Variable For K 0 To DL Next End Sub For a function you need parenthesis around the parameters Parenthesis are required even when there are no parameters Dim K As Integer K SUMAB 100 200 Call subroutine and store return value in K Debug Dec K cr End Function SUMAB A AS INTEGER B AS INTEGER As Integer SUMAB A B End Function 83 Subroutine Position Subroutines must be created after the main program To do this simply put End at the end of your main program as shown below End is only required if you have subroutines Dim A As Integer LOOP1 A AS 8 1 Debug DP A CR DELAYTIME Goto Loop1 End End of main program Sub DELAYTIME Dim K As Integer For K 0 To 10 Next End Sub Subroutines and functions are created after the End statement Gosub subroutines must be within the main program like shown below Dim AAs Integer Gosub ABC ABC End Sub DEF B as Byte End Sub Func
201. nels CB220 cB280 cB290 cri7xx cB405 A y A D channel 8 A D channel9 A D 10 A D 11 A D 12 A D 13 A D 14 A D 15 The ADIn statement does a single conversion per call channe channe channe channe channe channe 0232 1 0 34 that returns the average of 10 conversions giving the user more precise If you need more precision rather than speed we recommend the results using TADIn instead of ADIn It is also possible to create your own averaging or filtering code for better precision 134 TADIn iS a macro Alias Alias registerName aliasName registerName Register name such as PO MO TO Do not use D registers aliasName An Alias for the register chosen up to 32 characters Aliases may be given to Ladder registers Aliases can be used to make a program easier to read understand and debug Please note that Aliases although declared in BASIC can only be used in Ladder Logic Alias MO Alias MO Alias PO Rstate Kstate StartSw 135 Bcd2Bin variable Bcd2Bin bcdValue variable Variable to store results Returns LONG bcdValue BCD value to convert to binary Bcd2Bin converts a BCD Binary Coded Decimal number into a normal binary number Cubloc BASIC s default number format BCD is a way of expressing values as decimals For example the number 3451 in binary is as shown below 3451 0000 1101 0111 1011 0 D 7 B The f
202. nes 33 Hints for Microcontroller USEPrS cccsceceeeeeeeeeeee eee eaeeeeeaeeaeneeaeenes 34 Cubloc s Internal Structure ooccococonnnnnncnnnononononnanencnnnnrnn cora nannnnens 35 Cubl c Peripherals ui io ido yee 36 CHAPTER 2 HARDWARE wisscvsscecsnssstsossasessetecestovnsnssacesoosedienenssevencssoavetesenasisvecenenssesesesseasesseceo 39 Hardware Features icc secede hii la dees ee eee ede He eshte eet 40 CBZ Oa aaa a ae a AA a SA EERST ice 4i CB220 CB3 20 niania ie adiad iaia ah KESO EANN a cates 43 Supplying power to the CB220 CB320 000ococccncnnnncncocononanananannnnnos 45 CB280 0B38B0 0 cio a ib 46 How to supply power to the CB280 and CB380 0 0 occcccocnnnnncncnnnnnnnos 48 Boi es 49 A neve de de EEE A anual epee el evi ied ea wed ems inet 53 CBA OS ies vs aonan caus vat acmades inde sete davan diac ahaha daa 57 CBA RM ida ra 60 How to connect a battery to CB290 CB405b 0ococcccnccncnnccnnncnnncnnnnnns 63 DIMENSIONS A r ts Soon dead v ated es 64 CHAPTER 3 CUBLOC STUDIO Wa issscsisesceccestovecsedeossosseccsdnessiceosssventoatonsevscestodesoesesssbosetosensdeevens 69 About CubloG Stud ii A ean seve 70 Creating BASIC Cod rn den 72 D b ggiN g aaa 73 MENUS init ia ton aaa Ea E 74 CHAPTER 4 CUBLOC BASIC LANGUAGE sesesesesesesesesescsesesesesosesososososesesosesososesoseeeseeseessese 78 CubloG BASIC Feat re Sasina a oo 79 Simpl BASIG PO AM ii a as 80 SUD and BUNCUON a AA AAA 81 WATADICS aida etc RA a Ud exe ARA
203. nos 24 TO 80 VDC 5 PWR GND s SIGNAL Jl A SIGNAL GND alo gt gt DISABLE DIRECTION STEP 5 VDC CURRENT SET CURRENT SET Connect 3 Cubloc I O ports to the stepper motor driver The DISABLE and DIRECTION pins are only to enable and set the direction of the stepper motor Please refer to your stepper motor specifications for how many pulses are required to move the stepper motor one rotation 251 Sys variable Sys address variable Variable to store results No String or Single address Address 0 to 255 Use the Sys 0 and Sys 1 commands are used to read the status of the RS 232 buffers for both channel O and channel 1 Sys 0 returns the actual number of bytes written to the RS 232 transmit buffer after executing commands Put or PutStr Sys 1 returns the actual number of bytes read from the RS 232 receive buffer after executing commands Get or Get Str Sys 5 returns the value of the system timer which increments approximately every 10ms The value can only be read not changed The timer will increment up to 65 535 and then reset to 0 This timer can be used in applications that require and extra timer Sys 6 returns the address of the top of the stack in data memory At power on this value is 0 As variables are declared or subroutines and functions are called this value will increase This can be used provide an indication of a program s data memory usage at runtime All other v
204. not overlap Usable Constants as ACTION GMOY DO D10 5 c l The result of the ladder above is shown below NOTE n must be less than 255 415 WCMP DWCMP WCMP argl arg2 DWCMP argl arg2 Cubloc Studio 3 3 1 and later Compares argl and arg2 WCMP operates on words 16 bits and DWCMP operates on double words 32 bits BKEY WRCR D1 HA J Usable Constants Registers argl arg2 Jo fo F3 WMOV 301 D0 DO D2 1 C msomi 00301 00300 F_POR WMOY 300 D2 F2 DWCMP D0 D2 1H 1 F_init F66 MO 1H C F_ lt F73 MI i H t F_zero F67 M2 10 Fa Flags F73 zero flag ON if s1 and s2 are equal F66 less than flag ON if s1 is less than s2 F67 greater than flag ON if s1 is greater than s2 416 WINC DWINC WDEC DWDEC WINC d DWINC d WDEC d DWDEC d WINC increments the word value in d by one DWINC increments the double word value in d by one WDEC decrements the word value in d by one DWDEC decrements the double word value in a by one Usable C T Constants a START WMOY 100 DO mr ACTION WINC DO The result of the ladder above is shown below po 9 all p2 Bl 417 WADD DWADD WADD si s2 d DWADD s s2 d These commands adds s1 and s2 and store the result in d WADD adds word values and DWADD adds double word values Usable M F S C T Constants Registers si T jo fo fo jo s2 OO TO TO
205. ns 12C I2C commands supported 12CRead I2CWrite SPI SPI commands supported shiftIn ShiftOut PAD Keypad touchpad supported 79 Simple BASIC program Below is an example of a simple BASIC program with a Do Loop statement Dim A As Byte Do ByteOut 0 A A A 1 Loop This program outputs the increasing binary value of A to Ports PO P7 The next program uses a function to accomplish the same task Dim A As Byte Do ByteOut 0 A A ADD_VALUE A Loop End Function ADD VALUE B As Byte As Byte ADD VALUE BFI End Function By placing A A 1 in a function the user will be able to separate one big program into small manageable pieces As you can see here the main program ends at the End command and functions are added afterwards MAIN PROGRAM U FUNCTION Sub Program 7 7 m nun S 2 80 Sub and Function For subroutines you can either use Sub or Function Function can return a value but Sub can t Sub SubName Paraml As DataType ParamX As DataType Statements Exit sub Exit during sub routine End Sub Function FunctionName Paraml As DataType As ReturnDataType Statements Exit Function Exit during sub routine End Function To return values using Function simply store the final value as the name of the function as shown below Function ADD VALUE B As Byte As Byte ADD VALUE B 1 1 Return BFI End Function DEMO PROGRAM Debug Terminal EA
206. ns are case sensitive COMFILE does not equal comfile DEMO PROGRAM CUBLOC studio d cubloc_test math1 cul File Edit Device Run Setup Help Dan GABRA gt nt ME F1 BASIC F2 LADDER Ladder Mnemonie Const Device C260 Dim A As Integer Din B As Integer Dim C As Integer 4 10 B 3 c 123 B A Debug Dec C Cr c 123 B FA Debug Dec C Cr Debug Terminal ort BaudRate Parity Data Bits Ox a i P com frtszoo Nore fe l ar T Fix Right Side 104 Expressing Numbers There are three possible ways to represent numbers in Cubloc BASIC binary decimal and hexadecimal The binary and hexadecimal representations are useful when interfacing to digital devices The decimal representation is the standard human readable format Examples Binary amp B10001010 amp B10101 0b1001001 0b1100 Decimal 10 20 32 1234 Hexadecimal amp HA H1234 amp HABCD OxABCD 0x1234 Similar to C 1234 SABCD lt Similar to Assembly Language 105 The BASIC Preprocessor The BASIC preprocessor is a macro processor that is used automatically by the compiler to transform your program before compilation It is called a macro processor because it allows you to define macros which are brief abbreviations for longer constructs Cubloc BASIC uses a preprocessor similar to the C language Preprocessor directives like
207. o RS232C converter Downloading and monitoring is possible when connected to the PC When the Cubloc is disconnected from the PC it goes into a stand alone state The main program is stored in Cubloc s flash memory and will be retained between power cycles Each Cubloc can be programmed and or erased more than 10 000 times CB280 core module with Study Board 32 Hints for Traditional PLC Users For users with much experience in traditional PLCs they will find BASIC to be a completely new language Cubloc is a PLC with BASIC language capabilities added If uncomfortable with BASIC however the user may program using only the Ladder Logic Even a Ladder Logic user may be able to incorporate new features into the final product by making use of BASIC as BASIC offer additional capabilities and flexibility for communicating with other devices besides PLCs To use Cubloc the user does not have to know BASIC If the user does not require LCD display or keypad usage he or she does not need to use BASIC at all and can resort to using only Ladder Logic As you can realize more emphasis on human interfaces is becoming apparent in our industrial world Cubloc is able to overcome the deficiencies and disadvantages of traditional PLCs by being able to use both BASIC and Ladder Logic language DISPLAY KEYPAD E ma gt f We provide many BASIC user interface libraries which you can simply copy and paste to achieve the us
208. ogically OR s1 and s2 and store the result in d WOR divides word values and DWOR divides double word values E e Registers sa T ono or O ego T T T o omo leo d o lo o START WMOV 1200H D0 1 WMOV 34H D1 c l ACTION WOR DO D1 D2 l The result of above ladder diagram 1234H 421 WXOR DWXOR WXOR s1 s2 d DWXOR si s2 d These commands logically XOR s1 and s2 and store the result in d WXOR divides word values and DWXOR divides double word values Usable M F S C T Constants Registers si jo fo fo jo 2 ofoofo qd jojojo tf START WMOYW 1234H D0 J WMOV OFFH D1 J ACTION WOR D0 D1 D2 J The following is result of above LADDER DO D1 D2 When you want to invert specific bits you can use XOR logical operation 422 WAND DWAND WAND si s2 d DWAND si s2 d These commands logically AND s1 and s2 and store the result in d WAND divides word values and DWAND divides double word values Registers that M F S C T Constants may be used sio T fo jo fo jo k sz T T o jo Jo Jo k Ez fe af AA ros Or io it START WMO 1234H D0 c 1 WMO OFFH D1 c 1l ACTION WAND D0 D1 D2 C 1 The results of execution of LADDER above You can use AND operation when you want to use specific bits only 423 WROL DWROL WROL d DWROL d This commands rotates the bits in d 1 bit to the left le
209. ollowing is 3451 converted to BCD code As you can see each 4 bits represent one of the digits 3451 0011 0100 0101 0001 3 4 6 1 This command is useful when the user needs to convert a variable for a device such as a 7 segment display or a real time clock Dim A As Integer A Bcd2Bin amp h1234 Debug Dec A t Print 1234 See also Bin2Bcd 136 BCIr BCIr channel buffertype channel RS232 Channel 0 to 3 buffertype O Receive 1 Send 2 Both Bclr clears the specified RS 232 channel s input buffer output buffer or both buffers Use this statement if your code is about to receive data and there may be unneeded data already in the buffer BCIE 1 0 Clear RS232 Channel 1 s rx buffer iedlie AL Al Clear RS232 Channel 1 s tx buffer BOLE IZ clear RS232 Channel Wiis rX amp tx buffers 137 Beep Beep port length port Port number 0 to 255 length Pulse output period 1 to 65535 Beep is used to create a beep sound A piezo or a speaker can be connected to the specified port A short beep will be generated This is useful for creating button press sound effects or alarm sounds When this command is used the specified port is automatically set to output Beep 2 100 Output Beep on P2 for a period of 100 TS 138 Bfree variable Bfree channel bufferType variable Variable to store results No String or Single channel RS232 Channel number 0 to 3 bufferType O Receive Buffer 1 Send B
210. om 1 19200 0 100 50 On Recv DATARECV_RTN When data is received through RS232 jump to DATARECV_RTN Do Loop iniciales las DATARECV_RTN If BLen 1 0 gt 0 Then If there is at least 1 byte A Get 1 Read 1 Byte End If Return End Interrupt routine 141 ByteIn variable Byteln portBlock variable Variable to store results No String or Single portBlock I O Port Block Number 0 to 15 BytelIn reads from an I O port block a group of 8 I O ports Ports O to 7 are block O and ports 8 to 15 are block 1 The port block numbers vary for the different models of Cubloc When using this command all I O ports within the port block have their I O mode set to input and their input is stored in a variable Dim A As Byte A ByteIn 0 Read from Port Block 0 and store in variable A The CB220 and CB280 port block groupings are shown below Please refer to the pin port tables for the specific Cubloc module you are using souT O 1 2410 VIN sin O 2 23 vss ATN O 3 2210 RES vss 4 210 VDD Po gs5 201 P15 P16 190 P14 P2 g7 180 P13 BLOCK 0 P3 08 170 P12 BLOCK 1 P4O09 160 P11 PS g 10 150 P10 Pe O1 mm 140 P9 P7 g 12 130 P8 sour 1 6 17 voo TX1 330 49 TTLTX1 sin 20 0 18 vss RX1 340 50 TTLRX1 AN 30 019 RES AVDD 350 51 AVREF vss 40 2 Nc N C 36 52 P48 po 50 2 Pie P24 370 0 53 P31 p1 6 22 p17 P25 380 54 P30 3 P2 70 23 pis P26 39 55 P29 0 p3 8 24 P19 2 P27 400
211. on Values shown are in hexadecimal E JP Register S O O 0 d O 411 WMOV DWMOV WMOV s d DWMOV s d The WMOV command moves 16 bit data from s to a DWMOV is used for 32 bit data Usable Constants Register s s Source a pert eto fe START WMOY 100 DO Hr INO DWMOV 1234H D2 l When the input START turns ON DO will get 100 When INO turns ON D2 will get 1234H 412 WXCHG DWXCHG WXCHG s d DWXCHG s d These commands swap data between s and d WXCHG is for swapping word values and DWXCHG is swapping double word values Usable M F S C T Constants Registers ls Toodo START WMOY 100 DO H 1 WMOW 123 D1 EA l INO WXCHG DO D1 l When START turns ON DO gets 100 and D1 gets 123 When INO turns ON DO and D1 swap their data The result is as shown below pop 3 pp 100 p2 Bl Bl 413 FMOV FMOV s d n This command stores s in d n number of times in subsequent memory locations This command is usually used for initializing or clearing memory E EPP aA Registers EST SS ES E E en A eee la Jo Jo fo n O sTaRT WMOY 100 DO c l ACTION FMOV D0 D1 5 c l The result of the ladder above is shown below NOTE n must be less than 255 414 GMOV GMOV s d n This command takes n values starting from s and copies them to d To avoid collisions source and destination memory should
212. ong type value Delay delays program execution for the specified time in milliseconds The Delay command is best used for small amounts of time We recommend not using it for time measurements and other time critical applications as the actual delay time can vary depending on other running tasks Delay 10 Delay for about 10 ms Delay 200 Delay for about 200 ms Delay is implemented as the following subroutine Sub Delay dl As long dll var Long dl2 var Integer For dl11 0 To dl For d12 0 To 1 Nop Nop Nop Next Next End Sub 154 Do Loop Do Loop will infinitely loop the enclosed commands unless Do While or Do Until is used to conditionally terminate the loop An Exit Do statement can also be used within the DO LOOP to exit from the loop Do Commands Loop Dim K As Integer Do K Adin 0 Read AD input from channel 0 Debug Dec K Cx Delay 1000 Loop In the above example the program will loop indefinitely inside Do and Loop An Exit Do or GOTO statement must be used to get out of the infinite loop Do While Condition Commands Exit Do Loop Do Commands Exit Do Loop While Condition Do While will loop indefinitely until the While condition is met Do Until Condition Commands Exit Do Loop Do Commands Exit Do Loop Until Condition Do Until will loop indefinitely until Until condition is met 155 DEMO PROGRAM lt Debug Terminal Port Baud Rate Parity Data Bits
213. onnect an Output Relay The following diagram shows how to connect an output relay to a Cubloc I O port A photocoupler can be used to separate isolate 24V and 5V circuits and protect against noise Noise coming from 24V circuit will not affect the 5V circuit and vice versa Ag Plot 1 1 1N4148 Ko a NS PC 18T1 10K 222 TT y LOAD CuBLOC RELAY 10 Port et How to Connect an NPN TR Output This circuit diagram shows an NPN TR photocoupler separating the 5V circuit from the LOAD 24N CuBLOC 10 Port if aa PC ABT 24N How to Connect a DC24V Input Use a double polarity photocoupler to convert 24V signals to 5V signals When input is received the Cubloc will receive a logic high 5V signal 2 2K 1W CuBLOC i VO Port Q A d T W E 1880 A Sega 270 Nv AN K lt i _ 2 ey 22K KPC714 100 T TIT 5V 305 How to connect an AD Input To connect an AD input to the CB280 the AVDD and AVREF pins must be connected to a 5V source AVDD supplies power to the ADC of the Cubloc and AVREF is the reference voltage that the ADC uses to do conversions If a 5V source is connected to the AVREF pin input voltages from O to 5V will be converted and if a 3V
214. oordinate Debug Dec Y Cr Print y coordinate Return 170 GetStr variable GetStr channel length variable String Variable to store results channel RS 232 Channel length Length of data to receive Same as Get except the variable to store results can only be a String and the length of data is not limited to 4 bytes Const Device CB280 Dim A As String 10 Opencom 17115200 37507 10 Set Until 1 8 10 10 is a required dummy value it will be ignored On Recvl GoSub GOTDATA Do Do While In 0 0 Loop Wait until press button Connect PO Put Stal CUBOS CE Do While In 0 1 Loop Loop GOTDATA A GetStr 1 8 Debug A Return In order to run the program above please connect Rx to Tx as shown below 171 GetStr2 variable GetStr channel byteLength stopChar variable String variable to store results channel RS 232 Channel byteLength Length of data to receive stopChar Stop character ASCII code Same as the Getstr command except it will stop reading data when it encounters stopChar even if the data received is less than byteLength If stopChar is not found then it will operate just like Getstr 172 GoSub Return The GoSub command can call a subroutine The Return command must be used at the end of the subroutine GoSub ADD_VALUE ADD_VALUE A Adr 1 Return 173 GoTo The GoTo command will instruct the current program to jump to a specified label This is part of every
215. parameter can be any numeric constant or data register such as DO Usable T Constants Registers o START TON T0 100 H 1 START TAON T1100 Ton TAON lo jo fo In the ladder above when START turns ON timer TO increases from O to 100 in increments of 0 01 seconds When 100 is reached TO will turn ON Here 100 is equal to a time of 1 second for TON and 10 seconds for TAON 1sec mm start PETT To __ M7 When START turns OFF the timer is reset to its initial value and TO will turn OFF TON and TAON will reset their values upon powering OFF Using KTON and KTAON the battery backup feature can be used to retain the timer s values between power cycles The example below illustrates how to reset TAON 400 i My oe TO E if fe O TOFF TAOFF TOFF and TAOFF provide the capability to delay the effect of an input changing from ON to OFF for a specified amount of time When input turns ON the output turns ON immediately but when the input turns OFF the output is kept ON for the set amount of time and then turned OFF TOFF increases in increments of 0 01 seconds and TAOFF increases in increments 0 1 seconds Type of Time units Maximum Time Timer TOFF 655 35 sec TAOFF 6553 5 sec START TAOFF T1 100 START TOFF T0 100 e l Hooo r l For TON and TAON there are 2 parameters The first parameter can be any value from TO through T99 and the second parameter can be any numeric con
216. penCom 1 19200 0 100 50 PutStr 1 ILOVEYOU CR WaitTx 1 Wait until all data has been sent When this command is waiting other interrupts may be called In other words this command will not affect other parts of the Cubloc system 262 Chapter 7 Cubloc Display Library The Cubloc integrated display functions make it easy to control Comfile LCD products such as the GHLCD or CLCD Drawing lines circles boxes and printing strings can all be done with a single line of code Character LCD CLCD The CLCD products are blue or green LCDs that can display characters and numbers A control board on the back of the device receives data and controls the attached LCD panel The CLCD receives data via RS 232 or the CuNet I2C communication protocol 264 Set Display Set Display type method baud bufferSize type 0 RS 232LCD 1 GHB3224 2 CLCD method Communication method O CUNET 1 RS 232 CH1 baud Slave address when method 0 baudRate when method 1 bufferSize Send buffer size up to 128 This command is used to initialize the display settings It can only be used once All displays will communicate using the method set here This command configures the type of LCD the communication method the baud rate and the buffer size CLCDs will use method 0 Method 1 RS232 Channel 1 This method only supports the use of RS 232 channel 1 for display For the CB220 port 11 TX is used CHANNEL O Tx
217. port DC9V 12V Power Input USB download port X Power source select switch q LED connect with P30 L 0 LED P30 Power LED EE TES Power amp Reset ET i Digital I O ports dx D 2 FuUsMOD x Digital 1 0 ports iE 2 SEG 3 TE or Analog Input ports m ET Connect to LCD 5V level module CLCD RS232 41 Please be aware of the following when using the CB210 e Use Cubloc Studio V3 3 0 and above Cubloc Studio can be downloaded from Comfile Technology s website at http www ComfileTech com A USB Driver is included in the download You must install the USB Driver to use the CB210 Only PWMs 3 4 and 5 are available You cannot use PWM 0 1 and 2 You can use ports 16 to 21 for digital I O e You can use ports 16 to 21 for A D input but you must first configure the ports as input ports For A D input you should supply 3 3V 5V power to AVREF port e The CB210 cannot handle currents over 300mA e An LED is connected to port 30 42 CB220 CB320 The CB220 and CB320 are a 24 pin wide DIP style packages They have 16 I O ports and an internal 5V power regulator The CB220 and CB320 have 6 spare I O ports sout 1 M245 VIN 5 5v 12Vinput SIN 2 23 j vss ATN 3 22 RES vss 4 21 7 VDD SS_ADCO_PO 5 20 P15_HCNT1 Inputonly SCK_ADC1_P1 6 19 P14_HCNTO MOSI_ADC2_P2 7 18 P13 SPAREI O MISO_ADC3_P
218. r If this buffer fills up and data is sent to it the existing data in the buffer can be overwritten In order to avoid these situations use the WaitDraw command to wait until the buffer has enough space before sending graphic commands If graphics need to be drawn repeatedly WaitDraw can be used to prevent overrunning the buffer which may appear as noise on the LCD This command can only be used with the Cutouch 453 454 Touch Pad Input Example Set Pad On Pad and GetPad can all be used to determine which menu buttons were touched by the user All Pad commands are used for receiving and processing touch input We can use On Pad interrupts to capture touch events The following is an example program that uses the touch pad f 1 DEMO FOR Cutouch Const Device CT1720 Dim TX1 As Integer TY1 As Integer Set Pad 0 4 5 1 Activate Touch PAD Input On Pad GoSub abc 2 Declare pad interrupts Do Loop aber TX1 GetPad 2 3 Interrupt Service routine TY1 GetPad 2 Cabim ulevaaalil TXL rY 10 re 4 Draw a circle where it y was touched Return 1 SET PAD 0 4 5 This command will activate the pad inputs Syntax Set Pad mode packetSize bufferSize The Cutouch has a separate touch controller that will sense touch input and send it back to the CPU using the SPI protocol This touch controller will create a pad signal that is equal to mode 0 Most significant bit rising edge sampling Input pac
219. reqValue to musical notes o io 9885 4942 2471 B 18660 9330 ees 2333 po Db 16624 8312 4156 2078 D fis 7846 3923 1961 ll Eb fissia 7405 3703 1851 EFreqout 0 5236 Note A in Octave 4 440Hz FreqOut 0 1469 1 Note G in Octave 5 C DF F G A C D 4156 3703 3144 2774 2471 2078 1851 A 2618 165 Get variable Get channel length variable Variable to store results Cannot use String or Single channel RS 232 Channel 0 to 3 length Length of data to receive in bytes 1 to 4 Read data from the RS 232 port The Get command actually reads from the receive buffer If there is no data in the receive buffer it will quit without waiting for data and return O The Blen command can be used to check if there is any data in the receive buffer before trying to read data The length of data to be read must be between 1 and 4 If receiving a single Byte it would be 1 If receiving a Long it would be 4 For larger amounts of data use GetStr or GetA TIPS Use Sys 1 after Get or Getstr to verify how much data was actually read If 5 bytes are received but only 4 bytes are verified 1 byte is lost Const Device CB280 Dim A as Byte OpenComel 5200773 50 0 On Recvl GoSub GOTDATA Do Do While In 0 0 Loop Wait for a button press Connect PO Put 1 Asc Put 1 Asc But Asc Fut 1b Asc Put 1 Asc Puc 113p HELLO Che 13 Chr 10 Por IL AO iL Do While In 0 1 Loop Loop
220. rn the hyperbolic tangent of B Sqr Return Square Root of a value A Sqr B Return the square root of B Exp Return e A Exp X Returns el Log Log10 Return Log or Log10 of a value A Log B or A Log10 B For the natural logarithm Ln simply do A Log B Log Exp 1 119 Abs Return the absolute value of a Long Dim A As Long B As Long B 1234 A Abs B Return IB Debug Dec A 1 Peint 1234 FAbs Return the absolute value of a Single Dim A As Single B As Single B 1234 0 A Fabs B Return B Debug Float A We 1234 00 Floor Round down to the nearest whole number Dim A As Single B As Single B 3 5 A Floor B os a QIVOS dx Debug Float A Y Bra S510 120 Type Conversion Type conversion can be used to convert the variable to the desired representation Hex Converts the variable to a string representation of a hexadecimal value 16 bit Hex8 means to convert to 8 decimal places 1 to 8 can be used for decimal places Debug Hex A Debug Hex8 A TE A is I2SABC I23ABC is printed If A is 123ABC bb123ABC is printed pis a blank space in this case Debug Hex5 A If A is 123ABC 23ABC is printed first character ds ONE S CUBLOC studio d cubloc_test format cul file Edit Device Run Setup Help Bod AS a gt mu e a FI BASIC F2 LADDER Ladder Mnemonic Const Device CB280 Dim A As Long A H1234 Debug Hex A Cr Debug HEXB A Cr Debug HEX5 A Cr
221. rom the top left corner of the module s internal PCB not the external plastic case X 150 X 2100 Y 1600 Y 1600 id CB290 CB400 X 575 Y 150 X 0 Y 0 Unit 1 1000 Inch Mil X 150 X 2100 Y 1600 Y 1600 d CB405 lt x oo Unit 1 1000 Inch Mil 66 53 50mm 48 30mm Dt mala MADE IN KOREA c 67 MEMO Chapter 3 Cubloc Studio About Cubloc Studio After installing Cubloc Studio and executing it you will see the following screen RB Cubloc Studio cAprogram files BONE File Edit Device Run Setup Help DCE SSeS Qioetaa BASIC LADDER RRilcubioc stuuto e progeam fies 686 comfletools cublocstudio samples esevocul OO MS File Edit Device Run Setup Help DSE S 4a Qiao aa BASIC LADDER a EE lt 7 42 483 TI TL ed ARO HA Search F3 F4 F5 F6 F7 Fa F9 F11 F12 NOT END Insert Delete 0001 E 0002 0003 0004 0005 0006 0007 0008 0009 7 0010 0011 0012 JE x0 Y Modified You will see that at first Cubloc Studio will default to the BASIC editor If you press F2 the screen will change to the Ladder Logic editor and if you press F1 it will switch back to the BASIC editor 70 Source files are saved as two files under the file extensions CUL and CUB If you need to backup or move source files you must keep BOTH of these files together A
222. rs can be assigned from O to 7 MCS numbers should be used incrementally from O to 7 MCS 1 must be nested inside MCS O and MCS 2 must be nested inside MCS 1 When MCS O is OFF none of the MCS s nested inside of MCS O will be executed When the input to an MCS is OFF all outputs within that MCS block will turn OFF timers withing the MCS block will be reset and counters within the MCS block will stop counting The following table describes the behavior of various commands nested within an MCS block When MCSisON henMCSisOFF Normal Operation SETOUT Normal Operation State is retained RSTOUT Normal Operation State is retained Normal Operation Reset to default value State is retained but counting is stopped Commands 394 The following example shows MCS 1 nested within MCS 0 i Mo MCS 0 LHI J i Po P5 l HI C pee MOST l LHI C 1 I PI i PS nt L i MCSCLAI i iL 1 We ee a MCSCLRO T l co l l 2 2 22 222 2 E E SS a J MCS numbers can be used repeatedly but cannot be nested within one another y mo MCB 0 i 1 Ut 1 i l PO P5 I LH i i MCSCLA 0 I I E l I Sy ee eee 1 T 1 HI C 1 l 1P PE l HI l i MCSCLR 0 l y e l i l i l 395 Step Control S Registers are used for step control Step control arguments must follow the following format Relay 0 15 fore 7 126 Step control can be performed in two ways Normal Step and
223. s If Set OnTimer is Off then the ISR will not be executed when the interrupt occurs See also the On Timer command 233 Set OutOnly Set OutOnly On Off The CB290 CT1721 output ports are in a high impendence High Z state at power on in order to prevent the output of data prior to initialization Set OutOnly On must be used to enable the CB290 CT1721 s output only ports Const Device CB290 Set OutOnly On Low 24 Sout 18621 Vdd 410061 TUTX1 Sin 20022 Vss TtIRX4 Atn 30023 RES AVref Vss 406024 VBB MR P ESA SS_PO 50625 P8_ADCO E P32 Input ohly SCK_P1 6 26 P9 ADC1 i P33 MOSI_P2 70627 P10_ADC2 3 P34 MISOP3 80028 P11_ADC3 P35 P4 90029 P12_ADC4 P36 PWMO_P5 10 30 P13_ADC5 P37 PWM1_P6 11 31 P14_ADC6 510071 P38 PWM2_P7 12 32 P15_ADC7 520072 P39 P56 130033 P64 P57 14 34 P65 P48 P49 SCL CUNET SDA CUNET INT3 INT4 82 P89_PWM3 P58 1500 35 P66 QOZLreanyx grag ESO P59 160036 P67 Zaooooooooo0o0000 P51 P60 170037 P68 TNPIVOLDPOLNADA P52 P61 180038 P69 D O W D O 0 D 0 o D D D D O P53 P62 19 39 P70 eee ee P54 P63 20 8 40 P71 e ee 60 80 P55 o aor on 3 3385 8s S SENNO oD S o ON SINIANLERLISES CA ereeeeessessessssssserseeteeeesseesset 1 El xo er 2 EE 23 a EX Output only port CB290 P24 to P55 CT1720 CT1721 P24 to P55 234 Set Pad Set Pad mode packetSize bufferSize mode Bit mode 0 to 255 packetSize Packet size 1 to 255 bufferSize Receive buffer size 1
224. s and Double Words A byte is 8 bits a word is 16 bits and a double word is 32 bits 1BYTE TS SERRE O Pe O a et 1 WORD DOUBLE WORD Memory is divided into bytes so words and double words must be split across multiple bytes Therefore there are two ways to store words and double words Least significant byte first Little Endian or most significant byte first Big Endian Cubloc stores its data in Little Endian In the memory map to the right 1234H is stored in memory address O and 12345678H is stored in memory address 5 Note how 34H the least significant byte of 1234H is stored first in memory address 0 and 78H the least significant byte of 12345678H is stored first in memory address 5 OMNODARWN O The Registers C T D are in word units To store double words data 2 words are required therefore 2 registers are required Below is an example of storing a double word 12345678H D1 gets 1234H and DO gets 5678H DO 5678 D1 1234 D2 D3 D4 407 Binary Decimal Hexadecimal To program well we need to know binary decimal and hexadecimal numbers The following chart shows the relationships between these notations al o ooo o o110 J6 1000 _ 8 1001 9 10 11 1011 B 12 13 1101 pb 14 1110 JE In Cubloc s Ladder Logic we express binary and hexadecimal numbers in the following manner Binary 00101010B Hexadecimal OABCDH We put a B at the end of t
225. s command is used to set a port s I O mode and alias for Ladder Logic programs This is required before the ports can be used in Ladder Logic UsePin 0 In START UsePin 1 Out RELAY UsePin 2 In BKEY UsePin 3 0ut MOTOR Use the FreePin command to return reassign the port back to BASIC 259 UTMax UTMax variable variable Variable to increment No String or Single Increment the variable by 1 until the variables maximum is reached When the maximum is reached the variable is no longer incremented The maximum here refers to the variable s type s maximum value For Byte the maximum would be 255 and for Integer the maximum would be 65535 UTMax A Increment A by 1 260 Wait Wait time time interval variable or constant in milliseconds 10 to 2 147 483 640 Wait for the specified time in milliseconds This command will generate a delay using the system clock This delay function is accurate to 10ms It is much more precise than the Delay command Wait Wait Wait Wait 10 13 110 115 Delay 10 ms Delay 10 ms Delay 110 ms Delay 110 ms 261 WaitTx WaitTx channel channel RS 232 channel 0 to 3 This WaitTx command will wait until the send buffer is flushed Without WaitTx the following is necessary OpenCom 1 19200 0 100 50 PutStr 1 ILOVEYOU CR Do While BFree 1 1 lt 49 Wait until all data has been sent Loop Using WaitTx the process of sending data is simpler as shown below O
226. s command sets the port s I O mode to output and outputs logic low or OV GND Output 8 Set port 8 s I O mode to output LOW 8 Set logic low OV on port 8 When a port is set to logic high the port is internally connected to VDD 5V If it is set to a logic low the port is internally connected to VSS OV This allows either source or sink interfacing to external components up to 25mA for source or sink le vais San 191 MemAdr variable MemAdr targetVariable variable Variable to store results No String or Single targetVariable Variable whose physical memory address should be returned The MemAdr command will return the memory location of the specified target variable This can be useful when used with the Peek and Poke commands operations similar to C pointer manipulation can be performed Dim A as Single Dim Adr as Integer Adr MemAdr A Return the physical address of A MemAdr does not work with arrays 192 Ncd variable Ncd bitPosition variable Variable to store results No String or Single bitPosition Position of bit 0 to 31 The Ncd command is used to return a value with the specified bit set to 1 I Ned 0 Result is 00000001 1 I Ned 1 Result is 00000010 2 I Ned 2 Result is 00000100 4 I Ned 3 Result is 00001000 8 I Ned 4 Result is 00010000 16 I Ned 5 Result is 00100000 32 I Ned 6 Result is 01000000 64 I Ncd 7 Result is 10000000
227. s such as the isolation circuit etc are involved should be added to protect the core module from external noise Keep in mind that especially when a voltage over 5V could be applied to the A D input port repairable damage can occur to the module 480 Appendix A ASCIT CODE Code char Code char Code char Code char 481 Appendix B Note for BASIC STAMP users When using Parallax s Basic Stamp compatible development board please be aware of the following There is a capacitor on the Basic Stamp compatible development boards which may cause a download error in Cubloc Studio Please short or take out the extra capacitor connected to the DTR pin of the board as shown below The Cubloc already has this capacitor on the chip itself VIN vss RES VDD P15 P14 P13 P12 P11 P10 P9 P8 ONDAN Short here 482 Ladder Logic Special Registers IS EE F2 Turn on 1 SCAN time at POWER UP Set Ladder On F3 Reserved i Fam Reserved e J FST Reserved i O po F6 R F7 Reserved o O F8 1SCANeveryi ms_ Fo 1SCANeveryi00ms_ 483 FO F F2 F3 F4 F5 F6 F7 F8 F9 F67 F_ gt gt Result of WCMP DWCMP F72 F_CARRY F73 F_ZERO 484 AM acc tox 133 Als A A A oc 135 AS EEEL IA A AT 389 A hierdie ee Ae Galo 290 A A tick A dice deed et ated adabeads ata acataaekadae AO 131 il sawweses ene odecadshacdsced taeda Gentes atevagaas AKEE da AAAA EEES
228. set to a high Z high impedance input state at power ON When a port is set to output it will either output a high or low signal high is 5V and low is OV or GND ground 185 Incr Incr variable variable Variable to increment No String or Single Increment the variable by 1 Incr A Increment A by 1 186 Input Input port port I O port number 0 to 255 Sets the specified port to a high Z high impedance input state All I O ports of Cubloc modules are set to a high Z input state by default at power on High impedance means that the value of resistance is so high that it s neither high nor low it won t affect a circuit attached to the port Input 8 Set port 8 to a high Z input state 187 KeyIn variable Keyln ort debouncingTime variable Variable to store results No String or Single port Input port 0 to 255 deboucingTime Debouncing time 1 to 65535 The command KeyIn removes the input signal s contact bounce before reading an input You can use KeyIn only with active low inputs as shown below For active high inputs please use KeyInH When a button press is detected KeyIn will return 0 otherwise it will return 1 If you use 10 for the deboucing time the Cubloc will debounce for 10 ms Contact bounce usually stops after 10ms so a 10ms debouncing time will suffice for most applications A KeyIn 1 10 Read from port 1 after waiting 10ms for debouncing Pa Bouncing effect
229. slave address must match The display lave address can be set with the DIP switch 272 Cls Cls Initialize the LCD and clear all layers Set a little bit of delay to give the LCD time to initialize Cis Delay 200 Clear Clear layer Erase the specified layer s Clear 1 Erase Text Layer 1 Clear 2 Erase Graphic Layer 2 Clear 0 Erase all layers Same as CLs CsrOn CsrOn Turn the cursor on Default is OFF CsrOff CsrOff Turn the cursor off Locate Locate x y x x coordinate of LCD y y coordinate of LCD Set the position of the text cursor After the CLS command the LCD defaults to position 0 0 Locate 1 1 Moye cursor to 1 1 Print COMFILE 273 Print Print text text String String variable or String constant containing text to be printed This command prints characters on the text layer To print characters to the graphic layer the GPrint command can be used Locate 1 1 Move to position 1 1 Print COMFILE COMFILE To connect multiple Strings you can use a comma as shown below Print Mine Moi EE Same as PRINT ABCDEFGHI Use CR for carriage return new line Print eslora CR Print California and go to the next line 274 CLCDO ut CLCDOLt x y text x x coordinate of LCD y y coordinate of LCD text String String variable or String constant containing text to be printed The CLCDOut command was added to Cubloc Studio in v3 1 2 This command co
230. sour d1 Y_ 24H vin RX gt sin G2 231 vss amn g3 2210 RES vss 04 210 voo Po Os 20 P15 Pi ge 19D P14 P2 07 180 P13 P3 Os 170 p12 CHANNEL 1 P4 g9 160 P11 TX P5 O 10 150 P10 4 RX Pei i 14D Po P7 012 130 Ps For the CB280 pin 33 or pin 49 can be used Pin 49 outputs a 12V level signal and pin 33 outputs a 5V level signal CHANNEL 1 CHANNEL 0 CHANNEL 1 TX 4 souT 10 617 voo TXT mu 33 49 TILTx1 gt RX gt sin 2 18 vss RX gt RX1 34 50 TTLRX1 ATN 3 O 19 RES AVDD 35 51 AVREF vss 4 20 nc NIC 36 52 Pas po 5 21 Pic P24 37 53 P31 p1 6 22 P17 P25 38 54 P30 P2 70 023 Pis P25 39 55 P29 Pa e 02 pio PWM3 P27 40 56 P28 Pa 9 25 p20 PWM4 Par 41 57 P32 ps 10 26 p21 PWMS5 Pas 42 58 P33 pe 11 027 P22 P45 43 59 P34 p7 12 28 P23 P44 44 60 P35 P8 130 29 p15 P43 450 61 P36 P9 140 O 30 Pis P42 460 0 62 P37 P10 150 31 P13 P41 47 63 P38 pit 160 32 P12 P40 48 64 P39 265 The following baud rates are supported 2400 4800 9600 14400 19200 28800 38400 57600 76800 115200 230400 The recommended buffer size is around 50 to 128 If the send buffer size too small data will not be displayed correctly If the send buffer size is too big it will take up unnecessary memory Set Display 0 1 19200 50 set Baud rate to 19200 and send buffer to 50 The S
231. source is connected to the AVREF pin input voltages from 0 to 3V will be converted DC5V DC5V TTLTX1 TTLRX1 AVREF P48 P31 P30 P29 P28 P32 P33 P34 P35 P36 P37 P38 P39 The CB220 s AVDD and AVREF are internally connected to 5V The following is the simplest AD input circuit using a potentiometer When you turn the knob the voltage will be converted by the Cubloc ADC to a digital value from O to 1023 5V 10Kohm f O CUBLOC I O Port 306 The following illustrates a 4 20mA signal connected to the ADC input port You can use a 230 Ohm and 20 Ohm resistor in series instead of a 250 Ohm resistor 4 20mA CUBLOC I O Port 2500hm For an input voltage from O to 10V use 2 resistors as shown below This is called a voltage divider 1Kohm 0 10V CUBLOC 1 O Port 1Kohm How to use a PWM as Digital to Analog converter The Cubloc has 6 PWM ports If you use a simple circuit like that shown below you can make a digital to analog converter aay 10Kohm Ur CUBLOC PWM Port 47uF i 307 RS 232 HOWTO A PC s RS 232 interface typically use 12V signals while the Cubloc s RS 232 interface uses 5V signals To avoid the need to make a separate circuit to convert the 12V signals from the PC to the 5V signals of the Cubloc and vise versa the Cubloc was built with both a 12V RS 232 interface channel O the download port and a 5V RS 232 interface channel 1 The 12V RS 232 interface channel 0
232. splayed on the Debug Terminal which will automatically appear after the program is downloaded from Cubloc Studio lolx Dim A AS Integer Baud Rate Party DataBls Sr i m A 123 Ez h ris200 y none fe RK Debug Dec A Use Dec or Hex to convert numbers to strings for the Debug command If you do not use Dec or Hex numbers will be printed as raw ASCII usually providing no useful output If you insert a question mark before Dec or Hex the variable s name will be printed before the value Deb Debug Dec A Cr lo1x Port ex fu Debug Hex A Cr feom y T a 5 rx 150 You can also specify the number of characters to print Debug Hex8 A e a Terminal ane Baud Rate y 115200 en y m The HEX command will accept 1 through 8 HEX8 will print as an 8 digit hexadecimal number The DEC command will accept 1 through 10 You are free to mix strings and numbers Debug CHECK VALUE Hex A Cr e a Terminal 0 x Baud Rate Parity DataBits_ rx 12 i z ris200 None y fe RK CHECK VALUE A 7B The Debug command is useful for printing strings and numbers in a user friendly format During the execution of a Cubloc BASIC program when the Debug command is encountered the resulting values are immediately displayed on the debug terminal 151 If you insert a Debug statement into a program and the debug terminal displays output it verifies that the program has executed to that
233. sta 2000 or 98 installed If you would like to use it in Linux Unix Macintosh environment virtual machine software such as Vmware will be needed to host the Windows operating system An RS 232 port is also required or you may use a USB to RS232C converter Programs can be downloaded monitored and debugged when connected to a PC via RS 232 When the Cutouch is disconnected from the PC it functions as a stand alone device The main program is stored in the Cutouch s flash memory and will be retained even between power cycles Programs can be downloaded and erased thousands of times 441 Cutouch Dimensions 186 35 116 35 442 Cutouch sas Ports Block 0 Block 1 WINNT Se eee LL igirapeed Counter o High speed Counter1 BUZZER SS A ee ee P80 87 N C No Connection The Cutouch CT1720 I O Ports are TTL 5V The Cutouch Add On Board allows opto isolated 24V DC inputs and 24V TR outputs for J1 through J4 The Cutouch CT1721 is a combination of the CT1720 plus the Add On Board Please be careful to not input more than 5V into a Cutouch TTL ports as it can damage the product 443 There are extra RS232 headers as shown below E II corn technotogy a lal p mepo RT RS232 RS232 Download Addtional Channel 1
234. standing the advantages of both Ladder Logic and BASIC the user will 26 be able to create more efficient final products while saving development time and reducing cost 27 Multi tasking of Ladder Logic and BASIC There are many ways to implement both BASIC and Ladder Logic in one processor The current products on the market use BASIC as part of Ladder Logic These products support BASIC and Ladder Logic but these products have a few disadvantages Jo FUNC 1 PO P1 Print Setting Mode FUNC 1 A A 1 B B 1 RETURN The first disadvantage is that when BASIC is executing the execution time of Ladder Logic also gets affected For example if BASIC creates in an infinite loop Ladder Logic will stop Ladder Logic s main advantage is that it can process input in a guaranteed scan time If Ladder Logic cannot process within this guaranteed scan time because of BASIC it might be better to not use BASIC at all The second disadvantage is that BASIC routines can only be started from Ladder Logic BASIC is a powerful language and is able to process complex algorithms in a sequential manner But if we can only use BASIC as part of Ladder Logic we are not utilizing all of its capabilities The third disadvantage involves I O BASIC s execution of I O can create unwanted collisions with Ladder Logic The reason is that Ladder Logic I O is updated once per scan while BASIC I O is accessed immediately To address these problems
235. stant or data register such as DO Usable M F S C T Constants Registers o o of Torr TAOFF o In the ladder above when START turns ON the timer TO immediately turns ON When START turns OFF the timer will start decreasing from 100 to 0 When 0 is reached TO will turn OFF Here 100 is equal to a time of 1 second for TOFF and 10 seconds for TAOFF 1sec lt gt sTarT _ vo 401 402 CTU This CTU command is an UP counter When an input is received the counter is incremented by one When the counter reaches a specified value the specified register will turn ON There is also a reset input so the counter can be reset as needed PULSE CTU C0 100 e RESET j 100 pulse PULSE nanganan RESET A o co MA CTD This CTD command is a DOWN counter When an input is received the counter is decremented by one When the counter reaches 0 the specified register will turn ON There is a also a reset input so the counter can be reset as needed PULSE CTD C1 100 C RESET l j 100 pulse i puse AMOS Hand RESET E _ _ E C1 lO 403 UP DOWN COUNTER Below is a simple example of how an UP counter can be used to make an UP DOWN Counter PO CTU C0 100 c PI R P2 WDEC C0 1 PO is for counting UP P2 is for counting DOWN and P1 is for resetting the counter When the counter reaches 100 CO turns ON po 000000000 100i P2 P1 co COUNT co
236. stored in the send buffer 209 Please refer to the On Recv interrupt service routine for receiving data using the hardware serial buffer 210 PutA PutA channel array byteLength channel RS 232 channel 0 to 3 array The Byte array to send byteLength Number of bytes to send 1 to 65535 The command Puta is used to send a Byte array on the specified RS 232 channel The array data will be sent starting from the first element of the array Dim A 10 As Byte OpenCom 1 19200 0 50 10 PutA 1 A 10 Send 10 Bytes of Array A IMPORTANT If byteLength is larger than the array Cubloc will send random values Please refer to the On Recv interrupt routine for receiving data using the hardware serial buffer 211 PutA2 PutA2 channel array byteLength stopChar channel RS 232 channel 0 to 3 array The byte array to send byteLength Number of bytes to send 1 to 65535 stopChar Stop character ASCII code Same as the Puta command except it will stop transmission when the specified stop character in encountered in the array stopChar will be the last character to be sent 212 PutStr PutStr channel data channel RS 232 channel 0 to 3 data String data String variable String constant or Constant Sends String data on the specified RS 232 channel OpenCom 1 19200 0 50 10 BUESA COMEN CTECHNOLOGY Y De AC Similar to the Put command PutStr puts data to be sent in the RS 232
237. symbols among the registers in Ladder Logic ContactA Po PI P2 tt 111 Contact B Output Relay Function Registers Function registers include timers counters and other mathematical operation registers PO TON 10 100 c 1 Function Relay 380 Internal Registers Internal registers M only operate within the program Unless connected to an actual external port they are only used internally M registers can be used as input or output symbols ACTION MO Mo WOW 100 D0 1 P Registers Not Used as I O Ports Cubloc supports P registers from PO to P127 P registers are directly connected to I O ports one to one However most models of Cubloc have less than 128 I O ports Those P registers not connected to an I O port can be used as internal registers M registers 381 Using I Os Cubloc I O ports can be used by both BASIC and Ladder Logic Without defined settings all I O ports are controlled in BASIC The UsePin command must be used to set the I O ports for use in Ladder Logic UsePin 0 IN UsePin 1 0UT The above code sets PO as input and P1 as output for use in Ladder Logic Those ports declared with the UsePin command will be re flashed during a ladder scan Re flashing means that prior to a ladder scan those ports declared as IN with the UsePin command will have their input read and copied to the port s corresponding P register After the ladder scan those ports de
238. system subroutine Sub PulsOut pt As Byte ln As Word Dim dll as integer Reverse pt For dl1 0 to In Next Reverse pt End Sub 208 Put Put channel data byteLength channel RS 232 channel 0 to 3 data Data to send up to Long type value byteLength Length of data in bytes 1 to 4 This command sends data on the specified RS 232 channel For data variables and constants can be used To send a String please use the Putstr command instead OpenCom 1 19200 0 50 10 IMPORTANT E Dim A As Byte The Opencom A amp HAO command must be Put 1 A 1 Send amp HAO 0xA0 used beforehand to RS232 Channel 1 The data is first stored in the send buffer set by Opencom The Cubloc BASIC Interpreter will automatically keep transmitting the data until the send buffer is empty If the send buffer is full when the Put command is executed Put will overwrite the data currently in the buffer The BFree command can be used to check the send buffer beforehand to prevent overwriting existing data in the send buffer If BFree 1 1 gt 2 Then If send buffer has at least 2 bytes free Put 17A 2 End If Bfree is used to check how much free space the send buffer has before writing any data to it TIP After using Put or PutStr the function Sys 0 can be used to verify that the data has been stored in the send buffer OpenCom 1 19200 0 50 10 PutStr 1 COMFILE Debug Dec Sys 0 If output is 7 all data has been
239. t P82 104 yo 56 CB405 The CB405 is a package of 80 pins of which 64 can be used as I O ports It has a battery backup capable 55KB of memory The CB405 does not have an internal 5V regulator Sin B ORs 1332382 10021 20022 30023 40024 50025 Vdd 410061 420 062 430063 440064 2 450065 460 066 470067 480 063 490069 500070 510071 520072 530 3 540074 550 075 P44 560 076 TX1_P43 570077 RX1_P42 580 078 P58 CUNET SDA_P41 590 079 CUNET SCL_P40 60 4 4 80 P45 AVREF I N POWER IN Explanation DOWNLOAD SERIAL OUTPUT DOWNLOAD SERIAL INPUT DOWNLOAD SERIAL INPUT DOWNLOAD SERIAL INPUT GROUND 21 44 POWER 4 5V to 5 5V Power Supply IN AVDD 43 POWER ADC power IN N ADC Reference Voltage POWER N IN OUT IN OUT IN Battery Backup RESET pin RS232 to TTL232 curcuit RX contact RS232 Output 12V IN our RS232 to TTL232 curcuit TX contact IN OUT RXE 42 TIN RS232 Input 12V 57 The following I O ports are described in blocks yo spPiss 1 0 1 O SPI SS NEP O ASA 1 0 PwmcHanNeto yo PWM CHANNEL1 O IS TTLRX channel 2 PWM CHANNEL 2 TTLRX channel 2 vo fT 1 0 PWMCHANNEL6 1 0 PWM CHANNEL 1 0 PWMCHANNELS Po 1 0 Pp Po vo AAN vo l P17 26 yo aADcHanNeLi P18 27 o aADcHanNeL2 P19 28 yo ADCHANN
240. t This can be used when a Ladder Logic program needs to trigger a specific procedure in BASIC Please use the SetOut and DIFU command to write 1 to the register F40 When the BASIC interrupt routine is finished register F40 can be cleared by writing a zero to it During the interrupt service routine ISR execution writing a 1 to register F40 will not allow another interrupt to occur If register F40 is cleared from BASIC it signals the end of the ISR and can process another interrupt UsePin 0 In Set Ladder On Set Display 07 0716 77 50 On LadderInt GoSub msgl_rtn Dim i As Integer Low 1 Do i i 1 ByteOut 1 1 Delay 200 Loop msgl_rtn Locate 0 0 Print ON LadderInt Dec i Reverse 1 Return i SETOUT F40 F C 1 When PO turns on register F40 turns on and the msg1_rtn interrupt routine in BASIC is executed In the ISR a String is printed to the LCD 196 Although there is only one register F40 with which call an ISR in BASIC from Ladder Logic we can use data register D to process many different types of interrupts PO WMOV 3 00 1 E SETOUT F40 C J i WMOYV 2 D0 F c l SETOUT F40 1 Given the ladder above when PO turns on DO gets 3 and the interrupt routine is executed If P2 turns on DO gets 2 and the interrupt routine is executed In the ISR the user can then process the type of interrupt based on the value stored in DO msgl_rtn If _D 0 3 Then Locate 0 0 Print ON
241. t I O port number 0 to 255 Reads the current output value for the specified port This command is different from the In command it reads a port s current output not input Dim A As Byte A OutStat 0 Read from port 0 and store the output in A Pause Pause value Same as Delay 206 Peek variable Peek address length variable Variable to store result s No String or Single address RAM address length Number of bytes to read 1 to 4 Reads the specified length of data starting from the specified data memory address Poke Poke address value length address RAM address value The value to write length Number of bytes to write 1 to 4 Write the specified length of data starting at the specified data memory address Const Device CB280 Dim F1 As Single F2 As Single F1 3 14 EEWrite 10 Peek MemAdr F1 4 4 Poke MemAdr F2 EERead 10 4 4 Debug Float F2 CR 207 PulsOut PulsOut port period port Output port 0 to 255 period Pulse period 1 to 65535 This is a subroutine that outputs a pulse To create a high pulse the output port must be set to logic low beforehand To create a Low pulse the output Port must be set to logic high before hand If you set the pulse period to 10 you will create a pulse of about 2 6ms Likewise a Pulse Period of 100 will be about 23ms Low 2 High 2 PulsOut 2 100 23mS high pulse PulsOut 2 100 23mS low pulse PulsOut is a premade
242. t Baud Rate Party Data Bits TX E com fits200 None fe r 4 CUBLOC studio d cubloc_test stringfunc cul Fie Edit Device Run Setup Help 9735828 a gt wit Ble F1 BASIC F2 LADDER Ladder Mnemonic Const Device CE280 Dim stl As String 12 atl CUBLOC Debug Left stl 4 Cr Debug Right st1 4 Cr Debug Mid st1 2 4 Cr E Fix Right Side 127 Len stringValue Return the length of the given String Dim STI AS String 12 STI CUBLOC Debug Dec Len ST1 6 is printed since there are 6 characters in ST1 String asciiCode length Creates a string of a specified length with the given ASCII code repeated for the length of the String Dim SHEL As String 12 ST1 String 4841 5 Debug ST1 AAAAA is printed amp H41 is ASCII code for character A SPC numberOfSpaces Create a specified amount of blank space Dim SHEL As String ty 12 STI Sc 5 Debug VAT STI VA A A is printed Note the 5 blank spaced between each A Debug Terminal Baud Rate Parity Data Bits TX a Port CUBLOC studio d cubloc_test stringfunc cul COMI z 115200 None fa gt File Edit Device Run Setup Help es Ba XAA rmm FI BASIC F2 LADDER Ladder Mnemonic Const Device CBZ80 Dim stl As String 12 stl CUBLOC Debug Dec Len st1 Cr stl String h41 5 Debug st1 Cr stl spc 5 Debug A st1 A Cr
243. t ports to input before use of this command refer to the pin port table for the appropriate Cubloc module Data types up to 32 bits in size can be counted Byte Integer and Long The maximum pulse frequency is 2MHz Cubloc s counter is hardware driven meaning it runs independently from the main program It is able to count reliably in real time regardless of how busy the Cubloc processor is The Cubloc has 2 counter inputs Counter channel O uses the same resources as PWMO through PWM2 so you cannot use both at the same time However counter channel 1 can be used while PWM channel 0 is running The Set Count0 On command must be executed before using counter channel 1 Counter channel 1 requires no additional settings SOUT 24 VIN SIN El ae VSS ATN O3 220 RES vss 04 2110 VDD Po Q5 200 P15 COUNT 1 P16 190 P14 COUNT 0 P2017 18 P13 P3 08 170 P12 P49 160 P11 PS C 10 150 P10 P6 11 14 P9 PT 12 13 P8 Dim R As Integer Input 15 Set port 15 as input Counter Channel 1 R Count 1 Read current counter value Set Count On Activate counter channel 0 PWM0 1 and 2 becomes deactivated Input 14 Set port 14 as input Counter Channel 0 R Count 0 Read current Counter value 146 As illustrated below counter 0 uses the same resources as PWMO through PWM2 so please be careful not to use both at the same time COUNTER O TIMERA PWM2 PWM3 TIMER
244. ta P42 58 1 0 RX1 TTLRX channel 1 5 P43 57 I O TX1 TTLTX channel 1 P44 56 I O P45 55 1 0 P46 54 1 O HCNTO High speed counter channel O P47 53 1 O HCNT1 High speed counter channel 1 P48 65 I O P49 66 1 0 P50 67 1 O 6 P51 68 I O PWM CHANNEL 9 P52 69 I O PWM CHANNEL 10 P53 70 1 0 PWM CHANNEL 11 P54 71 I O P55 72 I O P56 80 I O RX3 TTLRX channel 3 P57 79 I O TX3 TTLTX channel 3 P58 78 I O 7 P59 77 1 0 P60 76 I O P61 75 I O P62 74 I O P63 73 1 O 62 How to connect a battery to CB290 CB405 When a supercapacitor is connected to VBB the memory can be maintained anywhere from a couple days to a couple weeks once powered off The CB290 CB405 consumes about 15 20mA of current when idling For a longer backup period a battery pack can be used A protection diode as shown below is necessary when using a battery as the device normally attempts to charge a capacitor through VBB Due to the relatively high standby current for battery backup it is recommended to keep the device powered if possible and only maintain battery backup for short periods in the case of an emergency VBB CB290 E 7 Power Features eOperating Voltage 4 5V to 5 5V Operating Clock 18 432MHz 1 O Port Source Current 20mA el O Port Sink Current 25mA eOperating Temperature 40 to 125 Degrees Celcius Maintenance Temperature 60 to 140 Degrees Celcius eOperating Humidity 5 to 95 RH Keep
245. td ii 200 OPEN COM A A tc EENE 201 OUR ae O se tes ahaha 204 DU A A ence tetas 205 QUES 206 PU ii A AAA id ie in 206 Peek Jar a eriistidnelvelicedsacced oc coumresenddemandnunesesareaeas rarer 207 POK Geordie teed ae A hae a So ares Bet 207 RUISQUE a A weve eoebee ha tae A A 208 PUT isinuot te rtaedtiordactash A its 209 PA A IA OAC tl ns MAN as 211 PLAZA a caches tian eet as esata cta 212 PUES eet aes oie avi ae Oe eas deeds Danelle ete 213 A E ATE 214 PO a ii 215 REAS tica da a a da dde 216 Resina o dla ad 217 ROVER A at A ASA 218 O cienedivestathasinvaste steesnstciewepeededesaviate des naaa a 219 Selecta Gas ex ieee A din 220 Set DeDUG Ades sidecse dss heyen ae iae Eia a A wale deere 221 Debug Command HOWTO inci 221 Ser A A REO 224 A IM E E S A aad decade deceit enone ieeenle 225 Set adders sist etets a lali 226 Set MOdDUSe saci eitecntus a a ees eee ee 227 Set OnGlobalW fanatica iaa ts 228 Set ONING AA E E A A 229 SetiOnLadderMtri A td een ea ys fesse ses 230 SON di A ia i cated aaa eave ies 231 SEOANE a ai 232 SECO TIM eii ria il aida 233 SOE QUO Ol Vision a idas cda 234 SA A Mawhdewmtenveadretedaoi nt daa da dea latte eta 235 Seti RS ZII Pay sien a dea dda tele A O iat eles een ee EN 238 SERA tica Shwe oda Mite nals na NEREA ANAE nace silage swage i Tube Be 239 SOUS A a 241 SerUnti ct na dao 242 SAME A AA A A A E 244 SAQUE it ad 245 SLEPAGCGe atacada anodino renos raa aaa a aD a oaia 247 Ser A e ETE 248 SLepStatl Dias a
246. te of data from the specified heap address HeapW HeapW address data address Heap memory address data Constant or variable with data Byte only Write 1 byte of data to the specified heap address Heap Memory Addressing The heap is divided into byte unit addresses When a Long variable is stored 4 bytes are stored and 4 memory addresses are used HWrite 0 amp H1234ABCD 4 amp HCD UNEO As you can see in the above table when a Long variable is stored in heap address 0 four memory addresses are taken HWrite 0 amp HABCD 2 Write amp HCD to address 0 and amp HAB to address il HWrite 1 amp H6532 2 Overwrite address 1 with amp H32 and write H65 to address 2 177 DEMO PROGRAM Const Device CB405 Dim A As Byte Dim i As Long J As Long i amp HABCD1234 HeapClear HWrite 0 1 4 Do HeapW 56830 100 HeapW 56831 123 Debug Dec Heap 56830 Cr Debug Dec Heapi 56831 7 Cr J HRead 0 4 Debug Hex J Cr Delay 100 Loop 178 High High port port I O port number Set the port to a logic high state 5V Output 8 1 Set Port 8 to output state High 8 get Port 8 to HIGH 5V When a port is set to high the port is internally connected to VDD 5V If it s set to Low the port is internally connected to VSS OV This allows either source or sink interfacing to external components up to 25ma for source or sink le vais 2 San 179 12CStart 12CStart Sets 12C
247. tepPulse channel port freq qty channel StepPulse channel 0 or 1 port Output port freq Output frequency Up to 15kHz qty of pulses to output up to 2147483647 This command outputs a set number of pulses at a set frequency up to 15kHz FreqOut and Pwm can also output pulses but the number of pulses cannot be controlled and only the dedicated PWM ports can be used With StepPulse any output port can be used and the number of pulses and pulse frequency can be controlled Depending on the Cubloc module used the number of available channels may change Please refer to the following table for module specific information PWM Channels that cannot be used during use of the command CB220 Channel 0 PWM 3 4 5 CT17XX CB400 CB405 EA or 1 Channel 0 PWM 3 4 5 Channel 1 6 7 8 StepPulse uses the Cubloc processor s PWM counters When using this command PWM3 PWM4 and PWM5 cannot be used For the CB400 CB405 when using channel 1 PWM6 PWM7 and PWM8 cannot be used With the CB2XX series only channel O may be used With the the CB400 CB405 StepPulse Can be used on 2 different channels simultaneously You can use any of the available I O ports on the Cubloc When the StepPulse command is executed the specified port s I O mode is automatically set to output Even after the command has finished generating pulses the port s I O mode remains output The output frequency can be set from 1hz to 15kHz Th
248. tet ant oe 288 DOS IZ A a 288 PM e A dia dad 290 AE a a 290 DEAR is iodo iaa 291 BMD cranna a an a dia aia aLa EAO dd gn Fabia Ove 291 A A tod da Aaa a a A e a ss wcbes shen abs ONAE ae e AEE 293 GPOP a ad a a OA Laie ein Gt A das at 293 E A EATA es unre cugedds So ednadedibecaas ouenebetante 295 OPUS Dir a dd 296 HP iio A A S 296 O 296 Seven Segment Display CSG cececeeeeeeseeeeeceeenereceenenteereeeseres 298 CSG DOC bevieceececs cncdcctontaenesbaa ba a i aaria 299 CSGNBUt asc ea aa deeet E 300 CSGXPUE Ao lite aseo nro 301 ES A aE Aa AAEN a N whe eves Goad ere Eaa 301 CSGHEX an o ns 301 CHAPTER 8 INTERFACING sscsssssssssossssecscsscsecsessssecsessesecsecsessesecsersssecsersesessecsersesesserees 303 INPUt OUtPUECIPGUIES ca dl cele ens 304 RS 232 HO WMO A iia 308 CUNETA dan aa 310 Cubloc Study Board Circuit DiagraM cococmncnccnncononnnnnnnnnnnnnnonnnnnnos 312 ADOUtTAGriict sack sheeeeete T 314 More About 12C AdVANCed cccccccceceecce rr 318 CHAPTER 9 MODBUS ciscccscvsccccsnsscsatstestsvecnstssesessesvedscessvovetscasesecteesessveseecesonvosesechecessosssgoesease 321 ADOUE MODUS tasar da 322 Modbus ASCII Master dlls 334 Modbus ASCII Slavei srajce innaka enhe t n i aame aaee adaini raihi aa 336 CHAPTER 10 APPLICATION NOTES sesesssesesssesesoseeesosesososesoroscsososesoseeesoeseeesesesesesesssesesesese 337 14 NOTE 1 S Witch IPUR 338 NOTE 23 KeypadInpltiit iia 340 NOTE 3 Temperature S NSOP ccc
249. the board s surface dry when in use Additional Information If a Cubloc module is supplied with power above the recommended voltage the device can be destroyed Also please be careful to avoid electrostatic discharge as it too can destroy the device Please be aware that P1 is an input only pin To reduce accidental power drain please set unused pins to input All I O ports are set to input as default at power on When not using SIN SOUT and ATN please do not connect them to anything 63 Dimensions CB220 30mm 1181mil lt gt 15 24mm 600 mil 25 4mm 1000 mil 2mm 78 74 mil 34 9mm 1374mil gt lt 2mm 78 74 mil 18 415mm 725 mil 64 54mm 2126 mil gt 49 53mm 1950 mil lt gt 3 w oe A eo eo eo ee loe CB290 3 2mm 78 74mi e C B4 F 00 se os 42mm 1653mil eS 36 83mm 1450 mil ee ee ee ee ee ee e ee ee SS ccccccccccccce oe Pecccceccccece eo gt lt 2mm 78 74 mil 10 8mm 425 mil 54mm 2126 mil lt gt 49 53mm 1950 mil ee gt A e 4 CB405 2mm 78 74 mil es ss 42mm 1653mil ee gt lt 2mm 78 74 mil csm CB290 400 405 ee Sm 551mil eae 65 Please refer to the diagram below for PCB design The numbers are offsets based on location 0 O f
250. tion GHI C as Byte End Function The End statement is used to differentiate between the BASIC main program and the program s subroutines The END statement in Ladder Logic is used to indicate the final Ladder Logic rung 84 Subroutine Parameters and Return Values Functions may use any data type except arrays as parameters and values Dim A 10 As Integer return Function ABC A AS Single as Single Return Single value End Function Function ABE A AS String 12 as String 12 Return String value End Function Function ABC A AS long Long value as a parameter End Function When return value is not declared Long will be used as return value Arrays cannot be used as parameters The following is not allowed Furctien ARRAYS PEAH AS teteges Arrays may not be used parameters But you may use one element of an array as a parameter Dim b 10 as Integer K ARRAYUSING b 10 Use 10 element of array b as a parameter Function ARRAYUSING A AS Integer as Integer End Function All subroutine parameters are passed by value not by reference If the parameter value is changed within a subroutine it will not affect the variable passed to the subroutine Dim A As Integer Dim K As Integer A 100 K ADDATEN A Debug Dec A Dec K CR A is 100 and K is 110 End Sub ADDATEN V As Integer vV vV 10 A does not change when V is changed ADDATEN V 85 86
251. tion note will demonstrate a few examples that generate sound with the Cubloc Sound can be generated using the Cubloc s I O port or PWM channel With a PWM channel sounds of varying frequency can be generated O sour VIN m O sin VSS O ATN RESO vss VDD O Po P15 O P1 B P2 P13 peaker 0 047uF Pa P12 de Pad g PS P10 0 g P6 PO q P7 P8 CB220 Const Device CB220 Dim PLAYSTR As String Low 5 Fregout 0 5236 Create a sound with frequency of 440Hz Delay 500 Delay Pwmoff 0 Stop Sound by turning off PWM The example above shows the CB220 s PWM channel 0 of CB220 being used with the Freqout command to produce a sound With commands like FreqOut and Delay simple sounds can be created Const Device CB220 Low 5 FreqOut 0 4403 Delay 200 Freq0uet 0 3703 Delay 200 Fregq0ut 0 3114 Delay 200 Freg0ut 0 2202 Delay 200 PwmOff 0 348 By changing the frequencies a simple program can be made that plays musical notes PA iB e loe Rs la fe pe m1 A c E G a c ABe e o E Je le 4 da KLN To express one note 2 characters are used the first character is for the frequency of the note and second character is for the length of the note Const Device CB220 Dim PLAYSTR As String Low 5 PLASIR FGSBJEZGILICET PLAY 0 PLAYSTR Do Loop End Sub PLAY CH As Byte NOTE As String Dim PL As Byte Dim CHAR As Byte Const Integer PLAYTABLE 5236 4665 4403 3923 3495 3299 2939 ASAS SS OZ GIL A O OSADO For PL 1 To Len
252. udio d cubloc_test abe cul accio pany BIE Lis File Edit Device Run Setup Help zz al 115200 gt none gt je gt Bang ABB A gt att EA FI BASIC F2 LADDER Ladder Mnemonic Const Device CB2Z80 define Rep Debug Dec Dim A As Integer A 123 rep A Cr Close I Fix Right Side 107 Conditional Directives A conditional directive is a directive that instructs the preprocessor to select whether or not to include a part of code before compilation Preprocessor conditional directives can test arithmetic expressions or whether a name is defined as a macro Here are some reasons to use a conditional BA program may need to use different code depending on the module it is to run on In some cases the code for one module may be different on another module With a conditional directive a BASIC program may be programmed to compile on any of the Cubloc Cutouch modules without making changes to the source code mIf you want to be able to compile the same source file into two different programs For example one version might be compiled with debugging statements and one without if constant Hendif The preprocessor directive if will compare a constant declared with CONST to another constant If the if statement is true the statements inside the if endif block will be compiled otherwise the statements will be discarded Const Device CB280 Delay 500 Device only returns the decimal num
253. uffer This function will return the number of free bytes in a receive or send buffer When sending data this command can be used to avoid overflowing the buffer When receiving data this command can help the program wait for a specified amount of data to be received before taking action Dim A As Byte OpenCom 1 1920001 100 50 If BFree 1 1 gt 10 Then Put TECHNOLOGY End If If the size of the buffer is set to 50 up to 49 bytes can be returned When the buffer is empty BFree will return 1 less than the buffer size 139 Bin2Bcd variable Bin2Bca binValue variable Variable to store results Returns Long binValue Binary value to be converted Bin2Bcd converts a binary value to BCD Binary Coded Decimal i 123456 j bin2Bcd i Debug Hex j Print 123456 See also Bcd2Bin 140 BLen variable BLen channel bufferType variable Variable to store results No String or Single channel RS 232 channel number 0 to 3 bufferType O receive buffer 1 send buffer BLen returns the current number of bytes in the specified RS 232 channel s buffer If the buffer is empty O will be returned When receiving data this function can be used to check how much data has been received before using Get or GetStr to read the data received If the receive buffer is full it will not be able to receive any more data To avoid this use receive interrupts See On Recv or increase the buffer size Dim A As Byte OpenC
254. uld initialize variables or use the RamClear statement to initialize all data memory to 0 If data memory is not cleared the values in memory could potentially be anything If the contents of memory are to be predictable you must either initialize each variable or use the Ramclear statement In the case of battery backed up modules the variables will remember their values after a power cycle powering off and on 94 Arrays Cubloc BASIC supports arrays of up to 8 dimensions Each dimension can contain up to 65 535 items Dim A 20 As Byte Declare an array of 20 Bytes Dim B 200 As Integer Declare an array of 200 Integers Dim C 200 As Long Declare an array of 200 Longs Dim D 20 10 As Single 2 dimensional Single array 20 x 10 Dim sT1 10 As String 12 Declare String array so OOO A 3 6 A 3 3 6 Be sure to make note of how much memory is used when using multi dimensional arrays 13 10 130 Bytes of Data Memory Dim SUL LO As String 12 4 10 20 800 Bytes of Data Memory Dim D 20 10 As Single 95 Bit and Byte Modifiers A variables bits and bytes can be accessed individually by using the commands shown below Dim A As Integer A LowByte H12 Store amp H12 at A s lowest byte LOWBIT Variable s bit O BITO to 31 Variable s bit O through 31 A BIT2 1 Make bit 2 of A equal to 1 A o w 4D NS SELLEL LLLE Nibble A nibble is 4 bits The user can access individua
255. upt Initiates an interrupt when Pad receives data 112 More about Interrupts The Cubloc and Cutouch have a Real Time Operating System RTOS which controls interrupt events This is slightly different from the microcontroller s hardware interrupts 1 When interrupt A occurs while interrupt A s ISR is executing another interrupt A cannot occur But interrupt B can occur Here A and B are different types of interrupts e g On Timer and On Recv 2 When interrupt B occurs while executing interrupt A s ISR interrupt B s ISR will be executed immediately and execution will return to interrupt A s ISR to finish 3 At the end of an ISR be sure to include a Return statement Otherwise the program may malfunction 4 If no interrupt is required for your program you can increase the execution speed of the Cubloc by setting turning off all interrupts using the Set OnGlobal off By default Set OnGlobal is set to On 5 In the case of On Recv data received during an On Recv ISR will simply be stored in the serial port s receive buffer Therefore the data will not be lost After the current On Recv ISR is finished if there s new data in the receive buffer another On Recv interrupt will be immediately generated The BClr statement can be used if you do not want to process another On Recv interrupt 6 If you declare an interrupt more than once only the last one declared will be in effect Please pay attention when creating t
256. urrentScreen As Byte define _MAINMENU 0 define _SUBMENU1 define _SUBMENU2 define _SUBMENU3 define _SUBMENU4 PUNB MAIN CurrentScreen _MAINMENU Do If CurrentScreen MAINMENU Then Set Onpad Off DisplayTime Set Onpad On Endif Delay 250 Loop ProcessTouch TX1 GetpadX TY1 GetpadY Select Case CurrentScreen Case _MAINMENU ProcessMainMenu Case _SUBMENU1 467 ProcessSubMenul Case _SUBMENU2 ProcessSubMenu2 Case _SUBMENU3 ProcessSubMenu3 Case _SUBMENU4 ProcessSubMenu4 End Select Return End Sub ProcessMainMenu If Menucheck 0 TX1 TY1 1 FlashMenu 0 CurrentScreen _SUBMENU1 Cra SUBMENU1 Elseif Menucheck 1 TX1 TY1 FlashMenu 1 CurrentScreen _SUBMENU2 els SUBMENU2 Elseif Menucheck 2 TX1 TY1 FlashMenu 2 CurrentScreen _SUBMENU3 ers SUBMENU3 Elseif Menucheck 3 TX1 TY1 FlashMenu 3 CurrentScreen _SUBMENU4 els SUBMENU4 Endif End Sub Sub ProcessSubMenul If Menucheck 0 TX1 TY1 1 FlashMenu 0 Beeper 1 Elseif Menucheck 1 TX1 TY1 FlashMenu 1 CurrentScreen _MAINMENU cuts IAIN Endif Then 1 Then 1 Then 1 Then Then 1 Then End Sub Sub ProcessSubMenu2 If Menucheck 0 TX1 TY1 FlashMenu 0 Beeper 2 il Elseif Menucheck 1 TX1 TY1 FlashMenu 1 Cunrents erecn Cls IAIN Endif End Sub Sub ProcessSubMenu3 If Menucheck 0 TX1 TY1 FlashMenu 0 Beeper 3 it Elseif Menucheck 1 TX1 TY1 FlashMenu 1 CurrentScreen
257. using Cubloc s 12C protocol and native commands Cutouch Series Cutouch is an integration of our graphic LCD touch panel and Cubloc core module With BASIC you can control the LCD and touch panel With Ladder Logic I O ports can be controlled in real time 38 Chapter 2 Hardware Hardware Features Cubloc has the following features e BASIC and or Ladder Logic 80KB or 200KB Flash Memory eBASIC Execution Speed 36 000 instructions per second eLADDER Execution Speed 10 millisecond scan time eData Memory for BASIC 2KB to 51KB eData Memory for LADDER 1KB to 4KB eEEPROM Memory 4KB 16 to 91 I O pins Ports 8 to 16 10 bit ADC channels 3 to 12 PWM channels DAC from 8 to 16bit eUART H W RS232C ports 2 to 4 channels eRTC chip included CB290 Model Comparison Chart cezzo cszso CB290 eso CB380 CB400 CB405 POKE BOKE 80KB 80KB 200KB 200KB 200KB 200KB 2KB 2KB 24KB 6KB 6KB 6KB 51KB 1KB 1KB 4KB 1KB 1KB 1KB 4KB aes ES ae ke f KB KB a 1 0 ports bo he wo vo vis Pe ho FD lsrs karz Package I O 24 pin 64 pin 08 pin E pin ea pin E pin E pin apes e 3 peme CN z E CR te E 2 p External Interru pts 40 2 e j No No No No CB210 The CB210 has 20 digital I O ports 6 of which can be used for A D input It can be connected to a PC via USB for downloading and debugging and serial communication It can be powered either by a 9V power supply or through the USB
258. we have created a BASIC and Ladder Logic processor that supports real time multi tasking BASIC runs BASIC and Ladder Logic runs Ladder Logic without causing collisions 28 Even if you only use BASIC you will be able to build innumerable applications In comparison to many other BASIC processors on the market today Cubloc s BASIC has a faster processing speed and the upper hand on its main features In the case of I O the user can specify the I O used by BASIC and Ladder Logic thereby eliminating I O collision problems If you use Ladder we recommend using some BASIC as a method of supervising the Ladder operations For example there is a Master Control feature in Ladder Logic allowing the user to set Control Zones Control Zones are sections within the Ladder Logic containing portions of the control circuit With the Master Control feature the user can enable disable Ladder Logic s Control Zones easily M1 MCSO IFA 1 THEN _M 1 1 If B 1 THEN_M 1 0 MCSCLR 0 In BASIC the user may read or write to Ladder Logic s data memory In the above example you can access Register M1 as _M 1 and write to it from BASIC 29 Advantages of an On Chip PLC Embedded Computer Cubloc s greatest advantages is that it is an On Chip PLC Normally we think of a PLC as a block type case with input and output lines These modules are usually mounted within yet another case with external power supplies additional output modules
259. x Right Side 477 RTCWrite RTCWrite address data address RTC chip s address data the variable or constant to store This command writes a new data value to the specified address of the RTC chip In other RTC chips clock inaccuracies can occur due to temperature changes The RTC chips which work properly at room temperature begin to tick abnormally as their crystals oscillations are affected by temperature The DS3231 is an RTC chip that avoids such problems It has a thermistor i e a temperature sensor along with a 32 KHz crystal The oscillation frequency is adapted based on the temperature sensed by the thermistor As a result the crystal oscillations don t fluctuate and the clock keeps better time But be aware that although the DS3231 keeps great time under varying temperatures it is still not 100 perfect and should be verified for time critical applications 478 HADIN variable HADIn channel variable Variable to store the result Integer or Long type channel AD channel This function stores the result of 16 bit A D conversion at the specified variable include CB405RT Do Debug Goxy 1 1 Dec5 HADIn 0 Wait 500 Loop For the above example program to work a 5V source should be connected to HAD_Vref and a volume resistance should be connected to the HAD_CHO as shown below Note that only voltages ranging from 1V to 5V can be connected to HAD_Vref and only voltages ranging from OV to
260. y 100 i 1 Loop The final value received must be divided by 2 to obtain the correct temperature 353 NOTE 7 DS1302 RTC The DS1302 RTC Real Time Clock is a chip that acts as an electronic time It has the ability to keep time and date in real time We will show you how to implement this clock chip into your application keeper Function e ee Data transfer when High SCLK System Clock Clock signal I O Data T Output Data input output Input Output Const Device CB220 354 Const iorst 7 Const iodio 6 Const ioclk 5 Dim i As Integer Dim adr As Byte High iorst ShiftOut ioclk iodio 0 amp h8e 8 Shurtou ito lao dto 0 0 8 Low iorst Delay 1 High iorst ShiftOut ioclk iodio 0 amp h80 8 ShiftOut ioclk iodio 0 amp H50 8 Low iorst i i Do High iorst adr amp h81 ShiftOut ioclk iodio 0 adr 8 i ShiftIn ioclk iodio 4 8 Debug Hex i cr Low iorst Delay 1000 Loop The code above will read address 0 the seconds value and display it in the debug window At the beginning of the program writes are enabled to the DS1302 chip and address O is set to 50 seconds Within the Do Loop data is read from the DS1302 The DS1302 has 6 addresses as shown below ADDRESS 0 sec CH 10 SEC Sac A i ADDRESS 1 min o MOMO EN 70 ADDRESS 2 hour 12 24 0 ap HR HR ADDRESS 3 date o o 10DATE DATE ADDRESS 4 month 0 oj o 10 MONTH L E L ADDRESS 6
261. y does not apply if the product has been modified or damaged by accident abuse or misuse 30 Day Money Back Guarantee If within 30 days of having received your product you find that it does not suit your needs you may return it for a refund Comfile Technology will refund the purchase price of the product excluding shipping handling costs This does not apply if the product has been altered or damaged Copyright amp Trademarks Copyright 2006 2010 by Comfile Technology Inc All rights reserved CUBLOC is a registered trademark of Comfile Technology Inc WINDOWS is a trademark of Microsoft Corporation XPORT is trademark of Lantronix inc Other trademarks are of their respective companies Notice This manual may be changed or updated without notice Comfile Technology Inc is not responsible for any actions taken outside the explanation of this manual This product is protected by patents across the world You may not change copy reproduce or translate it without the consent of Comfile Technology Inc Disclaimer of Liability Comfile Technology Inc is not responsible for special incidental or consequential damages resulting from any breach of warranty or under any legal theory including lost profits downtime goodwill damage to or replacement of equipment or property and costs or recovering reprogramming or reproducing any data stored in or use with Comfile Technology products Preface Comfile Technology has
262. ypad matrix of up to 8x8 lines The input port block and the output port block must be selected separately A pullup resistor 2 2K to 10K should be connected between each input port and 5V For ports not used within the input port block a pullup resistor must be used Unused ports may not be used for other purposes when using this command Ports not used within the output port block can be left unconnected Unconnected ports may not be used for other purposes The following is an example showing port block O as the input port block and port block 1 as the output port block Noa a wR o If no keys are pressed 255 will be returned Otherwise the pressed key s scan code will be returned 160 For Next For Next will loop the commands within itself for a set number of times For Variable StartingValue To EndingValue Incremental Step Commands Exit For Next In the below example an Incremental Step is not set By default each loop increments by 1 Dim K As Long For K 0 To 10 Debug Dp K CR Next For K 10 To 0 Step 1 Negative Step step from 10 to 0 Debug Dp K CR Next An Exit For command can be used within the For Next loop to exit at any time For K 0 To 10 Debug Dp K CR If K 8 Then Exit For Tt K equals 8 exit the For Next loop Next When choosing a variable to use for the For Next loop please make sure the chosen variable
Download Pdf Manuals
Related Search
Related Contents
TP-Link TL-SL5428E V2 User Guide inipr01 - infi90.com Manual de uso de la interfaz web de RT ASSEMBLÉE GÉNÉRALE MIXTE 取扱説明書 - 山田照明 CalCheck Manual Version 1 P810P850 User Manual Fixed Assets (1 of 2) User Manual Copyright © All rights reserved.
Failed to retrieve file