Home
User Manual Version 3.1
Contents
1. P64 33 Input P65 34 Input P66 35 Input P67 36 Input Block 8 P68 37 Input P69 38 Input P70 39 Input P71 40 Input P72 87 Input P73 88 Input P74 89 Input P75 90 Input Block 9 P76 101 Input P77 102 Input P78 103 Input P79 104 Input P80 91 Input P81 92 Input P82 93 Input P83 94 Input Block 10 P84 105 Input P85 106 Input P86 107 Input P87 108 Input P88 81 N C N C Do not use this 1 0 number P89 82 VO PWM Channel 3 P90 95 1 0 Block 11 PWM Channel 4 INT Channel 0 P91 96 10 PWM Channel 5 INT Channel 1 VDD 21 44 IN Power 4 5V to 5 5V VSS 22 64 IN GROUND RES 23 IN RESET Input LOW signal resets Normally HIGH or OPEN VBB 24 IN Battery Backup TXI 41 RS232 Channel 1 12V Data Output RXL 42 RS232 Channel 1 12V Data Input AVDD 43 ADC Power TAXI 61 RS232 Channel 1 5V TTL level Data Output TLRXI 62 RS232 Channel i 5V TTL level Data Input AvRer 63 ADC Reference Voltage 49 The CB290 output only pins P24 to P55 are in 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 The Set Outonly command actually toggles a 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 Basic or Ladder
2. A B E D E F G H I K L M N To express one note you can use 2 characters The first character is for the note and second character is for the length of the note lt Filename play cul gt Const Device cb280 Dim PLAYSTR As String Low 5 PLAYSTR G5E3E3G3E3C5 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 2618 2333 2202 1961 1747 1649 1469 0 For Pl 1 To Len NOTE Step 2 CHAR Asc Mid NOTE PL 1 sH41 Freqout CH PLAYTABLE CHAR CHAR Asc Mid NOTE PL 1 1 amp H30 Delay CHAR 100 Next Pwmoff CH End Sub When using PWM port for other purposes the Freqout command is no longer available for use In this case we can use any regular I O port to create sound We will use TOGGLE and UDELAY commands to set the I O Port to HIGH and LOW The following example shows how to make an alert sound with a regular I O port P4 335 lt Filename playport cul gt lt END gt 336 NOTE 5 RC Servo Motor RC Servo Motors 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 CUBLOC you can use the PWM outputs to easily implement an RC Servo motor in your project The RC servo motor has three wires The black wire is ground and red wire is for power
3. 122 Chapter 6 CUBLOC BASIC Statements amp 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 10bit ADCs and 16bit PWMs The user can use an ADC to convert analog to digital signals or use a PWM to convert digital to analog signal The ADIN command reads the analog signal value 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 The ADC port must be set to input before use When a voltage between 0 and AVREF is applied that voltage is converted to a value from 0 to 1023 AVREF can accept voltage between 2V to 5V The default reference is 5V If the user inputs 3V to AVREF voltage between 0 and 3V is converted to a value between 0 and 1023 Note CB220 AVREF is fixed to 5V Return value 1023 0 ov 5V Input voltage Dim A As Integer Input 24 Set port to input A Adin 0 Do a A D conversion on channel 0 and store result in A 124 The CB220 CB320 and CB280 CB380 ADC ports are shown below CB280 CB220 e sour fi vin os rat sin 2 api vss a aaar am ga res M er vss ga voo ADINPUT ro gs 2p Pis E orr ride sop pre e2 d7 18 pia apinput Ps ge 17h P12 PORT rede isp en Ps gio ash
4. Port Pin 0 Port Block_ Explanation souT i OUT DOWNLOAD SERIAL OUTPUT SN 2 IN DOWNLOAD SERIAL INPUT AN 3 IN DOWNLOAD SERIAL INPUT vss 4 POWER GROUND PO 5 V0 ADCO SPI SS PL 6 Input ADCi SPI SCK P2 7 1 0 ADC2 SPI MOSI P3 8 y o Block 0 ADC3 SPI MISO P4 9 10 ADC4 P5 10 yo PWMO ADCS P6 11 10 PWM1 ADC6 P7 12 yo PWM2 ADC7 P8 13 1 0 CUNET SCL P9 14 1 0 CuNET SDA P10 15 1 0 RS232C Channel 1 RX P11 16 1 0 Block 1 RS232C Channel 1 TX P12 17 yo P13 18 10 P14 19 1 0 High Count channel 0 Pi5 20 y o High Count channel 1 P18 yO P19 1 0 PWM3 P20 yO PWM4 INTO P21 10 Block 2 PWMS INT1 P22 yO INT2 P23 10 INT3 VDD 21 1 0 5V Output Input RES 22 IN RESET Input LOW signal resets vss 23 IN GROUND ViN 24 IN 5 5V to 12V_Input Power 41 SIN SOUT ATN are RS232 communication pins used with a PC or XPORT for DOWNLOAD DEBUG and MONITORING All CUBLOC models have SOUT SIN ATN pins and are connected to a PC serial cable as shown below 7 zah vin 2 231 vss 3 22h res 4 21h voo 5 2f pis 8 7 a 19 P14 180 P13 17D P12 8 160 Pn 10 15h P10 mm pro 12 13 Pa oooooonononno 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 LOW or HIGH The maximum current source sink
5. Modisd Froson 1H Geo Daia 100 The red box shown above is the cursor for Ladder Logic You may use the keyboard 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 to F12 to place the desired symbol You can also enter text for each symbol 350 1 Press F3 to make a contact Skale a cme PL an I a I a Fe a F3 F4 Fs re Fe Fe FS Fit F12 NoT END fa 2 2 Type START and press ENTER 4 1 RC S Ca ae N a F3 F4 Fs Fe Fe Fe Fo Fu Fi2 NoT END a eT at 3 Press F5 couple times and you will see that it creates a line 4 A Seo ea a ed F3 F4 Fs Fe Fe Fe Fo Fu Fi2 NoT END START 1H T 4 Press F7 and iyne RELAY HRE 4 491 eel lt F3 BB A Fa END Insert Delete Undo START 7 1HH En 2 a z 3 5 Go to the next rung line and press END 4 4 1 tatea 7 eal c gt o o F3 F4 Fs Fe Fr Fe F Fii F12 NOT END insert Delete undo START RELAY H H 3 2 ET 4 At the very end of the Ladder Logic you must always put an END command 351 Editing LADDER Text Editing Text To edit an existing TEXT place the cursor in the desired location and press ENTER Now you can edit the TEXT freely as
6. Glocate GLOCATE x y Specify the graphical text position on the current graphic layer cuTOUCH GLOCATE 128 32 locate new position Gprint curouca Gprint GPRINT string Print 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 CUBLOCIS FASTER GPRINT command to print a string at that location GPRINT CUBLOC IS FASTER CR Print String and go to next line CR 274 Dprint DPRINT string DPRINT is similar to GPRINT except that it will over write the current graphics RINT WVE CUBLOC CR Print Strine and go to next line o a19 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 before using Dprint 275 Offset OFFSET x y You can set an offset for printed characters on the graphic layer The default value is 0 You can control either the x or the y axis offsets CUBLOC IS FUN COMFILE TECHNOLOGY OFFSET 3 CUBLOC IS FUN COMFILE TECHNOLOGY After the command the strings will automatically adjust to the new offsets
7. Csgdec Use the CSGDEC command to print decimal values to the display Const Device ch280 Set 12c 9 8 must be used before csgdec command b 8 Do Csgdec 0 b csgdec command Delay 100 b b 1 If b 0 Then b 200 Loop To use CSG commands the SET 12C command must be used beforehand Slave Address Set the slave address of the CSG module at the back 0 to 3 can be set A total of 4 addresses can be set per I2C line pair CSG Dip switch DIP Switch Slave Address 123 on m L E o i 2 123 onf m nm 3 cs as BS COMPILE 286 To display more than 4 digits use 2 CSG modules as shown below and set different slave addresses for each ooooooog C1 I 9 IIE T T CT Csgnput CSGNPUT slaveadr digit data slaveadr CSG module Slave Address digit Digit position 0 to 3 data Data amp h30 to amp h39 amp h41 to amp h46 amp h30 is print 0 amp h31 is print 1 amp h39 is print 9 amp h41 is Print A amp h42 is Print b amp h46 is Print F Display the desired number on the specified CSG module The most significant bit of the data parameter controls the decimal point You can use amp H30 to 39 and amp H41 to amp H46 only Csgxput CSGXPUT slaveadr digit data slaveadr CSG module Slave Address digit Position 0 to 3 data Data Set the LED ON at the specifie
8. zeva Moaod Progam SIE Bys Daa 10 You will see that at first CUBLOC STUDIO will be in TEXT EDITOR Mode If you press F2 the screen will change to LADDER EDITOR Mode and if you press F1 it will switch back to TEXT EDITOR Mode 62 Source files are saved under file extensions CUL and CUB as TWO FILES If you need to backup or move source files you must save BOTH of these files A o A MrDocunens A enam My Pictures cers Open Fies oftype CUBLOC Source flef cul 7 Een A 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 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 IMPORTANT All CUBLOC modules implement code protection By encrypting the downloaded program data your code is safe from any attempt to read part of the chip s memory and copy the source code When you press the RUN button or CTRL R Save Compile Download and Execute are automatically processed LADDER and BASIC both are compiled with one RUN button If an error is found during compilation the cursor will relocate to the error position 63 Creating BASIC Code You can create BASIC code as shown below CUBLOC Text Editor is similar to most text editors and performs syntax highl
9. 45 How to supply power to the CB280 CB380 The CB280 or CB380 does not have an internal 5V regulator you must provide your own 5V power as shown below Pin 20 and 36 are not used please DO NOT CONNECT anything 46 CB290 The CB290 is a 108 pin package of which 91 pins 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 Sout Vad TKI TuTxt Sin Ves 2 TURK Atn RES C B 2 9 0 Avref Vee Vag Vss ss P0 Pa ADco p32 input hy SCR Pt PO_ADGI P33 MOSI_e2 MISO_P3 Pa pwno Ps PUMPS PWMZ PT P56 Ps7 P38 P50 Pe Per P62 Pa P35 P36 paT Pas Pa Pag Pag P10 ADC2 PI ADC3 P12TADCA PI3TADCS Pia ADCS ADCT a o 0 Pea bees KEN Port Pin VO Port Block Explanation SOUT 1 OUT DOWNLOAD SERIAL OUTPUT SIN 2 IN DOWNLOAD SERIAL INPUT ATN 3 IN DOWNLOAD SERIAL INPUT VSS 4 POWER GROUND PO 5 1 0 SPISS PL 6 Input SPI SCK P2 7 VO SPI MOSI P3 8 1 0 Block 0 SPI MISO P4 9 VO P5 10 yO PWM Channel 0 P6 11 yo PWM Channel 1 P7 12 10 PWM Channel 2 P8 25 yO ADCO AD Channel 0 P9 26 10 ADC1 AD Channel
10. I Fix Right Side 114 String Functions String functions are provided to assist the user in accessing and modifying data within a string DP Variable Decimal Places ZeroPrint The command DP converts a variable into a decimal string representation If ZeroPrint is set to 1 zeros are substituted for blank spaces Dim A as Integer DEBUG DP A 10 0 DEBUG DP A 10 1 ie EW owe Gun sap Heb Convert A into decimal String representation Set display decimal places to 10 If A is 1234 bbbbb1234 will be displayed b stands for blank spaces If A is 1234 0000001234 will be displayed Debug Terminal BoudRate Party FORMAT cul BaD y XB 48 a gt at Ble FI BASIC F2 LADDER Ladder Mnemonic Const Device cB260 Dim A As Integer A 1234 Debug Dp A 8 Cr Debug Dp A 10 1 I Fix Right Side 115 HP Variable Decimal Places ZeroPrint The command HP converts a variable into 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 Debug Terminal CUBLOC Studio 0 CUBLOC_Test FORMAT cul Baud Rate Party File Edt Device Run Setup Help Bans X88 AD aw CELE FI BASIC F2 LADDER
11. LTT TT A 3 6 A 3 3 6 Please make note of how much memory is used when using multi dimensional arrays 13 10 130 Bytes of Data Memory DIM ST1 10 AS STRING 12 gt 4 10 20 800 Bytes of Data Memory DIM 20 10 AS SINGLE 86 Bits and Bytes modifiers A variable s bits and bytes can be accessed indivually by using the commands shown below DIM A AS INTEGER A LOWBYTE sH12 Store amp H12 at A s lowest byte LOWBIT Variable s bit 0 BITO to 31 Variable s bit 0 through 31 A 1 e bit 2 of Al SESESESEES SEE SESE S Lowelr MO OO MO Ox SEEEEEEE SSEESEE apy ti LONG Lowert Nibble A nibble is 4 bits The user can access individual nibbles for ease of processing certain types of data LOWNIB Variable s NIBBLE 0 NIBO to 7 Variable s NIBBLE 0 to 7 in Nibble 3 of A LONG 7 T a a Nie wee wer Niao Lownie 87 Byte To specify certain bytes of a variable the below names can be used LOWBYTE BYTEO BYTE 0 of Variable BYTEL BYTE 1 of Variable BYTE2 BYTE 2 of Variable BYTES BYTE 3 of Variable A BYTEL amp HAB Store shab in LONG BYTES BYTE2 BYTE BYTEO LOWBYTE Word To specify a certain Word of a variable the below names can be used A W
12. The CUBLOC and CUTOUCH have an RTOS which controls interrupt events This is slightly different from the microcontroller s hardware interrupts 1 When an interrupt A occurs during the interrupt A another interrupt A cannot occur But a different interrupt B can occur Here A and B are different types of interrupts e g On Timer and On Recv 2 When an interrupt B occurs during the interrupt A interrupt B will be executed immediately and the Main Program will return to interrupt A to finish 3 At the end of your interrupt routine please make sure to include a Return command Otherwise your program can malfunction 4 There is no limit on the number of interrupts and how long an interrupt routine may be 5 Delay and Pulsout commands can be used during an interrupt However Delay and Pulsout time may be affected by other interrupts that occur during their execution To protect against such situations if timing is important please use Set Onglobal Off before calling Delay or Pulsout command like shown here Set Onglobal Off Delay 100 Delay command not affected Set Onglobal On 6 If no interrupt is required for your program you can increase the execution speed of the CUBLOC or CUTOUCH by setting all interrupts off using the command Set Onglobal Off By default Set Onglobal is set to On 7 In case of On Recv data received during an On Recv routine will simply be stored in the receive buffer Therefore the data will
13. 276 Pset PSET xy Places a dot at x y PSET 200 100 Place a dot Color COLOR value Sets the current drawing color 1 is black and 0 is white Default value is 0 COLOR 0 Set color to 0 Linestyle LINESTYLE value Sets the line style You can make dotted lines by increasing the value The default value is 0 a solid line Dotsize DOTSIZE value style Sets the dot size The value is the size of the dot and the style can either be 0 for a rectangular or 1 for a circular dot DOTSIZE 1 1 dot size to 1 and dot type to circle 277 Paint PAINT x y Fill the enclosed area within position x y PAINT 100 100 Fill the enclosed area within 100 100 Arc ARC x y 1 start end Draw an arc with x and y as the center Start and end are the values between 0 and 360 degrees ARC 200 60 100 10 20 Draw 10 to 20 degrees 278 Defchr DEFCHR code data Code Custom character code amp hdb30 to amp hdbff Data 32byte bitmap data Create custom characters using this command A character of size 16 by 16 can be created and stored in the LCD memory Then the character can be used just like any other regular character using the command PRINT or GPRINT and DPRINT A total of 207 custom characters can be stored in the memory At power off the characters are not preserved DEFCHR amp HDB30 HAA GHAA SHAA GHA SHAR GHAA SHAA GHAR _ GHAA SHAA SHAA
14. Getstr2 Gosub Return 165 12Cstop 12Cread 12Creadna T2Cwrite If Then Elseif In Incr Input Keyin Keyinh Keypad Ladderscan Low Memadr Ned Nop On Int On Ladderint Gosub On Pad Gosub On Recv On Timer 12 Opencom Ramclear Reset Set Debug Debug Command How to Set I2c Set Int Set Ladder on off Set Modbus Set Onglobal Set Onint Set OnLadderint Set Onpad Set Onrecv Set Ontimer Set Outonly Set Pad Set Rs232 Set Rs485 Set Until Shiftin Shiftout Stepstop Stepstat Stepaccel Timeset Udelay Usepin CHAPTER 7 CUBLOC DISPLAY LIBRARY Cs Csron Csroff Locate Print CLCD Module GHLCD Graphic LCD GHB3224 Series Overlay Contrast Light Font Style Cmode Line Lineto Box Boxclear Boxfill Circle Circlefill Ellipse Elfill Glocate Gprint Dprint Dotsize Paint Arc Defchr Bmp Gpush Gpop Gpaste Hpush Hpo Hpaste Seven Segment Display CSG Csgdec Csgnput Csgxput Csgdec Csghex CHAPTER 8 INTERFACING Input Output Circuits RS232 HOWTO CuNET CUBLOC STUDY BOARD Circuit Diagram About I2C More About I2C Advanced CHAPTER 9 MODBUS About MODBUS MODBUS ASCII Master Mode MODBUS ASCII Slave
15. LINKPOINT A label cannot use reserved constants numbers or include a blank space Do not do the following dder Reserved constant 123 Number About 10 Blank space 165 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 0 through 56831 amp H00000 through amp HDDFF graphics temperature tables etc The user can store large data for With a backup battery the HEAP memory can be used for datalogging and other persistent uses 55K bytes 000 ak bytes 000 aHDDFF SHFFE Heap Memory EEPROM Memory There are five HEAP memory access functions Function Syntax Feature HEAPCLEAR Heapclear Erase the entire Heap memory HREAD Variable HREAD Address Length Read the designated number of bytes set by Length from the Heap memory address and store into a variable HWRITE HWRITE Address Variable Length Store the designated number of bytes set by Length to the Heap memory Address HEAPW HEAPW Address Variable Store one byte to the Heap memory Address HEAP Variable HEAP Address Read one byte from the Heap memory Address and store into a variable 166 Hread Variable HREAD Address ByteLength Variable Variable to store results Address HEAP memory address ByteLength number of bytes to read constant or variable 1 to 4
16. Sends String data though an RS232 Channel OPENCOM 1 19200 0 50 10 PUTSTR 1 COMFILE TECHNOLOGY DEC I CR Similar to the Put command Putstr stores data to be sent in the send buffer Afterwards the CUBLOC BASIC Interpreter takes care of the actual sending Please also be careful to not overload the send buffer when it s full so you do not lose any data that needs be sent 204 Pwm PWM Channel Duty Period Channel PWM Channel Number 0 to 15 Duty Duty Value must be less than the Period Period Maximum of 65535 Outputs a PWM waveform Be aware that the PWM Channel Number is different from the I O port number For the CB280 Ports 5 6 and 7 are used for PWM 0 1 and 2 Before using PWM make sure to set the Ports used to OUTPUT mode and set them to a known state HIGH or LOW 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 PWM a Period of 65535 is a 16 bit PWM Actual PWM update frequency in Hz is as follows Frequency 2304000 Period The Duty value must to be less than the Period value The PWM output will remain active for Duty counts within the Period time window 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 bi
17. 181 385 406 Ladder Special relays 410 LADDERSCAN LAYER 265 left 118 LEN 119 LIGHT 267 LINE 270 LINESTYLE 227I LINETO 270 M MCS MCSCLR 381 MEMADR 184 MENU 426 MENUCHECK 426 MENUREVERS 426 MENUSET MENUTITLE MID OFFSET ON INT ON LADDERINT ON PAD ON RECV ON TIMER OPENCOM OR OUT OUTPUT OUTSTAT OVERLAY PAINT PAUSE PEEK POKE PRINT PRET ii PWM PWMOFF 206 R RAMCLEAR a 207 Reset 208 RET 407 RETURN 165 REVERSE 209 SBRT Select Case SET DEBUG SET DISPLAY SET I2C SET INTx SET LADDER On Set Modbus SET ONGLOBAL SET ONINTx SET ONLADDERINT SET ONPAD SET ONRECV SET ONTIMER SET OUTONLY SET PAD Set Rs232 407 eae s215 216 cae 226 229 230 235 232 SETOUT SHIFTIN SHIFTOUT Sin SPC SPI SQR STEPACCEL STEPOUT STEPPULSE STEPSET STEPSTAT STEPSTOP STRING STYLE SYS TADIN Tan TAOFF TAON TIME TIMESET TOFF TON UDELAY UP DOWN Counter Usepin UTMAX VAL VALHEX VALSNG VAR 398 250 427 ago 403 397 400 WXCHG WXOR 461
18. E7 46970 5__ 4 895769279 11003 Ke 4540 6 4 890207868 002 iS 42250 5__ 4 884394522 1000 a 40091 5__ 4 878320427 999 3 38055 4 4 871976604 sos 2 361344 4 865353924 996 a 343215 _ 4 858443112 995 lo 32610 0 _ 4 851234752___ 994 a 30993 7 _ 4 8437193 992 2 l29466 8__ 4 835887094 990 3 28023 9 4 827728362 989 la 26660 0 4 819233234 987 5 25370 2 4 810391755_ 985 le 24150 1 4 801193902 983 ia l22995 7__ 4 79162959 lesa is 21903 1__ 4 781688696 979 a 20868 5_ 4 771361072 977 10 19888 7 4 760636561 975 m 18960 5 4 749505017 973 12 118080 8 4 737956327 970 i3 17246 9 4 725980424968 i4 16456 1 4 713567319 965 i5 15706 0 4 700707114 963 i6 149944 4 68739003 960 i17 14318 9 4 673606431957 lbs 13677 7 4 659346849 954 19 13068 7 4 644602011 951 20 12490 3 4 629362861 948 21 11940 65 4 613620595_ 945 22 11418 2 4 597366683 942 23 10921 6 _ 4 580592903 _ 938 24 10449 3 _ 4 563291365 935 25 10000 0 _ 4 545454545 931 26 9572 5 _ 4 527075313 927 27 9165 6 4 508146964 923 28 8778 3 4 488663246 919 29 8409 4 4 468618396 915 Bo lsosg 1__ 4 4asoo7162 911 31 7723 3 4 426824842 __ 907 32 7404 3 4 405067304 902 33 7100 2 4 382731022 89
19. For the CB280 12V signals are provided for RS232 communication Please be careful to use only one of the 5V or 12V connections at a time The following shows a simple circuit diagram to convert from 12V to 5V RS232 signals using a MAX232 chip T 2 22 H ps 12 gt aBocR ow A amp np qe ep MT The MAX232 is a very useful chip for converting between 5V and 12V RS232 signals 10 maxz32 16 20 15 3q I 14 rs2s2coureur ad F 43 netooneur sq A Wb i2 mamn q Fl 44 mineur paesooumn 7 0 5 10 renews meneur 8 Ao ho mour CuNET CuNET is a communication protocol for CUBLOC peripherals such as CLCD GHLCD CSG modules With just 2 pins SCL and SDA you can communicate with up to 127 devices simultaneously CuNET uses CUBLOC s I2C protocol to communicate To use CuNET please make sure to add pull up resistors 4 7K each to the SCL and SDA lines SCL and SDA pins are in a open collector setting protecting against outside noise It automatically removes pulses less than 50ns sout Gt zah vin sin g2 238 vss amn G3 22 res vss ga 210 voo Po qs 20 P15 1 Je cno P1 ge 9p pig 2 5V RESET r2 g7 18h P13 zle sc P3 ge 17D pre e SDA P4 g9 160 P11 4 Ps gio 1s P10 Pei mmm 1p Ps P7 2 13F Ps 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 t
20. Only 1 dimensional arrays are allowed for constants Comparison Array Constant Array Storage Data Memory SRAM Program Memory FLASH Stored Time During Program run During Download Can be Changed Yes No Purpose Changing Values Unchanging values Power OFF Disappear Kept DEMO PROGRAM OC studio d cubloc_esticonstar EAE Bag xaa wm gt wit m IFI BASIC IF2I LADDER Ledder Mnemonic Const Device cB280 Const Byte DATAL 31 25 102 34 1 D O O 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 Debug Dec DATA1 3 Cr Debug Dec DATAL S C Debug Dec DATAT 1 Cr Debug Terminal Pot oud Rate Party Data Bte T Fix Right Side 92 Operators When using mathematical and logical operators the priority table below is used to determine which operator is evaluated first Operator Explanation Type Priority x To the power of Math Highest LMOD Multiply Divide MOD Math Add Subtract Math Left Shift Right Shift Logic Less than Larger than Compare Less or Equal to Larger or Equal to Same Different Compare AND XOR OR AND XOR OR Logic Lowest Please refer to the above table for checking priority of operator used Within each row above the highest priority is calculated from the left to right You can use operators within conditional statements IF Atl
21. Output only io l 9 10 Port Blocks 50 CB405 The CB405 is an 80 pin package of which 64 pins 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 Sout vaa TXE mme Sin ves RXE TuURXE Atn 5 i B 4 0 5 Avadl Avret Vss Ves Vad Vss PO P167 an0 ADB P32 Pas veout SERIE P177 abt Ap P33 Pao seel mosiye2 P181 an2 AD10 P3a P50 L miso rpa P197 AD3 AD11 P35 P51 Pwma PA P201 aos AD12 P38 P52 PWM10 wna PS P211 ADS A013 P37 P53 PWM unt PS P221 aD6 A014 Pae fa Pune PT P231 ADT A015 iPas P55 RX2 IPE P24 HONTI Pa7 Pos x2 P9 P25 HCNTO Pael Paz Piaf P25 Pas ps1 wma jPi P27 wma Pag Poa Pw P12 1 P281 Pw iNTO TX PABI Psa PwMe P13 PWMS INT 1 RX1 P42 P58 Pia INT2 SDA Pat 357 TX3 P15 Jeary INT3 SCL Pad P50 RXS Name Pin TO Explanation SOUT 1 OUT DOWNLOAD SERIAL OUTPUT SIN 2 IN DOWNLOAD SERIAL INPUT ATN 3 IN DOWNLOAD SERIAL INPUT VSS 4 22 64 POWERIN GROUND VDD 21 44 POWER IN 4 5V_to 5 5V Power Supply AVDD 43 POWER IN ADC power AVREF 63 IN ADC Reference Voltage VBB 24 POWER IN Battery Backup RES 23 IN RESET pin TILTXE 61 OUT RS232 to TTL232 curcuit TX contact TTLRXE 62 IN RS232 to TTL232 curcuit RX contact TXE 41 OUT RS232 Output 12V RXE 42 IN RS232 Input 12V 51 The following
22. Read data from the HEAP memory address You can read up to 4 bytes at a time Hwrite HWRITE Address Data ByteLength Address HEAP memory address Data Constant or Variable with data whole numbers only ByteLength number of bytes to write Write data to a HEAP memory address DIM A AS INTEGER 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 NOTE EEREAD and EEWRITE have same syntax as HREAD and HWRITE Function Memory Feature Type EEWRITE EEREAD EEPROM Retains data during power cycles without a battery The EEWRITE command takes about 5mS KB of available memory HREAD HWRITE SRAM Retains data during power cycles with a backup battery Without a backup battery data is lost HWRITE command takes about 20 micro seconds to execute Faster speed in comparison with EEWRITE 55KB of available memory 167 Heapclear HEAPCLEAR Set all 55KB of HEAP memory to zero Heap Variable HEAP Address Variable Variable to store results Address HEAP memory address Returns 1 byte of data from a HEAP memory address Heapw HEAPW Address Data Address HEAP memory address Data Constant or Variable with data Byte only Write 1 byte of data to a HEAP memory address HEAP Memory Addressing The HEAP memory is divided into byte unit addresses When a LONG variable is stored 4 bytes are stored and 4 memory ad
23. SET LADDER ON Declare device to use You must declare the device to be used The following are examples of how to use the CONST DEVICE command CONST DEVICE CB220 Use CI or CONST DEVICE CB280 Use CB280 This command must be placed at the very start of the program 369 Using Ladder Only You must at least do a device declaration port declaration and turn on the LADDER for BASIC even if you are going to only use Ladder The following is an example of such minimal BASIC code Const Device CB280 Device Declaration Usepin 0 In START Port Declaration Usepin 1 In RESETKEY Usepin 2 In BKEY Usepin 3 Out MOTOR Alias MO RELAYSTATE Aliases Alias MI MAINSTATE Set Ladder On start Ladder Do Loop BASIC program will run in infinite loop 370 Enable Turbo Scan Time Mode In order to use both BASIC and LADDER a scan time of 10ms is supported for LADDER If you would like to enable Turbo Scan Time Mode when not using BASIC you can follow the example below The LADDERSCAN command can be used inside a DO LOOP to enable Turbo Scan Time Mode Depending on the size of the Ladder program this scan time MAY change For small programs less than 50 rungs a scan time of 500us to 1ms is possible Const Device CB280 Device Declaration Usepin 0 In START Port Declaration Usepin 1 In RESETKEY Usepin 2 In BKEY Usepin 3 Out MOTOR Alias MO RELAYSTATE Aliases Alias MI MAINSTATE Do
24. Same as GETA command except it will stop reading data at the StopChar even if the data received is less than Bytelength If StopChar is not found then it will operate just like a GETA command StopChar is included in the received data You can use SYS 1 command to check the number of bytes read Dim A 10 As Byte Opencom 1 19200 0 50 10 Geta2 1 A 20 10 Read until Stop Character ascii code 10 is found or 20 bytes have been read Use with CUBLOC STUDIO 2 0 X and above 161 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 This function calculate a CRC when using MODBUS RTU Master Mode GETCRC will return a 16 bit integer CRC value of the set Array You can set the number of bytes to use for CRC calculation from the Array starting at 0 Const Device CB280 Opencom 1 115200 3 80 20 Set Modbus 1 9 Dim A 20 As Byte Dim B As Integer Ramclear Usepin 0 Out Usepin 9 Out Set Ladder On A O AQ A 2 A 3 A 4 A S 9 2 3 o 10 23 Geterc B A 6 Name of Array Debug Hex B Cr Please use byte arrays when using this function 162 Getstr Variable GETSTR channel length Variable String Variable to store results channel RS232 Channel length Length of data to receive Same as Get except the variable to store results can only
25. Sharing Data The CUBLOC has individual BASIC and LADDER data memory areas BASIC DATA MEMORY LADDER DATA MEMORY Variable Variable Variable Variable Variable Variable mmoom gt OA0zNV LADDER data memory can be accessed from BASIC easily by using system variables Using these system variables data can easily be read or written to and from LADDER Syaemvarabie Access Units LADDER Register P Bits _P 0 to _P 127 P Register M Bits _M 0 to _M 511 M Register WP Words _WP 0 to _WP 7 P Register Word Access WM Words WM 0 to _WM 3I M Register Word Access Words 0 to _T 99 T Register Timer Ea Words _C 0 to _C 49 C Register Counter 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 Words use _WP and _WD For example _WP 0 represents PO through p15 The following is an example program _D 0 1234 _D 1 3456 _D 2 100 FOR I 0 TO 99 MI 0 NEXT IF _P 3 1 THEN M 127 1 Accessing BASIC variables from Ladder is not possible but you can use Ladder interrupts to request that a BASIC routine change a Ladder variable 106 Use Ladder pins in BASIC using ALIAS command The ALIAS command can be used to set aliases for Registers except D used in LADDER Both BASIC a
26. 10 THEN GOTO ABC Whole numbers and floating point numbers can be mixed in a calculation The final result is cast to the type of the assigned variable DIM F1 AS SINGLE DIM A AS LONG Fl 1 1234 A Fl 3 14 A gets 3 even though result is 3 525456 Please make sure to include a period when using floating point numbers If your computer s language type is set to one that uses commas for indicating decimals floating point numbers will not be read correctly F1 3 0 4 0 Write 3 4 as 3 0 4 0 for floating values 00 0 FLOOR A 12 0 SOR B 200 as 200 0 12 as 12 0 AND XOR OR is used for logical operations and as Bit operators THEN C 1 and B 1 Logical Operation EN C 1 Logical Operation A B AND amp HF Set the upper 4 bits to zero Bit Operation A B XOR GHF Invert the lower 4 bits Bit Operation A BOR SHE Set the lower 4 bits to 1 Bit Operation 93 Strings can be compared with the sign Strings DIM ST1 AS STRING 12 ASCII values are compared for OK Check if ST1 is same as ST2 Operators used in our BASIC language may differ slightly from common Please refer to the below table math operators Operator Math Basic Example Add 3 4 5 6 A Subtract 10 3 63 B Multiply 2 4 A 5 Division 7 1234 3 3843 A To the power of a 543 AAZ MOD Remainder of mod 102 mod 3 In CUBLOC BASIC a slash
27. 252 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 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 through the RS232 or the CuNet 12C communication protocol 254 Set Display SET DISPLAY type method baud buffersize type 0 RS232LCD 1 GHB3224 2 CLCD Method Communication Method 0 CuNET 1 RS232 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 Please choose the type of LCD the communication method the baud rate and the buffer size CLCDs will use Method 0 Method 1 RS232 Channel 1 Use RS232 Channel 1 for display For the CB220 port 11 TX is used CHANNELO TX sour fT Zap vin RX sin g2 ze vss am ga 226 res vss ga 21h voo Po gs 20 pis pide sf pr r2 g7 seh ma Ps ge s7H ez CHANNEL pa ge 186 P1 TX Ps gio 56 proa RX rogna fi pe pr hie 1h rs For the CB280 pin 33 or pin 49 can be used Pin 49 outputs 12V
28. Laddar Mnemonic Const Device Dim A As Integer A ghabl2 Debug Hp A 6 Cr Debug Hp A 8 1 I Fix Right Side 116 FP Value Whole Number Di Fractional Number Digits Convert floating point variables into a formatted string with user defined whole and fractional number digits Dim A as Single A 3 14 DEBUG Float A 3 1400000 Prints all digits DEBUG FP A 3 2 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 commands or displaying to an LCD Debug Terminal Pot BawRao Poty DBS any 1 m come frts200 z fone z fe Re Cubloc Studio d cubloc_test fptest cul De dt peve Rin tup Hep Bad os XAA gt mH F1 BASIC F2 LADDER Ladder Mnemor Const Device Dim A As A 3 14 3 140000 Debug Float A Cr nia Debug FE Ar 3 2 Cr Clove I Fix Right Side CUBLOC floating point values are stored in accordance to the IEEE724 format The appearance of FP and Float may differ but the value stored in the variable will be the same LEFT Variable Decimal Places Cut specified decimal places of the string from the left side and return the value DIM ST1 AS STRING 12 ST1 CUBLOC DEBUG LEFT ST1 4 CUBL is printed RIGHT Variable Decimal Places Cut specified decimal places of the string from the right side and return the value DIM STl AS STRING 12
29. 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 using global flags An On Recv interrupt occurs after data is received on the serial port AND stored into the receive buffer When an Onrecv is set to On then an interrupt can be received using the On Recv command If an Onrecv is set to OFF then the code for On Recv will not be executed if the interrupt occurs See also the On Recv command Set ONRECV1 On Set ONRECV1 Off 223 Set Ontimer SET ONTIMER On Off At power On Set Onrecv is On by default This command turns On or Off the ability to receive On Timer interrupts using global flags An interrupt occurs at every time interval set by the On Timer command When the Ontimer is set to on then an interrupt can be received using the On Timer command If the Ontimer is set to OFF then the code for On Timer will not be executed if the interrupt occurs See also the On Timer command 224 Set Outonly SET OUTONLY On Off The CB290 CT1720 Rev B output ports are in high impendence High Z state in order to prevent garbage values being output at power ON You must use the Set OUTONLY ON command to enable CB290 CT1720 output only ports Const Device CB290 Set Outonly On Low 24 Model Output only port CB290 P
30. Set Pad 0 4 5 1 Activate Touch PAD Input On Pad Gosub abe 2 Declare pad interrupts Do Loop abe TX1 Getpad 2 3 Interrupt Service routine TY1 Getpad 2 Circlefill TX1 TY1 10 E 4 Draw a circle where it g was touched Return 1 SET PAD 0 4 5 This command will activate the PAD inputs Syntax SET PAD mode packet size buffer size The CUTOUCH has a separate touch controller that will sense touch input and send it back to the CPU through the SPI protocol This touch controller will create a PAD signal that is equal to mode 0 MSB RISING EDGE sampling Input packets are 4 bytes each X and Y 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 PAD input occurs it will jump to label ABC 3 This is the interrupt service routine When a PAD input occurs this part of the code will be executed until Return Getpad will read the data received from touch pad 2 bytes for x position and 2 bytes for y position 4 Draw a circle where touch input was received When this program is executed wherever you press on the screen a circle will appear Please use this program as a skeleton for your touch programs The following is a MENU command and ON PAD command example When 428 a button is pressed a beep will sound and the button will be inversed DEMO FOR CUTOUCH Const Device T1720 Dim TX1 As Intege
31. The following is a chart of commands that can be used with the DEBUG command You can control the DEBUG screen like an output screen or LCD Command Code Explanation Example Usage CLR a Clear Debug screen Debug CLR HOME 1 Move cursor to the upper left corner of Debug HOME the Debug screen GOXY 2 Move cursor to X Y Debug GOXY 4 3 CSLE 3 Move cursor one to the left CSRI 4 Move cursor one to the right CSUP 5 Move cursor one up CSDN 6 Move cursor one down BELL 7 Make beeping sound BKSP 8 BACK SPACE LF 10 LINE FEED Debug ABC LF CLRRI 11 Erase all characters on the right of cursor to the end of line CLRON T2 Erase all characters on the bottom of cursor CR 13 10 Carriage Return go to next line Debug ABC CR You must use above commands within a DEBUG command Debug Goxy 5 5 Dec I Debug Clr TEST PROGRAM 143 Decr DECR variable Variable Variable to decrement No String or Single Decrement the variable by 1 Decr A Decrement A by 1 144 Delay DELAY time Time interval variable or constant up to Long type 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 tasks running Delay 10 Delay about 10 ms Delay 200 D
32. WINC DWINC WDEC DWDEC WINC d DWINC d WDEC d DWDEC d WINC increments Word value in d by one DWINC increments Double Word value in d by one WDEC decrements Word value in d by one DWDEC decrements Double Word value in d by one Usable P M F S c T D Constants Registers d o o o START WMOV 100 DO KE _ _ Se 1 ACTION WINC DO 1 Below is result of LADDER execution DO 99 D1 D2 D3 WADD DWADD WADD s1 s2 d DWADD s1 s2 d Add s1 and s2 and store the result in d WADD is for Word values and DWADD is for Double Word Values Usable P M F s c T D Constants Registers s1 o o o fo s2 o o to To d o o o WSUB DWSUB WSUB s1 s2 d DWSUB s1 s2 d Subtract s2 from s1 and store the result in d WSUB is for Word values and DWSUB is for Double Word Values Usable P m F s c T D Constants Registers s1 o jo jo o s2 o lo jo jo d o fo fo START WMOV 100 DO 1 ACTION WSUB DO 5 D1 1 D1 gets 95 in the above LADDER diagram 398 WMUL DWMUL WMUL s1 s2 d DWMUL s1 s2 d Multiply s1 and s2 and store result in d WMUL is for Word values and DWMUL is for Double Word Values Usable P m F S c T D Constants Registers s1 o o o ko s2 o o o Jo d o o o START WMOV 1234H DO u 1 ACTION WMU
33. dummy dummy value Normally 0 Same function as I2CREAD command without acknowledgement A 12CREADNA 0 SCL spa _ 173 I2Cwrite Variable I2CWRITE data Variable Acknowledge 0 Acknowledge 1 No Acknowledge data data to send Byte value 0 to 255 Sends one byte of data through I2C This command creates an ACK pulse and returns 0 if there is acknowledge and 1 if there isn t If there is no acknowledge there was a communication error possibly due to incorrect wiring This can be used to trigger an error processing function such as below IF I2CWRITE DATA 1 THEN GOTO ERR_PROC If you don t need to check for ACK you can just use any variable to receive the ACK status as shown below A 12CWRITE DATA One byte of data transfer takes approximately 60 microseconds Please refer to Chapter 8 About 12C for detailed 12C communications description 174 If Then Elseif Endif You can use If Then Elseif Else EndIf conditional statements to control execution of your program If Conditionl Then Expression Expression2 Elseif Condition2 Then Expression3 Else lExpression4 End If Usage 1 If A lt 10 Then Bel Usage 2 If A lt 10 Then Bel Else C 1 Usage 3 If A lt 10 Then When using more than 1 line Bel do not put any Expressions after Then End If Usage 4 If A lt 10 Then Bel Else cal End If Usage 6 Usage 5 Te
34. 1B 53 2 Cursor ON Default ESC s 1B 73 2 Cursor OFF ESC B 18 42 2 Backlight ON Default ESC b 1B 62 2 Backlight OFF ESC H 1B 48 2 LOCATE 0 0 ESC L XY 1B4Cxxyy 4 100 uS Change the position of the cursor ESC 1B 44 Code 11 Character code 8 through 15 is D 8byte 8bytes 8 custom characters that the user is free to create and use This command will store the bitmap in this custom character memory area Code 8 15 Character code 1 01 ED Move to beginning of row 1 2 02 1 Move to beginning of row 2 3 03 1 Move to beginning of row 3 4 04 1 Move to beginning of row 4 If received data is not a command the CLCD will display it on the screen When connecting RS232 the maximum baud rate settings for 12V 4 pin levels is 38400 For TTL 5V levels 3 pin up to 115200bps can be used The following is an example of code using the CB280 to connect to a CLCD module through the CUNET protocol CLCD will display incrementing numbers Const Device Cb280 Set Display 2 0 1 50 Dim i As Integer When you execute this program the Set the SLAVE ADDRESS to 1 by manipulating the DIP switch 259 The slave address of CLCD and SET DISPLAY command should match 260 GHLCD Graphic LCD GHB3224 Series A GHLCD is able to display characters and graphics on three different layers Unlike our CLCD the GHLCD supports many different commands for easy drawing of lines circles and boxes Ther
35. 240 33 0 0 159800146 33 241 32 5 0 157350769 32 242 32 0 0 154946682 32 243 31 5 lo 1s2586936 31 244 31 0 lo 150270604 31 245 30 5 lo 147996779 30 246 30 0 lo 145764577 30 247 29 6 lo 143573131 29 248 29 1 lo 141421596 29 249 28 7 lo 139309144 29 250 28 2 lo 137234968 28 NTC THERMISTOR READ TABLE n 10K DIODE TYPE Const Device cb280 Const Integer TH TABLE 992 990 989 987 985 983 981 973 977 975 973 970 968 965 963 960 957 954 951 948 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 195 788 781 774 767 760 753 746 738 731 123 716 708 700 692 684 677 669 661 652 644 636 628 620 612 604 596 587 579 571 563 555 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 332 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 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 0 and 100 degrees For a larger range you can simply modify the code The formula fo
36. 346 Chapter 12 Ladder Logic WARNING If you do not use SET LADDER ON command Ladder Logic will not be executed 347 LADDER Basics The following is an example of one switch and a lamp a If you take out the power the following results m If you express the above circuit diagram as Ladder Logic the following results Hi pg As you can see LADDER is simply an easy way to express circuit diagrams A switch is comparable to the PO port and P9 is comparable to the LAMP There are many ways to connect other devices such as timers counters etc The following is an OR and AND connection in Ladder Logic Po P2 Po 348 In this circuit diagram PO and P2 are connected in the logical combination of AND PO and P3 are ORed If you express the above circuit diagram in Ladder Logic it will be as follows PO P2 i El In CUBLOC STUDIO the right side is not shown In CUBLOC Ladder Logic PO P1 P2 are called Registers Creating LADDER Programs The below screen shows you how Ladder Logic programs are created in CUBLOC STUDIO LOC studio c Wcubloc teers 1018 Edt Device Fun Setup Help 290 d Xe Apam Ble IFI BASC F2 LADDER Eer eale tal HO IFO O Ho ro Fr Ai A nor fra HOHE ES ES Mizara EI pa pe Mo Pe Pa HAT HH ee i MI WORK ON TOGLE M2SNORK OFF TOLE MPS ON INPUT MPG ON OFF TOGLE MPG ON LED
37. 8320 e360 Program Memory 80KB BKB BOE 200E 200K 200KE Data Memory BASIC KB BASIC2KB BASIC 24KB__ BASIC SIKE BASIC 6KB BASIC 6KB LADDER 1KB LADDER IKB LADDER 4KB LADDER 4kB LADDER 1KB LADDER 1KB HEAP 55KB Battery WR WA Availabe Available WA WA Backup EEPROM aE E E E aE KE T O ports 16 6 CEF DEFI CEF 1646 4942 Package 24pin DIP 64 pin 108 pin 80 pin Module 24 pin DIP 64 pin Module Module Module DC Channel B Channel B Channel 16 Channel Channel Channel PWM 3 Ghannel 6 Channel 6 Channel 12 Channel 3 Channel 6 Channel RS232 2 Channel 2 Channel 2 Channel 4 Channel 2 Channel 2 Channel External Interrupt None 4 4 4 a a HIGH COUNT 2 Channal 2 Channel 2 Channa 2 Channel 72 Channel 2 Channel INPUT RTC Tone Tone Yer Tone Wane Tone 40 CB220 CB320 The CB220 is a 24 pin Wide DIP style package It has 16 I O ports and an internal 5V power regulator CB220 rev B and CB320 has 6 spare I O Inputonly Sck_ADC1_P1 6 sour qf sng awds vss q ss_aoce_poq ZAH ViN 5 5v 12Vinput zah vss 22h RES 21h voo 20f Pis Hont 1af Pta_HcNTo 1af Ps iB p12 16h enx 15H P10_Rx1 14 Po sDA cUNET 13 Pe_scuicuner Mosi_Anc2 p2 miso_ancs_p3 d Anca pa d Pwmo_ancs Ps g Pwm1_ance Ps Cf Pwm2_anc7 P7 Cf i
38. AND logic 2 XOR logic 3 Clear screen then pop Pop from stack and display on the specified layer at position x y with specified logic GPOP 120 20 2 0 lt Gpaste GPASTE x y layer logic logic 0 OR logic AND logic 2 XOR logic 3 Clear screen then pop Paste from the stack and display on the specified layer at position x y with specified logic This is exact same command as GPOP except it will not pop from stack Therefore you can use this command if the current item in the stack must be used again 282 Hpush HPUSH x1 y1 x2 y2 layer The HPUSH HPOP HPASTE commands are similar to GPUSH GPOP and GPASTE except that the columns can only be a multiple of 8 as shown below The 320 pixels have been divided by 8 there are only 40 columns each 8 pixels wide 1 01234567890 239 HPUSH 6 20 12 100 2 Hpop HPOP x y layer Same as GPOP except the x value is 0 to 39 HPOP 10 20 2 0 Hpaste Hpaste x y layer Same as GPASTE except the x value is between 0 and 39 283 GHB3224C DIP Switch Settings On the back of the GHB3224B there are DIP switches to set the RS232 baud rate and 12C slave address us
39. Coil Input Status Function Codes 1 2 4 15 Device Address Decimal Data 1 to 128 P Registers 385 to 512 F Registers 4097 to 8192 M Register Word Access Holding Input Registers Function Codes 3 4 6 16 Device Address Decimal Data 40001 to 41000 D Registers 41001 to 42000 T Registers 42001 to 43000 C Registers 43001 to 44000 WM Registers Floating Device Addresses Please use Device Addresses within the available number of registers for the module used For example the CUBLOC CB280 has data registers DO through D99 There are only Device Addresses from 40001 to 40099 The addresses 400100 through 41000 are not to be used 310 Function Code 01 Read Coil Status Function code 02 Read Input Status This function code can read the bit status of PLC s Register The following is an example of reading Registers P20 through P56 from Slave Address of 3 Query Field RTU Bytes ASCII Bytes Header colon 1 Slave Address 0x03 1 03 2 Function Code 0x01 1 01 2 Start Address HI 0x00 4 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 CRLF 2 LRC is the 2 s complement of 8 bit sum of all packet values except 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 we can in
40. LadderScan Loop F16 is a special Register for checking the current scan time You can connect it to an I O port as shown below and check it with an oscilloscope FI PO H Below is an example of a conditional case where Turbo Scan Time is used Only when Register MO is ON will the Turbo Scan Time be enabled Do Set Ladder On 10 ms Scan when MO is OFF Do While _M 0 1 LadderScan Only Execute when M is ON Loop Loop 371 Things to Remember in LADDER Input symbol must be placed at the very left side of the Ladder Logic Output symbol must be placed at the very right side of the Ladder Logic dio untitled cul 1 Fle Edt Run Seup Help BoJ ABS meaa Fil BASIC F2 LADDER arta 1 le 43 40 5 RAEN ra ra rs rs r pe re Fir FghaoT Eno Po Ps mi ret 2 Pa 5 s Ht 4 5 6 7 Ei 8 s 10 Bi E e ee A 372 Identical outputs must not collide Po P5 C1 Po PS CJ You may not use more than one vertical line as shown below More than 1 division will give compile error Po Fp PS H H p Pe P3 P7 Po PI Ps I L Po P3 F7 HH 373 Ladder Logic moves from top to bottom P0 PI HHIH PO PS Po HET x Q O gt HHH A Function Register can not be on the left side of the Ladder Logic When a Ladder Logic rung becomes complex simply divide them so you can
41. Memadr Variable MEMADR TargetVariable Variable Variable to store results No String or Single TargetVariable Variable to find physical memory address The Memadr command will return the memory location of the specified 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 184 Ncd Variable NCD source Variable Variable to store results No String or Single Source source value 0 to 31 The command NCD is used to return a value with the specified bit set to 1 I NCD 0 Result is 00000001 I NCD 1 Result is 00000010 I NCD 2 Result is 00000100 I NCD 3 Result is 00001000 I NCD 4 Result is 00010000 I NCD 5 Result is 00100000 I NCD 6 Result is 01000000 I NCD 7 Result is 10000000 eN Cow Die Ter TFI BASIC F2 LADDER Ladder nerf Pot BeudRate Party DetaBis an Const Device CB280 ont gt 115200 None 7 erx Dim A As Long A 10 Debug Dec A Cr A Nul 1 Debug Dec A Cr A Ncda4 Debug Dec A Cr A Ded 15 Debug Dec A Cr Close I Fix Right Side 185 Nop Nop This command does nothing It simply takes up one command cycle time The Nop command is useful for tuning small intervals Low 8 Nop High 8 Output very short pulse to port 8 Nop Low 8 About 50 m
42. 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 of 474 0r7 194 594 o 4 227 02404 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 181 Ladderscan LADDERSCAN This command LadderScan will force 1 scan of LADDER When put inside an infinite loop it will force high speed Ladder processing Turbo mode If you use the command as shown below you will not be able to use BASIC at the same time Const Device CB280 Device Declaration Usepin 0 In START Port Declaration Usepin 1 In RESETKEY Usepin 2 In BKEY Usepin 3 Out MOTOR Alias MO RELAYSTATE Aliases Alias MI MAINSTATE Do LadderScan Loop 182 Low LOW Port Port I O Port number 0 to 255 Set the Port to LOW state This command sets the Port to output state and outputs LOW or OV GND OUTPUT 8 Set Port 8 to output state LOW 8 Set Port 8 to LOW 0V 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 Vad Vdd Vis vss HIGH O LOW 0 183
43. START SLAVE ADR FUNCTION DATA CRC END T1 12 13 T4 1 Byte 1 Byte N Bytes 2 Byte T1 T2 T3 T4 CUBLOC support CUBLOC supports MODBUS commands 1 2 3 4 5 6 15 and 16 Command _ Command Name 01 02 Bit Read 03 04 Word Write 05 1 Bit Write 06 1 Word Write 15 Multiple Bit Write 16 Multiple Word Write In MODBUS there are addresses which stand for Registers in CUBLOC CUBLOC s Registers P M F C T and D can be accessed using the following table Bit Units Word Units Address Register Address Register 0000H P 1000H M 2000H Not Used 3000H Not Used 4000H F 5000H T 6000H Cc 7000H D 8000H WP 9000H WM 0A000H WF 309 Device Address The table below shows MODBUS device addresses Device Addresses are used to identify different registers on the CUBLOC or CUTOUCH Most Host equipment including CUBLOC CUTOUCH PC and HMI will use the following rules Device Address Modbus Address Explanation 1 10000 Device Address 1 Subtract one to get Modbus Address 40001 50000 Device Address 40001 Subtract 40001 to get Modbus Address Device Addresses after 40000 are word registers meaning you can access 16 bits at a time Please refer to the below Device Addresses when using MODBUS with a CUBLOC or CUTOUCH Device Addresses here are shown as decimals Bit Access
44. The following is an example of BLOCK AND and BLOCK OR BLOCK AND PO P2 PS 1H PI Pg 1H PO P2 PE 1 PL P3 E BLOCKOR 378 SETOUT RSTOUT SETOUT will turn ON P5 when PO turns ON and will keep P5 ON even if PO turns off On the other hand RSTOUT will output OFF when P1 is ON and will keep P5 off even when P1 turns OFF PO SETOUT P5 1 PI STOUT P5 1 Registers tht P M F S c T D Constants can be used SETOUT o o o RSTOUT o o o PO Pi PS DIFU DIFD This command DIFU turns ON the output 1 scan time when input goes from OFF to ON Conversely DIFD turns OFF the output 1 scan time when input goes from ON to OFF PO x P5 F 0 PI PG D PO P1 P5 gt j 1 SCAN Pe gt j Scan 380 MCS MCSCLR The command MCS and MCSCLR allow the Ladder Logic between MCS X and MCSCLR X to be executed when turned ON If MCS is OFF the Ladder Logic between MCS X and MCSCLR X will not be executed By using this command the user is able to control a whole block of Ladder Logic Mes 0 7 In the above example when MO turns ON Ladder Logic between MCS 0 and MCSCLR is executed normally If MO is OFF P5 and P6 will not be processed MCS numbers can be assigned from 0 to 7 MCS numbers should be used from 0 increasingly to 1 2 3
45. USEPIN 1 0 In Out AliasName 1 O 1 0 Port Number 0 to 255 In Out In or Out AliasName Alias for the port Optional 455 Utmax UTMAX variable Variable Variable for decrement No String or Single Wait WAIT time time delay time mS 10 to 2147483640 Waittx WAITTX channel channel RS232Channel 0 to 3 Wmode WMODE value value 0 FAST 1 SLOW 456 Index endif if constant ifdef ifndef T4113 111 124 126 378 278 110 110 110 122 B BCD2BIN we 127 BCLR 128 BEEP 129 BFREE 130 BIN2BCD 2131 BOX 271 BOXCLEAR sare BOXFILL z273 BYTEIN BYTEOUT 134 CALLS CheckBf CHR a CIRCLE CIRCLEFILL COMPARE CONTRAST Cos COUNT COUNTRESET CSGDEC CSGHEX DECR DEFCHR DELAY DIFD DIFU DO LOOP 146 G DOTSIZE 277 HEAP 149 HEAPCLEAR 151 EEWRITE 152 EKEYPAD 153 ELFILL 273 ELLIPSE EXP 273 110 HWRITE oat LAT Hyperbolic Cos 114 Hyperbolic Sin 2111 Hyperbolic Tan 268 154 117 I2CREAD 156 I2CREADNA 157 I2CSTART I2CSTOP 458 I2CWRITE 174 175 176 177 If Then Elseif Else EndIf INPUT INTON KCTD KCTU KEYIN KEYINH KEYPAD KTAON KTON 389 389 179
46. 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 m oso IA 1 THEN_M 1 4 IfB 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 28 Advantages of an _ On Chip PLC Embedded Computer One of the main advantages of CUBLOC is that it is an On Chip PLC Normally we think of 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 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 29 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 the desired product which reduces the cost and size of your final product and most importantly allows your product to be one of a kind The following table shows differences between a tradit
47. 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 42 Supplying power to the CB220 CB320 CB220 320 has an internal 5V power regulator that accepts a DC input between 5 5V to 12V It will produce a stable 100mA 5V When using the internal regulator the supply voltage can be applied to pin 24 and 5V will appear on pin 21 If a 5V regulated power source is already available the user may simply connect it to pin 21 If your application requires more than the 100mA of current that can be supplied by the internal regulator please use a separate power supply Method 1 DC5 5 12V Th uT B vs h nes E oo Bess B pia Bes mr hriz Ben Be Hes Bre Method 2 w7B pr 1B en 15 Pio up po 1af Pa 43 CB280 CB380 The CB280 or CB380 is a 64 pin package and 49 of those pins can be used for I O The CB280 or CB380 does not have a 5V internal regulator you must supply a 5V regulated power source Port Pin 1 0 Port Explanation Block SOUT 1 OUT DOWNLOAD SERIAL OUTPUT SIN 2 IN DOWNLOAD SERIAL INPUT ATN 3 IN DOWNLOAD SERIAL INPUT VSS 4 POWER GROUND PO 5 VO SPISS PL 6 Input SPI SCK P2 7 yO SPI MOSI P3 8 1 0 Block 0 SP MISO P4 9 yO P5 10 10 PWM Chan
48. i CuNET 4 CuNeT dumper Bread Board i DCSVINPUT RS232 CHANNEL 1 POWER siw When 9V is supplied the 5V regulator inside the Study Board will automatically provide 5V to the module and peripherals DC Adaptor polarity can be used either way For normal operation please use a 9V adaptor with at least 200mA of current 298 Cubloc Study Board Schematic dese cenyyss 1 RS232 Channel 1 Connection point to use the RS232 Channel 1 please connect wires to the appropriate pin input on the upper right hand corner labeled RS232C cB280 2 For the CB280 connect RS232 Channel 1 as shown below 55 all Rx I5 Rx 3 When using CuNET all jumpers must be shorted If using pin 8 and 9 for general I O please leave all jumpers to the open state 299 About I2C CUBLOC provides an easy set of commands to communicate using the 12C protocol I2C communication is a widely used protocol mainly used for communicating with ADC EEPROM DAC External I O chips I2C uses two lines SDA and SCL and operates in either MASTER or SLAVE mode CUBLOC can only be used as a MASTER Please make sure to use the command SET I2C before using 12C commands 1I2C s START STOP When SCL Clock and SDA Data
49. 0 IN START Usepin 1 OUT RELAY Usepin 2 IN BKEY Usepin 3 OUT MOTOR 248 Utmax UTMAX variable Variable Variable for decrement No String or Single Increment the variable by 1 When the maximum is reached the variable is no longer incremented The maximum here refers to the variable 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 Wait Wait time Time interval variable or constant mS unit 10 to 2147483640 Wait for the specified time in milliseconds This command will generate a delay using the system clock This delay function is accurate to 10ms units It is much more precise than the Delay command Wait 10 Delay 10 ms Wait 15 Delay 10 ms Wait 110 Delay 110 ms Wait 115 Delay 110 ms 250 WaitTx WAITTX channel channel RS232Channel 0 to 3 This command WaitTx 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 have been sent LOOP Using WaitTx the process of sending data is simpler as shown below OPENCOM 1 19200 0 100 50 PUTSTR 1 ILOVEYOU CR WAITTX 1 Wait until all data have 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 251 MEMO
50. 02 Bit Read 03 04 Word Write 05 1 Bit Write 06 1 Word Write 15 Multiple Bit Write 16 Multiple Word Write Please refer to Chapter 9 for detailed MODBUS description and MOBUS ASCII and RTU examples The term returninterval is the delay time for CUBLOC or CUTOUCH to respond to the Master MODBUS device If the returninterval is set too fast the Master device might not be able to receive all data The default setting is 1 which is about 200 micro seconds The user may also set this value to 100 which is about 4 5ms or to 255 which is about 11ms 218 Set Onglobal SET ONGLOBAL On Off At power On Set Onglobal is ON by default This command turns on or off the ability to process ALL interrupts When Onglobal is turned Off and turned On all interrupt settings set before turning Off will be in effect SET ONGLOBAL OFF Turn ALL interrupts OFF If you don t use any interrupts you can turn off all interrupts to increase the execution speed of CUBLOC Set Onint SET ONINTx On Off At power On Set Onint is ON by default This command turns On or Off the ability to receive individual external interrupts using global flags The names of these flags correspond to the interrupt number supported by the device For example ONINT1 is used for Interrupt 1 When the ONINTx flag is set to ON for a specific interrupt then an interrupt can be received using the ON INTx command If the flag is set to OFF then the code fo
51. 0lines 49 0lines SV S3inputony 52 64 vo lines SV TTL Purpose YT TTD auur output ony 26 inputyoutout Tyo Coputyoutput Gnputyoutput ctoutput cingurete 7 wigureble inguraie configurable Teer pons 2 sera pons 2 senal pons a aE Chamel o RS2 Channel o RS2 crennel 0 Rs232c Channel 0 RS232C Seia Giay 12M channel 1 Sur Channel 103 chennelt Tr Chane 1 RS232C 12V arn SV Rs232 TTL SV Serial 5V RS232C 12V amp Configurable Baud Configurable Baud rates Ports Conngurabie TEV fates 2400bps to 2ao0ps to 230 400 bpe Baud fates Configurable 230 400 bps 240005 to Baud tates 230400 ops 2aodops to 230 400 bos Analog Channel 10 bit 8 Channel 10 bit Aog nel nel 1 B channel 10 bit ADCS 16 channel 10 bit ADCs Schama 6 6 thamel Te 5 Channel 165E Aa hanne Te Analog bit PWMs DACs bit PWMs DACs PWMs DACs PWMs DACs Outputs trequency rrequengys rrequencyeashzto Prequencys 35h2 to jonetorstin snetorsine Lemme ise External 4 Channels in taemai a cana 4 channels 4 channels 4 channels High annel 32 bit annel 32 bit Eh 2 nannela2 ie 2 channel 32 0 z channel 32bit 2 channel 32 bit pe P P Counters up to 2Mhz Counters up to 2Mhz Counters 2Mhz 2Mhz 5 to 12V 40mMA SV 40mA ports 5V 70mA ports 5V SOmA ports Powar ports unloaded unloaded unloaded unloaded RTC No No Yes No Data Memory None None optional Optional Backup
52. 10 AD CHANNEL 14 P39 52 10 AD CHANNEL 15 P40 60 1 0 SCL CUNET clock pin P41 59 10 SDA CUNET data pin P42 58__ 1 0 RXI TTLRX channel 1 5 P43 57 10 TXI TTLTX channel 1 P44 56_ 10 P45 55 10 P46 54 10 HCNTO High Counter 0 P47 53 10 HCNTL High Counter 1 Pas 65_ 70 P49 66 10 P50 67 10 6 P51 68 10 PWM CANNEL 9 P52 69 1 0 PWM CANNEL 10 P53 70 10 PWM CANNEL 11 P54 71 1 0 P55 72 10 P56 80 70 RG TTLRX channel 3 P57 79 10 3 TTLTX channel 3 P58 78_ 0 7 P59 77 yo P60 76 10 P61 75 10 P62 74 10 P63 73 10 53 How to connect a battery to CB290 CB405 When a supercapacitor is connected to the VBB of a CB290 CB405 the memory can be maintained for 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 that pin 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 of emergency use VBB cB290 mr Power Features Operating Voltage 4 5V to 5 5V Operating Clock 18 432MHz 1 O Port Source Current 20MA I O Port Sink Current 25MA Operating Temperature 40 to 125 Degrees Celcius Maintenance
53. 182 2 x 131 4 x 25 mm 182 2 x 131 4 x 25 mm Size Viewing Area Touch sensitive Viewing Area Touch sensitive 4 5 x 3 4 5 6 diagonal 4 5 x 3 4 5 6 diagonal 416 Hardware Requirements The Cubloc Studio software used to develop for the CUTOUCH will run on a computer with Windows XP 2000 or 98 installed If you would like to use it in Linux Unix Macintosh environment you will need to install virtual machine software of some type such as VMware that will allow the Windows operating system to run on it An RS232 port is also required or you may use a USB to RS232C converter Download and Monitoring is possible when connected to a PC When the CUTOUCH is disconnected from a PC it is in a stand alone mode The main program is stored in the CUTOUCH s flash memory and will be retained even with no power The user may download new programs and erase them 10 000 or more times per device Above Picture of CUTOUCH ready for programming 417 Software Development Environment The CUTOUCH uses Cubloc Studio as its main development environment For graphics we provide automatic code generating GUI Graphic User Interface software CuCANVAS and PixelStudio Cubloc Studio is used for BASIC and Ladder Logic programming on the CUTOUCH CuCANVAS is mainly used for creating boxes circles and menu buttons while PixelStudio allows the user to create up to 200 custom characters All development s
54. 3 12893 6 21 11561 9 11940 6 12320 7 22 11061 0 11418 2 11776 4 23 10584 56 10921 6 1259 2 24 10131 3 10449 3 10767 5 25 9700 0 10000 0 10300 0 26 9281 3 9572 5 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 1Kohm 1 NTC TH 5 1V ZENER DIODE 0 47uF CUBLOC A D CHANNEL 0 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 0 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 330 femp Resistance Voltage A D value 30 175996 6_ 4 971750865 1018 29 165473 9 4 969965259 11018 28 155643 6 _ 4 968080404 1017 Laz 146456 3 _ 4 966091647 1017 26 137866 4 _ 4 963994167 1017 25 129831 7 _ 4 961782976 1016 24 122313 4_ 4 959452909 1016 23 115275 4_ 4 956998627 1015 22 108684 3 4 954414614 015 bai 102509 3 _ 4 951695171 1014 9 552288 3 4 90617073 1005 g 49549 7 _ 4 901087406 1004
55. 4095 Data Data to write to EEPROM up fo Long type values ByteLength Number of Bytes to write 1 to 4 446 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 fo 15 Ellipse ELLIPSE x y rl r2 EIAI ELFILL x y ri r2 Freepin FREEPIN 1 0 1 0 1 0 PORT Number Font FONT fontsize efontwidth fontsize 0 to 8 Font Selection efontwidth 0 fixed width 1 variable width Fp Variable FP Value Whole Number Digits Fractional Number Digits Freqout FREQOUT Channel FreqValue Channel PWM Channel 0 to 15 FreqValue Frequency value between 1 and 65535 Get Variable GET channel length Variable Variable to store results cannot use String Single channel RS232 Channel 0 to 3 length Length of data to receive 1 to 4 Getere GETCRC Variable ArrayName Bytelength variable String Variable to store results Integer type ArrayName Array with data Must be a Byte array Bytelength of bytes to calculate CRC Getstr Variable GETSTR channel length Variable String Variable to store results channel RS232 Channel length Length of data to receive Getstr2 Variable GETSTR channel length stopchar Variable String Variable to store results channel RS232 Channel length Len
56. 6 Channel R5237 2 Channel 2 Channel 2 Channel 4 Channel 2 Channel 2 Channel External Interrupt None E 4 4 4 4 HIGH COUNT 2 Channa 2 Channel 2 Channa 2 Channel 2 Channel 2 Channel INPUT RIC Tone None Yes Tone None Tone Preface Comfile Technology has been developing PLC and BASIC controllers since 1997 Based on our past knowledge of this field we are providing a unique product that is powerful flexible and has the best features of both BASIC controllers and PLCs Programmable Logic Controllers As a result of our experiences developing and selling TinyPLC and PicBASIC modules older chip based PLCs and BASIC controllers we continue to work hard on new and improved products every year CUBLOC is able to adapt to the user s programming strengths by providing side by side BASIC and LADDER processing But unlike other products you can choose to use CUBLOC as a BASIC controller only or as a PLC controller only 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 process BASIC and Ladder Logic simultaneously through on chip multitasking By sharing data in common memory users are able to integrate both BASIC and LADDER effi
57. Ag Then FE NAIR Then Elseif A lt 20 Then per c 1 EE TS Elseif A lt 40 Then ot c 2 End If ie D 1 End If 175 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 Variable When you execute this command CUBLOC will automatically set the Port to input and read the status 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 TIPS By default all I O Ports are set to HIGH Z at power ON When a Port is set to output it will either output HIGH or LOW signal HIGH is 5V and LOW is OV or GND ground 176 Incr INCR variable Variable Variable to increment No String or Single Increment the variable by 1 INCR A Increment A by 1 177 Input INPUT Port Port I O Port number 0 to 255 Set the specified Port to High Z High Impedance input state All I O Ports of CUBLOC module are set to HIGH Z input 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 HIGH Z input state 178 Keyin Variable KEYIN Port debouncingtime Variable Variable to store
58. An additional 80 bytes are used for the DEBUG command Subs Functions and interrupt routines use up data memory space when running 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 reducing the memory available for global variables However this will often save memory as the local variables will be destroyed after the subroutine completes and the memory can be used by another subroutine When the user creates buffers with SET DISPLAY or OPENCOM the data memory will lose the amount of memory dedicated to those buffers Initializing Memory CUBLOC BASIC data memory is not cleared at power up The user should initialize variables to zero or use RAMCLEAR command to clear the whole memory Ramclear The data memory will contain garbage values at POWER UP In the case of Battery backed up modules the variables will remember their values after a power cycle powering Off and On If the content of the variables is important Ramclear should not be used 85 Arrays CUBLOC BASIC supports up to 8 dimensional arrays each dimension allowed up to 65535 members DIM A 20 AS BYTE Declare A s array size as 20 DIM 8 200 AS INTEGER Declare Integer array DIM C 200 AS LONG Declare Long array DIM 20 10 AS SINGLE 2 dimensional Single array DIM ST1 10 AS STRING 12 Declare String array
59. ByteLength Address 0 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 B Eeread 0 2 Store A in Address 0 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 EEPROM for data acquisition or data that requires a lot of writes we recommend using a module with battery backup memory instead such as the CB290 or CB405 One alternative is an RS232 CF or SD memory interface module The following is a table showing comparisons betweens SRAM and EEPROM Type Battery Backup SRAM EEPROM Life of Data Depends on battery capacity 40 Years Maximum Writes Infinite About 100 000 Writing Time Oms 3 to 5 ms General use Store often used variable Important data that needs to information over a power survive even a backup battery outage Example daily failure Example Product production counter Serial Number 152 Ekeypad Variable EKEYPAD portblockin portblockOut Variable Variable to store results Returns Byte Portblockin Port Block to r
60. 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 CUBLOC can simply request for data when it wants to it does not have to wait for the I C Slave device to respond As a result a CUBLOC CB280 module can interface with up to 24 separate I2C buses That s buses you can add multiple 12C devices per I2C bus The CUBLOC simulates a Master I C device Since it can only simulate a Master I C device the 12C devices connected must be Slave I C devices Note The I O port used for 12C communication must be an Input Output port not Input Only or Output Only sv ne SCL k l l i Slave Slave Slave Slave Slave Address Address Address Address Address tH ont a pr aor Even though the maximum range for a typical IC bus is around 12 feet a long distance extender chip such as the P82B715 can be used to extend the bus almost up to 3 4 mile A P82B96 can also be used as a buffer to protect the 12C devices in case of electrical surges and interference 304 we qf h vee xg FY LX LY Buffered Bus LDAorLCL sx P82B715 J sY 5x SY 12C Bus SDAor SCL ono O p we Extend to about 3 4 mile using
61. Iac Debug al I Fis Right Side 83 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 ST1 AS STRING 12 ST1_A Array is created at the same time Baal GIES ST1_A 0 ASC A Store A in the first character of ST1 When you declare Dim Stl as String 12 St1_A 12 is also declared automatically by the 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 BaudRete Party Data Bt None gt Peet BLOC studio d cubloc_testistring cul fon x 15200 fue e HIE Gove Bin sei Bep aad iad _ Sn 9 424 4 gt on Bo FI BASIC F2 LADDER Ladder Mnemoni Const Device CB280 Din A As Integer Dim st As a 30 st CONFILE Debug st Cr For A 0 To 12 st_a A As Then st_a a i End IF next pebug st cr I Fix Right Side With string arrays you may not use this feature Dim st 10 As String 3 About Variable Memory Space In the CB220 and CB280 2KB 2048 bytes of data memory is available You may not use the whole data memory for variables Part of the data memory space is reserved for use by peripherals such as DISPLAY and the RS232 buffers
62. Integer Dim TX1 As Integer TY1 As Integer Contrast 550 Set Pad 0 4 5 On Pad Gosub GETTOUCH Menuset 0 2 120 155 195 200 Menutitle 0 20 14 RESET Do Locate 15 6 Print DEC5 I Iner I Delay 200 Loop GETTOUCH TX1 Getpad 2 TY1 Getpad 2 If Menucheck 0 TX1 TY1 1 Then Pulsout 18 300 e 8 nd 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 MENUTITLE command sets the name of the button itself PULSEOUT outputs a BEEP sound to the piezo 431 SAMPLE 3 Draw a circle where your finger touches lt Filename CT003 CUL gt Const Device Ct1720 Dim TX1 As Integer TY1 As I Contrast 550 Set Pad 0 4 5 On Pad Gosub GETTOUCH Do Loop teger GETTOUCH TX1 Getpad 2 TY1 Getpad 2 Circlefill TX1 TY1 10 Pulsout 18 300 Return 432 SAMPLE 4 Make a virtual keypad and accept numerical values GETTOUCH lt Filename Const Device Ct1720 Dim TX1 As Integer TY1 As Integer Dim I As Integer Contrast 550 Set Pad 0 4 5 On Pad Gosub GETTOUCH Menuset 0 2 165 50 195 75 Menut 0 11 4 2 Menuset 1 2 205 50 238 75 Menutitle 1 11 4 2 Menuset 2 2 245 50 275 75 Menutitle 2 11 4 3 Menuset 3 2 165 85 195 110 Menutitle 3 11 4 4 Menuset 4 2 205 85 Menutitle 4 11 4 5 Menuset 5 2 245 85 275 110 Menuti
63. Library The CUTOUCH supports extra commands for easy to use menus These commands allow easy creation and manipulation of the menus With the menu system library a menu system as shown below can be made in less than 5 minutes Comfile Automobile gas pressurizer MENU Commands The CUTOUCH has memory space for about 100 MENU buttons Use the MENUSET command to set the x and y axis position as well as the style of the MENU Then the MENUTITLE command can be used to name the MENU When a touch input is received the MENUCHECK command can be used to decide which MENU button was pressed 0 99 Each MENU button can be reset to another x and y axis position and style by using the MENUSET command The only restriction is that up to 100 buttons can be present on one screen The user is free to reset each button to another usage for each screen resulting in virtually unlimited button and menu capabilities 424 Menuset MENUSET index style x1 y1 x2 y2 Index Menu Index Number Style Button Style 0 none 1 Box 2 Box with Shadow X1 y1 x2 y2 Menu Button location The Index value must be between 0 to 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 E 0 1 2 x1 y1 x2 y2 are the x and y axis positions of the left upper and lower right corners
64. Normal Close Input Output Register Symbol Input Output Registers are the most basic symbols among the Registers in Ladder Logic Contacta ro pi j H E J N enis SurpurRelay Function Registers Function Registers include timers counters and other math operation Registers PI TON T0100 l 1 Function Relay Internal Registers Internal Registers M only operate within the program Unless connected to an actual external port it is only used internally You may use M Registers as input or output symbols ACTION Mo Mo WMOV 100 D0 E 1 P Registers that are not used as I O ports CUBLOC supports P Registers from PO to P127 P Registers are directly connected to I O ports 1 to 1 But most models of CUBLOC have less than 128 I O ports In this case you may use the unused portion of P Registers like M Registers 366 Using I Os CUBLOC I O ports can be used by both BASIC and LADDER Without defined settings all I O ports are controlled in BASIC To control 1 0 ports in LADDER you must use the Usepin command and set the I O ports to be used in LADDER USEPIN 0 IN USEPIN 1 0UT The above code sets PO as input and P1 as output for use in LADDER The inner processes require that USEPIN will be re flashed in LADDER Re flashing means that the Ladder will read I O status beforehand and store the status in P Registers After scanning LADDER will re write the status of 1 O ports int
65. Output turns ON DZ si 52 DWord 32 bit When si lt 52 Output turns ON D gt si 52 DWord 32 bit When si gt s2 Output turns ON D lt si s2 DWord 32 bit When s1 lt s2 Output turns ON DO TI Mo You can mix different comparisons as shown below co 93 Mo 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 larger or equal to 99 390 Storing Words and Double Words A Byte is 8 bits a Word is 16 bits and a Double Word is 32 bits 1BYTE DOUBLE WORD There are 2 ways to store Word or Double Word data A Word or Double Word can be stored starting from the LOW BYTE or from the HIGH BYTE In CUBLOC it is stored from the LOW BYTE or LSB Least Significant Byte As you can see below 1234H is 0 34 stored in Memory Address 0 and A 12 12345678H is stored in Memory 3 Address 5 In every Memory 4 Address 1 byte of data is stored 3 7 34 8 12 9 The Registers C T D are in units of Words To store Double Word data 2 Word spaces will be required meaning two Register spaces Below is an example of storing a Double Word 12345678H D1 gets 1234H and DO gets 5678H DO 5678 D1 1234 D2 D3 D4 Binary Decimal Hexadecimal To program well we need to know binary decimal and hexadecimal numbers Th
66. 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 B 1 End Function By placing A A 1 in a function the user will be able to separate one big program into small chunks As you can see here the main program ends at the End command and functions are added afterwards MAIN PROGRAM End Sub Program 72 Sub and Function For subroutines you can either use Sub or Function Sub does not return any values and Function does return values 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 Return Bt End Function DEMO PROGRAM CUBLOC studio dlcubloc_test functest cul Ble Ese Dece kun set te pAVHU SSSRMr gt HS Device cB280 A Rahig Rac a er ADD_VALUE A on ADD_VALUE E 4 ADD_VALUE B 1 end Function 1 ys 73 Global and Local Variables When you declare variables inside a Sub or Function it is considered to be a Local variable The Local Vari
67. Relay se TL Prelay usage 362 Register Expression CB220 CB280 CB320 CB380 Registers The following is a chart that shows CB220 CB280 CB320 and CB380 Registers Register Name Range Units Feature Input Output Register P POtoP127 1 bit Interface w External devices Internal Registers M MOtoMS5ii_ 1 bit Internal Registers Special Register F FOtoFi27 1bit System Status Timer T TO to T99 16 bit 1 Word For Timers Counter C CO to C49 16 bit 1Word For Counters Step Enable S S0 to 515 256 steps For Step Enabling 1 Byte Data Memory D DO to 99 16bit 1 Word Store 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 you can use WP WM or WF Register Range Units Feature Name WP WPO to 7 16 bit 1 Word Register P Word Access WM WMO to WM31 16 bit 1 Word Register M Word Access WF WFO to WF7 16 bit 1 Word Register F Word Access WPO contains PO through P15 PO is located in the LSB of WPO and P15 is located in the MSB of the WPO These Registers are very useful to use with commands like WMOV PO MO Fo TO co Do cag T99 088 P127 piar S EZ ae Se Tobit Teit Tit Tit M511 lt 7 363 CB290 and CB405 Registers The following is a chart that shows CB290 and CB405 Registers The CB290 and CB4
68. TY1 As Integer Contrast 450 Set Pad 0 4 5 On Pad Gosub GETTOUCH Do Loop GETTOUCH TX1 Getpad 2 TY1 Getpad 2 Circlefill TX1 TY1 10 Pulsout 18 300 Return 190 On Recv ON RECVO GOSUB label ON RECV1 GOSUB label ON RECV2 GOSUB label ON RECV3 GOSUB label When data is received on RS232 Channel 0 to 3 this command will jump to the specified label 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 Do Channel 1 receives any data 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 Get 1 1 Read 1 Byte A 3 Get 1 1 Read 1 Byte A 4 Get 1 1 Read 1 Byte End If Return End of interrupt routine IMPORTANT When a RECV interrupt routine is being executed another RECV interrupt routine will not be allowed to be executed After it finishes current interrupt routine execution the processor will come right back to another ON RECV interrupt routine when there s still data being received data in receive buffer 191 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 at a specified interval Set the
69. The Master provides command while the Slave receives commands The slave can only send data to the master when requested it cannot initiate communications on its own Each slave has a unique address called Slave Address The Master using those Slave Addresses can talk to one slave at a time For 1 to 1 connections RS232 can be used For 1 to N connections RS485 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 Frame and analyzes it When responding to the Master Slave also sends in Frames There are two types of MODBUS ASCII and RTU The RTU type is binary and can be implemented by using less bytes in the communication ASCII uses LRM for error checking and RTU uses CRC The table below shows how ASCII and RTU are used 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 308 ASCII uses a colon to start and ends with CR or LF START SLAVE ADR FUNCTION DATA LRC END COLON 2 Bytes 2 Bytes n Bytes 2 Bytes CR LF RTU requires no special characters to start and finish It uses 4 bytes of blank space a delay to indicate the start and finish
70. The other yellow wire is for receiving a PWM signal A typical pulse rate is about 60 pulses per second gso wp gsm vss mr dam resp vss voo ge risp des pup de pap g P2 p g pnp 5 rop g rap pap Black GND The RC Servo motor will move to a location set by the pulse and duty value and will hold its position i ke m w w A pulse of 1ms will stop the RC servo at 45 Degrees A pulse of 1 5ms will stop the RC servo at 0 Degrees A pulse of 2ms will stop the RC servo at 45 Degrees Depending on the RC servo you use these specifications will vary lt Filename rcservo cul gt Const Device CB280 Low 5 Pwm 0 2500 32768 When the code above is executed a 1ms pulse will be generated from port number 5 The RC servo 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 port number 5 The RC servo will position itself to 45 degrees As you can see 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 6 RC servos The 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 lt END gt 338 NOTE 6 Digital Thermometer The D
71. Up and Pull Down resistors are required for proper communication Set Until SET UNTIL channel packetlength stopchar channel RS232 Channel 0 to 3 packetlength Length of packet 0 to 255 stopchar Character to catch This is a conditional statement you can put right after the ON RECV command Since the ON RECV command will cause an interrupt even when 1 byte of data is received this command can be used to set when the interrupt will be called When the specified character is received or the length of bytes received has exceed the set packetlength value then ON RECV will jump to the specified interrupt routine In this way you can control when you want to process received data The packet length is set in case the specified character never arrives You MUST use this command with 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 SET UNTIL 1 5 The user may also just set the packet size and not set the stop character as shown above The character may also be written in decimal as shown below SET UNTIL 1 100 4 232 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
72. amp H55 GHAA SHAR GHAA GHAR _ GHAA SHAA SHAA GHAR GHAA SHAR GHAA GHAR GHAA GHAR SHAA SHAA GHAA SHAA HAA GHAA print CHR sHDB30 Bmp BMP x y filenumber layer X y x y position to display BMP Filenumber BMP File number Layer Layer to display BMP The GHB3224 has FLASH memory to store BMP images Use the BMP Downloader to download BMP files Once BMP files are stored in the LCD you can simply use this command to print them to the LCD The GHB3224 has 102 400 bytes of Flash memory space to store BMP files You can store about 10 320x240 full screen images Graphic Data PUSH POP Commands On the GHB3224 series there is a separate stack for storing graphic data You can push and pop the current screen or part of the current screen to this stack By storing to the stack you can easily implement a copy cut and paste feature GPUSH and GPOP can be used for precise cutting of the current screen while HPUSH and HPOP can be used for high speed push and pop The stack is a LIFO last in first out that will pop the last data that was pushed There is about 32KB of stack memory You can store about 3 to 4 full screens Please refer to the picture below for a depiction of how the stack works won b fi 280 Gpush GPUSH x1 y1 x2 y2 layer Push the area with an x1 y1 x2 y2 box to the stack GPUSH 10 20 0 100 2 Gpop GPOP x y layer logic logic 0 OR logic 1
73. and so on MCS 1 must exist inside MCS 0 and MCS 2 must exist inside MCS 0 When MCS 0 is OFF all MCS inside MCS 0 will turn OFF When MCS turns OFF all outputs within that MCS block will turn OFF Timers will be reset and Counters will be stopped Command When MCS is ON When MCS is OFF OUT Normal Operation OFF SETOUT Normal Operation Maintain status after MCS turned OFF RSTOUT Normal Operation Maintain status after MCS turned OFF Timer Normal Operation Reset to default value Counter Normal Operation Maintain status after MCS turned OFF Other Normal Operation Stop Operation Commands The following screenshot shows MCS used within another MCS SSE Sap Soce Se oeesaS MCS MESELA O 1 he aaa a Nana Ub N 382 Step Control S Registers are used for step control The following is the correct format for step control Relay 0 15 Jot 0 255 7 126 In Step Control there s normal step and reverse step For normal step we can simply use the STEPSET command STEPSET Fo STEPSET 50 1 t te 1 PI STEPSET 80 2 1 Fe STEPSET 90 0 P_ oi 1 This command STEPSET will turn ON the current step if the previous step was ON Since it operates in one step at a time we call it STEPSET For example in the above ladder diagram when P1 turns ON S0 2 is turned ON if S0 1 is turned ON Then S0 1 is turned OFF When P2 turns ON S0 0 is turned ON
74. and sub routines in this case 407 INTON INTON s d INTON is same as WMOV command except it triggers an interrupt to a section of BASIC Usually P m F S c T D Constants Registers s Source o fo o Ta d Destination o o jo PO INTON 3 00 1 F 1 PI INTON 2 00 1 H F 1 408 TND TND is a conditional exit command When the user wants to abort Ladder scanning during operation TND can be used Fa Pe 1 l Po mo 2 HHE 1 ra Pa 3 Ewo at 1 When PO turns ON in the above program Ladderscan will abort SBRT CHATH e d 1 Po we Pi mo m3 let RET You can also use it for exiting from sub routines when a certain condition is met In the above example when P1 turns ON the subroutine will be aborted but Ladder scanning will keep executing 409 Special Registers You can use special Registers to find out about the current status of CUBLOC or use them for timing functions and applications Special Explanation Register FO Always OFF F1 Always ON F2 Turn on 1 SCAN time at POWER UP Set Ladder On F3 F4 F5 F6 F7 F8 1 SCAN On every 10ms F9 1 SCAN On every 100ms F10 F11 F12 F13 F14 F15 F16 Repeat ON OFF every 1 Scan time F17 Repeat ON OFF every 2 Scan times F18 Repeat ON OFF ev
75. and the other steps are turned off S0 0 or step 0 is used for reset Otherwise STEPSET will move in order 383 STEPOUT This command STEPOUT will allow only 1 step to be enabled at all times The last step to be turned ON will be the step to be enabled at any given moment Po STEPOUT S0 1 _2 re 1 PI STEPOUT 80 2 a 1 P2 STEPOUT S0 0 pa 1 When P1 turns ON S0 2 will turn ON When PO turns on S0 1 turns ON and S0 2 turns OFF A step will be kept on until another step is turned ON PO P1 P2 80 0 80 1 80 2 384 TON TAON When the input turns ON the timer value is decremented and output turns on when timer is done There are two kinds of timers one that works in 0 01 second units and another that works in 1 second units Type of Timer_ Time units Maximum Time TON 0 01 sec 655 35 sec TAON 0 1 sec 6553 5 sec START TON TO 100 1 START TAON 71 100 1 There are 2 parameters with commands TON TAON For the first parameter you can choose TO through T99 and for the second parameter you may use a number or a data memory such as DO Usable P m F s c T D Constants Registers TON TAON o o o o In the above LADDER diagram when START turns ON TO Timer will run from zero to 100 When 100 is reached TO will turn on Here 100 is equal to 1 second for TON and 10 seco
76. are HIGH I2C is in idle state If a START command is executed during the idle state 12C begins When SCL and SDA are both LOW I2C is in busy state If a STOP command is executed during the busy state 12C stops There is also a Repeated Start in I2C If a START command is executed during busy state 12C restarts SDA UA Li Repeated STOP Start Vf WU START SCL ipene Ss a e fey a 300 Using an EEPROM through I2C We will go through an example showing I2C 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 RW S conTRoLeyTE OJA HIGHADORESS JA 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 0 can be written into R W A is for acknowledgement of the 8 bits 1 byte sent Then HIGH ADDRESS LOW ADDRESS and DATA can be sent When all data is sent the Stop command can be transmitted It takes about Sms for each EEPROM write The following is an EEPROM write sequence in CUBLOC s BASIC code Set 12c 8 9 Set P8 as SDA P9 as SCL I2estart If I2ewrite sH1010000
77. bcdvalue BCD value to convert to binary This command converts a BCD Binary Coded Decimal number into a normal binary encoded number as used for all calculations in CUBLOC Basic BCD is often encountered when interfacing to real time clock chips Dim A As Integer A Bcd2bin amp h1234 Debug Dec A Print 1234 127 Bclr BCLR channel buffertype channel RS232 Channel 0 to 3 buffertype 0 Receive 1 Send 2 Both Clear the specified RS232 channel s input buffer output buffer or both buffers Use this command if your code is about to receive data and there may be unneeded data already in the buffer Belr 1 0 Clear RS232 Channel 1 s rx buffer Belr 1 1 Clear RS232 Channel 1 s tx buffer Belr 1 2 Clear RS232 Channel 1 s rx amp tx buffers 128 Bee p BEEP Port Length Port Port number 0 to 255 Length Pulse output period 1 to 65535 The BEEP command 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 PIEZO 129 Bfree Variable BFREE channel buffertype Variable Variable to store results No String or Single channel RS232 Channel number 0 to 3 buffertype 0 Receive Buffer 1 Send Buffer This function wi
78. be String and the length of data is not limited to 4 bytes Const Device cb280 Dim A As String 10 Opencom 1 115200 3 50 10 Set Until 1 8 On Recvl Gosub GOTDATA Do Do While In 0 0 Loop Wait until press button Connect P0 Putstr 1 CUBLOC Cr Do While In 0 1 Loop Loop GOTDATA A Getstr 1 8 Debug A Return 163 Getstr2 Variable GETSTR Channel Bytelength StopChar Variable String Variable to store results Channel RS232 Channel Bytelength Length of data to receive StopChar Stop character ascii code Same as the GETSTR command except it will stop reading data at the StopChar even if the data received is less than Bytelength If StopChar is not found then it will operate just like a GETSTR command Use with CUBLOC STUDIO 2 0 X and above 164 Gosub Return The GOSUB command can call a sub routine A RETURN command must be used at the end of the sub routine GOSUB ADD_VALUE ADD_VALUE A A 1 RETURN Goto The GOTO command will instruct the current program to jump to a specified label This is part of every BASIC language but we do not recommend the use of GOTO as it can interfere with structural programming Be especially careful when using Goto within a Gosub or subroutine since improperly terminating a subroutine can have undesired effects About Labels A Label can be set with character to specify a point for GOTO or GOSUB to begin execution ADD_VALUE
79. channel buffertype Variable Variable to store results No String or Single channel RS232 Channel number 0 to 3 buffertype 0 Receive Buffer 1 Send Buffer Bmp BMP x y filenumber layer X y x y position to display BMP Filenumber BMP File number Layer Layer to display BMP 444 Box BOX x1 yi x2 y2 Boxclear BOXCLEAR x1 yi x2 y2 Boxfill BOXFILL x1 y1 x2 y2 logic logic O OR 1 AND 2 XOR Bytein Variable BYTEIN Portlock Variable Variable to store results No String or Single PortBlock I O Port Block Number 0 to 15 Byteout BYTEOUT PortBlock value PortBlock I O Port Block Number 0 to 15 value Value to be outputted between 0 and 255 Cirde CIRCLE x y r Girclefill CIRCLEFILL x y r Checkbf Variable CHECKBF channel Variable Variable to store results No String or Single channel RS232 Channel 0 to 3 Color COLOR value Cis as Clear CLEAR layer Cmode MODE value value 0 BOX type 1 Underline type Compare COMPARE channel target port targetstate Channel High 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 Const CONST name as type value Const CONST type name as type value value value value Array Type Byte Integer Long String Single Contrast CONTRAST value
80. choosing a variable to use for the FOR NEXT loop please make sure the chosen variable is able to cover the desired range Byte variables can cover 0 to 255 For larger values a variable with 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 154 DEMO PROGRAM Const Device CB280 Dim A As Integer For A 1 To 9 Debug 3 Debug Dec A Debug Debug Dec 34A 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 Debug Terminal eri aie Pr NERS gr I Pix Right side am 155 Freepin FREEPIN I O NO I O PORT Number This command will return an I O port to BASIC control if it has previously been set to a LADDER port with Usepin 156 Freqout FREQOUT Channel FreqValue Channel PWM Channel 0 to 15 FreqValue Frequency value between 1 and 65535 Output the desired frequency to the desired 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 are PWM Channel 0 1 and 2 respectively The following is a basic chart showing several example FreqValues and the corresponding freq
81. complex commands 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 BMP images to the onboard memory and retrieve on command 37 Seven Segment Display Modules CSG Series Seven segment display modules can be easily implemented 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 1 0 ports can be controlled in real time We are constantly upgrading and developing new peripherals for CUBLOC core modules Please check out our website www cubloc com often for these updates 38 Chapter 2 Hardware Hardware Features CUBLOC has the following features BASIC and or Ladder Logic 80KB or 200KB Flash Memory BASIC Execution Speed 36 000 instructions per second e LADDER Execution Speed 10 millisecond scan time Turbo Mode 100 microseconds e Data Memory for BASIC 2KB to 51KB e Data Memory for LADDER 1KB to 4KB e EEPROM Memory 4KB e 16 to 91 I O pins Ports 8 to 16 10 bit ADC channels 8 to 16bit 3 to 12 PWM channels DAC UART H W RS232C ports 2 to 4 channels RTC chip included CB290 Model Comparison Chart Feature e220 e280 e290 ce40s
82. encountered Traditional touchscreens are not a complete integrated solution to your application They are usually touchscreen panels that will only display graphics and capture touch input In other words most touchscreens require an external controller in order to affect the real world through I O The CUTOUCH combines a traditional PLC with a touchscreen graphic LCD By integrating user input display output and control developers can now use one device as a complete control system CUTOUCH 415 CUTOUCH Specifications Processor CUTOUCH CT1720 CUTOUCH CT1721 roprocessor Dual Core Atmega128 18 432Mhz Dual Core Atmega128 18 432Mhz Program 80KB 80KB Memory Flash Data 24KB BASIC 4KB Ladder Logic 24KB BASIC 4KB Ladder Logic Memory RAM BASIC 4KB gic BASIC 4KB gic EEPROM KB EEPROM AKB EEPROM Program Speed 36 000 sec 36 000 sec General Purpose 82 1 0 lines ALL SV TTL 33 input only 32 output only 17 621 0 lines TTL amp 24V DC 1 TTL input 32 24V opto isolated inputs 1 0 32 24V TR outputs 17 TTL a input output configurable E 2 High speed hardware Independent 2 High speed hardware independent serial ports Channel 0 amp 1 RS232C serial ports Channel 0 amp 1 RS232C Serial Portsfor y ay Communication Configurable Baud rates 2400bps to 230 400 bps Configurable Baud rates 2400bps to 230 400 bos Analog Inputs 8 channe
83. features guaranteeing accuracy and precision of timing SINGLE TASK MULTI TASK LADOER Basic LABOER Basic LADDER Baic 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 The biggest advantage of Ladder Logic is that all circuits are laid out in parallel they are all processed as fast as the ladder scantime will allow This allows a more parallel execution path for unrelated functions T eC HH As you can see above both A and B circuits are in a waiting state ready to turn 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 Azo hime Again ForB 0to 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 Lad
84. from the Master Slave will send back an error code Field Hex ASCH 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 CRLF 2 These are the following types of error codes Code Error Name Explanation o1 ILLEGAL FUNCTION When a non supported function code is received 02 ILLEGAL DATA ADDRESS __ When an incorrect address is received 03 ILLEGAL DATA VALUE When bad data is received 09 LRC UNMATCH When LRC is incorrect The error check is only for MODBUS ASCII there are no error check in RTU MODBUS RTU uses CRC to check for errors in transmission 318 MODBUS ASCII Master Mode There are no special commands to set CUBLOC to Master Mode for MODBUS communication Master Mode simply needs to be able to use RS232 data communication using commands like CUBLOC s GET and PUT The following is an example of ASCII Master Mode implemented in CUBLOC BASIC Master Source Const Device cb280 Dim RDATA As String 80 Dim a As Byte ct As Byte Dim b As String 17 Dim Port As Integer Opencom 1 115200 3 80 80 On Recvl Gosub GETMODBUS Data Receive Interrupt routine Set Until 1 60 10 When Ending Code 10 on Channel 1 is discovered create an interrupt Do For Port 2 To 4 BitWrite Port 1 Turn PO P1 P2 ON Delay 100 Next For Port 2 To 4 BitWrite Port O Turn PO P1 P2 OFF Delay 100 N
85. how much data was actually read If 5 bytes were received and only 4 bytes got verified 1 byte was lost Const Device cb280 Dim A as Byte Opencom 1 115200 3 50 10 On Recvi Gosub GOTDATA Do Do while In 0 0 Loop Wait until press button Connect PO Put 1 asc H Put 1 asc E Put 1 asc L Put 1 asc L Put 1 asc 0 Put 1 13 1 HELLO Chr 13 Chr 10 Put 1 10 1 Do while In 0 1 Loop Loop GOTDATA A Get 1 1 Debug A Return 159 Geta GETA channel ArrayName bytelength channel RS232 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 RS232 data in a Byte array Data will be stored starting from the first element of the array Again please check the receive buffer with BLEN before reading to avoid garbage data Const Device cb280 Dim A 10 As Byte Opencom 1 115200 3 50 10 Set Until 1 8 On Recvl Gosub GOTDATA Do Do While In 0 0 Loop Wait until press button Connect P0 Putstr 1 CUBLOC Cr 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 160 Geta2 GETA channel ArrayName bytelength stopchar channel RS232 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
86. is I O Ports explained in PortBlocks Block Name Pin 1 0 Function Explanation PO 5 10 SPI SS PL 6 Input SPI SCK Input Only P2 7 Input SPI MOST Input Only o P3 8 Input SPI MISO Input Only P4 9 1 0 P5 10 10 PWM CHANNEL 0 P6 11 10 PWM CHANNEL 1 P7 12 10 PWM CHANNEL 2 PB 133 1 0 TTL232 RX2 TTLRX channel 2 P9 14 10 TTL232 TX2 TTLTX channel 2 P10 15 10 1 PIL 16 10 PWM CHANNEL 6 P12 17 1 0 PWM CHANNEL 7 P13 18 10 PWM CHANNEL 8 P14 19 10 P15 20 10 Pi6 25__ 1 0 AD CHANNEL O P17 26 10 AD CHANNEL 1 P18 237 yO AD CHANNEL 2 2 P19 28 10 AD CHANNEL 3 P20 29 10 AD CHANNEL 4 P21 30 10 AD CHANNEL 5 P22 31 10 AD CHANNEL 6 P23 32 1 0 AD CHANNEL 7 P24 33 10 Co processor SCL 1 P25 34 10 Co processor SDA 1 P26 35 10 Co processor INT 1 3 P27 36 10 PWM3 P28 37 10 PWM4 INTO P29 38__ 1 0 PWMS INTI P30 39 10 INT2 P31 40 1 0 INT3 1 Communication line for connecting to coprocessor Please try to save these pins for future coprocessor communication ports 52 Block Name Pin 1 0 Function Explanation P32 45 1 0 AD CHANNEL 8 P33 46 1 0 AD CHANNEL 9 P34 47 vo AD CHANNEL 10 4 P35 48 1 0 AD CHANNEL 11 P36 49 10 AD CHANNEL 12 P37 50 10 AD CHANNEL 13 P38 51
87. is used in place of division sign Please make sure to use parenthesis appropriately for correct calculations based on the order of operations table 94 1 5 gt Vw Z 5 3 4 3 4 2 6 Zt gt 246 3 4 Operator Priority When multiple operators are used the following operator priority is used 1 Operator inside parenthesis 2 Negative Sign 3 Exponent 4 Multiplication Division Remainder MOD 5 Addition Subtraction 6 Bitwise Left Shift Bitwise Right Shift lt lt gt gt 5 3 4 543 4 p C D E X G H J OA 3 DEMO PROGRAM E CUBLOC studio cubloc_testimath cul Ee Edt Deve Bun Setup telp Beano SG 4A4 gt at BS TFI BASIC F2 LADDER Ladder Mnemonic I Fik Right Side 95 Expressing Numbers There are three possible ways to represent numbers in CUBLOC BASIC Binary Decimal and Hexadecimal The Binary and Hexadecimal representations are useful for many control and processing needs The Decimal representation is the standard human readable format Examples Binary amp B10001010 BL 0b1001C Decimal 10 20 32 1234 Hexadecimal GHA amp H1234 amp HABCD OxABCD 0x1234 1234 ABCD 96 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 c
88. msgl_rtn Locate 0 0 Print ON Ladderint Dec i Reverse 1 Return PO SETOUT F40 1 When PO turns on Register F40 turns on and the msg1_rtn interrupt routine in BASIC will be executed In the interrupt routine a string is printed to the LCD 188 Although there is only one Register F40 to create an interrupt in BASIC from LADDER we can use data register D to process many different types of interrupts PO WMOY 3 00 H T d SETOUT F40 1 P2 WMOV 2 00 H F 1 SETOUT F40 1 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 interrupt routine the user can then process the type of interrupt based on the value stored in DO msgl_rtn I _D 0 3 Then Locate 0 0 Print ON Ladderint Dec i End If I _D 0 2 Then Locate 0 0 Print TEST PROGRAM Dec i End If Return For a short version of the above LADDER commands the user can use an INTON command which accomplishes both WMOV and SETOUT in one command The following is the equivalent shortened version of the above ladder PO INTON 3 00 H F 1 PI INTON 2 00 I F 1 189 On Pad Gosub ON PAD GOSUB label The ON PAD interrupt will jump to the specified label when the buffer amount is equal to the packet size assigned by the Set Pad command Please make sure to use RETURN command after the label Const Device Ct1720 Dim TX1 As Integer
89. not be lost After the current On Recv interrupt routine is finished if there s new data in the receive buffer another On Recv interrupt will be called immediately Belr command can be used in case the user does not want to process another On Recv Interrupt 8 If you declare an interrupt repeatedly the last one called will be in effect 104 Pointers using Peek Poke and Memadr The following is an example that uses the EEWRITE command and the EEREAD command to read floating point data Const Device CB280 Dim f1 As Single 2 As Single fl 3 14 Eewrite 0 1 4 2 Eeread 0 4 Debug Float 2 cr When you run this code the debug window will show 3 00000 instead of 3 14 The reason is that the EEWRITE command 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 Fl 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 F1 and then use the Peek command to directly access the memory and write 4 bytes We store that value in EEPROM Next we use Memadr F2 and Poke to read 4 bytes directly Warning Please use caution when using this command as pointers can affect the whole program Peek and Poke may only access data memory 105
90. 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 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 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 NEW in CublocStu v 2 4 F and above You can easily upgrade to CUBLOC STUDIO V2 4 X to use the new features of CUBLOC and CUTOUCH CUBLOC Studio V2 4 F and above supports new command as follows STEPACCEL Channel Port FreqBASE FreqTOP FreqACCEL Qty Channel StepPulse Channel Stepaccel supports only 0 Port Output Po
91. results No String or Single Port Input Port 0 to 255 deboucingtime Debouncing Time 1 to 65535 The command KEYIN removes 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 our recommendation is 10ms for most applications KEYIN 1 10 Read from port after removing bouncing effect inca 179 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 must 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 removing bouncing effect 180 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
92. see and understand them better as shown below 374 Po PI PS AHI O PE i nF G o PO PI PS AHI PO P2 Pe HH O O P3 Pr Gi Q ladder instructions Ladder low level instructions Command Symbol Explanation LOAD H H Contact A Normally Open LOADN E IF Contact B Normally Closed OUT Output NOT NOT Inverse the result j STEPSET Step Controller Output Step Set 1 STEPOUT Step Controller Output Step Out 1 MCS Master Control Start 1 MCSCLR Master Control Stop 1 DIFU Set ON for 1 scan time when HIGH signal DIFD Set ON for 1 scan time when LOW signal SETOUT Maintain output to ON T 1 RSTOUT Maintain output to OFF 1 END End of Ladder Logic 1 GOTO Jump to specified label 1 TABEL Label Declaration T 1 CALLS Call Subroutine 1 SBRT Declare subroutine RET End Subroutine TND conditional exit command 375 High level instructions Command Parameter Explanation Data Transfer Commands WMOV sd Word Data Move DWMOV sd Double Word Data Move WXCHG sd Word Data Exchange DWXCHG sd Double Word Data Exchange FMOV s d n Data fill command GMOV s d n Group move command Increment Decrement Commands WINC d Increment 1 to the Word DWINC d Increment 1 to the Double Word WDEC d Decrem
93. the P82B715 LDA LDA SDA a SDA i Lot Lek sot gt sot LONG CABLE CUBLOC peze7is P8285715 12C DEVICE By using the P82B96 ground and power can be isolated on the device ends 5 SOME mvec spa 1X Rx sou Care q Pa2B96 F w me scL TY eno O Dw Cy fey PETES 12v tv sv T 4 F LONG CABLE t soa D 4 gt gt soa t 4 lt gt gq t set D gt gt sot caes T P82B96 P82B96 Please refer to Phillips website for more information on the specific chips discussed here http www standardics nxp com 305 If you are using I C interface within 12 feet we recommend to use the following protection circuit If the 12C devices are connected with no buffers electrical interference can cause damage to either CUBLOC or the I C 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 to use P82B96 chips as buffers awd ag ag eno O 24LC32 vec Hsc m hw F F caste spa om FE 306 t pet CUBLOC Chapter 9 MODBUS About MODBUS MODBUS is a protocol developed by MODICON as an interface to their PLCs It is usually used with devices like touchscreens HMI devices and SCADA software many of them now support MODBUS In MODBUS there are Master and Slave devices
94. value Contrast Value Count Variable COUNT channel Variable Variable to store results No String or Single Channel Counter Channel number 0 to 1 445 Countreset COUNTRESET channel Channel Counter Channel 0 to 1 Csroff CSROFF Csron CSRON Ded Variable DCD source Variable Variable to store results No String or Single Source source value Debug DEBUG data data data to send to PC Decr DECR variable Variable Variable for decrementing No String or Single Defchr DEFCHR code data Code Custom character code amp hdb30 to amp hdbff Data 32byte bitmap data Delay DELAY time Time interval variable or constant Dim DIM variable As variabletype variable As variabletype Variabletype Byte Integer Long Single String Dotsize DOTSIZE value style Dp Variable DP Variable Decimal Places ZeroPrint ZeroPrint If ZeroPrint is set to 1 zeros are substituted for blank spaces Dprint DPRINT string Dizero DTZERO variable Variable Variable for decrement No String or Single Eadin Variable EADIN mux Variable Variable to store results No String or Single mux AD input Port Combination MUX 0 fo 21 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 Eewrite EEWRITE Address Data ByteLength Address 0 to
95. 0 1 Then ERR PROC Chip Address 0 If T2cwrite ADR BYTE1 1 Then ERR_PROC ADDRESS WRITE If I2cwrite ADR LOWBYTE 1 Then ERR_PROC If I2ewrite DATA 0 Then ERR_PROC 1 Byte WRITE I2cstop Delay 5 Wait until WRITE is done 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 RW Repeated Start RW NoAck S conrdoleyr OJA HGWAReSs JA dwanoress A S CONTAorayTE AJA DATA XJF S start Pa Ai Acknowledge ad Poin P Stop ae 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 Set I2c 8 9 I2estart If I2ewrite sH10100000 1 Then ERR PROC Chip Address 0 If I2cwrite ADR BYTE1 1 Then ERR PROC ADDRESS WRITE If I2cwrite ADR LOWBYTE 1 Then ERR_PROC I2estart Repeated Start If 2ewrite sH10100001 1 Then ERR PROC Read command DATA I2cread 0 Result store in DATA I2estop And now we will look at how to 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 I2c 8 9 I2estart If I2ewrite sH10100000 1 Then ERR PROC Chi
96. 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 LSB First Least Significant Bit First Before Rising Edge 5 MSB First Most Significant Bit First Before Rising Edge bitlength Length of bits 1 to 16 This command Shiftin receives shift input It uses 2 Ports CLOCK and DATA to communicate 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 AfterRising After Falling Edge Edge i CLK Before Rising Edge DIM A AS Byte A SHIFTIN 3 4 0 8 Port 3 is Clock Port 4 is Data Mode 0 8 bit received ox UUUUUUUL o 4 41 0 0 1 0 0 26H LSB MSB 233 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 sends shift output There are 3 modes Mode 2 i
97. 05 have more M C T and D Registers than the CB220 and CB280 Register Name Range Units Feature Input Output Register PO to P127 1 bit Interface w External P devices Internal Registers M MO to M2047 1 bit Internal Registers Special Register F FOtoF127 1 bit System Status Timer T TOto T255 16 bit i Word For Timers Counter C CO to C255 16 bit 1 Word For Counters Step Enable S S0 to 515 256 steps For Step Enabling 1 Byte Data Memory D DO to 511 16 bit 1 Word Store 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 you can use WP WM or WF Register Range Units Feature Name WP WPO to 7 16 bit i Word Register P Word Access WM WMO to WM63 16 bit 1 Word Register M Word Access WF WFO to WF7 16 bit 1 Word Register F Word Access WPO contains PO through P15 PO is located in the LSB of WPO and P15 is located in the MSB of the WPO These Registers are very useful to use with commands like WMOV 364 wPo fes Po WP1 wp2 WP3 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 ate ele 4A v A NormalOpen B
98. 1 P10 27 yO ADC2_ AD Channel 2 Pil 28 1 0 Block 1 ADC3_ AD Channel 3 P12 29 10 ADC4_ AD Channel 4 P13 30 0 ADC5_ AD Channel 5 P14 31 10 ADC6_ AD Channel 6 P15 32 y o ADC7_ AD Channel 7 47 Pi6 83 7 0 CUNET SCL P17 84 1O CUNET SDA P18 85 10 INT Channel 2 P19 86 1 0 Block 2 INT Channel 3 P20 97 10 P21 98 10 P22 99 10 High Count Channel 0 P23 100 V0 High Count Channel 1 P24 45 Output P25 46 Output P26 47 Output P27 48 Output Block 3 P28 49 Output P29 50 Output P30 51 Output P31 52 Output P32 65 Output P33 66 Output P34 67 Output P35 68 Output Block 4 P36 69 Output P37 70 Output P38 71 Output P39 72 Output P40 53 Output P41 54 Output P42 55 Output P43 56 Output Block 5 P44 57 Output P45 58 Output P46 59 Output P47 60 Output P48 73 Output P49 74 Output P50 75 Output P51 76 Output Block 6 P52 77 Output P53 78 Output P54 79 Output P55 80 Output P56 13 Input P57 14 Input P58 15 Input P59 16 Input Block 7 P60 17 Input P61 18 Input P62 19 Input P63 20 Input 48
99. 232 COM PORT for Download Monitor Select COM1 through COMA Editor Setup Environment Setup Editor Environment options for BASIC text editor Environment Options CUBLOC Studio Options Firmware Download Download Firmware to CUBLOC CORE Please use this to download firmware to CUBLOC CORE manually 67 MEMO 68 Chapter 4 CUBLOC BASIC Language IMPORTANT You must declare the device being used before using BASIC or LADDER Below is an example of declaring CUBLOC CB220 module Use CB220 This should be the first line of your program When this command is not used CB220 model will be chosen as default CONST Di 69 CUBLOC BASIC Features Interface to PC with RS232C Port CUBLOC uses an RS232 port to interface with the PC You also have the option of using it to connect to a MAXPORT and use monitoring downloading via the internet 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 copy amp paste code for common tasks into new programs instead of starting everything from scratch Function SUM A As Integer B As Integer As Integer Integer 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 A
100. 234 A FABS B Return B Debug Float A Print 1234 00 FLOOR Round down to the nearest whole number ngle B As Single FLOOR 3 14 gives 3 oat A Print 3 0 114 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 if A is 123ABC 123ABC is printed DEBUG HEX8 A if A is 123ABC bb123ABC is printed b is a blank space in this case DEBUG HEXS A Mif A is 123ABC 23ABC is printed first character Mis cut CUBLOC studio dNeubloc Ble st powe mn sap Hep B38 ABAAA ote FIL BASIC FZ LADDER Ladder Mnemonic quam Debug Te nst Device CB200 mi Dim A As Long Pa aa A amp H1234 ZE a foso rove 2 w Debug Hex Acre Debug HEXS A Cr Debug HEXS A Cr Furia ce 112 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 DEBUG DEC10 A f A is 1234 1234 is printed f A is 1234 bbbbbb1234 is printed b is a blank space in this case If A is 1234 234 is printed first character is cut DEBUG DEC3 A CUBLOC studio d cubioc_test format cul J Pot BeudRae Paty DHEBEE gry fro r giles io a
101. 24 to P55 CT1720 CT1721 P24 to P55 Set Pad SET PAD mode packet buffersize mode Bit Mode 0 to 255 packet Packet Size 1 to 255 buffersize Receive Buffer Size 1 to 255 The CUBLOC has a dedicated port for Keypad Touchpad inputs similar to a PC s Keyboard and Mouse ports This port can be used with the Set Pad command to create interrupts when input is received on the Keypad Touchpad etc This port is basically a Slave mode SPI communication To use PAD communications you must use a Set Pad command at the beginning of your program The PAD communication uses 4 wires SCK is used as clock signal SS as Slave Select MOSI as Master Out Slave In and MISO as Master In Slave Out ss ss sck Sck Mosi gt mosi MISO MISO aYd HONOL TOUCH PAD CONTROLLER CUBLOG I O ports PO through P3 can be used for PAD communications sour d7 zap vin sin g2 23 vss am ga 22 res vss ga 21 p voo ss po gs 2o pis sek e mge ih mosi 4 p2 d7 1p pis mso lt ps ge arh Piz ra ge 18h Pn Ps gio ash Pro ps gn mmm 1af po pr fiz 13 Pe 226 True TRX AVREF pas Par P30 P29 P28 P32 Paa Pas Pas Pas Par Pas ss p30 sour 10 17 voo ma SiN Rx aN avop vss we 8S po P24 sck lt pr P25 mosi lt P2 ors Miso 4 Pa Par par Pss Pas Pas Paa aa Par P40 The Packet setting is the size of
102. 34 P64to71 INPUT Block 8 8 Input Ports P72 to 79 INPUT Block 9 8 Input Ports P80 to 87 INPUT Block 10 8 Input Ports 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 to J4 The CUTOUCH CT1721 is a combination of CT1720 and the Add On Board Please be careful to not input more than 5V into a CUTOUCH TTL ports as it can damage the product 420 There are extra RS232 headers as shown below UBL i oi al o u J Poe RS232 RS232 Download Addtional Channel 1 cable Connector The Download RS232 Channel is a 4 pin type connector and RS232 Channel 1 is a 3 pin type connector as shown below You can connect them to the PC SIDE RS232 Pins as shown below GND DTR Download Monitoring RD RD DTR GND GND TD PC SIDE BD S242 Channel 1 421 Backup Battery The CUTOUCH will maintain data in its volatile memory after power OFF by using a backup battery If backup is not needed the program must clear the memory at the beginning of the program Use RAMCLEAR at the beginning of your BASIC code section to clear all data memory at the start of the program The CUTOUCH comes with a self charging 1 0F super capacitor which can last about a day u
103. 4 Print PRINT String Variable String String Variable When using variables constants String representation of the variable constant will be printed Pset PSET x y Pulsout PULSOUT Port Period Port Output Port 0 to 255 Period Pulse Period 1 to 65535 Put PUT channel data bytelength channel RS232 Channel 0 to 3 Data Data to send up to Long type value Bytelength Length of Data 1 to 3 Puta PUTA channel ArrayName bytelength channel RS232 Channel 0 to 3 ArrayName Array Name Bytelength Bytes to Send 1 to 65535 Puta2 PUTA2 channel ArrayName bytelength Stopchar channel RS232 Channel 0 to 3 ArrayName Array Name Bytelength Bytes to Send 1 to 65535 Stopchar Stop character ascii code Putstr PUTSTR channel data channel RS232 Channel 0 to 3 Data String Data String variable or String constant Pwm PWM Channel Duty Period Channel PWM Channel Number 0 to 15 Duty Duty Value must be less than the Width Period Maximum of 65535 Pwmoff PWMOFF Channel Channel PWM Channel 0 to 15 Ramclear RAMCLEAR 452 Reset RESET Reverse REVERSE Port Port 1 O Port Number 0 to 15 Set SET DISPLAY type method baud buffersize display type 0 Rs232LCD 1 GHLCD GHB3224 2 CLCD Method Communication Method 0 CuNET 1 COM1 baud Baud rate CuNET
104. 50 Light LIGHT value value Backlight O OFF 1 ON Turn the backlight ON and OFF Default is ON Font FONT fontsize efontwidth fontsize 0 to 8 Font Selection efontwidth 0 fixed width 1 variable width The GHB3224 LCD has 4 different font sizes and 2 different widths Font Type Font 0 1 10 x 16 2 3 4 5 16x16 6 7 24 x 24 8 48 x 48 Const Device CB290 Cis Delay 100 Font 0 0 Glocate 10 10 GPrint FONT 0 0 ABCDEFGHIJKLMN Font 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 Font 0 1 Glocate 10 120 GPrint FONT 0 1 ABCDEFGHIJKLMN Font 2 1 Glocate 10 140 GPrint FONT 2 1 Font 6 1 Glocate 10 160 GPrint FONT 6 1 ABCDEFGHIJ Font 8 1 Glocate 10 185 GPrint FONT 8 1 BCDEFGHIJKLMN 268 Style STYLE bold inverse underline bold 0 Normal 2 or 3 Bold inverse 0 Normal 1 Inverse underline 0 Normal 1 Underline You can use the STYLE command to add Bold Inverse or Underline to your fonts ata pan Max INVERSE Sia ARE 269 Cmode CMODE value value 0 BOX type 1 Underline type Choose the type of cursor to use Default is the Underline type I 0 BOX Type 1 Under Line Type Line LINE x1 y1 x2 y2 Draw a line from x1 y1 to x2 y2 NE 10 20 100 120 Draw line ay Lineto LINE
105. 6 Time Chart Monitoring Click Here aand XAA r ote With Time Chart Monitoring you will be able to see Ladder Logic contacts as a time chart The minimum width of the time chart is 40ms You can use the Zoom control function 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 control icon vae _ Zoom control an Relay select Use Unuse Time interval display To use the Time Chart Monitor you must set Debug off in Basic To do this simply add the Set Debug Off command at the very beginning of your code Set Debug Off While using the Time Chart Monitor Ladder Monitoring may not be used 357 WATCH POINT When you want to watch the status of registers and timers outside the current Ladder Monitoring screen you can use the Watch Point feature You can use two apostrophes to add a WATCH POINT For example you want to see PO right next to some other Register that is on exact opposite side of the screen Examples PO Pi DO aago xaa TFI BASC FAJ LACOER adr nemani paar ee jelk e mer T ji u o ss w U yoo avene e i o w Please be aware that it s two APOSTROPHES not a QUOTATION MARK 358 Options Window Ladder Style S
106. 8 Ba 6810 2 _ 4 359813102 893 35 6533 7 4 336311306 888 36 6269 8 4 312224084 883 B7 6018 0 _ 4 287550592 878 Bs 5777 7 4 262290722 873 Bo 5548 3 4 236445118 868 50 3606 1 3 914475937__ 802 51 3472 1 3 881948015 795 552 3343 7 3 848917708 788 53 3220 8 3 815397329 781 isa 3103 1 3 781399998 774 55 2990 2 3 746939622 767 56 2882 1 3 712030877 760 57 2778 4 3 676689176_ 753 Iss 2679 0 3 640930651 746 59 2583 6 3 604772114 738 lei 1220 4 2 748157207 563 82 1181 9 2 7084025 555 83 1144 8 2 668747011 547 lea 1109 0 2 629210536_ 538 igs 1074 5 2 589812422 530 86 1041 3 2 550571543 522 331 87 1009 2 2 511506263__ 514 iss 978 3 I2 472634416 506 l89 948 5 2 433973277 498 90 919 8 2395539544 491 loa 892 0 2 357349316_ 483 o2 865 3 2 319418079 475 93 839 4 2 281760687 467 loa 814 5 2 244391354 460 95 790 4 2 207323646 452 96 767 1 2 170570465_ 445 97 744 7 2 134144055 437 lps 723 0 2 098055989 430 l9 702 0 I2 062317177 422 hoo 681 8 2 026937858_ 415 hor 662 2 1 99192761 laos o2 643 3 1 957295352401 o3 625 0 1 92304935 i394 o4 607 3 1 889197225 387 hos 590 2 1 855745964 380 hos 573 7 1 822701928 373 hoz 557 7 1 790070865_ 367 hos 542 2 1 757857926_ 360 hog 527 2 1 726067674_ 353 239 33 5 0 162295782 33
107. BASIC F2 LADDER Ladder Mnemonic BaudRate Party tats Dim 32939000 3 14 a0 Debug Dec Acr Debug Dec B Cr Debug Dee C Cr Debug Float DCE range VAR Command Same function as DIM VAR can be used in place of DIM to declare variables Below are examples of how to use VAR A Var Byte Declare A as BYTE sti Var String 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 sT Var String 12 10 Declare String Array 80 String A String size can be set up to 127 bytes value of 64 bytes will be used as the String size When the size is not set a default Dim ST As String 14 For maximum usage of 14 bytes Dim ST2 As String Set as 64 byte String variable When setting a String as 14 bytes another byte is allocated by the processor to store NULL When storing COMFILE TECHNOLOGY in a 14 byte String the last 4 characters bytes will not be stored Dim ST As String 14 ST COMFILE TECHNOLOGY LOGY is not stored HNOLOGY COMFILE p Losy do not fit here In CUBLOC BASIC must be used for String An apostrophe may not be used COMPILE TECHNOLOGY can not be used inside the String can not be used inside the String COMFILE TECHNOLOGY can not be us
108. BC Multi dimension arrays are supported CUBLOC supports multi dimensional arrays Arrays with a maximum of 8 dimensions are supported only 1 dimension is allowed for string arrays DIM A 100 20 AS BYTE 70 Hardware RS232 Communication CUBLOC uses hardware RS232 UART communication instead of software RS232 allowing real time processing to continue during RS232 operations Conditional Statements are supported CUBLOC BASIC supports SELECT CASE and DO LOOP conditional statements 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 functions I2C 12C commands supported I2CREAD IZCWRITE SPI SPI commands supported SHIFTIN SHIFTOUT PAD Keypad touchpad supported Advanced Basic Language Enhancements include support define support if ifdef endif conditional compile support Incr Decr commands same function as C s Pointers allowed PEEK POKE and MEMADR String Arrays 1 Dimension 71 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
109. Bits tx fisxo fone gt Arumi FI BASIC F2 LADDER Ladder Mnemonic Const Device CB280 Dim st1 As String 12 Dim i As Integer 12 sti 123 j 140000 i val st1 Debug Dec i cr Dim f1 As single sti 3 14 fl valeng st1 Debug Float f1 Cr Close T Fix Right Side VALHEX String variable Return a converted hexadecimal value of the String DIM STI AS STRING 12 DIM I AS LONG ST1 ABCD123 I VALHEX ST1 GHABCD123 is stored in variable I 121 CHR ASCII code Return the character of desired ASCII code DIM ST1 AS STRING 12 ST1 CHR amp H41 DEBUG STI Print A amp H41 is ASCII code of character A ASC String variable or Constant Return the converted ASCII code of the first character of the String DIM STL AS STRING 12 DIM I AS INTEGER STI 123 I ASC ST1 SH31 is stored in variable I ASCII code of 1 is amp H31 or 0x31 Caution A variable must be used when using string functions DEBUG LEFT INTEGER 4 A string by itself cannot be used ST1 INTEGER DEBUG LEFT ST1 4 A string must be stored as a variable first Debug Termin Bsud Rats Party Detabts rx s20 Noe fe CUBLOC studio d cubloc_testichr cul Be Edt Device Bun Setup Hp mam 4a F1 BASIC F2 LADDER Const Device Dim st1 As String 12 Stl Chr amp h41 Debug st1 Cr sti 123 Debug Hex Asc st1 Cr
110. Di 404 WROR DWROR WROR d DWROR d Rotate the value in Register d 1 double word to the right The value left gets stored in the Carry flag WROL moves one word whereas DWROL moves double word Registers tht P M F s c T D Constants may be used d o o o j d BKEY WROR D1 na If D1 has 8421H the following results DO D1 0C210H 405 GOTO LABEL GOTO label LABEL label The command GOTO will jump to the specified label START GOTO SKI 1 BEKY TON 70 100 c 1 LABEL SK 1 _ _ 1 When START turns ON the LADDER program will jump to label SK_1 In the below example LADDER diagram when DO equals CO the program will jump to SK_1 Lis GOTO SK I 1 406 CALLS SBRT RET CALLS label SBRT label CALLS will call a sub routine SBRT is the starting point for a sub routine RET is the ending point for a sub routine Main Program i i START CALLS CHK ATN 1 I F 4 il RET i SSS 1 RETmust be used when ji there are sub routines SBRT CHK ATN 4 j art of sub routine t 1 BKEY TON 70 100 2 1 1 1 1 L End of sub routine 1 End of Ladder Please be aware that when adding sub routines to your program you need to add RET to the end of main program to differentiate from sub routines END goes at the very end of main program
111. E p a Fs cine iia vets cece a As you can see in above screen Device name I O status alias and other features can be set simply by clicking You can set aliases for Registers set Modbus to be ON and set the baud rate for the Modbus You can always review the current BASIC code generated in real time by pressing Output BASIC code review tab 360 Lateerainment edt Di Ray fafi ider on Sa aur Be Eearisee D E E pes pas cowo carai For using A D PWM or COUNT you can simply read from the D Registers for the results For ADCO the AD value is stored in D 10 The user can simply read from Register D10 to find the value of ADO For PWM3 the user can simply write to Register D29 to output PWM For HIGH COUNT1 simply read Register D39 If the user wishes he can change the Register to store or write values by changing the BASIC code Please press Replace Basic Code when you are done to product the final BASIC code Please be aware that older code will be deleted at this point You can also save the setup to a file by clicking on SAVE AS Click on LOAD to bring back saved setup values Usage of Ladder Register With this feature the user can see the aliases of all Registers By using this feature the user will be able to save a great deal of time while debugging and developing the final product Please go to Run gt View Register Usage to open this window Usage of Ladder
112. Hpaste HPASTE x y layer 448 Hp Variable DP Variable Heximal Places ZeroPrint ZeroPrint If ZeroPrint is set to 1 zeros are substituted for blank spaces Hpop HPOP x y layer Hpush HPUSH x1 y1 x2 y2 layer Taestart T2CSTART T2cstop T2CSTOP T2cread Variable I2CREAD dummy Variable Variable to store results No String or Single dummy dummy value Normally 0 T2creadna Variable I2CREADNA dummy Variable Variable to store results No String or Single dummy dummy value Normally 0 T2ewrite Variable T2CWRITE data Variable Acknowledge 0 Acknowledged 1 No Acknowledgement data data to send Byte value 0 to 255 In Variable IN Port Variable The variable to store result No String or Single Port 1 0 Port number 0 to 255 Incr INCR variable Variable Variable for increment No String or Single Input INPUT Port Port 1 0 Port number 0 to 255 Keyin Variable KEYIN Port debouncingtime Variable Variable to store results No String or Single Port Input Port 0 to 255 deboucingtime Debouncing Time 1 to 65535 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 Keypad Variable KEYPAD PortBlock Variable Variable to store results Returns Byte No String or Single PortBlock
113. L DO 1234H D1 E 1 The result of 1234H 1234H is stored in D1 as a double word of 14BSA90H DO 1234H D1 5A90H D2 14BH START DWMOV 123456H DO 1 ACTION DWMUL DO 1234H D2 c 3 The result of 123456H 1234H is stored as 4B60AD78H in D2 DO 3456H D1 0012H D2 0AD78H D3 4B60H D4 0 DS 0 399 WDIV DWDIV WDIV s1 s2 d DWDIV s1 s2 d Divide s1 by s2 and store the result in d and leftover in d 1 WDIV is for Word values and DWDIV is for Double Word Values Usable P m F S c T D Constants Registers st o lo o lo 52 o o o o d o o o pe WDIV D0 D24 Hr 1 DO 1234H D1 D2 3 D3 D4 611H D5 1 e DWDIV D0 D2 D4 1 DO 5678H D1 1234H D2 7 D3 0 D4 0C335H DS 299H D6 5 D7 0 400 WOR DWOR WOR si DWOR si s2 d s2 d Do Logical operation OR on s1 and S2 and store result in d WOR is for Word values and DWOR is for Double Word Values The result of above ladder diagram DO D1 D2 Usable P M F S C T D_ Constants Registers si Oo tO 0 0 s2 0 00 0 d o jo jo START WMOV 1200H D0 H c 1 WMOV 34H D1 5 E 1 ACTION WOR D0 D1 D2 1 1200H 34H 1234H WXOR DWXOR WXOR si DWXOR si s2 d s2 d Store result of s1 XOR s WX
114. LOC A FLOOR SQR F Do Floor on SQR F Colons Colons cannot be used to append commands in CUBLOC BASIC as is possible in some other languages Bel C 1 Incorrect Correct 78 Variables There are 5 types of variables in CUBLOC BASIC e BYTE 8 bit Positive Number 0 to 255 INTEGER 16 bit Positive Number 0 to 65535 e LONG 32 bit Positive Negative Number 2147483648 to 2147483647 SINGLE 32 bit Floating Point Number 3 402823E 38 to 3 402823E 38 e STRING String 0 TO 127 bytes A Byte is an 8 bit positive number representing 0 to 255 An Integer is a 16 bit positive number representing 0 to 65535 A Long is a 32 bit positive or negative number representing 2 147 483 648 to 2 147 483 647 A Single is a 32 bit positive or negative floating point number representing 3 402823x10 to 3 402823 x 10 BYTE worD Lone For storing negative numbers please use LONG or SINGLE Use the DIM command for declaring variables as shown below Dim A As Byte Declare A as BYTE Dim B As Integer C As Byte Comma may NOT be used Dim ST1 As String 12 Set String size for String Dim ST2 As String Set as 64 bytes default Dim AR 10 As Byte Declare as Byte Array Dim AK 10 20 As Integer Declare as 2D Array Dim ST 10 As String 10 Declare a String Array 79 DEMO PROGRAM LOC studio ds cubloc_test variable cul LFI
115. Mode MODBUS RTU Master Mode CHAPTER 10 APPLICATION NOTES NOTE 1 Switch Input 14 NOTE 2 Keypad Input NOTE 3 Temperature Sensor NOTE 4 Sound Bytes NOTE 5 RC Servo Motoi NOTE 6 Digital Thermometer NOTE 7 DS1302 RTC NOTE 8 MCP3202 12 Bit A D Conversion NOTE 9 Read and write to an EEPROM CHAPTER 12 LADDER LOGIC LADDER Basics Creating LADDER Programs Editing LADDER Text Monitoring Time Chart Monitoring WATCH POINT Register Expression Ladder symbols Using I Os Use of Aliases Starting LADDER Declare device to use Using Ladder Only Enable Turbo Scan Time Mode Things to Remember in LADDER ladder instructions LOAD LOADN OUT NOT AND OR SETOUT RSTOUT DIFU DIFD MCS MCSCLR STEPSET STEPOUT TON TAON TOFF TAOFI UP DOWN COUNTER KCTU KCTD Comparison Logic Storing Words and Double Words Binary Decimal Hexadecimal WMOV DWMOV WXCHG DWXCHG FMOV GMOV WINC DWINC WDEC DWDEC WADD DWADD WSUB DWSUB WMUL DWMUL WDIV DWDIV WOR DWOR WXOR DWXOR WAND DWAND WROL DWROL WROR DWROR GOTO LABEL CALLS SBRT RET INTON TND Special Registers CUTOUCH What is CUTOUCH CUTOUCH Specifications Hardware Requirements Software Development Environment CUTOUCH 1 0 Ports Backup Battery KEEP Timer and KEEP Counte Menu System Libra
116. N when drawing is complete GLayer GLAYER layernumber Layernumber 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 on the layer set as 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 overmode overmode Logical Mode 0 or 1 and 2 xor This command determines the drawing logic mode between Layer 1 and Layer 2 Layer 1 is text and Layer 2 is graphics By using this command the user can specify the combining 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 266 Contrast CONTRAST value value Contrast Value 1 to 1024 Control 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 4
117. ON and OFF gso vn p gsn vss m gam b starTkey Lge Ae eh P dm Pn z Toa ke ge RP ao STOPKEY S Bib mr des moh 10Kohm grs esb der eo 68220 As you can see above the PO and P4 ports will be connected to a pull down resistor resistor attached to ground The CB220 will read these switches as 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 I In 0 Then a If In 4 1 Then a Out 14 a Loop When the switch is pressed a bouncing effect occurs from the switch s mechanical spring 324 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 command KEYINH rather than IN which will remove the bouncing effect by 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 sets the time for removing the bouncing effect also called debouncing time In other words the 20 means to wait 20ms before accepting input In the industrial field there can be a lot of noisy environments which can affect switch signals In order to block noise the us
118. OR is for logical operation XOR in WORD units whereas DWXOR is for DOUBLE WORD units Usable P m s c T D J Constants Registers s1 o lo lo lo s2 Delo fo fo d o o fo START WMOV 1234H D0 1 WMOV OFFH DI E J ACTION WXOR D0 D1 D2 3 The following is result of above LADDER DO D1 D2 1234H OFFH 12CBH When you want to invert specific bits you can use XOR logical operation 402 WAND DWAND WAND si DWAND si s2 d s2 d Store result of s1 AND s2 WAND is for logical operation AND in WORD units whereas DWAND is for DOUBLE WORD units The results of execution of LADDER above You can use AND operation when you want to use specific bits only DO D1 D2 Registers tht P M F S c T D Constants may be used s1 o o o o s2 o o o Jo D o o fo START WMOV 1234H D0 t 1 WMOV OFFH D1 a 1 ACTION WAND DO D1 D2 1 1234H OFFH 34H 403 WROL DWROL WROL d DWROL d Rotate the value in Register d 1 double word to the left The value left gets stored in the Carry flag WROL moves one word whereas DWROL moves double word Registers that P M F S c T D Constants may be used D o fo fo BKEY WROL DO jf If DO has 8421H the following results DO 0843H
119. Operating 40 C to 120 C 40 C to 120 C 40 C to 120 C 40 C to 120 C 25 0 DE pin Module pin Module pin Module Package prata 64 pin Modul 108 pin Modul 80 pin Modul 12Lxoewx LaLxiw x 0 4 0 4 H 2 4 Lx1 9 Wx05 H 2 4 Lx 1 9 Wx 0 5 H 30x15 3x11 35x25 4x11 59 4x47 8x13mm 59 4 47 8x 13 mm mm mm 21 B320 icture Program 200KB 200KB Memory Data KB BASIC 6KB BASIC Memory 1KB Ladder Logic 1KB Ladder Logic EEPROM AKB EEPROM AKB EEPROM Program pss 36 000 inst sec 36 000 inst sec General 151 0 tines SV TT Samaan ROEE A rames 48 0 ies csv TTD Opn 1 0 Spare 1 0 6 5V TTL at Z serial ports Z serial ports Channel 0 RS232C i Channel 0 RS232C 12V 12V Channel 1 RS232C 12V amp Serial Channel 1 TIL SV TTL 5V Configurable Baud rates Ports Configurable Baud rates 2400bps to 230 400 bps 2400bps to 230 400 bps Analog 8 Channel 10 bit ADCs 8 Channel 10 bit ADCs Inputs 3 Channel 16 bit PWM 6 Channel 16 bit PWMs DACS Analog DACs Frequency 35hz to Frequency 35hz to 1 5Mhz Outputs i smhz External 4 Channels in Spare 1 0 4 Channels Interrupts een USB 2 channei 32 bit Counters up 2 channel 32 bit Counters up to pee to 2Mhz 2Mhz Counters Power 57 I2 faa pars SV 40mA ports unloaded RTC No No Data Memory None None Backup Operat
120. PLC Embedded computer CUBLOC User Manual Version 3 1 Everything for Embedded Control COMFILE TECHNOLOGY Comfile Technology Inc www cubloc com Copyright 1996 2008 Comfile Technology Blank Page sour CUBLOC CB220 sng Core Module CB320 4x4 Pinout ss_apco_po r inputonyscx_apcs Pr Mos_anca_r2 pSPARENO guso_anca_pa d Pi pums Anca Pa G P20 POMA vee pwmo_ADcs_Ps PENENT pin ADCS d Pwm2_anc7 P7 d 2 3b vss 3 22 RES 508 8 208 pts nent 7 EB epee Bese v2 1af ps_sct cuner CB280 Sis C gipio CB380 ee oiii aosi p2 Pig ADER miso_P3 Abe GUNET seu pao Pst_pwme p52 pwm PBS PAWMI 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 replace 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 warranty 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
121. Pio Po mmm 1p Po er di2 sf Ps Please refer to the table below for ADC channels CB220 CB280 CB290 CT17Xx CB405 CB320 CB380 A D channel 0 1 0 0 VO 24 08 Yoo 1 0 16 A D channel 1 1 01 y0 25 109 YO 1 0 17 A D channel 2 1 02 10 26 10 10 YO2 1 0 18 A D channel 3_ 1 0 3 Y0 27 011 y03 1 0 19 A D channel 4 1 04 1 028 1 0 12 V04 1 0 20 A D channel 5_ 1 05 10 29 1013 V05 1 021 A D channel 6 1 0 6 1 030 1 0 14 106 1 0 22 A D channel 7 1 07 1031 10 15 VO7 1 0 23 A D channel 8 1 0 32 A D channel 9 10 33 A D channel 10 1 0 34 A D channel 11 1 0 35 A D channel 12 1 0 36 A D channel 13 10 37 A D channel 14 1 0 38 A D channel 15 1 0 39 The ADIN command only converts once upon execution TADIN is a macro that returns the average of 10 conversions giving the user more precise results If you need more precision rather than speed we recommend the use of TADIN instead of ADIN averaging or filtering code for better precision It is also possible to create your own 125 Alias ALIAS Registername AliasName Registername Register name such as PO MO TO Do not use D area AliasName An Alias for the Register chosen up to 32 character Aliases may be chosen for Ladder registers Aliases can help the user write code that is easier to read and debug Alias MO Rstate Alias MO Kstate Alias PO StartSw 126 Bcd2bin Variable BCD2BIN bcdvalue Variable Variable to store results Returns LONG
122. Port Block 0 to 15 449 Layer LAYER layerlmode layer2 mode layer3 mode Layerimode Set Layer 1 mode 0 off Layer2mode Set Layer 2 mode 0 off Layer3mode Set Layer 3 mode O off 1 Ladderscan LADDERSCAN Light LIGHT value value Back light O OFF 1 ON Line LNE xi yi x2 y2 Linestyle LINESTYLE value Lineto LINETO x y Low LOW Port Port 1 0 Port number 0 to 255 Locate LOCATE X Y Menu Variable MENU index pos Variable Variable to store results 1 selected 0 unselected Index Menu Index pos Position O x1 Memadr Variable MEMADR TargetVariable Variable Variable to store results No String or Single TargetVariable Variable to find physical memory address Menucheck Variable MENUCHECK index touchx touchy Variable Variable to store results 1 if selected 0 if unselected Index Menu Index Number Touchx Touch pad x axis point Touchy Touch pad y axis point Menu MENUREVERSE index Reverse Index Menu index number 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 location Menutitle 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 450 Ned Variable NCD source Variable Variable to store results No String o
123. RS232 Channel 1 Tx 29 P12 1 0 port 30 P13 1 0 port 31 Pid HCOUNTO 1 0 port 32 P15 HCOUNTI 1 0 port 33 P10 1 0 port 34 PLL 1 0 port 35 P40 1 0 port 36 PAI 1 0 port 37 Paz 1 0 port 38 Pas 1 0 port 39 Pad 1 0 port 40 PAS 1 0 port 41 Za 1 0 port 42 P47 1 0 port 43 Pas 1 0 port 44 P39 1 0 port 45 P38 1 0 port 46 P37 1 0 port 47 P36 1 0 port 48 P35 1 0 port 49 P34 1 0 port 50 P33 1 0 port 51 P32 1 0 port 52 VDD Power supph 53 VSS Ground 54 P31 ADC7 T O port 55 P30 ADCS 1 0 port 56 P29 ADCS 1 0 port 57 P28 ADCS 1 0 port 58 P27 ADCS 1 0 port 59 P26 ADCZ 1 0 port 60 P25 ADCT 1 0 port 61 P24 ADCO 1 0 port 62 AREF Ref for ADC 63 VSS Ground 64 AVDD Power supply for ADC Please refer to Appendix F for a detailed CB280CS specification 58 Example CB280CS Application Schematic toPC aL CUBLOC CB280CS Main Chip o vss 59 MEMO 60 Chapter 3 CUBLOC STUDIO CUBLOC STUDIO Basics After installing CUBLOC STUDIO and executing it you will see the following screen CUBLOCstuie Fumiitled cut 1 DER le Edt Dewe fun Senp Help Ban sxan A gt aa TTT Basic F2 LADDER Laddar Mnemonic E CUBLOCstudlo unitled cul J FB ie Cer Gece fin Saup Eao Bod SSS a gt wale TFIVEAG FET ODER Ladder neroni elle A te 484 Allil elelee puc viens
124. S1620 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 Celcius can be measured by the DS1620 in units of 0 5 Degrees ear wh geno vss ar gam aes i gre h ge mh gs pnp ge pnp ges ewh re rsh E220 lax TH tee aap Zao reou fy mr P520 lt Filename ds1620 cul gt Const Device CB280 Const iorst 7 Const ioclk 6 Const iodg 5 Dim I As Integer Delay 100 High iorst init ds162 Shiftout ioclk iodq 0 12 8 Shiftout ioclk iodq 0 3 8 Low iorst High iorst Shiftout ioclk iodq 0 shEE 8 Low iorst Do High iorst Shiftout ioclk iodq 0 shaa 8 i Shiftin ioclk iodq 4 9 bod debug dec i cr Low iorst Delay 100 Loop The final value received must be divided into 2 to obtain the current temperature lt END gt 339 NOTE 7 DS1302 RTC The DS1302 RTC Real Time Clock is a chip that will act as an electronic time keeper 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 CEZ sw ahr ars vss voo deo msp de pwb de psp 32768Hz de meb g US eae CS o mhte eh mr 051302 ca220 Pin Function I O Direction _ Explanation RST Reset Input Data transfer when High SCLK System Clock Input Clock signal yo Data Input Data i
125. ST1 CUBLOC DEBUG RIGHT ST1 4 BLOC is printed MID Variable Location Decimal Places Cut specified decimal places starting from the location specified and return the value DIM ST1 AS STRING 12 ST1 CUBLOC DEBUG MID ST1 2 4 UBLO is printed Debug Terminal Re Bausfate Party DABS ane f TI CUBLOC studio d cubloc_testistringfune cut raze here hone oS Ble pdt Device Bun Setup Help I 2 fee de zor Bad GABE A gt we IFI BASIC F2 LADDER Ladder mnemonic Const Device cB260 Dam stl As String 12 stl CUBLOC Debug Left att 4 cr Debug Right st1 4 Cr Debug Mid st1 2 4 Cr I Fix Right Side 118 LEN Variable Return the length of the string specified DIM ST1 AS STRING 12 ST1 CUBLOC DEBUG DEC LEN ST1 6 is printed since there are 6 characters in ST1 STRING ASCII code length Create a specified length string with specified ASCII code value DIM ST1 AS STRING 12 ST1 STRING amp H41 5 DEBUG STI AAAAA is pi amp H41 is ASCII code for character A SPC decimal places Create specified amount of blank space DIM ST1 AS STRING 12 ST1 SPC 5 DEBUG A ST1 A AbbbbbA is printed Here b is for blank space lt u aanas Patty OEE an A E CUBLOC studio d cubloc_tststringfunc cul Gos free k Te EM Dewe Bin Selo HEP nk Bap XASAD 20 E TFI BASIC F2 LADDER Ladder Mnemonic i Const Device
126. Slave address Buffersize Send Buffer Size Set SET DEBUG On Off debug Set i2c SET 12C DataPort ClockPort DataPort SDA Data Send Receive Port 0 to 255 ClockPort SCL Clock Send Receive Port 0 to 255 Set SET LADDER On Off ladder Set Set MODBUS mode slaveaddress returninterval modbus mode O ASCII 1 RTU slaveaddress Slave Address 1 to 254 retuminterval retum interval value 1 to 255 default value is 1 Set SET OUTONLY On Off outolny Set SET PAD mode packet buffersize Pad mode Bit Mode 0 to 255 packet Packet Size 1 to 255 buffersize Receive Buffer Size 1 to 255 Set SET RS232 channel baudrate protocol rs232 channel RS232 Channel 0 to 3 Baudrate Baudrate Do not use variable protocol Protocol Do not use variable Set SET UNTIL channel packetlength stopchar until channel RS232 Channel 0 to 3 packetlength Length of packet 0 to 255 stopchar Character to catch Set SET INTx mode Int x 0 to 3 External Interrupt Channel mode 0 Falling Edge 1 Rising Edge 2 Changing Edge Set SET ONGLOBAL On Off Onglobal Set SET ONINTx On Off onint Set SET ONLADDERINT On Off onladderint 453 Set onpad SET ONPAD On Off Set onrecy SET ONRECVO On Off SET ONRECV1 On Off SET ONRECV2 On Off SET ONRECV3 On Off Set Ontimer SET ONTIMER On Off Set SPI SET SPI dk mosi miso mode clk port for clock output mosi port for data Maste
127. TO x y Draw a line from the last point to x y LINETO 200 50 K Continue drawing line from the last point 270 Box BOX x1 y1 x2 y2 Draw a box with diagonal positions of X1 Y1 and X2 Y2 F BOX 10 20 200 100 Draw box Boxclear BOXCLEAR x1 y1 x2 y2 Clear the box with diagonal positions of X1 Y1 and X2 Y2 R 10 20 200 100 Clear box D Boxfill BOXFILL x1 y1 x2 y2 logic logic 0 OR 1 AND 2 XOR Draw a box with diagonal positions of X1 Y1 and X2 Y2 and fill according to specified logic O OR will display all overlapped areas i 1 AND will display only the overlapped areas 2 XOR will display the overlapped areas inversed BOXFILL 10 20 200 100 0 Draw and fill box 271 Circle CIRCLE x y Draw a circle with x y as the center and with r as the radius 100 50 Draw ci Circlefill CIRCLEFILL x y r Draw and fill a circle with x y as the center and with r as the radius 272 Ellipse ELLIPSE x y 11 12 Draw an ellipse with x y as the center and with r1 as the horizontal radius and r2 as the vertical radius ELLIPSE 200 100 100 50 Draw ellipse EIfill ELFILL x y 11 12 Draw and fill an ellipse with x y as the center and with r1 as the horizontal radius and r2 as the vertical radius ELFI Draw and fill ellipse 200 100 100 50
128. Temperature 60 to 140 Degrees Celcius Operating Humidity 5 to 95 RH Keep the board s surface dry when testing and or operating Additional Information If CUBLOC module is supplied with power above recommended voltage the chip can be destroyed Please be careful of static electricity that could damage the chip Please be aware that P1 is an input only pin To reduce accidental power drain please set unused pins to input all I Os are set to input as default at power on When not using SIN SOUT and ATN pins please do not connect them to anything 54 Dimensions CB220 30mm 1181mil 15 24mm 600 mil 25 4mm 1000 mil 2mm 78 74 mil 34 9mm 1374mil gt Je 2mm 78 74 mil 18 415mm 725 mil 55 59 4mm 2338 mil 49 53mm 1950 mil CB290 CB405 36 83mm 1450 mil 2mm 78 74 mil 47 8mm 1882mil E ape 14 0 14 9mm 551 586mil _ CB290 CB405 9 5mm 374mil Please refer to the diagram below for PCB design The numbers are offsets based on location 0 0 from the top left corner of the module s internal PCB not the external plastic case x 180 x 2100 Yi1600 1600 Unit 171000 inch mit 56 CUBLOC Chipset CB280CS The CB280CS has exactly the same features as a regular CB280 module but in a chipset format The CB280CS must be soldered into a custom circuit board This will lower your overall production cost while
129. To Clipboard button will also copy the contents of the code generation window to the clipboard jeal Time Code Generation BASIC Cote for CLELOC SUB NUMKEYO FONTO STVLEDOO MeNUSET 02 19085215 90 MENUITTLE 0 88 MENUSET 1 2 22585 250 80 MENUTITLE 1 94 2 MENUSET 272 250 552065 80 MENUTITLE 2 04 9 MENUSET 32 190 100 218 125 MENUITTLE 3 94 4 MENUSET 4 2 225 100 250 125 MENUITTLE 4 343 MENUSET 5 2 280 100 285 125 MENUITTLE 5 94 5 MENUSET 6 2 190 135 215 160 MENUITTLE 6 94 7 MENUSET 7 2 225 138 250 160 MENUTITLE 7 934 3 MENUSET 0 2 250 138 206 160 MENUTITLE 0 943 MENUSET 92 190 170 218 105 MENUTITLE 9 94 0 MENLISET 19 2225 170 285 195 MENUTITLE 10 12 4 ENTER FONT 4 0 leno sua To Ciipooard Save to Fie You can also use include files instead of copying and pasting for repetitive menu creations Click Save to File button and save as an include inc file save Your Desiun To BASIC Code TES HS AID APFNOTE EERE ETONE TH OEA IASAD BOCA Coen a HA eee 437 Include files make it easy to change the interface of your program without a lot of cut and paste operations within your main code The following program is exactly same as SAMPLE4 except we use an include file for the virtual keypad GETTOUCH 438 Const Dim Tx Contra Set Pac On Pad NUMKEY I 0 Do Loop 1x1 wie I Men Elseif Elseif Elseif Elseif El
130. When this command is executed the set part of the screen becomes part of the button s area Menutitle MENUTITLE index x y string Index Menu index number Xy 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 425 Menucheck Variable MENUCHECK index TouchX TouchX Variable Variable to store results 1 if selected 0 if unselected Index Menu Index Number TouchX Touch pad x axis point TouchY Touch pad y axis point Use this command to determine which menu button has been pressed TouchX and Touchy are the user s touchpad input points If the Menu is selected 1 is returned otherwise 0 is returned If Menucheck 0 TX1 TY1 1 Then Menureverse 0 Beep 18 180 End If Menureverse MENUREVERSE index Index Menu index number The specified menu box is inverted This is useful to provide visual feedback to a user indicating that a menu button has been pressed Total cost Menu Variable MENU index pos Variable Variable to store results 1 selected 0 unselected Index Menu Index pos Position 0 x1 1 y1 2 x2 3 y2 If you need to find the current coordinates of Menu buttons set by the Menuset command you c
131. a packet that will cause an interrupt For example the Cutouch panel requires 4 bytes to be received before an interrupt is called Buffersize 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 routine The buffer size is usually set to 5 or 10 times the packet size Mode will set the receiving mode of the received data Please refer to the below table Mode vaue Bit Diagram Pattern LSB First amp H20 0010 XXXx MSB First amp H00 0000 XXXX SCK Low amp HO8 xxx Uomi Edge Dax Triggered SCK High Edge amp H00 oox M Triggered 0xxx Sampling BHO4 oox after SCK X1xx M _IUT ott Sampling BHOO oox before SCK x0xx 227 You can add the values of the receiving modes For example for MSB first High Edge Triggered SCK and sampling after SCK 0x00 0x00 0x04 0x04 Here are some of the common examples sx _TUUUUUUUL amp H00 Sample ce MUUUUUUUL amp H04 sampe SCK UY amp H08 Samma sx MUUUUUUU amp HOC Sample LI it For PAD communications you can use Comfile s Keypads or Touch screens The Set Pad command will automatically set the ports PO through P3 the user doesn t have to set them 228 Set Rs232 Set Rs232 channel bau
132. ables are created upon call of the Sub or Function and removed at exit This means that the Local Variables will use the Data Memory and then free it for other resources Local Variables may only be referred to or used inside the Sub or Function On the other hand Global variables may be used in all parts of your code Main Program Global Variable Sub ProgramA Sub Program B Local Variable Local Variable Dim A As Integer Declare A as Global Variable LOOPL A A 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 your code but K may only be used inside the subroutine DELAYTIME Arrays may not be used for Local Variables Arrays must be declared as Global Variables 74 Calling subroutines Once the subroutine is created you can use them like a regular command For a Sub you do not need parenthesis around the parameters For multiple parameters use a comma to separate them 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 aro
133. alled a macro processor because it allows you to define macros which are brief abbreviations for longer constructs In CUBLOC BASIC a preprocessor similar to C language can be used Preprocessor directives like include and define can be used to include files and process code before compiling include filename Include file in the source code For files in the same directory as the source file you can do the following INC E MYLIB cub For files in other directories you will need to include the full path name as shown here INC wece CUBLOC 1ib 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 For 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 motorpo low motorport The following example uses define for replacing a line of code 97 fdefine FLAGREGL 2 fdefine fled FLAGREGL BITO fdefine cale 4 i 256 fled 1 Set FLAGREGI s bit zero to 1 IF fled 1 then f led 0 Make it easier to read j cale calculations can be simplified NOTE define will not
134. alue Fe Debug Termina Ta DEBUG DEC A CR Baud Rate Party Data Bis AET DEBUG HEX A CR fers reas ore fe 141 You can also specify the number of characters to print DEBUG HEXS A iix TES Parir paag eon u feom x 115200 x Nore m oe 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 EE Baud Rete Parity ee eee feom z s220 x none Ife zl ex The DEBUG command is useful for printing out strings and numbers in a user friendly format During execution of CUBLOC BASIC program when DEBUG command is encountered the resulting values are immediately displayed on the DEBUG Terminal 142 If you insert a DEBUG command into a program and the DEBUG Terminal displays those values during execution it proves that the program has executed to that point By using DEBUG commands you will be able to detect the location of bugs in your program and monitor variables change in real time If you enter characters in the upper part of the Debug Terminal it will be sent to the DOWNLOAD port of CUBLOC This can be used 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 commands
135. an 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 If Menu button 0 s 1 is less than 100 426 Waitdraw WAITDRAW This command will wait for a drawing command to finish before resuming execution ELFILL 200 100 100 50 Fill an ellipse WATTDRAW Wait until drawing is finished This command is especially useful for animations and if you have trouble displaying graphics at a high update rate The CUTOUCH has an internal buffer for receiving graphic commands from the internal CUBLOC controller If this buffer fills up and data is sent to it the existing data could get corrupted In order to avoid these situations you can use the WAITDRAW command to wait until the buffer has enough space before sending graphic commands If you need to draw graphics repeatedly we recommend you use WAITDRAW to prevent overrunning the buffer which may appear as noise on the LCD This command can only be used with CUTOUCH 427 Touch Pad Input Example You can use SET PAD ON PAD and GETPAD commands to find out which menus were touched by the user All PAD commands are used for receiving and processing touch input We can use ON PAD interrupts to receive touch inputs The following is an example program that uses the touch pad DEMO FOR CUTOUCH Const Device CT1720 Dim TX1 As Integer TY1 As Integer
136. ar to Address 10 except it will increment until 65535 before resetting to 0 Address 10 through 13 must be used with CUBLOC STUDIO 2 0 X and above versions 244 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 Address Value Range Bit Structure 0 Second 0t059 2 digit place I digit place 1 Minute 0to 59 2 digit place 1 digit place 2 Hour Oto 23 Fyi digit 1 digit place place 3 Date Oi to si 21 digit 1 digit place place 4 Day Oto T digit place 5 Month 1toi2 10__ 1 digit place 6 Year 00to99 2 digit place 1 digit place The following is an example showing how to set the time and output the current time to the debug window Const Device CB290 Dim I As Byte Timeset 0 0 Sec Timeset 1 6H32 Min Timeset 2 6H11 Hour Timeset 3 6H1 Date Timeset 4 6H5 Day of the week Timeset 5 amp H6 Month Timeset 6 6H5 Year Do I Time 6 Debug Year 200 Hex I 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 Debug June 245 Case 6 Debug July Case 7 Debug August Case 8 Debug September Case 9 Debug November Case 10 Debug December End Select I Time 3 Debug Hex2 I Debug I Ti
137. ble I O ports on the CUBLOC When the STEPACCEL command is executed that Port is automatically set to the ouput state Even after the command has finished generating pulses the Port remains in output state Output Frequency can be set from 1hz to 3 3KHz This command will run in the background independently so the user may use system resources for other tasks 238 DEMO PROGRAM IF BASC F2 LADDER Ladder Mnemonic Fune Script Conse Device CB230 Be Do While In 0 0 Loop Steppulse 0 5 5000 300 Do while rmn 0 1 Loep 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 above code oB2so sv PO ia mr rs m 5KHz 130 Pulses 15KHz 300 Pulses ee 239 You can connect a stepper motor and stepper motor driver such as below to control a stepper motor CONTROLLER j DRIVER sve FH SR i CURRENT SET t POWER GROUND 42470 0 VDC Connect 3 I Os of CUBLOC 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 on how many pulses are required to move the stepper motor one rotation 240 Sys Variable SYS address Variable Variable to store results No String or Single address Address 0 to 255 Use command Sys to read the sta
138. cB280 Dim stl As String 12 sti cuptoc Deb Dec Len st1 Cr stl string ihdl 5 Debug sti stl 8pc 5 Debug A st1 A Cr gt Fix Right Side 119 LTRIM String variable Cut all blank spaces on the left side of the string and return the value DIM STL AS STRING 12 ST1 COMPILE ST1 LTRIM ST1 DEBUG AAA ST1 AAACOMFILE is printed RTRIM String variable Cut all blank spaces on the right side of the string and return the value DIM STL AS STRING 12 ST1 COMPILE ST1 RTRIM ST1 DEBUG ST1 TECH COMPILETECH is printed Blank spaces on the right are removed Debug Terminal Pot BaudRete Party CUBLOC studia d cublac_testtstringfunc cul oom z s20 Ele Edt peice Bn sup Hep BaD GER A gt He FI BASIC F2 LADDER Ladder Mnemonic Const Device CB280 Dim stl As string 12 etl custoc Debug Lerim st1 Core Cr Debug Rtrim st1 Core Cr Close I Fix Right Side 120 VAL String variable Return a converted numerical value of the String DIM ST1 AS STRING 12 DIM I AS INTEGER STI 123 I VAL ST1 123 is stored in variable I as a number VALSNG String variable Return a converted floating point numerical value of the String DIM ST1 AS STRING 12 DIM F AS SINGLE STI 3 14 F VALSNG ST1 3 14 is stored in variable F as a floating point number Baud Rate Parity Data
139. can be set to zero st a a Jo 1 Jo Jo o J Jolololojol i Jo i Reg P27 pzs pzs pza P23 P22 pos p20 P30 P29 pea Response Field RTU Bytes ASCII Bytes Header z 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 0B 2 Error Check CRC 2 LRC 2 Ending Code CRLF 2 316 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 Query Field RTU Bytes ASCII Bytes Header 2 colon i 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 0XD1 1 D1 2 Data 1 LO 0x03 1 03 2 Data 2 HI 0X0A 1 OA 2 Data 2 LO 0x12 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 317 Error Check If there is error in the data
140. ciently and 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 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 you receive comes with the latest version of Cubloc Studio at the time the CD was created Please be aware that the software may be upgraded often Please check www cubloc com to download the latest version of CublocStudio Please run Setup gt Firmware Download after installing a new version of CublocStudio as the newest firmware is included with the upgraded software Please check www comfiletech com often for latest Manual Please make sure to insert the CUBLOC module correctly as inserting it improperly can cause damage to the chip Please be aware that our 1 Year Warranty only covers defective items Table of Contents CHAPTER 1 GETTING STARTED What is CUBLOC CUBLOC Specifications Ladder Logic and BASIC Multi tasking of Ladder Logic and BASIC Advantages of an On Chip PLC Embedded Computer Development Environment Download and Monitoring through the Int
141. cks as shown below ifdef LOWMODEL LOW 0 elseifdef HIGHMODEL HIGH 0 telse LOW 1 fendif 100 ifndef name endif ifndef is the opposite of the ifdef directive If a constant has not been defined the statements inside a i endif block will be compiled otherwise the statements are discarded define LOWMODEL 0 ifndef LOWMODEL LOW 0 endif elseifndef and else may be used for more complex blocks as shown below ifndef LOWMODEL LOW 0 f elseifndef HIGHMODEL HIGH 0 telse LOW 1 tendif Finally the directives may be mixed as shown below if MODELNO 0 LOW 0 felseifdef HIGHMODEL HIGH 0 telse LOW 1 tendif An exception is that if may not be used inside another if 101 To use LADDER ONLY If you do not need to use BASIC you can program in LADDER 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 Out RELAY Alias MO MOTORSTATE Set Aliases Alias Ml RELAYISTATE Set Ladder On start Ladder Device model aliases and pin input and output status must be set in BASIC Ladder must be started in BASIC with SET LADDER ON command To use BASIC ONLY Simply use BASIC Ladder is off as default Set Ladder On Just don t use this command Ladderscan And this one too 102 Interrupts An interrupt can occur during the main program to process immediate ne
142. connected to 5V The following is the simplest type of AD input circuit using a potentiometer When you turn the knob the input will be converted by the CUBLOC ADC to a value from 0 to 1023 5v 10Kohm O CUBLOC I O Port 292 The following is an AD input that receives 4 to 20mA of input You can use a 230 Ohm and 20 Ohm resistor in serial instead of a 250 Ohm resistor 4 20mA CUBLOC 1 0 Port 2500hm For 0 to 10V input use 2 resistors as shown below This is also called a voltage divider 1Kohm 0 10V CUBLOC I O Port 1Kohm How to use PWM as Digital to Analog converter The CUBLOC has 6 PWM ports If you use the simple circuit shown below you can make a D A converter 10Kohm 0 5V duteur pO CUBLOC PWM Port 47uF IE 293 RS232 HOWTO Pins 1 and 2 are for connecting to the 12V signals of RS232 Channel 0 Download port The CB220 model has ports 10 and 11 for RS232 Channel 1 5V signals sav av UUU ae The reason 5V and 12V signal levels exist is as follows Since a PC uses RS232 12V signals we would need to make a separate circuit to convert to 5V signal levels for the CUBLOC Since the CUBLOC has a 12V signal inteface the user doesn t have to worry about making a converter circuit Downloading to a CUBLOC is very easy since you can connect a PC RS232 cable directly to pins 1 and 2 For RS422 and RS485 converters 5V signals are provided on RS232 Channel 1 294
143. cr Print results to LCD Delay2 500 Little Delay from ADO and Adl use OPAMP 1 Loop End Sub Delay2 DL As Integer Dim I As Integer For I 0 To DL Next End Sub The EADIN command does not support the full 10 bit resolution that the regular ADIN supports When using 1X and 10X multipliers 8 bit resolution is used When using 8X and 200X multipliers 7 bit resolution is used WARNING The OPAMP electrical characteristics limit the detectable input range to 0 5V 4 5V With the CB405 the EADIN command can only be used with ADC channels 0 through 7 Please refer to the following table for ADC channels and corresponding port numbers for your CUBLOC or CUTOUCH Channel CB220 CB280 CB290 CT17X0 CB405 ADCO Yoo 1 0 24 108 100 1 0 16 ADCI V01 1 0 25 1 09 OL 1 0 17 ADC2 YO2 1 0 26 1 0 10 102 1 0 18 ADC3 103 1 0 27 1011 103 1 0 19 ADC4 104 1 0 28 1 0 12 104 1 0 20 ADCS 105 1 0 29 1 0 13 105 1 021 ADCE 106 1 0 30 1 0 14 106 1 0 22 ADC7 107 1 031 1 0 15 107 1 0 23 150 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 EEPROM 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 151 Eewrite EEWRITE Address Data
144. d position When displaying anything other than numbers this command can be used to control each segment LED a r e c qJ ly Bit 7 6 5 4 3 2 1 o LED H G F E D B A To print character L positions D E and F must be turned ON Since the bit value would be 0011 1000 in hex that s amp H38 or 0x38 CSGXPUT 0 0 amp H38 would be the exact command to use Csgdec CSGDEC slaveadr data slaveadr CSG Slave Address data Data Print decimal value to the CSG Csghex CSGHEX slaveadr data slaveadr CSG Slave Address data Data Print hexadecimal value to the CSG 288 Chapter 8 Interfacing Input Output Circuits How to connect LEDs Connect the LED as shown below and output HIGH to the connected I O port to turn the LED ON 330 ohm CuBLOC I O Port How to connect pushbuttons Connect the pushbutton as shown below and set the connected I O port to INPUT mode When the button is pressed the CUBLOC will read HIGH otherwise it will read LOW Ta CuBLOC 1 0 Port 10Kohm How to connect a potentiometer Connect the potentiometer as shown below to a A D I O port and use the ADIN command to read the position of the potentiometer 10Kohm 4 QO CuBLOC 1 0 Port The CUBLOC core module uses 5V power When using a larger voltage please use an appropriate voltage converter or regulator 290 How to Connect an Output Relay The following diag
145. der 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 The biggest advantage that Ladder Logic possesses 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 main reason why it s used for machine control and other automation fields Ladder Logic is more logic oriented not a complete programming language To do complex processes it has its limits For example to receive input from a keypad display to 7 Segment or LCD and process user s 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 language is very similar to the English language IF GOTO etc allowing the beginners and developers to learn in matter of hours instead having to deal with months of learning curves 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 s
146. 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 Do Loop TIMERTN cr I I is incremented 1 every second Return IMPORTANT Please pay attention when creating the interrupt routine It must require less time to execute than the interval itself If interval is set at 10ms the interrupt routine must be within 10 ms about 360 instructions Otherwise collisions can occur within the program 192 Opencom OPENCOM channel baudrate protocol recvsize sendsize channel RS232 Channel 0 to 3 Baudrate Baudrate Do not use variable protocol Protocol Do not use variable recvsize Receive Buffer Size Max 1024 Do not use variable sendsize Send Buffer Size Max 1024 Do not use variable To use RS232 communication this command must be used first The CUBLOC has 2 or 4 channels for RS232C communication depending on model Channel 0 is used for Monitor Download but the user can use it for RS232 communication if she he wishes to disable monitoring Download through that port will still work regardless The following are allowed baudrate settings for CUBLOC RS232 2400 4800 9600 14400 19200 28800 38400 57600 76800 115200 230400 For the protocol parameter please refer to the table below Bit7 Bite Bits Bit4 Bits Bit2 Biti__ Bito Parity Stop Bit Bit of Bits o 0 NONE O 1 Sto
147. differentiate uppercase and lowercase letters They will all be processed as uppercase characters For example define ALPHA 0 and define alpha 0 are considered the same DEMO PROGRAM Debug Terminal CUBLOC studio d cubloc_testlabe cul ene Fle Edt Devce Run Seun Heb 115200 a asas 483 A gt ow wl FI BASIC F2 LADDER Ladder Mnemonic Const Device CB280 fdefine Rep Debug Dec Close I Fix Righ Side 98 Conditional A conditional is a directive that instructs the preprocessor to select whether or not to include a part of code before compilation Preprocessor conditionals can test arithmetic expressions or whether a name is defined as a macro Here are some reasons to use a conditional A 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 preprocessing conditional a BASIC program may be programmed to compile on any of CUBLOC CUTOUCH modules without making changes to the source code If you want to be able to compile the same source file into two different programs One version might print the values of data for debugging and the other might not if constant endif 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 otherwi
148. dio o Weubloc Tle Edt Device Dun Setup Bele Sa GSR A gt ou Be TFIDRASIC IFA LADDER Ladder Mnemonic 42 493 alt els eltelte fe FP Fet Fn em ar Ent nsen Deiere Lindo Copy hia H MI WoRKLOH TOGLE MasHORK OFF TOGLE MPG ON INPUT MPG ON OFF TOGLE MPG ON LED 1 2 Modiiod Prosan 16t Evies Data 1001 Use the mouse to click and drag to select the desired copy area Press CTRL C to copy and CTRL V to paste Similar to text editing you can press CTRL X to cut and paste also Please be aware that in LADDER editing UNDO is not supported 355 Monitoring CUBLOC STUDIO supports real time monitoring of Ladder Logic Click Here BGO S ABR A gt eo oI Status of contacts that are ON will be displayed GREEN Timer and counter values will be displayed as decimal values You can control the monitoring speed by going to Setup Menu gt Studio option gt Monitoring speed When the monitoring speed is too fast it can affect CUBLOC s communications as monitoring takes up resources We recommend a value of 5 for the monitoring speed Tie Ean Once ful Sono HE ITSE Ladi maronie slejejs bl eae ta wo A an m oe H Hle oy Fa o HiT en a o ii rolama w Pa we 102 PHE sol a 4 ttf ua E OWE TNE wna vo Ei mm 2 Sy e ron E e Please make sure to stop monitoring before editing or downloading 35
149. drate protocol channel RS232 Channel 0 to 3 Baudrate Baudrate Do not use variable protocol Protocol Do not use variable You can only use Opencom command once to open a serial port In order to change the baudrate and protocol the Set Rs232 command can be used For the protocol parameter please refer to the table below Bit7 Bite Bits Bit Bits Bitz Biti__ Bito Parity Stop Bit Bit of Bits o 0 NONE o o 0 5bit 1 Stop Bit o 1 Reserve 1 o 1 6bit 2 Stop Bits 1 0 Even 1 0 7bit 1 1 Odd 1 1 8bit The below table shows typical settings basex d on the previous table Bits Parity Stop Bit Value to Use 8 NONE 1 3 8 EVEN 1 19 Hex 13 8 ODD i 27 Hex 1B 7 NONE 1 2 7 EVEN 1 18 Hex 12 7 ODD 1 26 Hex 1A Opencom 1 19200 3 30 20 open Rs232 channel 1 Set Rs232 1 115200 19 Change Baudrate amp Parity 229 Set Rs485 Set Rs485 Channel PortNumber Channel RS232 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 must occur one at a time The RS485 is known for being stable under noisy conditions You can refer to the fo
150. dresses are used HWRITE 0 gH1234ABCD 4 0 cD AB 34 12 wne As you can see in the above table when a LONG variable is stored in HEAP memory address 0 four memory addresses are taken HWRITE 0 amp HABCD 2 HWRITE 1 amp H6532 2 168 DEMO PROGRAM 169 High HIGH Port Port I O Port number Set the Port to a logic HIGH state 5V OUTPUT 8 Set Port 8 to output state HIGH 8 Set 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 Vid vis HIGH O LOW 0 170 I2Cstart 12CSTART Set I2C SDA and SCL to Start mode After this command SDA and SCL go Low I2Cstop I2CSTOP Set I2C SDA and SCL to Stop mode After this command SDA and SCL go HIGH 171 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 I2C command Use any value for the dummy value A 12CREAD 0 SCL spa _ Ack This command will send an ACK signal back to the slave I2C device after reading a byte an SCL pulse will be sent while SDA is kept LOW 172 I2Creadna Variable 120READNA dummy Variable Variable to store results No String or Single
151. e are also commands to copy cut and paste graphic and a BMP Downloader program for downloading images to the GHLCD The GHB3224 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 GHLCD Library is 99 compatible with CUTOUCH modules Layert The text layer size is 40x15 as shown in the grid below Each character size is 8 by 16 pixels 4 01234567890 OBNAMURWNAD For graphics 320 by 240 pixels are available on the GHLCD series o 319 239 Please note that graphics or characters will be printed in random places when trying to print outside the specified range of pixels shown here 262 On the graphic layers text and other objects can be placed anywhere on the 320x240 pixel range On the text layer text must be located on the 40x15 grid 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 GHICD CUNET Set Address to 1 Send buffer to 50 Warning CUNET Slave address and Display Slave address must match Display Slave address can be set
152. e following chart shows the relationships between these three types of number representation Decimal Binary Hexadecimal 0 0000 0 1 0001 1 2 0010 2 3 0011 3 4 0100 4 5 0101 5 6 0110 6 7 0111 7 8 1000 8 E 1001 9 10 1010 A ir 1011 B 12 1100 G 13 1101 D 14 1110 E 15 ii F 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 the binary number and an H for hexadecimal numbers To clearly identify that ABCD 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 in the way you express binary and hexadecimal numbers We use amp B100010 or amp HAB to express those type of numbers 392 WMOV DWMOV WMOV s d DWMOV s d The command WMOV moves 16 bit data from s to d DWMOV can be used for 32 bit data Usable Register P M E S a T D Constants s Source o fo Jo o d Destination o o o START WMOV 100 DO 1 iNo DWMOV 1234H D2 1 When the input START turns ON DO will get 100 When INO turns ON D2 will get 1234H DO 100 D1 D2 1234H D3 0 D4 393 WXCHG DWXCHG WXCHG s d DWXCHG s d The command WXCHG exchanges data between s and d WXCHG is for exchanging 1 Word and DWXCHG
153. e inc Open serial port for MODBUS Set Baudrate as 115200bps and 8 N 1 with receive buffer of 200 bytes and send buffer of 100 bytes Opencom 1 115200 3 200 100 Data Receive Interrupt routine On Reevl Gosub GETMODBUS Clear A11 Buffers Belr 1 2 User Timer for MODBUS Timeout On timer 1 Gosub MyClock Debug MODBUS FloatingPoint Value Write RTU Example cr Test writing 32bit SINGLE to Register Address 0 of device 1 Debug writing 3 14 and 6 99 Long value to register 0 Cr writesingle 1 0 3 14 writesingle 1 0 6 99 Example showing how to send multiple floating point variables by making a simple function as WriteMultiplesingle SDataArray 0 1 11 SDataArray 1 2 22 SDataArray Debug Writing multiple Single values to address 0 Cr writemultiplesingle 1 0 3 Do Loop Modbus Receive routine include ModbusRTUrecv bas End Modbus Low Level include file include ModbusRTULib016 bas Please check our forum at www cubloc com for more Modbus ASCII and RTU examples and MODBUS BASIC include file downloads 321 MEMO 322 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
154. e time and when using the Freqout command on a channel a PWM command cannot be used on the same channel The following is a chart that correlates FreqValue to musical notes Note Octave 2 Octave 3 Octave 4 Octave 5 A 20945 10473 5236 2618 Bb 19770 9885 4942 2471 B 18660 9330 4665 2333 17613 8806 4403 2202 Db 16624 8312 4156 2078 D 15691 7846 3923 1961 Eb 14811 7405 3703 1851 13979 6990 3495 1747 F 13195 6597 3299 1649 Gb 12454 6227 3114 1557 G 11755 5878 2939 1469 Ab 11095 5548 2774 1387 Freqout Note A in Octave 4 440Hz Freqout Note G in Octave 5 C D F G A C D 4156 3703 3144 2774 2471 2078 1851 A 2618 158 Get Variable GET channel length Variable Variable to store results Cannot use String Single channel RS232 Channel 0 to 3 length Length of data to receive 1 to 4 Read data from the RS232 port The command Get actually reads from the receive buffer If there is no data in the receive buffer it will quit without waiting for data and return 0 The command BLEN can be used to check if there is any data in the receive buffer before reading trying to read data The length of data to be read must be between 1 and 4 For receiving a Byte type data it would be 1 For receiving a Long type data it would be 4 For larger amounts of data please use GETSTR or GETA TIPS Use SYS 1 after GET or GETSTR to verify
155. eceive input 0 to 15 PortblockOut Port Block to output 0 to 15 The command EKEYPAD extends KEYPAD to read up to 64 key inputs Two Port Blocks are used to read a keypad matrix 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 Unused ports may not be used for other purposes The following is an example showing Port Block 0 as input and Port Block 1 as output If no keys are pressed 255 will be returned Otherwise the pressed key s scan code will be returned 153 For Next FOR NEXT will loop the commands within itself for a set number of times For Variable Starting Value To Ending Value Incremental Step Commands Exit For Next In the below example an Incremental Step is not set The FOR NEXT loop will increment 1 every loop by default 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 If K equals 8 exit the FOR NEXT loop Next When
156. ed DIP Switch RS232 Baud Rate 12C Slave Address 123 on aaa 2400 0 123 ON C e 4800 1 9600 2 ON an i 19200 EE On E 28800 4 123 ON E 38400 5 123 on m m 57600 6 L 123 ON E M 115200 7 Please choose one communication method to use at a single time CuNET or RS232 284 GHB3224 DIP Switch number 4 is not Either 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 handle segment matrix control and refreshing which increases in complexity with each digit added To simplify the matter we have developed an easy to use seven segment display called the CSG module ooog c E Ei 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 below table to easily and quickly display the numbers you want cs as O O o courte Command Explanation Example Usage CSGDEC_SlaveAdr Data Output decimal value CSGDEC 0 I CSGHEX_SlaveAdr Data Output hex as decimal value CSGHEX 0 1 CSGNPUT SlaveAdr Digit Control digit places CSGNPUT 0 0 8 Data CSGXPUT SlaveAdr Digit Control digit places and output data CSGNPUT 0 0 9 Data as binary number
157. ed inside the String You can use CHR amp H22 to express and CHR amp H27 to express and CHR amp H2C to express Example for printing to an LCD Print Chr H22 COMFILE TECHNOLOGY Chr sH22 Apostrophe Print Chr amp H27 COMFILE TECHNOLOGY Chr amp H27 81 To connect multiple Strings you can use a comma as shown below Print ABC DEF GHI Same as PRINT ABCDEFGHI Use CR for Carriage Return Next Line Print California CR Print California and go to the next line DEMO PROGRAM Fart cas on An CUBLOC studio 4 Device CH250 31 As string Dim s2 As string 10 S1 COMPILE TECHNOLOGY 52 KOREA SOCCER Debug 51 Cr Debug 2 cr T Fix Right Side 82 Merge Multiple Strings To merge multiple strings together use as shown below Dim al As String 30 Dim a2 As String 30 al Comfile a2 Technology al al a2 Inc Debug al cr The above program will show Comfile Technology Inc on the debug screen DEMO PROGRAM Debug Terminal BaudRae Poty DENIS ar m maa eee e CUELOC studio d2 eubloc_testistring cu Ee EM oeie De Sep ien 29D Ska A gt ES O FTBASIC F2 LADOER Ladder Mnemonic i const Device caz00 mal as string 30 Din a2 Ac string 30 a1 m centile Technology al al a2 4
158. edge or changing edge SET INTO 0 Set external interrupt to be on the Falling Edge P a INTO Pa Nm 2 e INT2 PAS 24 INT3 Pet 216 Set Ladder on off SET LADDER On Off Ladder is set to Off by default Use this command to turn On Ladder Logic The following is an example of minimal BASIC code 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 Out MOTOR Alias MO RELAYSTATE Aliases Alias M1 MAINSTATE Set Ladder On Start Ladder Do Loop BASIC program will run in infinite loop 217 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 functions MODBUS can connect to RS232 Channel 1 only To enable MODBUS slave mode please use the Set Modbus command This command will enable the MODBUS slave It must come after OPENCOM command and only runs on RS232 Channel 1 Baudrate stop bit and parity can be set with OPENCOM Opencom 1 115200 3 80 80 Please set receive buffer of at least 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 Command Command Name 01
159. eds of some sort The ON GOSUB command can be used to set a new interrupt When that interrupt occurs the main program stops execution and jumps to the label designated by the previous ON GOSUB command Once the interrupt routine in the label is finished the RETURN command is used to return back to the main program ia MAIN PROGRAM INTERRUPT ROUTINE External key input can be activated and RS232 data can be received at any moment 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 an interrupt routine While an interrupt routine is running another interrupt request of the same type is ignored If an RS232 RECV interrupt occurs during execution of an RS232 RECV interrupt routine it will be ignored On the other hand if an INT Edge interrupt occurs during execution of an RS232 RECV interrupt routine it will be executed immediately before returning to the RS232 RECV interrupt routine Interrupt Type Explanation On Timer Create interrupt within the set interval On Int Create interrupt when external input is received On Recv Create interrupt when RS232 receives data On Ladderint Create interrupt when Ladder Logic requests an interrupt On Pad Create interrupt when Pad receives data 103 More about Interrupts
160. efined We recommend the use of HIGH or LOW command to set output mode LOW 8 Set Port 8 to output mode and output LOW signal 197 Outstat Variable OUTSTAT Port Variable Variable to store results No String or Single Port 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 the status of output not input DIM A AS BYTE A OUTSTAT 0 Read from Port 0 and store the current status in A Pause PAUSE value Exact same function as DELAY 198 Peek Variable PEEK Address Length Variable Variable to Store Result No String or Single Address RAM Address Length 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 Variable to store results up to Long type value Length Bytes to read 1 to 4 Write the specified length of data starting at the specified data memory Address Const Device CB280 Dim Fl As Single F2 As Single Fl 3 14 Eewrite 10 Peek Memadr F1 4 4 Poke Memadr F2 Eeread 10 4 4 Debug Float F2 CR 199 Pulsout PULSOUT Port Period Port Output Port 0 to 255 Period Pulse Period 1 to 65535 This is a SUB library that outputs a pulse To create a High pulse the output Port must be set to LOW beforehand To create a Low pulse the outpu
161. egisters in units of Words through this function code The following is an example showing Slave Address 3 s D1 being written Query Field RTU Bytes ASC Bytes Header 1 colon 1 Slave Address 0x03 2 03 2 Function Code 0x06 2 06 2 Start Address HI 0x70 2 01 2 Start Address LO 0x01 2 70 2 Length HI 0x12 2 12 2 Length LO 0x34 2 34 2 Error Check CRC 2 LRC 2 Ending Code 2 CRLF 2 Response Field RTU Bytes ASCII Bytes Header colon 1 Slave Address 0x03 1 03 4 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 as 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 turned ON OFF Query Field RTU Bytes ASCII Bytes Header z 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 0B 2 Byte Count 0x02 1 02 2 Data 1 0XD1 1 D1 2 Data 2 0x05 1 05 2 Error Check CRC 2 LRC 2 Ending Code CRLF 2 The following table shows how the DATA in the above query is divided P27 is placed in the MSB of the first Byte sent and P20 is placed in the LSB There will be total of 2 bytes sent in this manner Leftover bits
162. elay about 200 ms Delay is pre made system s sub program sub delay dl as long dll var long d12 var integer for d11 0 to dl for d12 0 to 1 nop nop nop next next end sub 145 Do Loop DO LOOP will loop the enclosed commands unless DO WHILE or DO UNTIL is used to set a condition in which the loop can be terminated An EXIT DO command can also be used within the DO LOOP to exit from the loop Commands Dim K As Integer Do K Adin 0 Read AD input from channel 0 Debug Dec K Cr Delay 1000 Loop In the above example the program will loop infinitely inside DO and LOOP An EXIT DO or GOTO command 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 infinitely loop until the condition in WHILE is met Do Until Condition Commands Exit Do Loop Do Commands Exit Do Loop Until Condition DO UNTIL will infinitely loop until condition in UNTIL is met 146 DEMO PROGRAM CUELOC Studia D CUBLOC_Test SELECT cul Be Ee pwa Bn sit oo S G AEG A gt oe Const pevice ca260 eA lt 10 Debug vee Ape toop I Fix Fight Side CUBLOC Studio D NCUBLOC_TostiSELECT cut Be Em Dewe mn senp be 233 9 x23 A gt mmm Foxit sige 147 Dtzero DTZERO variable Variable Variable for decrement No String or Single Decrement the variable by 1 When the variab
163. ement at the very beginning of your source code If it exists already the Const device statement will simply be replaced 66 Reset Ladder Monitor on Chit BASIC Debug Terminal Time Chart Monitor clear CUBLOC flash memory write enable fuse off View Relay Usage Check Syntax Menu Explanation Run Compile Basic and Ladder 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 Reset Reset CUBLOC Module Ladder Monitor on Start Ladder Monitoring BASIC Debug Terminal Open BASIC Debug Terminal Window This window opens automatically when there s a DEBUG command in the source code Time Chart Monitor View Time chart monitor window Clear CUBLOC s Flash Clear CUBLOC s Flash Memory Memory Write enable fuse off 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 new Firmware Download View Register Usage After Compiling View Register usage of Ladder Logic Check Syntax Check Syntax Setup Menu Menu Explanation PLC Setup Wizard Automatic BASIC source code generation for Ladder Logic PC Interface Setup Setup the RS
164. ent 1 to the Word DWDEC d Decrement 1 to the Double Word Math Commands WADD s1 s2 d Word Add DWADD s1 s2 d Double Word Add WSUB s1 s2 d Word Subtract DWSUB s1 s2 d Double Word Subtract WMUL s1 s2 d Word Multiplication DWMUL_ s1 s2 d Double Word Multiplication WDIV s1 s2 d Word Division DWDIV s1 s2 d Double Word Division Logical Operation Commands WAND s1 s2 d Word AND DWAND s1 s2 d Double Word AND WOR s1 s2 d Word OR DWOR s1 s2 d Double Word OR WXOR s1 s2 d Word XOR DWXOR s1 s2 d Double Word XOR Bit Shift Commands WROL d Word 1 bit Shift Left DWROL d Double Word 1bit Shift Left WROR d Word 1 bit Shift Right DWROR d Double Word 1 bit Shift Right 376 LOAD LOADN OUT LOAD is for Normally Open Contacts and LOADN is for Normally Closed Contacts LOAD OUT Po m Nse L T w P3 j coaon Registers that P M F s c T D Constants can be used LOAD o o o o o o LOADN OUT o o PO P2 P1 P3 377 NOT AND OR NOT Symbol Po PS f S Po PI PS I H j C PO P5 Pq iN AND NOT symbol inverses the results If PO is ON then P5 will be OFF AND is when two Registers are horizontally placed next to each other Both Registers PO and P1 must be True ON in order for P5 to be True ON For OR operation two Registers are vertically placed next to each other When either PO or P1 is ON P5 will be ON
165. eqBASE FreqTOP 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 Steppulse STEPPULSE 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 Stepstat Variable STEPSTAT Channel Variable Variable to store results Channel StepPulse Channel 0 or 1 Stepstop STEPSTOP Channel Channel StepPulse Channel 0 or 1 Style STYLE bold inverse underline bold 0 Normal 2 or 3 Bold inverse jormal 1 Inverse underline 0 Normal 1 Underline Sys Variable SYS address Variable Variable to store results No String or Single address Address 0 to 255 Tadin Variable TADIN Channel Variable Variable to store results No String or Single Channel AD Channel Number Not Port number 0 to 15 Time Variable TIME address Variable Variable to store results No String or Single address Address of time value 0 to 6 Timeset TIMESET address value address Address of time value 0 to 6 value time value 0 to 255 Udelay UDELAY time time interval 1 to 65535 Usepin
166. er can implement a circuit diagram similar to one shown below By using a photocoupler the user is able to raise the voltage and minimize the effect that noise will have on the switch input DC24v DC5V 2 2Kohm ew FK CUBLOC 1 0 PC 18T1 10Kohm lt END gt 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 i Cr pe ofja 8 E MOC id Po f e p 7 22 P2 P3 af P4 r pp __ P7 The CSG module is a 4 digit seven segment LED module that can be connected via CUNET or I2C protocol to display numbers and custom characters mfal aia 0 0 0 0 cst 4s O O S Coure lt Filename csgprint cul gt Const Device CB280 Set I2c 9 8 Dim I As Byte Do Csgdec 0 1 cere Loop 326 If you connect the CSG to the CuNet connectot and execute the above program the CSG module will show incrementing numbers The key matrix can be read easily through the command KEYPAD If you look carefully at the keypad you will see that scancode does not match the actual key pressed In order to read the correct key we will use a KEYTABLE before outputting the value to the CSG Const Device CB280 Set I2c 9 8 Dim I As Integer Dim K As Integer Const Byte KEYTABLE 1 4 7 10 2 5 8 0 3 6 9 11 12 13 14 15 Do I Keypad 0 If I lt 16 Then I KEYTABLE I C
167. er does not have to know BASIC He She may simply use only LADDER for development If the user does not require LCD display or keypad usage he or she does not need to use BASIC at all As you can realize more emphasis on user interface 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 language DISPLAY KEYPAD C MACHINE CONTROL We provide many BASIC libraries for user interfaces which you can simply copy amp paste to achieve the user interface structure desired 33 Hints for Microcontroller Users Microcontrollers are self contained programmable computers such as PIC AVR and 8051 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 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 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 will cut the users development time as much as 20 times and provide a MCU
168. ernet Hints for Traditional PLC Users Hints for Microcontroller Users CUBLOC s Internal Structure CUBLOC Peripherals CHAPTER 2 HARDWARE Hardware Features CB220 CB320 Supplying power to the CB220 CB320 CB280 CB380 How to supply power to the CB280 CB380 CB290 CB405 How to connect a battery to CB290 CB405 Dimensions CUBLOC Chipset CB280CS CHAPTER 3 CUBLOC STUDIO CUBLOC STUDIO Basics Creating BASIC Code Debugging Menus CHAPTER 4 CUBLOC BASIC LANGUAGE CUBLOC BASIC Features Simple BASIC program Sub and Function Variables String About Variable Memory Space CHAPTER 5 CUBLOC BASIC FUNCTIONS CHAPTER 6 CUBLOC BASIC STATEMENTS amp LIBRARY 10 Arrays Bits and Bytes modifiers Constants 90 Constant Arrays 91 Operators Expressing Numbers The BASIC Preprocessor Conditional To use LADDER ONLY To use BASIC ONLY Interrupts More about Interrupts Pointers using Peek Poke and Memadr Sharing Data Math Functions Type Conversion String Functions Adin Alias Bcd2bin Belr Beep Bfree Bin2bcd Byteout CheckBf Compare Count Countreset Ded Debug Decr Delay Do Loop Dtzero EAdin Eeread Eewrite Ekeypad For Next Freepin Freqout Get Geta Geta2 Geterc Getstr
169. ery 4 Scan times F19 Repeat ON OFF every 8 Scan times F20 Repeat ON OFF every 16 Scan times F21 Repeat ON OFF every 32 Scan times F22 Repeat ON OFF every 64 Scan times F23 Repeat ON OFF every 128 Scan times F24 Repeat ON OFF every 10ms F25 Repeat ON OFF every 20ms F26 Repeat ON OFF every 40ms F27 Repeat ON OFF every 80ms F28 Repeat ON OFF every 160ms F29 Repeat ON OFF every 320ms F30 Repeat ON OFF every 640ms F31 Repeat ON OFF every 1 28 seconds F32 Repeat ON OFF every 5 12 seconds F33 Repeat ON OFF every 10 24 seconds F34 Repeat ON OFF every 20 48 seconds F35 Repeat ON OFF every 40 96 seconds F36 Repeat ON OFF every 81 92 seconds F37 Repeat ON OFF every 163 84 seconds F38 Repeat ON OFF every 327 68 seconds F39 Repeat ON OFF every 655 36 seconds F40 Call LADDERINT in BASIC F41 F42 410 If you write 1 to F40 you can create a LADDERINT in BASIC Please refer to ON LADDERINT GOSUB command for details F2 causes 1 Scan ON at the time of BASIC s SET LADDER ON command Blank special Registers are reserved Please do not use them 411 MEMO 412 Integrated Touch Screen Controller CUTOUCH User Manual Everything for Embedded Control COMFILE TECHNOLOGY Comfile Technology Inc www comfiletech com 413 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 indust
170. etain a temperature setting for a temperature controller you could simply store the value of the temperature in the EEPROM in case of power outage The CUBLOC has an internal EEPROM of 4KB For small and simple data you may use this internal EEPROM In the case of larger data storage needs you can use an EEPROM like the 24LC512 to store up to 64KB of data Here we will show you how to access the 24LC32 4KB EEPROM through the I2C protocol The serial EEPROMs usually support either SPI or 12C 12C EEPROM names start with 24XXXX and SPI EEPROM names start with 93XXX lt Filename eeprom cul gt Const Device CB280 Dim adr As Integer Dim data As Byte Dim a As Byte data sha6 adr amp h3 Set I2c 7 6 Do I2estart If T2cwrite sb10100000 1 Then Goto err proc a I2cwrite adr bytel a I2ewrite adr lowbyte 344 a I2ewrite data I2cstop Delay 1000 I2cstart 2cwrite amp b10100000 2cwrite adr bytel 2cwrite adr lowbyte I2cstart 2cwrite amp b10100001 a I12cread 0 I2cstop Debug Hex a cr ADR ADR 1 DATA DATA 1 Loop err_proc Debug Error Do Loop This example program will write a number to the EEPROM and read from it When this program runs correctly numbers will increment on the DEBUG screen You can easily modify this code to support other EEPROMs Note Please wait at least 5ms after a write to the EEPROM lt END gt 345 MEMO
171. ext Loop GETMODBUS If Blen 1 0 gt 0 Then If buffer empty then A Blen 1 0 Store the buffer length in A Debug GOT RESPONSE B Getstr 1 A Store received data in B Debug B End If Return End Sub BitWrite K As Integer D As Integer Dim LRC As Integer Putstr 1 0305 Putstr 1 Hp k 4 1 319 If D 0 Then Putstr 1 0000 LRC 3 5 K Bytel K Byte0 calculate LRC Else Putstr 1 00FF LRC 3 5 K Bytel K Byte0 0xFF LRC End If Putstr 1 Hex2 LRC 13 10 Send End Sub MODBUS ASCII Slave Mode 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 rs232 TX RX Rs232 P2 pi CHI ax xtra gt Pa gt i GND GND mr CB280 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 We can use the SET UNTIL command 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 When the slave is not connected the program will never jump to GETMODBUS 320 MODBUS RTU Master Mode The following is an example of RTU Master Mode implemented in CUBLOC BASIC to write 32 bit floating point values 2 Word Registers to an RTU slave device 1 Const Device CB280 include crctabl
172. gth of data to receive Stopchar Stop character ascii code Geta GETA channel ArrayName bytelength channel RS232 Channel 0 to 3 ArrayName Array to store Received data No string or Single Bytelength Number of Bytes to store 1 fo 65535 447 Geta2 GETA channel ArrayName bytelength stopchar channel RS232 Channel 0 to 3 ArrayName Array to store Received data No string or Single Bytelength Number of Bytes to store 1 fo 65535 Stopchar Stop character ascii code Glayer GLAYER layernumber Layernumber Set the graphic layer 0 1 2 Glocate GLOCATE x y Gpaste GPASTE x y layer logic logic 0 OR logic 1 AND logic 2 XOR logic 3 Clear screen then pop Gprint GPRINT string Gpush GPUSH x1 y1 x2 y2 layer Gpop GPOP x y layer logic OR Heap Variable HEAP Address Variable Variable to store results Address HEAP memory address Heapclear HEAPCLEAR Heapw HEAPW Address Data Address HEAP memory address Data Constant or Variable with data Byte only Hread Variable HREAD Address ByteLength Variable Variable to store results Address HEAP memory address ByteLength of bytes to read constant or variable Hwrite HWRITE Address Data ByteLength Address HEAP memory address Data Constant or Variable with data whole numbers only ByteLength of bytes to write High HIGH Port Port 1 0 Port number
173. hat types of temperature sensors are there 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 figure out how to connect and use it with CUBLOC The NTC thermistor is a temperature sensitive resistor Depending on the temperature the value of resistance will change By reading the value of this resistance we can figure out the current temperature A common NTC thermistor resembles a diode With this thermistor we can sense between 30 and 250 degrees Celcius temperature lt 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 0 31260 0 32610 0 33987 7 1 29725 7 30993 7 32286 7 2 28275 6 29466 8 30680 6 3 26904 5 28023 9 29163 6 4 25607 8 26660 0 27730 3 5 24381 0 25370 2 26375 7 6 23220 0 24150 1 25094 9 F 22120 9 22995 7 23883 7 8 21080 1 21903 1 22737 7 9 20094 1 20868 5 21653 3 10 19159 9 19888 7 20626 7 11 18274 4 18960 5 19654 6 12 17434 8 18080 8 18733 8 13 16638 5 17246 9 17861 4 14 15883 1 16456 1 17034 4 15 15166 2 15706 0 16250 4 16 14485 7 1494 4 15506 9 17 13839 56 14318 9 14801 5 18 13225 9 13677 7 14132 2 19 12642 8 13068 7 13496 9 329 20 12088 7 12490
174. he buffer currently has TIPS 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 stored in the send buffer Please refer to the On Recv interrupt routine for receiving data using the hardware serial buffer Puta PUTA channel ArrayName bytelength channel RS232 Channel 0 to 3 ArrayName Array Name Bytelength Bytes to Send 1 to 65535 The command Puta is used to send a Byte Array 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 you try to send more bytes than the array has CUBLOC will send garbage values Please refer to On Recv interrupt routine for receiving data using the hardware serial buffer 202 Puta2 PUTA channel ArrayName bytelength stopchar channel RS232 Channel 0 to 3 ArrayName Array Name Bytelength Bytes to Send 1 to 65535 Stopchar Stop character ascii code Same as the PUTA command except it will stop transmission at a set character in the array StopChar will be the last character to be sent Use with CUBLOC STUDIO 2 0 X and above 203 Putstr PUTSTR channel data channel RS232 Channel 0 to 3 Data String Data String variable or String constant or Constant
175. icro Sec 186 On Int ON INTO GOSUB label ON INT1 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 INTO Gosub GETINTO Set INTO 0 Falling Edge Input Do Loop GETINTO A A 1 Record number of interrupts Return 187 On Ladderint Gosub ON LADDERINT GOSUB label If Register F40 turns on in LADDER and the ON LADDERINT GOSUB command is used then the processor will jump to the routine specified by On Ladderint command This can be used when a LADDER program needs to trigger a specific piece of BASIC code 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 routine execution writing a 1 to Register F40 will not allow another interrupt If Register F40 is cleared from BASIC it signals the end of the interrupt routine and is ready to receive another interrupt Usepin 0 In Set Ladder On Set Display 0 0 16 77 50 On Ladderint Gosub msgl_rtn Dim i As Integer Low 1 Do isitl Byteout 1 4 Delay 200 Loop
176. ighting of certain commands studio D Tpe testloutofram cul Be Edt eves Rn Setup Heb Basie XDAA ate ea F1 BASIC F2 LADDER Lasdar Mnemaric const Device B405 Dim sti Ae string pin sta as string Din aal As Sering Dim aad Ae string mel S Siprigeanmare iets Cia aa timer chr 10 Set Display 2 0 0 50 Opencom 3 115200 3 100 100 on reev3 Gocub aaa Set Until 3 100 10 cls Do Debug Debug Lst2 Cr Delay 200 Print loc 0 0 ct2 If mn 4 1 then Putaz 3 aal_a 80 10 Do while In 4 1 Loop endif If In 10 1 then Puta 3 aa2_a 80 10 Do While In i0 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 Debugging E CUELOC studio d Weource cublocstudioWtests Eile Edit Device Bun Setup Help JAS GSA s mi E F1 BASIC F2 LADDER Ladder Mnemanic Const Device cR2E0 Delay 10 Debug Hello Debug Terminal Pon O Baarme Paty Daants an HA M T Finfish Side As shown in the above screenshot the DEBUG command can be used to monitor your BASIC program while it s running Be aware that you are not allowed to use both Debugging and LADDER Monitoring at the same time You must remove Debug commands or comment them out with an apostrophe before attempting to use LADDER Monitoring Another option is to use
177. ing Tempe 40 C to 120 C 40 C to 120 C ature Package 24 pin DIP 600mil 64 pin Module L2 Lx0 6 W x 0 8 H LELXI W x 0 87 Se 35x 25 4 x 11 mm 30x 15 3 11 mm 22 The main advantage of CUBLOC is that it fills Ladder Logic s weaknesses with 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 IF IN 0 0 THEN OUT 2 A TFI BASIE IFA LADDER Laddar Mremoni o print 27 emnat pag pesy 20 Loop until Blen Rs23 Delay 10 Bcl R8Z32CH 0 For 7 D Te 127 ster Print atir a Deine de r42 belay 5 s For 1 128 To 255 s Print atira A belay 5 ws belay 100 a Print ar Delay 100 Pot Rs232cm Ase tex d EEA Picture of CUBLOC Studio is shown above 23 There are other PLCs on the current market that support both LADDER and BASIC These PLCs do not multi task BASIC is part of their Ladder Logic and 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 covers these weaknesses through its multi tasking
178. integrating CB280 functions into your product seamlessly Since this chipset has the same features as a regular CB280 we recommend you develop your applications on the CB280 before going into production with a chipset version The CB280CS includes the main chip and sub chip only Any other parts must be sourced by the user veo 2 ra ge B vo ge J5 g B g z g ah CUBLOC E vop j vss g CB280CS oH re R5 2 CUBLOC7 M Ro ue Main Chip ol Sas Ra cys CB280CS gt py de A ra ub Chip chs x Bre R3 of S ro de H ew B ro piave ge B ro Main chip pinout Pin Port Function Desc T VDD Power Supph 2 RXO DOWNLOAD RX RS232 RX 3 TXO DOWNLOAD Tx RS232 TX 4 P18 1 0 port 5 P19 PWM3 1 0 port 6 P20 Pwd 7 INTO 1 0 port 7 P21 PWM5 INT1 1 0 port E P22 INT2 1 0 port E P23 INT3 1 0 port 10 PO SS 1 0 port i PL SCK 1 0 port 12 P2 MOST 1 0 port 57 13 P3 MISO 1 0 port 14 Pa 1 0 port 15 P5 PWMO 1 0 port 16 P6 PWM 1 0 port 17 P7 PWM2 1 0 port 18 P16 1 0 port 19 P17 1 0 port 20 JRESET Reset Low active 21 VDD Power supply 22 VSS Ground 23 XTALOUT Xtal output 24 XTALIN Xtal input 25 Pa CUNET_SCL 1 0 port 26 P9 CUNET_SDA 1 0 port 27 RX1 RS232 CH1 RX RS232 Channel 1 Rx 28 TX1 RS232 CH1 TX
179. ional PLC and On Chip PLC Micro computer CUBLOC Traditional PLC CUBLOC Production Din Rail Attachment Din Rail or PCB Labor Costs High Low Mass Difficult Easy Production Final Product High Low Cost Final Size Large Compact If you are currently distributing a system using a traditional PLC please review our products and compare the costs if you change it to a PCB type We believe that you will have much more satisfactory final product at a fraction of cost 30 Development Environment To use Cubloc Studio the user can install it on a Windows 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 of some type such as VMware etc that allows the Windows operating system to run on it An RS232 port is also required or you may use a USB to RS232C converter RS232 p vn vss res voo Bess pew pes p e12 Be P pra ah es fire Download 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 even with no power The user may download new programs and erase them 10 000 or more times per device Bad ooh Pocono oO CB280 core module with Study Board 31 Download and Monito
180. is for exchanging Double Word Usable P m F s c T D Constants Registers s o fo o d o o fo START WMOV 100 DO C P WMOV 123 D1 lt r 1l INO WXCHG DO D1 S 3 When START turns ON DO gets 100 and D1 gets 123 When INO turns ON DO and D1 exchange their data The result is as shown below DO 123 D1 100 D2 D3 D4 394 FMOV FMOV s d n Store value in s to d and n number of times after that to additional locations This command is usually used for initializing or clearing memory Usable P m F S c T D Constants Registers s mE d o fo jo n START WMOV 100 DO 1 ACTION FMOV 00 015 pua 1 Below is result of LADDER execution DO 100 D1 100 D2 100 D3 100 D4 100 D5 100 Notice Please Set n less than 255 GMOV GMOV s d n Store value starting at s to d by n memory locations Please make sure not to overlap memory locations as this could cause data collisions Usable P M F S c T D J Constants Registers S o o o D o o o N ACTION GMOV D0 D10 5 1 Below is result of LADDER execution DO 12 D1 34 D2 56 D3 78 D4 90 D5 D6 D7 D8 D9 D10 12 D11 34 D12 56 D13 78 D14 90 D15 D16 Notice Please Set n less than 255 396
181. ize LADDER size adjust Une Space LADDER line space adjust Boarder Color C Black Whe LADDER background color Monitoring Speed Fast m Sow 7 LADDER monitoring speed setting Auto Excute mode F Auto Run when download Auto run when download If you select Auto Run when download the program will automatically reset itself after downloading This can become a problem for machines that are sensitive to resets By turning this option OFF you will be able to control when the program is resetted after downloading In the help menu you will find Upgrade information and the current version of CUBLOC Studio 359 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 UB IFZ LACOER mch 4b Wie 1 waal 13 f rs m Plees Dutot BASIC code redam Vo maps 6 0 eomenar a E F AD chanet 0 gt Din beara at ate F AD channel 1 gt DII F AD chamai 2 gt bie ee a i o1 eo one rs FF A shamal gt O18 T Hoh cou 309 Boro E AD hamai 5 gt DIS Poe wg hamal E 2 DNE Gom on F A chamal gt 17 6 tan Count 9038 PO m ama Pia owas ae a eee ap a re Ma athens r Paas ema pa Eom E he E mo F use MODBUS on CH E pa E me r
182. l 10 bit ADCs Input Voltage Range 0 to SV B channel 10 bit ADCS Configurable Voltage 0 to SV OR 0 to 10v Analog Outputs 6 Channel 16 bit PWMs DACS Output Voltage Range 0 to 5V Configurable Frequency 35hz to 1 5Mhz 76 Channel 16 bit PWMs DACS Output Voltage Range 0 to SV Configurable Frequencies 35hz to 1 5Mhz External Interrupts 4 Channels 4 Channels High Speed 2 Channel 16 bit Counters up to 2 Channel 16 bit Counters up to Counters 2Mhz 2Mhz Required Power 9 24V DC Required Power 24V DE Current Consumption w ports Current Consumption w ports unloaded unloaded paneer 24V w Backlight ON 170mA 24V w Backlight ON 170mA 24V w Backlight OFF _70mA 24V w Backlight OFF 70mA 12V w Backlight ON 340mA 12V w Backlight ON 340mA 12V w Backlight OFF 130mA 12V w Backlight OFF 130mA RTC Real Time Clock Yes Yes Timers T User Configurable Timer Configurable Interval Units 10ms 1 User Configurable Timer Configurable Interval Units 10ms Data Memory Back Yes a 1 Farad rechargeable Super Capacitor is included Yes a 1 Farad rechargeable Super Capacitor is included up Operating 0 Cto 70 C 0 C to 70 C Temperature Tntegrated Touch screen Panel w Integrated Touch screen Panel w Package 2mm Headers and 2mm Headers and 2 5mm RCABLE Headers 2 5mm RCABLE Headers TAP x 5 17 x 0 98 TAP x 5 17 x 0 98
183. l as response Response Field RTU Bytes ASCII Bytes Header colon T 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 0XE8 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 CRLF 2 313 Function Code 05 Force gle C PLC s can remotely control the status of Registers in units of bits through this function code The following is an example showing Slave Address 3 s P1 Register being turned ON To turn ON Registers FF 00 is sent and to turn OFF Registers 00 00 is sent Query 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 Error Check CRC 2 LRC 2 Ending Code CR LF 2 The response shows that the data was entered correctly You MUST use FF 00 and 00 00 to turn ON OFF Registers other values will simply be ignored Response Field RTU Bytes ASCII Bytes Header z 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 314 Function Code 06 Preset Single Registers PLC s can remotely control the status of its R
184. le reaches 0 the variable is no longer decremented This differs from the Decr command which will underflow the variable and wrap around to the highest value for the variable type chosen DTZERO A Decrement A by 1 148 EAdin Variable EADIN mux Variable Variable to store results No String or Single mux AD input Port Combination MUX 0 to 21 This command can be used for a more precise analog conversion The CUBLOC has an internal operational amplifier module ADIN command the opamp is not used OP AMP ADC Please set the MUX value by following the chart below When using the MUX OPAMP OPAMP Multiplier Resolution 0 ADCO ADCO 10 8 Bits 1 ADC1 ADCO 10 8 Bits 2 ADCO ADCO 200 7 Bits 3 ADCI ADCO 200 7 Bits 4 ADC2 ADC2 10 8 Bits 5 ADC3 ADC2 10 8 Bits 6 ADC2 ADC2 200 7 Bits 7 ADC3 ADC2 200 7 Bits 8 ADCO ADC1 8 Bits 9 ADC1 ADC1 1 8 Bits 10 ADC2 ADCI 1 8 Bits 11 ADC3 ADCI 1 8 Bits 12 ADC4 ADCI L 8 Bits 13 ADCS ADCI 1 8 Bits 14 ADCE ADCI 1 8 Bits 15 ADC7 ADC1 1 8 Bits 16 ADCO ADC2 1 8 Bits 17 ADC1 ADC2 1 8 Bits 18 ADC2 ADC2 1 8 Bits 19 ADC3 ADC2 1 8 Bits 20 ADC4 ADC2 1 8 Bits 21 ADC5 ADC2 1 8 Bits 149 The EADIN port must be set to input beforehand Dim J As Long Input 24 Set the port to input Use port 24 25 for CB280 Input 25 Do j Eadin 8 AD Conversio Locate 0 0 Print hex5 J
185. lee Const Device ce280 Dim A s Long A 523470 Debug Dec A Debug DECIO A Cr Debug DECI A Cr Debug Dee 7 Arer T 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 If A is 1234 A 1234 will be printed DEBUG HEX A If A is ABCD A ABCD will be printed DEBUG HEX B If B is a sub routine variable let s say of sub routine CONV B_ CONV ABCD will be printed B is in CONV 113 FLOAT Use FLOAT to convert floating point values to String Const Device cb280 Dim F1 As Single Fl 3 14 Debug Float Fl cr t Print 3 14000 Dim ST As String 15 ST Float Fl First store in a String ST Left ST 3 Convert to 3 decimal places Debug ST Print 3 14 CUBLOC studio d cubloc Els Ede peves un sep HEP EEFE EI EEEN em e ee Termina FI BASIC tral LADDER Ladder Mnemonic Pot BaudRale Pariy D aBis am 9 Const Device C200 feom z s20 b Sen Din Fl As Single Fla 3 14 Debug Float F1 st lormat cul T Fix Right Side You can also store into a string before printing debug statements or displaying to the LCD CUBLOC studio d cubloc_test format cul Port BaudFate Party Data Bits Const Device Ch280 Sia di Ay shave com 118200 gt Nene Dim 1 As String 12 F1 3 14 1 Float F1 uebug s
186. level signal and 33 outputs 5V level signal CHANNEL CHANNELO Tx RK CHANNEL 255 The possible Baud Rate settings are as follows 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 SET DISPLAY command can only be used once at the beginning of the program Method 0 Use CuNET CuNET is a type of I2C protocol that is part of CUBLOC For the CB220 use I O Port 8 Clock and Port 9 Data sour d7 zaj vin sin i 236 vss aw 22h res vss g v rg ag E n 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 to 12C for CuNet displays only ONE device may be attached 256 Cls Initialize the LCD and clear all text Set a little bit of delay for the LCD to initialize DELAY 200 Csron Turn Cursor ON Csroff Turn Cursor OFF Locate LOCATE xy X X axis position of LCD Y Y axis position of LCD Set the position of the text cursor After a CLS command the LCD defaults to
187. like chip that is upgradeable through RS232 cable or even through the internet by using an XPORT By providing a way to upgrade the final product the value is increased If you have experience programming with MCUs we guarantee you that development of your final product will be much easier 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 control needs flash programmer target board target board MCU engineer s desk CUBLOC engineer s desk CUBLOC s Internal Structure BASIC processor adder processor BASIC LADDER Data Memory Data Memory The BASIC Interpreter controls a Flash storage area for the user s BASIC programs The LADDER processor also has a Flash storage area for the user s LADDER program I O ports are shared between BASIC and LADDER allowing free access to both BASIC data memory can only be accessed by the BASIC Interpreter while LADDER data memory can be accessed by both the BASIC Interpreter and the LADDER Processor BASIC 1 and LADDER 2 share the same Flash memory The total available memory space is 80KB for some models 200KB for others BASIC and LADDER can both use up to the entire memory area if needed I O ports 5 can be used both by BASIC and LADDER The user must specify I O ports to use i
188. ll return the number of free bytes in a receive buffer or a 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 before taking action DIM A AS BYTE OPENCOM 1 19200 0 100 50 IF BFREE 1 1 gt 10 THEN PUT TECHNOLOGY END IF If buffer size is set to 50 up to 49 free bytes can be returned The function will return 1 less than the set buffer size when buffer is empty 130 Bin2bcd Variable BIN2BCD binvalue Variable Variable to store results Returns Long binvalue Binary value to be converted This command BIN2BCD converts a binary value to BCD Binary Coded Decimal representation BCD is a way of expressing values as decimals For example 3451 in binary is as shown below 3451 0000 1101 0111 1011 0 D z B The below 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 5 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 i 123456 j bin2bed i Debug Hex j Print 123456 131 Blen Variable BLEN channel buffertype Variable Variable to store results No String or Single channel RS232 Channel number 0 to 3 buffertype 0 Receive Buffer 1 Send Buffer This function Blen returns current number
189. llowing circuit schematic for connecting TTL signals from a CB280 to an RS485 chip SN75176B H son cuBLoc cB280 Ba TTLRX g Glas E S 485 TTLTX D iy 12008 560 0 The 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 ie ee ee eee SlaveAdr 01 SlaveAdr 02 Slave Adr 03 230 The SET RS485 command allows a CUBLOC or CUTOUCH to control the data line whenever it want to send or receive While the data is being sent the Transmit Enable pin will output Active High This will automatically be done by the CUBLOC RTOS NOTE If you are using a 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 Trasmit Enable pin WU Pag When using the SET RS485 command the Port chosen may not be used for other purposed ina We a k oe be A fua Z o ah De D aA 1 Please refer to the diagram on the left when connecting multiple CUBLOCs or CUTOUCH using RS485 Please use a 120 Ohm terminating resistor for the device at the end The two 560 Ohm Pull
190. loop Ladder Logic will also 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 include BASIC capabilities The second weakness 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 weakness involves I O BASIC language s execution of I O can create unwanted collisions with LADDER The reason is that Ladder Logic I O is updated once per scan while in BASIC 1 O is immediately accessed After solving these problems we have created a BASIC and Ladder Logic processor that supports real time multi tasking BASIC runs BASIC and LADDER runs LADDER without causing collisions 27 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 the main features In the case of I O the user can specify the I O used by BASIC and LADDER 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
191. ly code it and place buttons We can save time by using CuCANVAS Run CuCANVAS and press the Add Form button on the upper right hand corner Enter a desired name for your new form Here we used NUMKEY File Edit Generate Tools View Help Osage f Numkey Ald Form Uso tab hey io solectnaighbor onos n Tuumkey oorre ies ee a eee ee On the left side of CuCANVAS you will see a toolbar with an arrow box filled box circle filled circle line text and menu box Please select the last button menu box and draw a small box on the screen The 0 on the button means the menu number is 0 In the actual screen this number will not be displayed Please type 1 in the Title field on the top You have successfully made a 1 button 435 Tile Eat Cereme Tesis View Help ose Tela Numkey METE Bo gt secmeos mas ef vO oe You can quickly make the rest of the buttons and a keypad like the one shown below can be created in less than 5 minutes Fie Ea Berrse Tons Vew Kelp joes Agee Numkey mrd E es ee ee A e 436 Now is the fun part Simply click on Generate on the menu bar and click View Basic Code CuCANVAS will generate a Sub function that includes the buttons you have just created Simply copy Ctrl C and paste CTRL V to CUBLOC Studio You have created a complete menu in minutes The
192. me 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 ert I Time 1 com m5200 None o Debug Hex2 I I Time 0 Debug Hex I cr Delay 1000 Loop Debug Terminal Screenshot 246 Print date Party Triday Friday Friday Trigay Udelay UDELAY time time interval 1 to 65535 A more precise delay function The delay will start out at about 70 micro seconds Every unit added will add 14 to 18 micro seconds For example Udelay 0 would be about 70 micro seconds Udelay 1 would be about 82 to 84 micro seconds When Interrupt or LADDER 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 by LADDER or BASIC interrupts consider stopping LADDER and all interrupts before using this command Udelay 100 Delay about 1630 micro seconds 247 Usepin Usepin I O In Out AliasName W O I O Port Number 0 to 255 In Out In or Out AliasName Alias for the port Optional This command is used to set the I O Port status and alias name for LADDER programs It is required to do so before using the ports in LADDER Usepin
193. mp on beginning When using this command for the very first time use the RESET signal to reset the counter value Otherwise the counter will start at the last updated value random if not set before KCTD This command is exactly same as the CTD command except this command will be able to remember the counter value when the module is powered off The module used for this command MUST support battery backup CB290 CB405 In comparison the CTD command will lose its count value when the module is powered off KCTU and KCTD must be used with modules that support battery backup such as the CB290 CB405 and CuTouch 389 Comparison Logic Compare 2 Words 16 bit or 2 Double Words 32 bit values and turn on an output when the conditions are satisfied Comparison Data Types Explanation Command sl s2 Word 16 bit When si and s2 are same Output turns ON lt gt si s2 Word 16 bit When si and s2 are different Output turns ON 3 si s2 Word i6 bit When si gt s2 Output turns ON lt si s2 Word 16 bit When si lt s2 Output turns ON gt si s2 Word i6 bit When s1 gt s2 Output turns ON lt si s2 Word 16 bit When s1 lt s2 Output turns ON D si 52 DWord 32 bit When s1 and s2 are same Output turns ON D lt gt si S2 DWord 32 bit When s1 and s2 are different Output turns ON D gt si 52 DWord 32 bit When si gt s2
194. n LADDER and BASIC All I O ports can be used in LADDER 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 Play 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 LED RS232 communication I2C piezo ADC toggle switches and LCDs are included We recommend the Start Kits which include a study board a CUBLOC module necessary cables and a manual LCD DISPLAY Module CLCD GHLCD Series Various LCD displays are provided for use with CUBLOC using CUNET 12C protocol With one line commands PRINT CLS etc you can easily start printing to the LCD without
195. nd LADDER may freely use these aliases Usepin 0 In START Usepin 1 Out RELAY Alias MO MOTORSTATE Alias Ml RELAYISTATE Alias SUBTIMER RELAY 0 Set port 1 to LOW MOTORSTATE 1 Set MO to 1 Same as M 0 1 A RELAYISTATE Store MI status in variable A B SUBTIMER Store T1 status in variable B 107 MEMO 108 Chapter 5 CUBLOC BASIC Functions Math Functions SIN COS TAN Return Sine Cosine and Tangent values CUBLOC uses radians as units Use SINGLE for most precise results ASSIN B Return Sine value C S B Retu ine value B Return Tangent value ASIN ACOS ATAN Return Arc Sine Arc Cosine and Arc Tangent values CUBLOC uses radians as units Use SINGLE for most precise results SINH COSH TANH Return Hyperbolic Sine Hyperbolic Cosine and Hyperbolic Tangent values Return Hyperbolic ne value of B Return Hyperbolic ne value of B Return Hyperbolic Tangent value of B SQR Return Square Root value A SOR B Return square root value of B EXP Return EX A EXP X Return E LOG LOG10 Return LOG or LOG10 value AsLOG B or A LOG10 B For the natural logarithm Ln simply do A Log B Log Exp 1 110 ABS Return Absolute value for long type Dim A As Long B As Long ABS B Return B Debug Dec A print 1234 FABS Return Absolute value for Single type Dim A As Single B As Single B 1
196. nd its corresponding numerical value Sunday Monday Tuesday Wednesday Thursday Friday Saturday alal alwn System clock RTC This command will allow you to use the system timer of a CUBLOC as an RTC You can use TIME and TIMESET functions to access the following addresses Address Returning Value Range 10 Seconds O to 59 an Minutes Oto 59 12 Hours 0 to 65535 13 Continuous 0 to 65535 Seconds The Address 10 will increment its value by 1 every one 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 0 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 clock RTC Address 10 to 13 values are stored as raw binary values unlike the on chip RTC on CB290 and CB405 There is no need for the user to convert the values using BCD2BIN and BIN2BCD The System Clock RTC uses the processor s system timer and there can be a slight time difference lt 1 during a 24 hour period Const Device CB405 Dim i As Integer cls Timeset 10 58 Timeset 13 254 Do i Time 10 Debug Goxy 0 0 dec4 i Cr Debug Goxy 0 1 decd Time 13 Delay 100 I Fis Loop Address 13 will increment its value by 1 every second simil
197. nds for TAON 1sec START To When START turns OFF the timer is reset to the original set value of 100 and TO turns off TON TAON commands will reset their timer values upon powering OFF To use the features of battery backup you can use KTON KTAON which will maintain their values when powered OFF Below is an example of how to reset TAON Fi Mo TAON TO 100 J7 E 1 T Fal mo m TOFF TAOFF When input turns ON output turns ON immediately When the input turns OFF the output is kept ON for the set amount of time Like TON and TAON there are 2 commands for two different time units Type of Timer Time units Maximum Time TOFF 0 01 sec 655 35 sec TAOFF 0 1 sec 6553 5 sec START TOFF 70 100 E 1 START TAOFF T1 100 c 1 There are 2 parameters for the commands TOFF and TAOFF For the first parameter you can choose TO through T99 For the second parameter you may use a number or a data memory such as DO Usable P m F s c T D Constants Registers TOFF TAOFF o lo lo j In the above LADDER diagram when START turns ON the TO Timer will immediately turn ON After 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 1 second for TON and 10 seconds for TAOFF sec lt START TO 386 CTU Thi
198. nel 0 P6 11 10 PWM Channel 1 P7 12 10 PWM Channel 2 P8 13 10 CuNET SCL P9 14 10 CuNET SDA P10 15 10 P11 16 1 0 Block 1 P12 32_ 10 P13 31 10 P14 30 10 High Count Channel 0 PIS 29 10 High Count Channel 1 P16 21 10 P17 22 1 0 P18 23 1 0 P19 24 1 0 Block 2 PWM Channel 3 P20 25 1 0 PWM Channel 4 INT Channel 0 P21 26 10 PWM Channel 5 INT Channel 1 P22 27 1 0 INT Channel 2 P23 28 10 INT Channel 3 44 P24 37 70 ADCO AD Channel 0 P25 38 10 ADC1 AD Channel 1 P26 39 10 ADC2 AD Channel 2 P27 40 1 0 Block3 ADC3 AD Channel 3 P28 56_ 1 0 ADC4 AD Channel 4 P29 55 10 ADCS AD Channel 5 P30 54 10 ADC6 AD Channel 6 P31 53 1 0 ADC7 AD Channel 7 P32 57 10 P33 58 10 P34 59 10 P35 60 1 0 Block 4 P36 6_ 1 0 P37 62 10 P38 63 10 P39 64 10 P40 48 1 0 P41 47__ 1 0 P42 46 1 0 P43 45 1 0 Block 5 P44 4 1 0 P45 43__ 1 0 P46 a2 1 0 P47 a o P48 52 1 0 VDD 17 N Power 4 5V to 5 5V VSS 18 IN GROUND RES 19 IN RESET Input LOW signal resets Normally HIGH or OPEN TXI 33 RS232 Channel 1 12V Data Output RX1 34 RS232 Channel i 12V Data Input AVDD 35 ADC Power TAXI 49 RS232 Channel 1 5V TTL level Data Output TLRXI 50 RS232 Channel 1 5V TTL level Data Input AVREF 51 ADC Reference Voltage
199. nput output Input Output Output lt Filename ds1302 cul gt Const Device CB220 Const iorst 7 Const iodio 6 Const ioclk 5 Dim I As Integer Dim adr As Byte High iorst Shiftout ioclk iodio 0 sh8e 8 Shiftout ioclk iodio 0 0 8 Low iorst Delay 1 High iorst Shiftout ioclk iodio 0 amp h80 8 Shiftout ioclk iodio 0 6H50 8 Low iorst adr amp h81 Shiftout ioclk iodio 0 adr 8 i Shiftin ioclk iodio 4 8 340 Debug Hex i cr Low iorst Delay 1000 Loop The above code will read ADDRESS 0 the seconds value and display it onto the DEBUG window At the beginning of the program we will enable writes to the DS1302 chip and set the ADDRESS 0 to 50 seconds Within the Do Loop we will read the data from DS1302 The DS1302 chip has 6 addresses as shown below ADDRESS 0 sec cu OSS ES ADDRESS 1 min o ROMAN MN ADDRESS 2 hour ADDRESS 3 date i A sooress monn Co o o ron nen g ADDRESS 6 day ADDRESS 6 year 10 YEAR YAR These addresses can be used to read and write to the DS1302 Please note that the data is in BCD code format lt END gt 341 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 pro
200. ns for the CB405 Channel 1 0 Port SV TTL 1 P42 RX P43 2 P8 RX P9 TX 3 P56 RX P57 TX The CB405 has a internal MAX232 that can be used to convert any of the 5V TTL signals to 12V level signals connecting Channel 3 Now you can simply connect any 12V RS232 device to TXE and RXE The following is an example of Vas VBB CB405 Vad Vss soul E p ee ete sell dese 15 484 A eis NSBS kares An Este 9 Apa Bia rag 52 Banto ano es Ears Peay ERS EM ae Vee p22 ab8 ABE pa 195 Out OUT Port Value Port I O Port number 0 to 255 Value Value to be output to the I O Port 1 or 0 Outputs 1 or 0 to the specified Port When you execute this command the CUBLOC will automatically set the Port to output and set the Port state You do not need to use the Output command to set the Port beforehand when using this command our 8 1 Output HIGH signal on Port 8 This is same as using command High 8 our 8 0 output LOW signal on Port 8 This is same as using Low 8 196 Output OUTPUT Port Port I O Port number 0 to 255 Set the Port to output state All I O Ports of CUBLOC module are set to HIGH Z input by default at power on OUTPUT 8 Set Port 8 to output state You can also use the HIGH or LOW commands to set a Port to the output state When using the Output command HIGH or LOW state is not clearly d
201. o P Registers INPUT REFLASH LADDER SCAN OUTPUT REFLASH _ In BASIC IN and OUT commands can be used to control I O ports This method directly accesses the I O ports whether it is read or writes In order to avoid collision between the two the I Os used in BASIC and LADDER should be specified Once a port is declared with the USEPIN command it can only be used in LADDER and cannot be directly accessed in BASIC except through the ladder registers USEPIN 0 1N START USEPIN 1 0UT RELAY You can also add an alias such as START or RELAY as shown above for easy reading of the Ladder Logic Use of Aliases When creating Ladder Logic using Register numbers such as PO P1 and MO the user can use aliases to help simplify their programs Po P5 b P1 STAATKEY MA4INMO TOR swi In order to use alias you need to declare them in BASIC You can simply use the ALIAS command to use aliases for registers you desire to use ALIAS MO ALIAS M2 ALIAS M4 MAINMOTOR STATUSL MOTORSTOP You have an option of either using USEPIN or ALIAS command to use aliases in LADDER 368 Starting LADDER CUBLOC executes BASIC first You can set LADDER to start by using the command SET LADDER ON When this command is executed LADDER is executed constantly at a scan time of 10 milliseconds If you do not use SET LADDER ON command Ladder Logic will not be executed
202. o SDA This 4 pin connector will be used as standard for CuNET communications When using CuNET the CUBLOC core module will act as the master and the device connected to as the slave All CuNET devices will respond to the CUBLOC while in an idle state CuNET operates in a Master Slave mode Slave cannot start communication with the master For externally initiated communication you must use PAD communication PAD can receive inputs from other devices Please refer to the ON PAD command for detailed information 296 A CuNET device s pin 2 connects to 5V of the main module when the device is to be powered from the CuNET bus Power MAIN CuNET Module A CuNET device s pin 2 can be connected to RESET of the main module when a separate power suppy is connected to the CUNET device Active LOW to RESET causes CUBLOC to reset Power Power MAIN CuNET Module CuNET cables up to 3 feet long can be used For longer communications up to about 1 mile you can use the Phillips I2C long distance interface chip P82B96 or P82B715 CUBLOC STUDY BOARD Circuit Diagram The study board is useful for first timers and developers of CUBLOC Simple experiments including switches LED RS232 communication I2C piezo ADC toggle switches and LCDs are possible 1 RS232 CH1 Contact 2 CB280 TXIRX Contact Download Port Reset Switch Contact LED S Ws Balco Connector VO Ports Contact
203. o aLock 1 133 Byteout BYTEOUT PortBlock value PortBlock I O Port Block Number 0 to 15 value Value to be output 0 to 255 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 Port Block are set to output and the binary value is applied to the ports Byteout 1 255 Output 255 to Port Block 1 Ports 8 through 15 are set to HIGH I O Port 1 only supports input Therefore BYTEOUT 0 will not set Port 1 to Output 134 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 It will not erase the data after reading unlike the GET command Only 1 byte can be read at a time A Checkbf 1 Check current data in the receive buffer 135 Compare COMPARE channel target port targetstate Channel High 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 high counter value reaches a set target point the processor will set an I O Port to Low or High count J f NUNN ed If Targetstate is set to 1 and the Target number of pulses have been received the Port will output logic HIGH Likewise if
204. o output up to 2147483647 Output a set of number of pulses at a set frequency up to 15kHz FREQOUT and PWM can also output pulses but the user cannot control the number of pulses and must use the PWM ports only With STEPPULSE the user can use any of the output ports and control the total number of pulses at a desired frequency Depending on the CUBLOC module used the number of available channels may change Please refer to the following table for detailed info Module Channels Channel PWM Channels that cannot be used during use of the command B220 280 290 1 0 Channel 0 PWM 3 4 5 CT17XX CB405 2 Oord 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 PWMS cannot be used For the CB405 when using Channel 1 PWM6 PWM7 and PWM8 cannot be used With CB2XX series only Channel 0 may be used With CB405 2 Channels may be used simultaneously for STEPPULSE You can use any of the available I O ports on the CUBLOC When the STEPPULSE command is executed that Port is automatically set to the ouput state Even after the command has finished generating pulses the Port remains in output state Output Frequency can be set from 1hz to 15kHz This command will run in the background independently so the user may use system resources for other tasks 236 Stepstop STEPSTOP Channel Channel StepPulse Channel 0 o
205. of bytes of data in the specified RS232 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 these situations receive interrupts should be used or the buffer size should be increased Dim A As Byte Opencom 1 19200 0 100 50 On Recvl DATARECV_RTN When data is received through RS232 jump to DATARECV_RTN Do Loop infinite loop 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 132 Bytein Variable BYTEIN PortBlock Variable Variable to store results No String or Single PortBlock I O Port Block Number 0 to 15 Read the current status of an I O Port Block a group of 8 I O ports Port 0 to 7 is Block O and Port 8 to 15 is Block 1 Depending on the model of CUBLOC the Port Block numbers for various port groups can vary When using this command all 1 O Ports within the Port Block are set to input and the received input value 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 sour d p vi aLock
206. oftware can be downloaded on our website under Download epmopees amanera aes eT eT oe a 418 CUTOUCH I O Ports Model Name T1720 Input Only 33 Output Only 32 A D Input or 1 0 8 High Counter Input or 1 0 2 Other 1 0s 8 Total 82 cT1720 The 82 I O ports on the shown here T1720 can be accessed using the connectors J1 J2 J3 J4 are 2mm pitch A PCB board is recommended for TTL access J12 J13 J14 are 2 5mm pitch RCABLE headers connectors can be used Comfile RCABLE 419 Connector Name 1 0 Port Block Explanation PO 10 ADCO PL 1 0 ADCI P2 1 0 ADC2 312 P3 10 BlockO ADC3 33 P4 1 0 ADC4 P5 10 ADC5 P6 10 ADC6 P7 1 0 ADC7 PS 10 PWMO P9 y o PWM1 P10 y o PWM2 J13 P11 1 0 Block 1 PWM3 33 P12 1 0 PWM4 INTO P13 10 PWM5 INTL P14 1 0 INT2 P15 10 INT3 H4 P16 10 HIGH COUNT INPUT 0 P17 IN HIGH COUNT INPUT 1 P18 OUTPUT Internally connected to Piezo BUZZER Cannot be accessed from Ladder PI9 to N C P23 P24to 31 OUTPUT Block 3 8 Output Ports 2 P32 to 39 OUTPUT Block 4 8 Output Ports P40 to 47 OUTPUT Block 5 8 Output Ports P4gto 55 OUTPUT Block 6 8 Output Ports P56 to63 INPUT Block 7 8 Input Ports
207. ontain their previous values Ramclear should be used if this behavior is not desirable 208 Reverse REVERSE Port Port I O Port Number 0 to 255 Reverse the specified Port output High to Low or Low to High OUTPUT 8 Set Port 8 to output LOW 8 Set output to LOW REVERSE 8 Reverse LOW to HIGH 209 Rnd Variable RND 0 The command Rnd creates random numbers A random number between 0 and 65535 is created and stored in the specified variable The number inside Rnd has no meaning DIM A AS INTEGER A RND 0 Internally this function is pseudorandom it creates a random number based on the 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 210 Select Case Select Case If the condition Value of Case is met the Statement under the case is executed Select Case Variable Case Value Value Case Value Value Statement 11 Statement 21 Case Else End Select Select Case A Case case case case case End Select Select Case K Case case case case case End select Statement 31 Use Comma for more than 1 value Use lt for logical operations Use ELSE for all other cases If less than 10 If less than 40 211 Set Debug SET DEBUG On Off Set Debug is set to On by default You can use thi
208. ord is 16 bits LOWWORD WORDO Word 0 of variable WORD1 Word 1 of variable A WORDL amp HABCD shabed in word 1 of A Lone LOWWORD Tips Need to access 5 bits of a variable Try NewVariable Variable AND 0x1F This will mask the last 5 bits of the variable 88 DEMO PROGRAM TA Debug Terminal Boul Rats Party DdoBie gry fn u FI BASIC F LADDER ee 2r isan none gt or J const Device cB280 Dim A As long A SH12345678 Debug Hex A BYTRO Cr A BYTE Ce A BYTE Cr A BYTES Cr chaBeD Debug Hex A Cr I Fix fiyhi Side 89 Constants Constants can be used to declare a fixed value within the program This essentially allows a number to be assigned a name often improving readability and debugging of the source code The command CONST can be used to declare constants in CUBLOC CONST PI AS SINGLE 3 14159 CONST WRTTIME 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 3 14159 Declare as SINGLE CONST WRITIME 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 Command CON can be also used to declare constants in the following way PI CON 3 14159 Declare as SINGLE WRITIME CON 10 Declare as By
209. ot declared Long will be used as return value Exceptions include using arrays as parameters Do not do the following R PRAVUSTNG AL EZ Arrays may not be used as parameters End Function 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 as values not pointers If the parameter value is changed within a subroutine it will not affect the actual variable used as a parameter as shown below 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 v v i0 A does not change when V is changed ADDATEN V End Sub 77 In contrast some languages include pointers or Reference by Address in which the actual Data Memory address is passed to the subroutine CUBLOC only supports Call 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 _ TECHNOLOGY Comments Use an apostrophe singlequote to add comments Comments are discarded during compile and will not take up extra Program Memory ADD VALUE B 1 Add 1 to B Comment Nested subroutines Nested subroutines are supported in CUB
210. p Address 0 If I2cwrite ADR BYTE1 1 Then ERR PROC ADDRESS WRITE If I2cwrite ADR LOWBYTE 1 Then ERR_PROC I2estart Repeated Start If I2ewrite sH10100001 1 Then ERR PROC Read command For I 0 To 10 ADATA I T2cread 0 Read 10 bytes continuously ADATA is an array Next I2cstop 302 I2c 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 err_proc Const Device cb280 Dim adr As Integer Dim data As Byte Dim a As Byte data shal adr amp h3 Set I2c 3 2 Do write 1 Byte Zestart If I2ewrite b10100000 1 Then Goto err_proc 2ewrite adr bytel 2ewrite adr lowbyte 2cwrite data T2estop Delay 1000 Read 1 Byte T2estart Zewrite 610100000 a I2cwrite adr bytel 2cwrite adr lowbyte T2ostart 2cwrite amp b10100001 2cread 0 2cstop Print Results Debug Hex a cr 24LC32 camy Delay 500 Loop a0 m scl fre Aa SDA P3 Debug Error 1 Do Loop 303 More About I2C Advanced I C is a common protocol used by many devices today CUBLOC uses 12C as one of its main communication protocols CuNET is built on the I C protocol The main advantage of CuNET is that it s hardware controlled for LCDs Not CSG modules or I O ports 12C commands such as I2CWRITE and
211. p Bt O 0 5bit 0 Reserve 1 2Stp sts 0 1 6 bit 1 0 Even I 0 7bit 1 1 Odd 1 1 8 bit The below table shows typical settings based on the previous table Bits Parity Stop Bit Value to Use 8 NONE 1 3 8 EVEN 1 19 Hex 13 8 ODD 1 27 Hex 1B 7 NONE 1 2 7 EVEN 1 18 Hex 12 7 ODD 1 26 Hex 1A ENCOM 1 19 30 20 Set to 8 N 1 193 The user can set the send and receive buffer size The send and receive buffers take up space in the data memory Although you can set each buffer up to 1024 bytes it will take up that much data memory The number of variables you can use will decrease We recommend receive buffer size from 30 to 100 and send buffer size from 30 to 50 For the CB220 module pins 1 and 2 can be used for Channel 0 Ports 10 and 11 can be used for RS232C Channel 1 CHANNELO 1X lt sour d RX sng AN 7 zaj vin 2 23h vss 3 226 RES 4 216 voo 5 20H pis 6 19 Pre 7 1h Pia A ir piz CHANNEL1 p Pn TX 1 15H Pio e RX nam upro 2 13 pa For the CB280 module there are dedicated RS232 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 Use Set RS232 command to reset the baud rate and parameters during execution of your program 194 CB405 RS232 HOWTO The following is a table of the 5V TTL signal pi
212. p 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 pads labeled External Battery under the super capacitor not visible when back cover is in place DEMO FOR CUTOUCH Const Device CT1720 Dim TX1 As Word TY1 As Word TX Ty1 0 Clear just this variable RAMCLEAR Clear all RAM In LADDER all registers S M C T and D are maintained by the backup battery Register P is cleared at power ON by default If you only want to clear parts of a Register not all Registers you can use the following method to clear Const Device cT1720 Dim I As Integer For I 0 to 32 Clear only Register MO to M32 MI 0 Next Set Ladder On Most traditional PLCs have KEEP memory for storing data in case of power down CUTOUCH also has this feature using a super capacitor which recharges itself and acts as a backup battery You also have the option of using larger capacitor or an actual battery 422 KEEP Timer and KEEP Counter The KEEP timer will retain its data values when powered off and continue from those data values when power is turned on KCTU and KCTD commands can be used in place of CTU and CTD commands in order to make use of the KEEP timer and KEEP counter Please refer to KCTU KCTD commands for detailed information 423 Menu System
213. pecific 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 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 understanding the advantages of both Ladder Logic and BASIC the user will be able to create more efficient final products while saving development time and cost 26 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 there is one clear weakness FUNC FUNC 1 pee H B RETURN The first weakness is that when based on the execution time of BASIC Ladder Logic also gets affected If the BASIC code is made up of an infinite
214. position 0 0 LOCATE 1 1 Move cursor to 1 1 PRINT TLE Print PRINT String Variable String String Variable When using variables constants The string representation of the variable constant will be printed CATE 1 1 Move to position 1 1 ILE DEC I 257 CLCD Module On the back of the CLCD a control board is attached This control board receives CuNET signal and prints on the CLCD DIP Siw wma A T CUNET RS232 5VRS232 CLCD can also communicate using RS232 There are two RS232 connectors one for 3 pin 5V level signals and the other for 4 pin 12V level signals 9 o son 2 aS ENN F Ple Fe CUNET RS232 5VRS232 Use the CLCD DIP switch to set the 12C slave address The 4 DIP switch is not used DIP Switch RS232 Baud rate T2C Slave Address 1r ba E 2400 o TEs ig ES 4800 1 9600 2 19200 3 28800 4 38400 5 57600 6 258 123 oes 115200 7 CUNET or RS232 communication can both be used If both are connected please make sure when one of them is working the other is not The following is the CLCD command table Command Example Byte Execution Explanation hex s Time ESC C 1B 43 2 15mS Clear screen A 15ms delay must be given after this command ESC S
215. r Code char 00H NUL 20H SPACE 40H 60H 01H SOH_ 21H 4iH_ A 61H a 02H STX 22H 42H B 62H b 03H ETX 23H 43H c 63H c 04H EoT 24H 44H D 64H d OSH ENQ 25H 45H E 65H e 06H ACK 26H amp 46H F 66H f 07H BEL 27H h 47H G 67H g 08H BS 28H 48H H 68H h 09H HT 29H 49H I 69H I OAH LF 2AH aah I 6AH j oBH _ VT 2BH 4BH K 6BH k OCH FE 2CH 4CH L 6CH l ODH CR 2DH_ 4DH_ M 6DH_ m OEH so 2EH 4EH N 6EH n OFH SI 2FH 1 4FH o 6FH o 10H DLE 30H o 50H P 70H p 11H DCI 31H 1 51H Q 71H q 12H DC2_ 32H 2 52H R 72H r 13H Dc3__ 33H 3 53H s 73H s 14H DC4 34H 4 54H T 74H t 15H NAK 35H 5 55H u 75H u 16H SYN 36H 6 56H v 76H v 17H ETB 37H 7 57H w 77H w 18H CAN 38H 8 58H x 78H x 19H EM 39H 9 59H Y 79H y 1AH SUB 3AH 5AH 4 7AH z 1BH ESC 3BH i 5BH L 7BH 1CH FS 3CH lt 5CH 7CH l 1DH_ GS 3DH__ 5DH_ 7DH_ 1EH RS 3EH gt 5EH 7EH 1FH uS 3FH 2 5SFH 7FH DEL 442 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 of the board as shown below The CB220 already has this capacitor on the chip itself sour qt zab vin sin 2 23 v
216. r TY1 As Integer Dim k As Long Contrast 550 Set Pad 0 4 5 On Pad Gosub abe Menuset 0 2 8 16 87 63 Menutitle 0 13 13 Start Menuset 1 2 96 16 176 63 Menutitle 1 13 13 End Menuset 2 2 184 16 264 63 Menutitle 2 13 13 Restart Low 18 Do Loop TX1 Getpad 2 TY1 Getpad 2 Circlefill TX1 TY1 10 If Menucheck 0 7X1 TY1 Menureverse 0 Pulsout 18 300 Send out beep to piezo End If If Menucheck 1 7X1 TY1 Menureverse 1 Pulsout 18 300 End If If Menucheck 2 TX1 TY1 Menureverse 2 Pulsout 18 300 End If Return 1 Then 1 Then 1 Then 429 CUTOUCH Sample Programs SAMPLE 1 Let s make a simple counter that will print to the screen The source files used here are in your CUBLOC Studio installation directory Usually C Program Files Comfile Tools CublocStudio 3241 lt Filename CT001 CUL gt Const Device Ct1720 Dim I As Integer Contrast 550 LCD CONTRAST SETTING Do Locate 15 6 Print DEC5 I Iner I Delay 200 Loop Please adjust your screen s contrast accordingly using CONTRAST command Depending on the model you may be able to adjust the contrast using an adjustable knob on the back of CUTOUCH In this case you have the option to set the contrast manually 430 SAMPLE 2 The following example program will display a RESET button and will increment the number shown every time the button is pressed 3241 lt Filename CT002 CUL gt Const Device Ct1720 Dim I As
217. r 1 STEPSTOP command will stop Pulse Output Channel immediately 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 0 is generating pulses _F 56 will be logic HIGH 1 When Channel 1 is generating pulses _F 57 will be set to logic HIGH 1 If no pulses are being output at the moment the F registers will be set to logic LOW 0 STEPPULSE CHO F56 STEPPULSE CH1 Stepaccel STEPACCEL Channel Port FreqBASE FreqTOP 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 FrequncyTop Frequncy Base T Frequncy Accel Number of Pulses Output a set of number of pulses at a set frequency up to 3 3kHz with acceleration Stepaccel command supports only 1 channel so must use number 0 at the Channel argument You can use any of the availa
218. r ON INTx will not be executed if the corresponding external interrupt occurs See also the SET INTx command which controls external interrupts Set ONINTO On Set ONINT1 On Set ONINT1 Off Set ONINT2 Off Set ONINT3 On 220 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 interrupts using global flags When the OnLadderint is set to On then an interrupt can be received using the On Ladderint command If the global is set to OFF then the code for On Ladderint will not be executed if the Ladder interrupt occurs See also the On Ladderint command aeli lal CUBLOC studio d WA Sil 2 _cubloc 0 Wiadderabaagye EI TAD BOE CHOO HAm seq see S ae p nmm E FI BASIC F2 LADDER Ladder Mnemonic Const Device CB2S0 Dim A As Integer Ramclear Set Ladder on On Ladderint Gosub FROMLADDER Do Loop FROMLADDER Debug Dec A CR Incr A Return Clos T Fis Aiah Blas 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 Onpad interrupts using global flags When the Onpad is set to on then an interrupt can be received using the On Pad command If the Onpad is set to OFF then the code for On Pad will not be executed if the interrupt occurs See also the Set Pad and On Pad commands 222
219. r Single Source source value 0 to 31 Nop NOP Offset OFFSET x y On int ON INTx GOSUB label x 0 to 3 External Interrupt Channel On ON LADDERINT GOSUB label ladderint On pad ON PAD GOSUB label Onrecv ONRECVI GOSUB label On timer ON TIMER interval GOSUB label Interval Interrupt Interval 1 10ms 2 20ms 65535 655350Ms 1 to 65535 can be used Opencom OPENCOM channel baudrate protocol recvsize sendsize channel RS232 Channel 0 to 3 Baudrate Baudrate Do not use variable protocol Protocol Do not use variable recvsize Receive Buffer Size Max 1024 Do not use variable sendsize Send Buffer Size Max 1024 Do not use variable Out OUT Port Value Port 1 0 Port number 0 to 255 Value Value to be outputted to the 1 0 Port 1 or 0 Output OUTPUT Port Port 1 0 Port number 0 to 255 Outstat Variable OUTSTAT Port Variable Variable to store results No String or Single Port I O Port Number 0 to 255 Overlay OVERLAY overmode overmode Logical Mode 0 or 1 and Paint PAINT x y Pause PAUSE value 451 Peek Variable PEEK Address Length Variable Variable to Store Result No String or Single Address RAM Address length Length of Bytes to read 1 to 4 Poke POKE Address Value Length Address RAM Address Value Variable to store results up to Long type value length length of bytes to read 1 to
220. r acquiring the A D conversion value from the R T table is as follows 5 V x THR 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 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 You can easily make a chart by using a spreadsheet to enter these formulas lt END gt 333 NOTE 4 Sound Bytes In this application note I will be showing you simple ways to create key touch sound musical notes and an alert sound An I O port or a PWM Channel of CUBLOC can be used for sound With a PWM Channel you can create various frequencies of sound o mr nonnnnann coo ooo i The above example shows PWM Channel 0 of CB220 being used with Freqout command to produce a sound Const Device cb280 Dim PLAYSTR As String Low 5 Freqout 0 5236 create a sound with frequency of 440Hz Delay 500 Delay Pwmoff 0 Stop Sound by turning off PWM With commands like Freqout and Delay simple sounds can be created lt Filename playcdec cul gt Const Device C8280 Low 5 Freqout 0 4403 Delay 200 Freqout 0 3703 Delay 200 Freqout 0 3114 Delay 200 Freqout 0 2202 Delay 200 Pwmoft 0 334 By changing the frequencies we have made a simple program that can play musical notes Octave 4 Octave 5 A B C D E F G A B G D E F G
221. r output Slave input miso port for data Master input Slave output mode communication mode bit MSB start 1 LSB star t bit 2 O wait at the clock LOW i bit 1 OUTPUT sampling point O before rising edge 1 after falling edge bit 0 INPUT sampling point 0 before rising edge 1 after falling edge 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 MSB First Most Significant Bit First After Falling Edge LSB First Least Significant Bit First Before Rising Edge MSB First Most Significant Bit First Before Rising Edge bitlength Length of bits 8 to 16 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 8 to 16 SPI Indata SPI Outdata Bits Indata input data Outdata output data bits Number of bits 1 to 32 454 Stepaccel STEPACCEL Channel Port Fr
222. ram shows how to connect an output relay to a CUBLOC I O port A photocoupler can be used to separate 24V and 5V and protect against noise Noise coming from 24V side will not affect the 5V side and vice versa ea mr LOAD How to Connect an NPN TR Output This circuit diagram shows an NPN TR photocoupler separating 5V from the LOAD zaye cuoc Pi vO Fen tin O gt t Ea weit LOAD pie resem mr aw How to Connect a DC24V Input Use a double polarity photocoupler to convert 24V signals to 5V When input is received the CUBLOC will receive a HIGH 5V signal wo Pon QF wy p see 2 zav ave aah he fea Oe TT 3v st How to connect an AD Input To connect an AD input to the CB280 the AVDD and AVREF pins must be connected to 5V AVDD supplies power to the ADC of CUBLOC and AVREF is the reference voltage that the ADC uses to do conversions If 5V is connected to the AVREF pin 0 to 5V input voltage will be converted and if 3V is connected to AVREF pin 0 to 3V input voltage will be converted Desv Desv mm TTurxt AVREF pas Pat P30 P20 pas Pa2 Pas paa Pas Pas P37 Pas Pao RES nic Pis 2 PIT Pis Pio P20 Pa P22 P23 Pis Pu Pia P12 The CB220 s AVDD and AVREF are internally
223. rial automation However most touchscreen devices require connection to an external PLC and require learning yet another complex interface description method In addition cost of touchscreen interfaces has remained relatively high The CUTOUCH is a complete touchscreen controller which can handle graphical interface and direct I O at the same time This reduces complexity and cost in your machine designs 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 and math and perform custom RS232 communication tasks that are difficult to accomplish with a traditional PLC Ladder Logic is still available and runs alongside the BASIC program allowing the user to perform sequential processing and real time logic as in traditional PLCs The CUTOUCH has reprogrammable flash memory for the BASIC and LADDER programs An RS232 serial port is used to download and debug code using a Windows PC The CUTOUCH will operate as a stand alone device when detached from the PC serial port If you are thinking about developing a device that uses a touchscreen please review the CUTOUCH The integrated approach saves time and lets you concentrate on solutions instead of problems Comfile Technology Inc 414 What is CUTOUCH The CUTOUCH is different from traditional touchscreens you may have
224. ring through the Internet XPORT is an internet module that converts RS232 signals into TCP or UDP packets You can use XPORT and CUBLOC to download and monitor programs through the internet By using this feature you will be able to update and provide customer service for your products even if it s located in other parts of the world We provide custom MAXPORT firmware Downloading Monitoring Server programs and embeddable applets for downloading and monitoring your CUBLOC module You may use this program to manage thousands of devices MAXPORT module Ei MoPORT Downloader v 1 2 6 Search Local Area Network fr XPONTS Select far CUBLOC Firmware cam ee em CUBLOC Object Fle Downloader CUBLOC Firmware ooo c Downloader MavPORT Firmware Bownicsder va TFTP Status Monitor Co O O iem Sat IP Addrase Set all to ZERO for Automatic IP via DHCP m Sat Debu ON Monitoring Download Server Program for multiple MAXPORTs 32 Hints for Traditional PLC Users For users with much experience in traditional PLCs they will find BASIC a completely new language CUBLOC is a PLC with BASIC language capabilities added The user may program only using the ladder language if desired Even a Ladder Logic user may be able to incorporate new features into the final product by making use of BASIC which has additional capabilities and flexibility in communicating with other devices than PLCs To use CUBLOC the us
225. rns the average of 10 ADIN converted values When working under noisy environments using Tadin could help in obtaining more precise results Tadin is a premade function function tadin num as byte as integer dim ii as integer ta as long ta 0 For 0 To 9 ta ta Adin num Next TADIN TA 10 End Function 242 Time Variable TIME address Variable Variable to store results No String or Single address Address of time value 0 to 6 The CUBLOC module CB290 has an internal RTC chip You can use the Time and Timeset commands to set and return time values to and from the RTC Time information such as current time day of the week and year can be set to the RTC and read from it in real time Time is kept current even when module powers off if a backup battery is used The following is a chart showing the addresses of the RTC and its corresponding values You cannot use these commands for CB220 and CB280 since they do not have an RTC Addres Value Range Bit Structure s 0 Secon 0to59 2 digit place 1 digit place d 1 Minute 0 to 59 2 digit place 1 digit place 2 Hour Oto 23 2 digit place 17 digit place 3 Date Oito3i 2 digit place 1 digit place 4 Day Oto 6 1 digit place 5 Month ito 12 2 digit 1 digit place 6 Year 00t099 2 digit place 17 digit place Please refer to the chart below for day of the week a
226. rogram stays in the Do Loop and will never get out of it 3 How to simulate an LCD You can simulate an LCD using the Debug terminal Simply use the Goxy XX YY to access a particular location on the terminal as shown below eX Drar Da in jasgs zana puomia IPLB rel Lamoen Laaer wanono EKA Tom Debug Terminal DER Use the command Port Baud Rate Debug CLR to clear com Zij115200 Zj jNone Zilje the Debug window At any time during development you can disable and also not include Debug statement during Compiling by using the command Set Debug Off Close f Fix Right Side 214 Set I2c SET 12C DataPort ClockPort DataPort SDA Data Send Receive Port 0 to 255 ClockPort SCL Clock Send Receive Port 0 to 255 This command sets the I2C DataPort and ClockPort SDA and SCL for 12C communication Once this command is executed both Ports become OUTPUT HIGH state Please use Input Output Port for I2C and use two 4 7K resistors as shown below SCL SDA Some of the I O ports only support Input or Output Please check the Ports in the data sheet for the model you are using 215 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 On Int command in order to receive external interrupt inputs The mode of interrupt input can be set here to either falling edge rising
227. rt 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 FrequncyTop Frequncy Base Number of Pulses Output a set of number of pulses at a set frequency up to 3 3kHz with acceleration NEW CUBLOC Module CB320 CB380 The new CUBLOC Module CB320 CB380 have more program and data memory plus two more serial ports than older CUBLOC modules Core Module CB380 Core Moduel CB320 Same as CB280 except 200KB Program memory 6KB Data memory Same as CB220 except 200KB Program memory 6KB Data memory To use the CUBLOC module CB320 CB380 you need to use CublocStudio v 2 5 B and above Feature e220 e280 cB290 8405 cB320 380 Program Memory 80E TKE TOKE 20E 2O0KE ETE Data Memory BASIC2KB BASIC2KB BASIC 24KB BASIC SIKE BASIC 6KB BASIC 6KB LADDER 1KB LADDER 1KB LADDER 4KB LADDER 4KB LADDER 1KB LADDER 1KB HEAP 55KB Battery WA WA avaliable Avaliable WA NA Backup EEPROM E KE aK KE KE KE TO ports 16 6 CEF DEFI CEF T6 6 CESI Package 24pin DP 64 pin 108 pin 80pin Module 24 pin DIP 64 pin Module Module Module ADE Channel 8 Channel E Channel T6 Channel channel Channel PWM 3 Channel Channel 6 channel 12 Channel 3 Channel
228. ry MENU Commands Menuset Menutitle Menucheck Menureverse Menu Waitdraw Touch Pad Input Example CUTOUCH Sample Programs APPENDIX Appendix A ASCII CODE 16 Appendix B Note for BASIC STAMP users Appendix D BASIC Command Summary 17 18 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 CUBLOC 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 cB220 CB280 CB290 CB405 E kK EA Program soke soe soe 200K8 Memory Data AEEA 2RS EASICT ZAKBIBASIC 2KB GASIC 4KB Lad Memory Aet ea 4K6 Ladder Logic der Logic 55KB Heap EEPROM axe EEPROM AKB EEPROM TRB EEPROM AKB EEPROM Program 36 000 inst sec 36 000 ist see 36 000 inst sec 36 000 inst sec Speed Js j J j SEO Tnes SV TID General 16 61
229. s command is an UP Counter When an input is received the counter is incremented by one When the counter counts to a specified value the set Register will turn ON at that point There is a Reset input so the counter can be reset as needed PULSE cTU co 100 F 4 RESET a 100 pulse purse MAN ANN reset M co CTD This command is a DOWN Counter When an input is received the counter is decremented by one When the counter reaches 0 the set Register will turn ON at that point There is a Reset input so the counter can be reset as needed PULSE CTD C1 100 I F c RESET i R 100 pulse purse DAAN ANN RESET m c1 UP DOWN COUNTER Below is a simple example of how an UP Counter can be used to make an UP DOWN Counter PO cTuco i00 fc PI R P2 WDEC C0 F c 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 co COUNT k co 388 KCTU This command is exactly same as the CTU command except this command will be able to remember counter values when the module is powered off The module used for this command MUST support battery backup CB290 CB405 In comparison the CTU command will lose its count value when the module is powered off PI KCTU c0 100 fc P2 R 100 pulse Po fo P1 Ze Use RESET to set the counter to O atthe Power off a
230. s command to control debugging functions in BASIC When you don t need the DEBUG feature you can use this command to turn off all DEBUG commands instead of modifying every instance of Debug When this command is used all DEBUG commands are not 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 the program The user can check the value of variables during execution of a program simulate an LCD and do other tasks to help save development time 1 How to Check if program is being reset Sometimes you will want to check if your program is being reset This is usually due to faulty programming Simply put a Debug statement at the beginning of your program such as Debug Reset o as shown below Const Device CB280 Debug Terminal Debug Pol Sanpae Paty Dales feon z frame fe fe Do High 0 Delay 200 Low 0 Delay 200 Loop T Fix Righi Side 212 2 How to check if a particular point of the program is being executed Simply insert a Debug command where you would like to know if that part of the program is executed as shown below Debug Terminal const Device 8280 Suu fwty Das ay Fy Do risa fee elle lees nigh 0 belay 200 tou 0 Delay 200 Loop Debug This Part I Fix Right Side The debug statement above will never execute as the p
231. s for the I2C protocol In I2C communication an ACK signal is required for every 8 bits SHIPTOUT 3 4 0 4H55 8 Port 3 Clock 234 Port 4 Data Mode 0 send 0x55 bitlength 8 bit CLK L DATA 1 0 1 0 1 0 1 0 55H LSB MSB Spi Indata SPI Outdata Bits Indata input data Outdata output data bits Number of bits 1 to 32 This command sends data output with input same time SHIFTOUT and SHIFTIN command is supports only one direction at the same time But SPI command send and recive simultaneously This command supports any I O ports Must use SET SPI command before SPI command It s define I O port for SPI commands 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 0 MSB start 1 LSB star t bit 2 0 wait at the clock LOW 1 wait at the clock HIGH bit 1 OUTPUT sampling point 0 before rising edge 1 after falling edge bit 0 INPUT sampling point 0 before rising edge 1 after falling edge Ex Set Spi 9 8 7 0 Const Device CB280 Dim Dtin as Byte Set Spi 9 8 7 0 Dtin Spi Dtout 32 MASTER SLAVE Steppulse STEPPULSE Channel Port Freq Qty Channel StepPulse Channel 0 or 1 Port Output Port Freq Output Frequency Up to 15kHz Qty of pulses t
232. se statements will be discarded Const Device CB280 Delay 500 Device only returns the decimal number Device 220 Debug CB220 module used endif The above example illustrates how depending on the type of CUBLOC CUTOUCH 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 99 Using the preprocessor directive elseif or else you can create more complex if endif blocks Const Device CB220 Delay 500 Device only returns the decimal number I Device 220 Debug CB220 module used elseif device 280 Debug CB220 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 statement You may only compare constants declared with the CONST command for the if statements ifdef name endif When using if to compare constants you can use ifdef to see if a constant has been defined previously using define or CONST If the constant has been defined previously 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 blo
233. seif Elseif Elseif Device Ct1720 1 As Integer TY1 As Integer Dim I As Integer st 550 d 0 4 5 Gosub GETTOUCH lt Filename CT005 CUL gt Execute the Sub routine in INCLUDE file Getpad 2 Getpad 2 check 0 TX1 TY1 1 PRPA EA Pulsout 18 300 Menucheck 1 TX1 TY1 Trend I r 2 Pulsout 18 300 Menucheck 2 TX1 TY1 Iei lt c4 I 1 3 Pulsout 18 300 Menucheck 3 TX1 TY1 ESEE I r 4 Pulsout 18 300 Menucheck 4 TX1 TY1 Isi lt c4 TETES Pulsout 18 300 Menucheck 5 TX1 TY1 Tei lt c4 I 1 6 Pulsout 18 300 Menucheck 6 TX1 TY1 Tei lt c4 Poy Pulsout 18 300 Menucheck 7 TX1 TY1 Then Then Then Then Then Then Then Then pepe bend Pulsout 18 300 Elseif Menucheck 8 TX1 TY1 1 Then Israa I I 9 Pulsout 18 300 Elseif Menucheck 9 TX1 TY1 1 Then Tsrag Pulsout 18 300 Elseif Menucheck 10 TX1 TY1 1 Then B Pulsout 18 300 End If Locate 3 3 Print HEX4 I Return End INCLUDE CTO0S INC We must place the include command at the end of the code as the generated code is in the form of a Sub 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 439 440 APPENDIX Appendix A ASCII CODE Code char Code _ cha
234. sgdec 0 1 End If 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 into the variable K which is in BCD code We then use the function BCD2BIN to convert the BCD value back into binary Const Device CB280 Set 12c 9 8 Dim I As Integer Dim K As Integer Dim M As Integer RSA Const Byte KEYTABLE 1 4 7 Do 0 2 5 8 0 3 6 9 11 12 13 14 15 I Keypad 0 If I lt 16 Then KEYTABLE I If I lt 10 Then K K lt lt 4 K K I Csghex 0 K End If 1 WAIT UNTIL KEY DEPRESS 327 Do While Keypad 0 lt 255 Loop M Bed2bin K Debug Dec M CR End If Loop When there is no input the returned scancode is 255 By using Do While keypad 0 lt 255 we will wait until a key is released which will return a scancode of 255 This is to allow the processor to stop reading input while a key is pressed Otherwise the processor might receive multiple key inputs since the execution time of the CUBLOC is very fast By using _D 0 M you can pass the scancode value to Register DO of Ladder Logic If you need to use a keypad in LADDER you can modify this code a little bit to get your results quickly lt END gt 328 NOTE 3 Temperature Sensor There are many uses for devices that sense temperature Refrigerators heaters air conditioners automobiles and many other devices are a few examples W
235. ss an gs 22 res vss g4 218 voo pods 20H prs Pie isp pt P2 d7 18h pis Pa ge arh P12 Pa ge tep en Ps g 10 15h Pio eo mm 14h Po er qhi2 13 Pe sour qi vin sn g2 B vss Rx Amn ga p res vss qa B voo 1 ro gs A ris pide 19 pra DTR r2 g7 seh P13 Pa ga 17 Pie Pa gs seh en Ps g 10 15h P10 regnm 14 Ps Sharid Pr a2 13h Pe 443 Appendix D BASIC Command Summary Command Usage Adin Variable ADIN Channel Variable Variable to store results No String or Single Channel AD Channel Number not I O Pin Number Alias ALIAS Registername AliasName Registername Register name such as PO MO TO Do not use D area AliasName An Alias for the Register chosen up to 32 character Arc ARC x y r start end Bcd2bin Variable BCD2BIN bedvalue Variable Variable to store results Returns LONG bedvalue BCD value to convert to binary Beir BCLR channel buffertype channel RS232 Channel 0 to 3 buffertype 0 Receive 1 Send 2 Both Beep BEEP Port Length Port Port number 0 to 255 Length Pulse output period 1 to 65535 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 Buffer Bin2bcd Variable BIN2BCD binvalue Variable Variable to store results Returns Long binvalue Binary value to be converted Bien Variable BLEN
236. t PWM with duty of 200 and Width of 1024 IMPORTANT PWM Channels 0 1 and 2 must use the same value of Period since they share the same resources Their duty values can be different PWM Channels 3 4 and 5 also must use the same value of Period since they share the same resources Their duty values can be different Pwmoff PWMOFF Channel Channel PWM Channel 0 to 15 Stops the PWM output The following are PWM channels available on each module pwno e PWN lt bu PWN 3 Please refer to the table below for PWM Channels and corresponding I O ports CB220 CB280 CB290 CT17X0 CB405 PWMO Vos Vo5 Vos 108 Vos PWMI 106 106 106 109 106 PWM2 07 107 VO7 1 0 10 VO7 PWM3 1 0 19 1 0 89 1 011 1 0 27 PWM4 1 0 20 1 0 90 1 0 12 1 0 28 PWMS 1021 1091 10 13 1 0 29 PWM6 1011 PWM7 1 0 12 PWM8 1 0 13 PWM9 1051 PWM10 1 0 52 PWMI1 1 0 53 206 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 variables to zero There are CUBLOC modules that support battery backup of the RAM If you don t use Ramclear command in these modules CUBLOC will remember previous values of RAM across power cycles 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 c
237. t Port must be set to 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 system sub program sub pulsout pt as byte 1n as word dim dll as integer reverse pt for dl1 0 to 1n next reverse pt end sub 200 Put PUT channel data bytelength channel RS232 Channel 0 to 3 Data Data to send up to Long type value Bytelength Length of Data 1 to 4 This command sends data through the specified RS232 port For Data variables and constants can be used To send a String please use Putstr command instead M1 19200 0 50 10 IMPORTANT 2 pre The command ene OPENCOM must be used beforehand A amp HAO PUT 1 A 1 Send amp HA0 0xA0 to RS232 Channel 1 The data is first stored in the send buffer set by Opencom The CUBLOC BASIC Interpreter will automatically keep sending the data in the send buffer until it s empty If the send buffer is full when the PUT command is executed the PUT command will not wait for the buffer to empty In other words the data waiting to be sent will be thrown away The command BFREE can be used to check the send buffer beforehand for such cases IF BFREE 1 1 gt 2 THEN If send buffer has at least 2 bytes free PUT 1 A 2 END IF BFREE checks for how much space t
238. te MYROOM CON 310 Declare as Integer MsGL CON ACCESS PORT Declare as String 90 Constant Arrays In constant arrays the user is able to store a list of numbers before the program begins A program requiring a large number of constant values can be simplified as shown below Const Byte DATAL 31 25 102 34 1 0 0 0 0 0 65 64 34 I1 0 A DATAI I Store 31 in A Tel A DATAI I Store 25 in A Const Byte DATAl CUBLOC SYSTEMS String data can be stored in Byte constant arrays The ASCII code of the character is returned If DATA1 0 is read ASCII code of C is returned Likewise if DATA1 1 is read ASCII code of U is returned Integer and floating point numbers can be used as shown below CONST INTEGER DATAL CONST LONG DATA2 CONST SINGLE DATA3 6000 3000 65500 0 3200 345678 356789 165500 0 0 3 14 0 12345 1 5443 0 0 32 0 For multiple line constant arrays the following ways can be used 1 CONST BYTE DATAL 31 25 102 34 1 0 0 0 0 O 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 DATA2 31 25 102 34 1 0 65 64 34 _ 101 123 44 39 12 39 Strings can be used as shown below CONST STRING 6 STRTBL COMFILE BASIC ERROR PICTURE 91 Please set the size of the String to be greater than any of the members of the constants
239. ter inputs Counter Channel 0 uses the same resources as PWMO PWM2 you cannot use both at the same time However Counter Channel 1 can be used while PWM Channel 0 is running To use Counter Channel 0 the SET COUNTO On command must be used beforehand Counter Channel 1 requires no additional settings sout Gt zah vin sin g2 23h vss am g3 22b RES vss g4 216 voo Po gs 20f pis 4 COUNT 1 P ge iaf pia lt COUNTO r2 g7 18 P13 Pa ge 17 P12 Pa gs 16D Pn Ps g10 15h P10 Pregn mmm 14h po P7 g 12 13 Pa Dim R As Integer Input 15 Set port 15 as input Counter Channel 1 R Count 1 Read current Counter value Set CountO On Activate Counter Channel 0 PWMO 1 2 becomes deactivated Input 14 Set port 14 as input Counter Channel 0 R Count 0 Read current Counter value 137 Since Counter 0 uses the same resources as PWM as shown below please be careful not to use PWMO at the same time COUNTER O ewe TIMERA ews TIMERB Measure frequency from pulse output PWM 0 channel Const Device CB Dim A as Integer Input 15 Low 5 Freqout 0 2000 Low 0 280 On Timer 100 Gosub GetFreq Do Loop GetFreq A Count 1 Debug goxy 10 2 Debug dec5 A Countreset 1 Reverse 0 Return 138 Countreset COUNTRESET channel Channel Counter Channel 0 to 1 Reset the specified Counter Channel to 0 Countreset 0 Clear Channel 0 Coun
240. the Targetstate is set to 0 and the Target number of pulses have been received the Port will output logic LOW Channel Compare Range HCOUNT Channel 0 Oto 255 HCOUNT Channel 1 0 to 65535 The high counter itself supports up to 32 bits but the COMPARE command is limited since this command was designed to not affect the overall multitasking of the CUBLOC main processor Note For channel 0 please use the Set CountO On command before using the Compare command Dim i As Integer lt Debug Terminal Set CountO On TW E a a ee ae Compare 0 10 61 1 pit Mt Near A A Do i Count 0 Debug Goxy 0 0 dec4 i Cr Delay 100 Loop The above uses High Counter Channel O with target of 10 When the Counter 0 value becomes 11 Port 61 will ouput logic HIGH T Faih Side 136 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 Count Channel Please set the Counter Input Ports refer to the pin port table for the appropriate CUBLOC module to input before use of this command Up to 32 bit values can be counted Byte Integer Long Maximum pulse frequency is 500kHz CUBLOC s counter is hardware driven meaning it runs independently from the main program It is able to count in real time No matter how busy the CUBLOC processor gets the counter will count reliably The CUBLOC has 2 Coun
241. the command Set Debug Off which will automatically ignore any Debug statements 65 Edit Device File Menu Ladder impor Soe ery Save ds Save Obiect Print Ladder Bin BAS Prin Setup Bownload tom abe te BASIC Section FI accor Seon Pe ceu C MCubloc TestNECD TEST eu Setup Help 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 different name Save Object 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 reverse engineer it You can use Download from Object File to download an object file to CUBLOC Create object files for internet downloading with CuMAX or CuMAX Server Print Ladder Print Ladder Logic section only Print Basic Print Basic section only Print Setup Setup printer for printing Ladder Logic section Download from Object file Download an object file to the CUBLOC module Basic Section Switch to Basic Section for editing Or press F1 Ladder Section Switch to Ladder Logic Section for editing Or press F2 Last 4 Files Edited View last 4 files edited Exit Exit CUBLOC Studio Device Menu If a Const device statement does not exist in your source code Device Menu will create a Const device stat
242. tle 5 11 4 6 Menuset 6 2 165 120 1 Menutitle 6 11 4 7 Menuset 7 2 205 120 235 145 Menutitle 7 11 4 8 Menuset 8 2 245 120 275 145 Menutitle 8 11 4 9 Menuset 9 2 165 155 1 Menutitle 9 11 4 0 Menuset 10 2 205 155 275 180 Menutitle 10 17 4 ENTER I 0 Do Loop 35 110 5 145 5 180 CT004 CUL gt 433 TX1 Getpad 2 TY1 Getpad 2 If Menucheck 0 TX1 TY1 1 Then I I lt lt 4 I I 1 Pulsout 18 300 Elseif Menucheck 1 TX1 TY1 1 Then TER ie Pulsout 18 300 Elseif Menucheck 2 TX1 TY1 1 Then Ti aod me tee a Pulsout 18 300 Elseif Menucheck 3 TX1 TY1 1 Then TSAA TETES Pulsout 18 300 Elseif Menucheck 4 TX1 TY1 1 Then TIKOA SIr Pulsout 18 300 Elseif Menucheck 5 TX1 TY1 1 Then Tei lt lt 4 I I 6 Pulsout 18 300 Elseif Menucheck 6 TX1 TY1 1 Then Isi lt lt 4 TARET Pulsout 18 300 Elseif Menucheck 7 TX1 TY1 1 Then I 1 lt lt 4 I I 8 Pulsout 18 300 Elseif Menucheck 8 TX1 TY1 1 Then THIKA I 1 9 Pulsout 18 300 Elseif Menucheck 9 TX1 TY1 ima Pulsout 18 300 Elseif Menucheck 10 TX1 TY1 1 Then TSY Pulsout 18 300 End If Locate 3 3 Print HEX4 I Return The final value I is stored as BCD code you can use the BCD2BIN command to convert back to a binary number Then 434 SAMPLE 5 Let s try using CuCANVAS to make some menus To create the virtual keypad shown in the previous page it would take a long time to manual
243. tocol Here we will show you how to implement this 12 bit A D converter into your project gsar gsm O ATN gss dro gei ge T d Lite tifa f 4 a o re ayn op 4 MCS3202 8220 mr Pin Function T O Direction Explanation cs Chip Select Input Low for data communication CLK Clock Input Clock signal DI Data Input Input Data input from MCP3202 DO Data Output Output Data output from MCP3202 lt Filename mcp3202 cul gt 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 Channel 0 PES Channel 1 Shiftout ioclk iodi 0 i 4 ad Shiftin ioclk iodo 3 12 High iocs Debug Dec ad Delay 100 Loop 342 The MCP3202 will convert voltage coming into CHO and CH1 ports to a data value and retain it The user can simply use SPI communication to read the value that the MCP3202 has converted 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 to the DEBUG window RIES ene E fers s20 z une 1 5 are Close I Fi Right Sido lt END gt 343 NOTE 9 Read and write to an EEPROM With an EEPROM you can store between 0 5 to 64 KB of data Data is retained even after powering off For example if you wanted to r
244. treset 1 Clear channel 1 139 Dcd Variable DCD source Variable Variable to store results No String or Single Source source value The DCD command is the opposite of the NCD command It will return the bit position starting at LSB bit 0 of the highest bit that is a 1 I DCD 15 Result is 3 since 15 0b00001111 SE CUBLOC studio d cuboetestiunary cul ES peve Bn Sep neo ag GSS a gt aw FI BASIC F2 LADDER Ladder Mnerl Port Baud Rate Party Data Bits Const Device CE280 cont 115200 None fe Dim A As Long A 10 Debug Dec A Cr Debug Terminal A NUL 1 Debug Dec A Cr A Ncda Debug Dec A Cr A Ded 15 Debug Dec A Cr Close T Fix Right Side 140 Debug DEBUG data data data to send to PC CUBLOC supports RS232 debugging with the DEBUG command The user can insert DEBUG commands as desired within a program The result of the DEBUG command is displayed on the DEBUG Terminal which will automatically appear after the program is downloaded from Cubloc Studio DIM A AS INTEGER es Tormijii pestle 3 Bauirate Paty Daabts arn 9 M aaka com s200 x ene z fe Z ax 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 v
245. tus of RS232 buffers for both Channel 0 and 1 e Address 0 Actual bytes of sent data in send buffer after executing commands PUT or PUTSTR e Address 1 Actual bytes of sent data in receive buffer after executing commands GET or GETSTR e Address 5 Timer value that increments every 10ms e Address 6 Data Memory RAM Address SYS 5 will return the value of the system timer which increments every 10ms You may only read the value not change it The Timer will increment up to 65535 and then reset to 0 You can use this system timer for applications requiring an extra timer SYS 6 will return the current Data Memory Address At power ON the Data Memory Address is reset to 0 After calling Sub routines or Functions the Data Memory Address will increment If will also increment when Sub routines or Functions are called within a Sub routine or a function Interrupts will also increment the Data Memory Address When the Data Memory Address exceeds the total Data Memory available it will cause overflow By using this function you can avoid overflow CB280 has a maximum of 1948 bytes of Data Memory Please try to have at least 100 bytes of free Data Memory for a safety buffer Sys 6 Store the current Data Memory Address in A 241 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 It retu
246. uencies The highest possible frequency is set by 1 and the lowest possible frequency is set by 65535 A value of 0 does not produce any output FreqValue Frequence FreqValue Frequency 1 1152 KHz 200 11 52 KHz 2 768 kHz 1000 2 3 KHz 3 576 KHz 2000 1 15 KHz 4 460 8KHZ 3000 768 Hz 5 384 KHz 4000 576 Hz 10 209 3 KHz 10000 230 Hz 20 109 7 KHz 20000 115 2 Hz 30 74 4 KHZ 30000 76 8 Hz 100 22 83 KHZ 65535 35 16 Hz You can calculate FreqValue with the following formula FreqValue 2304000 Desired Frequency Before using this command please set the specified PWM Port to output mode and set to a High or Low state To stop the frequency output you can use the command PWMOFF The following is an example Const Device cb Dim i As Integer Low 5 2S Fregout 0 10 Do Loop Set Port 5 to low and output Produce a 209 3Khz wave Infinite loop 157 Since Freqout uses the same resources as PWM there are some restrictions 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 you use Freqout on PWM Channel 3 PWM Channels 3 4 and 5 cannot be used for a PWM command You can product different frequencies on PWM Channel 0 and 3 To sum up the user may produce two different frequencies at on
247. und 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 45 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 A 1 Debug DP A CR DELAYTIME Goto Loopl End End of main program Sub DELAYTIME Dim K As Integer For K 0 To 10 Next End Sub Sub and Function subroutines come after the End Gosub subroutines must be within the main program like shown here Dim AAs Integer Gosub ABC ABC End Sub DEF B as Byte End Sub Function GHI C as Byte End Function The End command is used to differentiate between the BASIC main program and the subroutines END command used in Ladder Logic is to indicate the end of Ladder Logic 76 Subroutine Parameters and Return Values Functions may use any data type as parameter and return values Dim A 10 As Integer Function ABC A AS Single as Single Return Single value End Function Function ABC 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 n
248. vert the bits 1100 0011 Then add one which is 1100 0100 0xC4 LRC 0xC4 ASCIL o s o i o Jo 1 3 Jo fo 2 s Jc ls aw ex a 30 33 30 31 30 30 31 33 30 30 32 35 43 34 13 311 Response to the query above is Response Field RTU Bytes ASCII Bytes Header colon 1 Slave Address 0x03 1 03 2 Function Code 0X01 1 01 2 Byte Count 0x05 1 05 2 Data 1 0x53 1 53 2 Data 2 0X6B 1 6B 2 Data 3 0x01 1 01 2 Data 4 OxF4 1 F4 2 Data 5 0X1B 1 1B 2 Error Check CRC 2 LRC 3 Ending Code CR LF 2 If you look at the response to the query you can see that bit 20 through 27 makes one byte P20 is placed as LSB of Data 1 and P27 is placed as MSB of Data 1 Likewise we can acquire all of P20 through P56 and the leftover bits can just be disregarded 312 Function Code 03 Read Holding Registers Function Code 04 Read Input Registers This function code can read 1 Word 16 bits usually used for Counters Timers and Data Registers The following shows an example that reads Slave Address 3 s D Register 0 to 2 Query Field RTU Bytes ASCII Bytes Header z 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 CRLF 2 1 Word is has 2 bytes so we are going to get 6 bytes tota
249. with the DIP switch 263 Cls CLS Initialize the LCD and clear all layers Set a little bit of delay for the LCD to initialize cts 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 Cursor ON Default is OFF Csroff CSROFF Turn Cursor OFF Locate LOCATE xy X X axis position of LCD Y Y axis position of LCD Set the position of the text cursor After the CLS command the LCD defaults to position 0 0 LOCATE 1 1 Move cursor to 1 1 PRINT COMPILE 264 Print PRINT String Variable String String Variable When using variables constants String representation of the variable constant will be printed Print 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 COMPILE COMFILE Layer LAYER layertmode layer2 mode layer3 mode Layer1mode Set Layer 1 mode O off 1 on 2 flash Layer2mode Set Layer 2 mode 0 off 1 on 2 flash Layer3mode Set Layer 3 mode O off 1 on 2 flash Set the mode of the specified layer The flash mode will flash the layer at 16Hz Layer 1 and 2 are ON and Layer 3 is OFF when LCD is first turned ON Use this command to hide the process of drawing lines circles etc Set the layer OFF when drawing and set the layer O
250. you like START TON 11 100 1 H1 1 Erasing a Cell i HF 5 Enter SPACE key i ar C Erasing a Rung one line STAAT FELAY tA of H j END A rung is a row in Ladder You can press CTRL D to erase a rung This actually moves the rung to a buffer START RELAY it El END 2 352 Rung Recovery To recover an erased rung press CTRL U STAAT relay 1 wwe oue 2 H END Cell Insert and Delete START TON 70 100 1H 1 If you press the DEL key from the current position the cell is erased and items on the right are pulled one cell to the left START TON 70 100 1H 1 If you press the INS key from the current position a blank cell is inserted and items on the right are moved one cell right START TON 70 100 1 t 1 Rung Copy When the same style of rung is needed you can press CTRL A and it will copy the above rung except text will not be copied START TON 70 100 1 H c 1 Comments You can enter comments by adding an apostrophe THIS IS SAMPLE PROGRAM m Fs aL You can use a semi colon to drop to the next line For example This is Sample Program Date 24 Sep 2007 Comfile Technology THS 1S SAMPLE PROGRAM DATE 24 SEP 20 COMPLE TECHNOLOGY 354 LADDER BLOCK COPY and PASTE You can make a selection of a block to copy and paste to different parts of the LADDER program E CUBLOC stu
Download Pdf Manuals
Related Search
Related Contents
Smart-AVI HDS-2P video splitter Bula Sensor F2L.vp Recording Application for StudioLive Les défis de la gestion de classe au secondaire Fluorimètres et capteurs à diffusionECO Manuale d - Westen Italia Copyright © All rights reserved.
Failed to retrieve file