Home

What is CUBLOC?

image

Contents

1. 430 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 longer time to just code it We can save ourselves time by using CuCANVAS Please run CuCANVAS and press Add Form button on the upper right hand corner Enter a desired name for your new form Here we used NUMKEY Y ASS CuCANVAS File Edit Generate Tools View Help D c b cit Numkey Add Form Use tab key to select neighbor ones 1 Numkey a O e A a a 116 25 On the left side of CuCANVAS you will see a tool bar 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 O on the button means the menu number is O 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 431 Y Numkey cvs CuCANVAS File Edit Generate Tools View Help Dn H Gm Numkey Use tab key to select neighbor ones 4 o a O o A a a You can make the rest of the buttons and the keypad like the one shown below can be made in less than 5 minutes Y Numkey cvs CuCANVAS File Edit Generate Tools View Help JD o Ci m la Numkey Use tab key to select neighbor ones 1 Humkey
2. 116 25 ess x yf sef x 432 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 button that you have just created Simply copy Ctrl C and paste CTRL V to CUBLOC Studio and wala You have a menu in couple minutes For copying you can either press Ctrl C or press on the To Clipboard button at the bottom Real Time Code Generation ax BASIC Code for CUBLOC SUB NUMKEY FONT 0 0 STYLE 0 0 0 MENUSET 0 2 190 85 215 90 MENUTITLE 0 9 4 1 MENUSET 1 2 225 85 250 90 MENUTITLE 1 9 4 2 MENUSET 2 2 260 55 285 90 MENUTITLE 2 9 4 3 MENUSET 3 2 190 100 215 125 MENUTITLE 3 9 4 4 MENUSET 4 2 225 100 250 125 MENUTITLE 4 9 4 5 MENUSET 5 2 260 100 285 125 MENUTITLE 5 9 4 6 MENUSET 6 2 190 135 215 160 MENUTITLE 6 9 4 7 MENUSET 7 2 225 1 35 250 160 MENUTITLE 7 9 4 8 MENUSET 8 2 260 135 285 160 MENUTITLE 8 9 4 9 MENUSET 9 2 190 170 215 195 MENUTITLE 9 9 4 0 MENUSET 10 2 225 170 285 195 MENUTITLE 10 12 4 ENTER FONT 4 0 To Clipboard Save to File You can also use include files instead of copying and pasting for repetitive menu creations 433 Click Save to File button and save as an include inc file Save Your Design To BASIC Code EN aixi ASAD E APPNOTE S e amp ieckES CTO05 INC T2 08N ASS He BAD CUBLOC BASIC Code inc s HA HA h
3. END E i xa vil Modified Program 1452 Bytes Data 1 y CUBLOC studio d WHSH TSW cubloc 2 0 Wiadderlab4 lol xl Tee MAE CHOSD SA BS Sea SJ BRIAN FI BASIC F2 LADDER Ladder Mnemonic Const Device CB280 2 Dim A As Integer a a RN FROMLADDER Eo Bis mE De com 115200 None 8 a Loop FROMLADDER Debug Dec A CR Incr A Return Close Fix Right Side 220 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 221 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 RecvX interrupts using global flags A On RecvX interrupt occurs after data is received on the serial port AND stored into the receive buffer When the Onrecv is set to On then an interrupt can be received using the On RecvX command If the Onrecv is set to OFF then the code for On RecvX will not be executed if the interrupt occurs See also the On Recv command Set ONRECV1 On Set ONRECV1 Off 222
4. WSUB DWSUB WSUB si s2 d DWSUB si s2 d Subtract s2 from s1 and store 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 si O O O O s2 9 O O O d O O O START WMOV 100 DO B l ACTION WSUB DD 5 D1 1 D1 gets 95 in the above LADDER diagram 394 WMUL DWMUL WMUL si s2 d DWMUL si 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 ojo o o s2 o o lo lo d o o o START WMOV 1234H DO t 1 acmon WMUL DO 1234H D1 t 1 START DWMOY 123456H DO t 3 ACTION DWMUL DO 1234H D2 1 The result of 123456H 1234H is stored as 4B60AD78H in D2 4B60H AO AO 395 WDIV DWDIV WDIV si s2 d DWDIV si 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 si O O O 9 s2 O O O O d O O O ACTION WDIV DO D2 D4 ha t 1 ACTION DWDIV DO D2 D4 t 1 5678H 1234H 7 0C335H 299H A AO 396 WOR DWOR WOR sili s2 d DWOR si s2 d Do Logical operation OR on s1 and S2 and store result in d WOR is for
5. Use Set RS232 command to re set your baudrate and parameter during execution of your program 194 CB405 RS232 HOWTO The following is a table of 5V TTL signal pins of the CB405 Channel I O Port 5V TTL 1 P42 RX P43 TX 2 P8 RX P9 TX 3 P56 RX P57 TX The CB405 has a internal MAX232 that can be used to connect any of the 5V TTL signals to 12V level signals connecting the Channel 3 Now you can simply connect 12V RS232 signal to TXE and RXE Sout Sin Atn Vss PO input SCK P1 ony MOSI P2 MISO P3 P4 PWMO P5 PWM1 P6 PWM2 P7 RX2 P8 TX2 P9 P10 PWM6 P11 PWM7 P12 PWM8 P13 P14 P15 P22 AD6 P23 AD7 P24 P25 P26 P27 PWM3 P28 PWM4 INTO P29 PWM5 INT 1 P30 INT2 P31 INT3 AVdd 4 Vdd AD8 P32 AD9 P33 AD10 P34 AD11 P35 AD12 P36 AD13 P37 AD14 P38 AD15 P39 HCNT1 P47 HCNTO P46 P45 P44 TX1 P43 RX1 P42 SDA P41 SCL P40 TtITXE TtIRXE AVref Vss P48 P49 P50 P51 PWM9 P52 PWM10 P53 PWM11 P54 P55 P63 P62 P61 P59 The following is an example of 195 Out OUT Port Value Port I O Port number 0 to 255 Value Value to be outputted to the I O Port 1 or 0 Output 1 or O to the specified Port When you execute this command CUBLOC will automatically set the Port to output and output the Value set You do not need to use the Output command to set the Port beforehand when using this command
6. CUBLOC core module traditional PLC There are different models each with a unique program memory size and number of I O ports Please make a selection based on your product s requirement 20 CUBLOC Specifications CB220 CB280 CB290 Picture Program Memory 200KB Data 2KB BASIC 1K 2KB BASIC 1K 24KB BASIC 4KB Ladd 51KB BASIC 4KB Ladd Memory B Ladder Logic B Ladder Logic er Logic er Logic 55KB Heap EEPROM 4KB EEPROM 4KB EEPROM 4KB EEPROM 4KB EEPROM Program 36 000 inst sec 36 000 inst sec 36 000 inst sec 36 000 inst sec Speed 91 I O lines 5V TTL General aa lines SV mns lines 5V 33 input only 32 64 1 0 lines 5V TTL Purpose input output input output output only 26 input output I O configurable configurable input output configurable configurable 2 serial ports 2 serial ports 2 serial ports 4 serial ports Channel 0 RS2 Channel 0 RS2 Channel 0 RS232C Channel 0 RS232C 32C 12V 32C 12V 12V Channel 1 12V Channel 1 to 3 Serial Channel 1 TTL Channel 1 RS232C 12V amp TTL 5V RS232C TTL 5V Ports for 5V RS232C 12V amp Configurable Baud Configurable Baud Communic Configurable TTL 5V rates 2400bps to rates 2400bps to ation Baud rates Configurable 230 400 bps 230 400 bps 2400bps to Baud rates 230 400 bps 2400bps to 230 400 bps alla ADCs ADCs bit 16 channel 10 bit ADCs 3 Channel 16 6 Channel 16 6 Channel 16 bit 12 Channel 16 bit bit P
7. Please refer to the table below for PWM Channels and corresponding I O ports CB220 CB280 CB290 CT17X0 CB405 PWMO I O 5 o5 o5 1 0 8 1 O 5 PWM1 1 O 6 1 O 6 1 O 6 I O 9 1 O 6 PWM2 1 0 7 1 0 7 1 0 7 I O 10 1 0 7 PWM3 1 0 19 1 0 89 I O 11 I O 27 PWM4 I O 20 1 0 90 I O 12 T O 28 PWM5 I O 21 I O 91 I O 13 T O 29 PWM6 I O 11 PWM7 T O 12 PWM8 I O 13 PWM9 I O 51 PWM10 T O 52 PWM11 I O 53 206 Ramclear RAMCLEAR Clear CUBLOC BASIC s RAM BASIC s data memory can hold garbage values at power on Ramclear can be used as a type of garbage collector to clear the ram 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 before powering off 207 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 208 Rnd Variable RND O The command Rnd creates random numbers A random number between O 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 within CUBLOC this function is Pseudo Random it creates a random number based on the previous values When powered off and turned back on again the same
8. 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 304 ASCII type 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 blank space to indicate start and finish It uses 4 bytes of START SLAVE ADR FUNCTION DATA CRC END TI T2 T3 T4 1 Byte 1 Byte N Bytes 2 Byte T1 T2 T3 T4 CUBLOC supports MODBUS command amp Address 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 C 7000H D 8000H WP 9000H WM 0A000H WF 305 Devi
9. Modbus Receive routine include ModbusRTUrecv bas End Modbus Low Level include file include ModbusRTULib016 bas Please check our Forum on the internet www cubloc com for more Modbus ASCII and RTU examples and MODBUS BASIC include file downloads 317 MEMO 318 Chapter 10 Application Notes NOTE 1 Switch Input Let s say for example you are developing some kind of a machine 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 processes it to its assigned task We will make a START and STOP button that will light a lamp ON and OFF START ew Ls STOP KEY G 10Kohm 330ohm As you can see above PO and P4 ports will be connected to a pull down resistor resistor attached to ground 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 Filename startstopkey cul gt Const Device cb220 Dim a As Byte Do If In 0 1 Then a 1 If In 4 1 Then a 0 Out 14 a Loop When the switch is pressed a bouncing effect occurs from the switch s mechanical spring 320 The above picture shows how bouncing can confuse CUBLOC controller by bouncing up and down 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 r
10. CUT BT Output HIGH signal on Port 8 This is same as using command High 8 OUT 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 as default at power ON OUTPUT 8 Set Port 8 to output state You can also use HIGH LOW command to set to output state When using Output command HIGH or LOW state is not clearly defined We recommend the use of HIGH or LOW command to set to output mode LOW 8 Set Port 8 to output mode and output LOW signal 197 Outstat gt Variable OUTSTAT Port Variable Variable to store results No String or Single Port I O Port Number 0 to 255 Read the current outputted value for the specified Port This command is different from IN command in that 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 Length of Bytes to read 1 to 4 Read specified length of data from RAM Address 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 4 Write s
11. Field Header Slave Address Function Code Start Address HI Start Address LO Length HI Length LO Byte Count Data 1 HI Data 1 LO Data 2 HI Data 2 LO Data 3 HI Data 3 LO Error Check Ending Code Response Field Header Slave Address Function Code Start Address HI Start Address LO Length HI Length LO Error Check Ending Code RTU 0X03 0X10 0X70 0x00 0x00 0X03 0X06 OXD1 0X03 OXOA 0X12 0X04 0X05 CRC RTU 0X03 0X10 0X70 0X00 0X00 0X03 CRC Bytes NM HB ppp HH PRP REE Bytes NR ASCII colon Bytes NNNNNNNNNNNNNNN 313 Error Check If there is error in the data from the Master Slave will send back an error code Field Header Slave Address Function Code Error Code Error Check Ending Code Hex 0X03 0X81 0X09 ASCII Bytes colon 03 81 09 LRC CR LF NNNNNB There are the following types of error codes Code Error Name Explanation 01 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 314 MODBUS ASCII Master Mode There are no special commands to set CUBLOC to Master Mode for MODBUS communicatio
12. GOSUB label GOSUB label GOSUB label GOSUB label is received on RS232 Channel X 0 to 3 this command ON RECVX will automatically let the program jump to the specified label The processor will automatically check for receiving data and cause 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 Loop Channel 1 receives any data Infinite Loop DATARECV RTN If Blen 1 0 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 RECVX interrupt routine is being executed another RECVX 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 RECVX 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 execute a interrupt routine at every specified interval Set the desired interval in milliseconds and a label to jump to when interrupt occurs 192 On TIMER 100 Gosub TIMERTN Dim I As Integer I 0 Do Loop TIMERTN Iner p I is incremented 1 every second
13. Picture of CUBLOC Studio is shown above 22 There are PLCs on the current market that supports both LADDER and BASIC These PLCs do not multi task and run Single 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 affect the Ladder Logic of the program CUBLOC covers these weaknesses through its multi tasking features guaranteeing accuracy and precision of timing Unlike many BASIC processors on the market today CUBLOC supports Ladder Logic and multi tasking with BASIC language CUBLOC has a multi tasking structure that runs BASIC and LADDER simultaneously that allows accurate LADDER scan timing and still process BASIC You even have a choice of simply using BASIC or LADDER by itself SINGLE TASK MULTI TASK LADDER BASIC LADDER BASIC LABDER BASIC CUBLOC is a brand new type of industrial controller By being able to do things that traditional PLCs couldn t through BASIC language we have expanded the horizons of both PLCs and BASIC micro computers Unlike some BASIC controllers out on the market today 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 becomes a walk in the park With 32 bit IEEE floating point math support and MODBUS ASCII RTU support the user will find tha
14. 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 223 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 outputting at power ON You must use Set OUTONLY ON command to set the CB290 CT1720 output ports to output status Const device cb290 Set outonly on Low 24 10021 TUTX1 20022 THURXA1 30023 AVref bad m CRECEN EN SS P0 50025 P8 D En Input ohly SCK P1 6 26 P9 i ES 70027 P10 1 ai d MISO P3 8 28 P1 ADC3 E P35 P4 9 29 P12_ADC4 P36 d PWMO P5 10030 P13 ADC5 P37 Output Only PWM1_P6 11 31 P14_ADC6 E P38 SCL CUNET SDA CUNET PWM2_P7 12032 PIS ADC7 Solas P39 P56 13 33 P64 20052 P48 P57 14 34 P65 CA EE P58 150035 P66 ogeroo 2358323 P50 P59 160 36 P67 Zaooaa 0000 P51 P60 17 37 P68 TINO 5923 P52 P61 180038 P69 595355 BOGS P53 P62 19 39 P70 111302 e P54 P63 200640 P71 e 00 e P55 ooroo oro 33533 38858 SHOR N MON DOT ON SSANANRR RRS SOD AAA 1 0 28 E
15. Declare as SINGLE CONST WRTTIME 10 Declare as Byte CONST MYROOM 310 Declare as Integer since it s over 2997 CONST MSG1 ACCESS PORT Y Declare as String CON Another way of CONST The Command CON can be also used to declare constants in the following way PI CON 3 14159 Declare as SINGLE WRTTIME CON 10 Declare as Byte MYROOM CON 310 Declare as Integer MSG1 CON ACCESS PORT Declare as String 90 Constant Arrays By using constant arrays the user is able to store a list of numbers before the program begins By using constant arrays the program can be simplified as shown below Const Byte DATA 31 25 102 34 1 0 0 0 0 0 65 64 34 I 0 A DATA1 1 D SUO c STAI As cP ale rani A DATA I M SEOrE 2o DNIA Const Byte DATA1 CUBLOC SYSTEMS String data can be store 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 Whole and floating point numbers can be used as shown next CONST INTEGER DATA1 6000 3000 65500 0 3200 CONST LONG DATA2 12345678 356789 165500 0 0 CONST SINGLE DATA3 3 14 0 12345 1 5443 0 0 32 0 For multi lines of constants following ways can be used 1 CONSH Aus DAWA Gil 25 102 835 41 0 0 O O 0 GS GA 3 12 123 94 200 0 123 44 39 120 239 7 ahs Xin 207 Aoi
16. Final Size Large Compact If you are currently using a traditional PLC please review our product 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 fractional cost 29 Development Environment To use CUBLOC the user may use a Windows XP 2000 or 98 operating system equipped computer If you would like to use it in Linux Unix Macintosh environment you will need to install a virtual machine software of some type such as VMware etc that allows 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 with the PC When 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 as many times as he or she wishes Cubloc core module with Study board 30 Download and Monitoring 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 progra
17. Overlay OVERLAY overmode overmode Logical Mode O or 1 and 2 xor Paint PAINT x y 448 Pause PAUSE value 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 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
18. 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 GPRINT command can be used LOCATE 1 1 Move to position 1 1 PRINT COMFILE DEC I 253 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 S W CUNET RS232 5V RS232 CLCD can also communicate using RS232 There are two RS232 connector one for 3 pin 5V level signals and the other for 4 pin 12V level signals S A ase oes e G CUNET RS232 5V RS232 Use the CLCD DIP switch to set the I2C slave address The 4 DIP switch is not used DIP Switch RS232 Baud rate I2C Slave Address TAg e HEN 2400 0 123 min 4800 1 123 Naa 9600 2 73 a tm 19200 3 123 On E uu 28800 4 123 ra 38400 5 7T 9 3 e 57600 6 423 pzs 115200 7 254 One of CUNET or RS232 communication can be used If both are connected please make sure when one of them is working other is not The following is CLCD command table Command Example Byte Execution Explanation hex S Time ESC C 1B 43 2 15mS Clear screen A i5ms delay must be gi
19. System Clock RTC uses the processor s system clock and there can be slight time difference 1 during a 24 hour period Const Device CB405 xe Debug Terminal Port Baud Rate Party DataBts ery y a Dim i As Integer cow 115200 None s om ells Timeset 10 58 Timeset 13 254 Do i Time 10 Debug Goxy 0 0 dec4 i Cr Debug Goxy 0 1 dec4 Time 13 Delay 100 Loop T Fix Right Side Address 13 will increment its value by 1 every one second similar 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 241 Timeset TIMESET address value address Address of time value 0 to 6 value time value 0 to 255 Use TIMESET command to store new time values Address Value Range Bit Structure 0 Second 0to59 2 4 digit place 1 digit place 1 Minute 0to59 2 digit place 1 digit place 2 Hour 0 to 23 and digit 1 digit place place 3 Date 01 to 31 2nd digit 1 digit place place 4 Day 0to6 1 digit place 5 Month 1 to 12 10 1 digit place 6 Year 00 to 99 294 digit place 1 digit place The following is an example code showing how to set new time and outputting current time to the debug window Const Device CB290 Dim I As Byte Timeset 0 0 USSG Timeset 1 amp H32 Min Timeset 2 amp H11 DET Timeset 3 amp H1 Date Timeset 4 amp H5 Day of
20. Usepin 2 Qut Usepin 3 Qut Usepin 4 0ut Usepin 5 Out Relayout Usepin 6 Qut Soloutl Usepin 7 ut Motorl Usepin 8 Qut Usepin 9 Out Countreset 0 Input 0 DGD Adno TEGi Adi 11 Adin 75 DGB COUNT O Loop Load Save As Replace Basic Code 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 357 Usage of Ladder Register With this feature the user can see alias 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 IS T Jc JD 358 Register Expression CB220 CB280 Registers The following is a chart that shows CB220 CB280 Registers Register Name Range Units Feature Input Outp
21. d 9zde e Zrd gsde e tld EIE 1zd e vd 65d e S d 5 o 8Zd e e pra 09d e e 9 d MET 62d e e Std 19d e e ddd mim 0 d e e 9rd Z9de e Bld Lede e td 9d e e 6 d LES Zed e e 8bd pode e 08d w al E d e e 6rd S9de e 18d om vede e 09d 99d e e Zed Sede e 1d 19d e e 8d 9Ede e ZSd 89d e e 8d 1 d e e Sd 69d e e Sed 8t de e Sd 04d e e 98d 6 d e e SSd bide e 8d OIN 9 N OIN e 9 N CN 9 N 5 N Ave 9 e DIN PPA e ssp Avo essa ST 79 ppAe essa Ny e ess The 82 I O ports on the CT1720 can be accessed using the connectors Input Only Output Only A D Input or I O Total 415 Comfile RCABLE J1 22 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 Connector Name 1 0 Port Block Explanation PO I O ADCO P1 IO ADC1 P2 I O ADC2 J12 P3 1 0 Block O ADC3 33 P4 1 0 ADC4 P5 I O ADC5 P6 I O ADC6 P7 1 O ADC7 P8 IO PWMO P9 IO PWM1 P10 lo PWM2 J13 P11 1 0 Block 1 PWM3 33 P12 1 0 PWM4 INTO P13 1 O PWM5 INT1 P14 IO INT2 P15 IO INT3 J14 P16 IO HIGH COUNT INPUT 0 P17 IN HIGH COUNT INPUT 1 P18 OUTPUT Internally connected to Piezo BUZZER Cannot be accessed from Ladder P19 to N C P23 P24 to 31 OUTPUT Block 3 8 Output Ports J2 P
22. t 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 and sub routines in this case 403 INTON INTON s d INTON is same as WMOV command except it can cause an interrupt in BASIC part of CUBLOC Usually P M F S C T D Constants Registers s Source O O O O d Destination O O O PO INTON 3 00 yx SL 1 P1 INTON 2 00 1 404 TND TND is a conditional exit command When the user wants to abort Ladder scanning during operation TND can be used F29 P2 1 HI J PO TND 2 HH 1 F30 P4 s HI C END 4 t 1 When PO turns ON Ladderscan will abort SBRT CHK RTN r 1 PO M2 d Pi TND 1 P2 M3 1 RET A 1 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 405 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 Fi Always ON P2 Turn on 1 SCAN time at POWER UP Set Ladder On
23. 157 di Loop 322 If you connect CUNET to CSG and execute the above program the CSG module will show numbers that will count up 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 lt Filename keypadnum cul gt 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 IEIS TE Then I KEYTABLE I Csgdec 0 I EDG LE 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 lt Filename num4in cul gt Const Device CB280 Set T2098 Dim I As Integer Dim K As Integer Dim M As Integer EMO Const Byte KEYTABLE 1 4 7 10 2 5 8 0 3 6 9 11 12 13 14 15 Do I Keypad 0 OSEE onem I KEYTABLE I If I lt 10 Then K K lt lt 4 Ke Kee Csghex 0 K End If WAIT UNTIL KEY DEPRESS 323 Do While Keypad 0 255 Loop M Bed2bin K Debug Dec M CR pixel ARE Loop When there is no input the returned scancode is 255 By using Do While keypad 0 lt 255 we will wait until a ke
24. 1720 Debug CT1720 module used endif else may only be used ONCE in a if statement You may only compare constants declared with 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 it 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 blocks like shown here ifdef LOWMODEL LOW 0 elseifdef HIGHMODEL HIGH 0 else LOW 1 endif 100 ifndef name endif ifndef is exactly the opposite of ifdef directive If a constant has not been defined the statements inside if 4 endif block will be compiled otherwise statements are discarded define LOWMODEL 0 ifndef LOWMODEL LOW 0 endif elseifndef and else may be used for more complex blocks like shown here ifndef LOWMODEL LOW 0 elseifndef HIGHMODEL HIGH 0 else LOW 1 endif Finally the directives may be mixed as shown below dif MODELNO 0 LOW 0 ttelseifdef HIGHMODEL HIGH 0 else LOW 1 endif An exception is that if may not be used inside another 7if 101 To use LADDER ONLY If you do not need to use BASIC you can just program in
25. 3 Pay 35 7 P40 uo 1 pwmo Ps p t5 E sp ptt PWM1 P6 E 16 e 33 E3 P10 Fe NR amp N N ANN R h 8 R8 8 5 8 uUguumgumuuuuuHuuuuu Ege esssrsesctert EH 25388 BE Pd zz E boo ON zz zc 83 5V e VDD OSCOUT O vss P 18 4320MHz OSC ILLATOR Example 3 Wn CB280CS Main Chip A o E 18 4320MHz Oscillator CB280CS Sub Chip 59 MEMO 60 Chapter 3 CUBLOC STUDIO Editor Compiler CUBLOC STUDIO Basics After installing CUBLOC STUDIO and executing it you will see the following screen CUBLOCstudio untitled cul DER File Edit Device Run Setup Help B amp u d 428 mu BE x FI BASIC F2 LADDER Ladder Mnemonic amp CUBLOCstudio untitled cul 1 DER Eile Edit Device Run Setup Help Dang XARMA p mm mE FI BASIC F2 LADDER Ladder Mnemonic PLC ar ur al I 52 PARA am el Z 55 1 0 10 10 1O F3 F4 F5 F6 Pt F8 Fg Fu F12 NOT END Insert Delete Undo Copy Wizard 31 32 33 34 35 36 37 38 Modified Program 9602 Bytes Data 101 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 Look in Am Documents y er
26. 6 P51 68 I O PWM CANNEL 9 P52 69 IO PWM CANNEL 10 P53 70 IO PWM CANNEL 11 P54 71 IO P55 72 IO P56 80 I O RX3 TTLRX channel 3 P57 79 I O TX3 TTLTX channel 3 P58 78 IO 7 P59 77 1 O P60 76 IO P61 75 IO P62 74 IO P63 73 IO 53 How to connect Battery to CB290 CB405 When a super capacitor is used for VBB of CB290 CB405 a length of couple days to couple weeks can be backed up once powered OFF CB290 CB405 consumes about 15 20mA of current when idling For longer backup period a battery can be used Using a battery with large capacity could yield up to 1 year of data backup Make sure to use a diode as shown below for using batteries VBB CB290 i p Power Features Operating Voltage 4 5V to 5 5V Operating Clock 18 432MHz I O Port Source Current 20mA I O Port Sink Current 25mA Operating Temperature 40 to 125 Degrees Celcius Maintenance 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 block noise please set all pins not used to input and set all outputs to Low when not being used All I Os are set to input as default at power ON When not us
27. 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 global is set to ON for a specific interrupt then an interrupt can be received using the ON INTx command If the global is set to OFF then the code for ON INTx will not be executed if the corresponding external interrupt occurs See also the SET INTx command which controls external interrupts to fire Set ONINTO On Set ONINT1 On Set ONINT1 Off Set ONINT2 Off Set ONINT3 On 219 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 CUBLOC studio d WASH 2W cubloc 2403 Wladderlab4_1 cul T T O CHAD see SIO TENH jeu A ECR M ates FI Basic F2 LADDER Ladder Mnemonic PLC HEE MESES Wizard Fa Fa es re Ff Fe peer Hi e ien Be Fn INTON 300 1 A 5 bl 2 FO 1O Insert Delete 40 1O Undo Copy ici Fa
28. CUTOUCH is a complete integration of a Touch panel graphic LCD and CUBLOC embedded computer In the recent years there has been increase of use of touch screens in the industrial field But to use one the user required connecting to a PLC and learning complex methods in order to use it In addition cost of touch screen has been very expensive Our CUTOUCH is a new type of embedded controller that integrates Touch screen PLC and graphic LCD all into one The biggest difference between CUTOUCH and other touch screens is that it s the only Visual Touch screen controller that can be programmed with BASIC and LADDER in the world today BASIC language can be used to draw graphics and print characters to the LCD and receive input from the touch screen before processing the x and y positions Sensor input through I O turning relays on off AD DA conversion and RS232 communication are very easy to implement in comparisons to traditional non BASIC PLCs With the Ladder Logic side of CUBLOC the user may do sequential processing and real time logic processing as in traditional PLCs CUTOUCH has a flash memory for BASIC and LADDER programs A serial port can be used to download and debug After downloading is done it can run in a Stand alone state If you are thinking about developing a device that uses a touch screen please review CUTOUCH and we guarantee you that you will ultimately spend more time designing and less time developin
29. J Hread 0 4 Debug Hex J Cr Delay 100 Loop 169 High HIGH Port Port I O Port number Set the Port to HIGH state This command sets the Port to output state and outputs HIGH or 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 whereas if it S set to Low the port is internally connected to VSS 170 I2Cstart I2CSTART Set I2C SDA and SCL to Start mode After this command SDA and SCL go LOW UN SCL EN Pg START I2Cstop I2CSTOP Set I2C SDA and SCL to Stop mode After this command SDA and SCL go HIGH 171 I2Cread Variable I2CREAD dummy Variable Variable to store results No String or Single dummy dummy value Normally 0 Read a byte from the I2C Ports set by SET I2C command Use any value for dummy value A I2CREAD 0 SCL SDA This command will send back acknowledge ACK signal back to the slave I2C device After reading a byte a SCL pulse will be send while SDA is kept LOW This will send back an acknowledge signal to your I2C slave device 172 12Creadna Variable 12CREADNA dummy Variable Variable to store results No String or Single dummy dummy value Normally 0 Same function as IZCREAD command without acknowledgement A I2CREADNA 0 SCL SDA 173 I2Cwrite Variable I2CWRITE data Variable Acknowledge 0 Acknowledg
30. Menutit Menuset Menutit Menuset Menutit Menuset Menutit Menuset Menutit I 0 Do Loop GETTOUCH 0 2 165 50 195 75 e 0 11 4110 12 209 390 035 18 Li A UA 245 50 275 75 y Te 65 85 195 110 raa 205 85 235 110 PASS 245 85 275 110 d T 65 120 195 145 jd Pn 205 120 235 145 jd THE 245 120 275 145 AUOD 65 155 195 180 2 9 11 4 0 10 2 205 155 275 180 e 10 17 4 ENTER 000 200000 50 00 N00 N c0 NO0 JhF 20 N20 Po NO C IND IND IND 429 TX1 Getpad 2 amit Getpad 2 If Menucheck 0 TX1 TY1 1 Then lt lt 4 Pulsout 18 300 Elseif Menucheck 1 TX1 TY1 Then lt lt 4 d 2 Pulsout 18 300 Elseif Menucheck 2 TX1 TY1 Then lt lt 4 E3 Pulsout 18 300 Elseif Menucheck 3 TX1 TY1 Then lt lt 4 4 Pulsout 18 300 Elseif Menucheck 4 TX1 TYl Then lt lt 4 5 Pulsout 18 300 Elseif Menucheck 5 TX1 TY1 Then lt lt 4 6 Pulsout 18 300 Elseif Menucheck 6 TX1 TY1 Then lt lt 4 stall Pulsout 18 300 Elseif Menucheck 7 TX1 TY1 Then lt lt 4 toG Pulsout 18 300 Elseif Menucheck 8 TX1 TY1 Then lt lt 4 I 9 Pulsout 18 300 Elseif Menucheck 9 TX1 TY1 Then lt lt 4 Pulsout 18 300 Elseif Menucheck 10 TX1 TY1 1 Then 0 Pulsout 18 300 End If Locate 3 3 Print HEX4 I Return The final value I is stored as BCD code you can use BCD2BIN command to convert back to a binary number I I
31. P27 180 P13 BLOCKO P3 08 170 P12 BLOCK 1 P4 g9 160 P11 P5 10 15H P10 Pe O 1 BENI 141 P9 P7 012 130 P8 sour 16 617 vob T TTETAS SIN 20 18 vss EX TIER ATN 30 19 RES DD AVREF vss 46 20 wc NIC Pas Po 5 21 P16 gu Bss Pi 60 022 P17 Fas i 3 p2 7 23 Pis pze P29 0 P3 8 24 p19 2 Rar land P4 90 25 P20 Par P32 P5 100 26 P2 Pag P33 P6 10 27 p22 pag pet P 120 O 28 P23 5 pas P35 4 P8 130 O 29 P15 pag P36 P9 140 30 Pia PAZ PST 1 P10 150 31 P13 PA Pag P11 160 32 P12 Pao pag 133 Byteout BYTEOUT PortBlock value PortBlock I O Port Block Number 0 to 15 value Value to be outputted between 0 and 255 Output the value to a Port Block 8 I O Ports are collectively called as a Port Block Port O to 7 is Block O and Port 8 to 15 is Block 1 Depending on the model of CUBLOC the Port Block number can vary When using this command all I O Ports within the Port Block are set to output and the value is outputted Byteout 1 255 GEPUT 20 CO POTE oce Ports 8 through 15 are set to HIGH I O Port 1 only supports input Therefore BYTEOUT O 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 Without affecting the RS232 receive buffer the command CheckBf can be used to check the current data in the receive buffer Although it will read what is in the
32. S 0 Secon 0 to 59 2 4 digit place 1 digit place d 1 Minute Oto 59 2 4 digit place 1 digit place 2 Hour 0 to 23 2 digit place 1 digit place 3 Date 01 to 31 2 4 digit place 1 digit place 4 Day 0to6 i digit place 5 Month 1 to 12 2 digit 1 digit place 6 Year 00 to 99 2 4 digit place 1 digit place Please refer to the chart below for day of the week and its corresponding numerical value Sunday Monday Tuesday Wednesday Thursday Friday Saturday OY U1 C N O 240 System clock RTC This command will allow you to use the system timer of CUBLOC as an RTC You can use TIME and TIMESET functions to access the following addresses Address Returning Value Range 10 Seconds 0 to 59 11 Minutes 0 to 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 O At power ON all Addresses are set to 0 TIMESET command can be used to set the time at 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
33. needs you may return it for a refund Comfile Technology will refund the purchase price of the product excluding shipping handling costs This does not apply if the product has been altered or damaged Copyright amp Trademarks Copyright 2006 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 Data Book may be changed and updated without notice For the addition of new features information can be updated without notice Comfile Technology Inc is not responsible for any actions taken outside the explanation of this data book 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 CublocStudio v 2 0 X 1 You can simple upgrade to CUBLOC STUDIO V2 X to use new features of CUBLOC and CUTOUCH New Functions
34. 2 4 597366683 942 0921 6 4580592903 938 osde 3_14 963291365_ 935 4 545454545 931 572 8 e52075913 p27 165 6 4508146964 p23 e778 3__l4 488663246 _ p19 seins 915 Bossi aeae pui 723 3 4 426824842__ 907 7404 3 44 405067304 Bn 4382731022 898 s102 le 3s9813102 603 o533 7 4 336311306__ ss8 o269 8 4 312224084 se3 018 0 4 287550592 878 777 la 262290722 873 5548 3 Ja 236445118 868 3606 1 3 914475937 802 3472 1 3 8s1i948015 795 3343 7 848917708 788 220 8 815397329 781 3103 1 3 781399998 774 2990 2 3 746939622 767 327 328 56 57 58 59 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 239 240 241 242 243 244 245 246 247 248 249 250 2882 1 712030877 760 753 746 738 1220 4 2 748157207 563 1181 9 2 7084025 555 1144 8 2 668747011 547 538 l1074 5 2 589812422 530 522 1009 2 2 511506263 514 506 948 5 2 433973277 498 919 8 2395539544 491 892 0 2357349316 483 865 3 2 319418079 475 p39 4 2 281760687 467 814 5 2 244391354 460 790 4 2 207323646 452 767 1 2 170570465 445 44 7 2 134144055 a37 723 0 2 098055989 430 702 0 2 062317177 22 681 8 2 026937858 415 1 99192761 408 43 3 1957295352 0i 394 387 1 855745964 380 373 367 360 1 726067674 353 33 33 32 130 o 1549466822
35. 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 that much data memory space SET DISPLAY 0 1 19200 50 Set Baud rate to 19200 and send buffer to 50 SET DISPLAY command can only be used once at the beginning of the program Method O Use CuNET CuNET is a type of I2C protocol that is part of CUBLOC For CB220 use I O Port 8 Clock and Port 9 Data souT O 1 24 0 VIN SIN 12 230 vss ATN 13 22 RES vss 14 21H voD Pos 200 P15 P1 ge 190 P14 p27 180 P13 P3 j8 17H P12 P4 9 16H PH Ps 10 150 P10 P6 O 11 140 P9 SDA P7 O 12 130 P8 SCL CuNET can be used with displays that support it CuNET does not used 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 the I2c for displays only ONE device may be attached 252 Cls Initialize the LCD and clear all layers Set a little bit of delay for the LCD to initialize CLS DELAY 200 Csron Turn Cursor ON Default if OFF Csroff Turn Cursor OFF Locate LOCATE x y X X axis position of LCD Y Y axis position of LCD Set the position of the text layer After the CLS command the LCD defaults to position 0 0 LOCATE 1 1 Move cursor to 1 1 PRINT COMFILE Print
36. 32 31 31 30 00 lo 145764577 3o 29 29 29 28 2 0 137234968 28 NTC THERMISTOR READ TABLE y 10K DIODE TYPE Const Device cb280 Const Integer TH TABLE 992 990 989 987 985 983 981 979 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 8 3 868 862 857 851 845 839 833 827 821 815 808 802 795 788 781 774 767 760 753 146 738 731 723 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 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 Filename ntcth cul gt By using the TADIN command for AD conversion CUBLOC will automatically calculate the average of 10 A D conversion reads By using this command you get more precise results The sample program shown here will be able to sense between O to 100 degrees For larger range you can simply modify the code The formula for acquiring A D conversion value from the R T table is as follows x THR 1000 THR THR is the resistance value 1000 is for 1K Ohm resistor and 5 is for 5 volts The 10 bit A D converter of CUBLOC will return a value between O and 10
37. 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 I O number P89 82 I O PWM Channel 3 P90 95 IO Block 11 PWM Channel 4 INT Channel 0 P91 96 I O 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 TX1 41 RS232 Channel 1 12V Data Output RX1 42 RS232 Channel 1 12V Data Input AVDD 43 ADC Power TTLTX1 61 RS232 Channel 1 5V TTL level Data Output TTLRX1 62 RS232 Channel 1 5V TTL level Data Input AVREF 63 ADC Reference Voltage 49 The CB290 output only pins P24 to P55 are in high impedance state High Z at power ON You can use Set Outonly On to set them all to output states Set Outonly On This command only works with CB290 rev B The revision number is written on the bottom side of the CB290 module A fake port 88 was made to make the Set OUTOnly command which is same as LOW 88 Therefore when using the CB290 Rev B you may not use port 88 P88 for other purposes Please do not use USEPIN 88 when using with LADDER 4109061 TUTX1 X1 429 062 TURX1 10e e 30 110031 120032 130033 Output Only 5900
38. Arc Tangent value SINH COSH TANH Return Hyperbolic Sine Hyperbolic Cosine and Hyperbolic Tangent values A SINH B Return Hyperbolic Sine value of B A COSH B Return Hyperbolic Cosine value of B A TANH B Return Hyperbolic Tangent value of B SQR Return Square Root value A SQR B Return square root value of B EXP Return EX A EXP X Return E LOG LOG10 Return LOG or LOG10 value A LOG B or A LOG10 B Tips For 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 B 1234 A ABS B Return B Debug Dec A Print 1234 FABS Return Absolute value for Single type Dim A As Single B As Single B 1234 0 A FABS B Return B Debug Float A Print 1234 00 FLOOR Round down to the whole number Dim A As Single B As Single B 3 14 A FLOOR B FLOOR 3 14 gives 3 Debug Float A Print 3 0 111 Type Conversion Type conversion can be used to convert the variable to desired bit representation HEX Converts the variable to hex 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 HEX5 A if A is 123ABC 23ABC is printed first character is cut s CUBLOC studio d cubloc_test format cul File Edit Device Run
39. 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 into 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 reading garbage data Const Device cb280 Dim A 10 As Byte Opencom 17115200737 507 10 Set Until 1 8 On Recvl Gosub GOTDATA Do Do While In 0 0 Loop Wait until press button Connect PO PUES TERRA CUBLOC CE Do While In 0 1 Loop Loop GOTDATA Geta 1 A 8 Debug A 0 A 1 A 2 A 3 A 4 A 5 A 6 A 7 Return CB280 TTLRX TTLTX 9 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 Same as GETA command except it will stop reading data at the StopChar even if there are data left to read set by the Length If StopChar is not found then it will operate just like a GETA command StopChar is stored into the String Variable You can use SYS 1 command to read of bytes read afterwards 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 Varia
40. CUBLOC STUDIO 62 Cubloc Study board 1 Schemetic da 295 CuCANVAS een 431 CUTOUCH een 410 CuTOUCH I O Ports 415 D DOTSIZE 4s set AISISo 273 Double Word size 387 DOWN Counter 383 DP exis 115 117 DPRINT 2x21 ated seedaats 271 DS1620 Leeds 335 DTZERO ener 148 DWADD enm 394 DWAND nnnm 399 DWDEG detects desudecddeseest onda 393 DWDIV voii tes rine 396 DWING zn iie eee iere secet 393 DWMONY escitas 389 DWMUL 2 eres 395 DWOR 25st 397 DWROE teste 400 DWROR reireihepeanu nhe tee pnr 401 DWSUB nte Ier 394 DWXGEHQG eiecit eet 390 DWXOR iiece hioc dl 398 E EADIN suite ria 149 EEPROM 152 297 340 EEREAD 151 167 168 EEWRITE 152 167 168 EKEYPAD 12 nnt 153 BL FIL bee iiio recreo nee 269 ELIPSE niei 269 EXP aiite di 110 express binary and hexadecimal EMERICUS 388 F FABS dani 111 Flash Memory ee 40 FLO A Tacita eee etes 114 FLOOR ociosa iones 111 EMM ind 391 FOND riostada orn aas 264 FOR NEXT irine aiir 154 FREQOUT 157 234 235 function code sss 307 Function Relays 361 G GET A 159 GETA T Eee 160 161 162 Integer eene 79 GETSTR 2 ne 163 164 Internal Relay 362 GHB3224 2 rein 257 interrupt eee 103 G
41. Constant can be used s SETOUT O O O RSTOUT O O O 375 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 P5 F t E P6 oa P1 B At SCAN P6 6 1 SCAN MCS MCSCLR The command MCS and MCSCLR allow for the Ladder Logic between MCS X and MCSCLR X to be executed when turned ON If MCS is OFF the Ladder Logic in 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 MCS 0 7 MCSCLR 0 t 1 In the above example when MO turns ON Ladder Logic between MCS 0 and MCSCLR are executed normally If MO is OFF P5 and P6 will turn OFF MCS number can be used from 0 to 7 MCS number should be used from 0 increasingly to 1 2 3 etc MCS 1 must exist inside MCS O and MCS 2 must exist inside MCS 0 Likewise up to 7 MCS blocks can be used When MCS 0 is OFF all MCS inside MCS O will turn OFF When MCS turns OFF all outputs within that MCS block will turn OFF Timer will be resetted Counter 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 def
42. Cubloc_Testi bmpdown cul C Cubloc_Test tata cul Exit Menu New Open Ladder Import Save Save As Save Object Print Ladder Print Basic Print Setup Download Object file Basic Section Ladder Section Last 4 Files Edited Exit from Device Menu Explanation Create new file Open file Import Ladder Logic part of a CUBLOC program Save current file Save current file under different name Save current program as an object file Use this to protect your source code Object file is strictly binary format file so others cannot reverse engineer it You can use Download from Object File to download your object file to CUBLOC Create object files for internet downloading with CuMAX or CuMAX Server Print Ladder Logic Section only Print Basic Section only Setup Printer for printing Ladder Logic Section Download an Object file to the CUBLOC module Switch to Basic Section for editing Switch to Ladder Logic Section for editing View last 4 files edited Exit CUBLOC Studio Or press F1 Or press F2 If Const device statement does not exist in your source code Device Menu will create a Const device statement at the very beginning of your source code replaced 66 If it exists already the Const device statement will simply be Run Menu Run Ctrl R Reset Ladder Monitor on BASIC Debug Terminal Time Chart Monitor clear CUBLOC flash memory Write enable Fuse off View Relay Usage C
43. Debug st Cr For A 0 To 12 If st a A Asc Then st a A Asc z End If Next Debug st Cr I Fix Right Side With string arrays you may not use this feature Dim st 10 As String 3 84 About Variable Memory Space In the case of 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 The 80 bytes are used for DEBUG command Sub and Function routines and interrupt routines use up data memory space Of the available 2048 bytes about 1800 bytes can be used for global variables The more Sub Function routines you use you will have less memory available for variables and constants When the user uses buffers with command SET DISPLAY or OPENCOM the data memory will lose that much amount of memory space to use for variables Initializing Memory CUBLOC BASIC data memory is not cleared at POWER UP The user must 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 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 D
44. 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 can use used to set desired bit of 0x00000000 to 1 and return a 32 bit value i ded OR Ue E ORT OE Result NCD 0 NCD 1 Result NCD 2 Result NCD 3 Result NCD 4 Result NCD 5 Result NCD 6 Result NCD 7 Result is ls is is als is is is 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000 lt CUBLOC studio d cubloc_test unary cul File Edit Device Run Setup Help Fan g XE CAS gt m FI BASIC F2 LADDER Ladder Mnem Const Device CB280 Dim A As Long 4 10 Debug Dec A Cr A Not 1 Debug Dec A Cr A Ned 4 Debug Dec A Cr A Ded 15 Debug Dec A Cr un Terminal Baud Rate Parity Data Bits BTE con 115200 one e arx Close Fix Right Side 185 Nop Nop This command does a no operation command command cycle time It simply takes up one Low 8 Nop High 8 Output very short pulse to port 8 About 50 micro Sec Nop Low 8 186 On Int ON INTx GOSUB label x 0 to 3 External Interrupt Channel This command On Int must be called before accepting external interrupt inputs CUBLOC has 4 external interrupt Ports The interrupt Ports c
45. Function you need parenthesis around the parameters Parenthesis is required even when there is 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 75 Subroutine Position Subroutines must be created after the main program To do this simply put End at the end of your main program like shown here End is only required if you have subroutines Dim A As Integer LOOP1 A A 1 Debug DP A CR DELAYT IME 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 End Sub DEF B as Byte End Sub Function GHI C as Byte End Function End command is used to differentiate between 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 Function may use any data type as parameters and return values Dim A 10 As Integer Function ABC A AS Single as Single End Function Return Single value Y 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 Functio
46. KEYIN removes bouncing effect before reading the input You can use KEYIN only when inputting LOW ACTIVE as shown below For inputting HIGH ACTIVE please use KEYINH When there s input Keyin will return 0 and 1 when there isn t If you use 10 for deboucing time CUBLOC will check input for bouncing for 10 ms Bouncing usually lasts around 10ms so our recommendation is 10ms for most applications A KEYIN 1 10 Read from port after removing bouncing effect we Bouncing effect 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 HIGH ACTIVE inputs For LOW ACTIVE inputs KEYIN command must be used When there s input Keyinh will return 1 and 0 when there isn t 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 Keypad to read input from keypad A Port Block can be used to read a 4 by 4 keypad input Keypad input can be connected to the lower 4 bits of the Port Block and keypad output can be connected to higher 4 bits of the Port Block 12 Please refer to the below diagram 14 ty N x4 Ay 02 47 s as 4 4 A 1215742 aS A 2l ez vf p 121081 N
47. 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 367 Things to Remember in LADDER Input symbol must be placed at the very left side of the Ladder Logic PO P5 1 PD P5 E Output symbol must be placed at the very right side of the Ladder Logic CuBLOCstudio untitled cul sini x File Edit Run Setup Help Bead X Ga a gt m 3l F1 BASIC F2 LADDER 368 Identical outputs must not collide PD P5 J PO P5 1 C You may not use more than one vertical line as shown below More than 1 division will give compile error po PI P5 nali J P2 P5 dh P7 Po Pl P5 H HH H p PB E EM P P3 p Li ES 369 Ladder Logic moves from top to bottom Po Pi PO T j P5 FHI O P5 P Pl I FH QUA Function Register can not be on the left side of the Ladder Logic When a Ladder Logic becomes complex simply divide them so you can see and understand them better as shown below P Pl P5 nal C P2 Pb i P3 P7 PO PI P5 1 EHI C PD F2 PE rH FJ P3 P7 E 370 ladder instructions Ladder low level instructions Command Symbol Explanation LOAD E Contact A Normally Open LOADN E Cont
48. None None Yes None 40 CB220 CB220 is comes as a 24pin DIP type package internal 5V power regulator It has 16 I O ports and an SOUT O 1 VIN 5 5V 12Vinput SiN O 2 VSS ATNO 3 RES VSS d 4 VDD ss_POO 5 P15_HCNT1 Input only SCK_P10 6 P14_HCNTO MOSI_P2 O7 P13 MISO_P3 D 8 P12 P4 o9 16D P11_TX CH1 PWMO P5 10 15 H P10_RX CH1 PWM1_P6 O0 11 mm 14 H P9_SDA CUNET PWM2 P7 O 12 13 1 P8 SCL CUNET CB220 Port Pin I O 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 I O ADCO SPI SS P1 6 Input ADC1 SPI SCK P2 7 I O ADC2 SPI MOSI P3 8 1 0 Block O ADC3 SPI MISO P4 9 IO ADC4 PS 10 IO PWMO ADC5 P6 11 IO PWM1 ADC6 P7 12 I O PWM2 ADC7 P8 13 I O CuNET SCL P9 14 I O CuNET SDA P10 15 I O RS232C Channel 1 RX Pil 16 1 0 Block 1 RS232C Channel 1 TX P12 17 I O P13 18 I O P14 19 IO High Count channel 0 P15 20 I O High Count channel 1 VDD 21 I O 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 connection pins to the PC XPORT for DOWNLOAD DEBUG and MONITORING All CUBLOC models have SOUT SIN ATN pins and you can connect to the PC serial cable as shown below Oth
49. OP AMP Please set the MUX value accordingly by following the chart below MUX OPAMP OPAMP Multiplier Resolution 0 ADCO ADCO 10 8 Bits 1 ADC1 ADCO 10 8 Bits 2 ADCO ADCO 200 7 Bits 3 ADC1 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 1 8 Bits 9 ADC1 ADC1 1 8 Bits 10 ADC2 ADC1 1 8 Bits 11 ADC3 ADC1 1 8 Bits 12 ADC4 ADC1 1 8 Bits 13 ADC5 ADC1 1 8 Bits 14 ADC6 ADC1 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 By using the OPAMP more precise results or a noise filtering effect can be obtained Dim J As Long Input 24 Set the port to input Use port 24 25 for CB280 TAPULI 25 Do j Eadin 8 AD Conversion from ADO and Adl use OPAMP 1 Locate 0 0 Print hex5 J cr u Print resultes to LCD Delay2 500 Little Delay 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 full 10 bit resolution that the regular EADIN 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 has characteristics that it will read between 0 5V and 4 5V W
50. P2 7 Input SPI MOSI Input Only 0 P3 8 Input SPI MISO Input Only P4 9 1 0 P5 10 I O PWM CHANNEL 0 P6 11 1 O PWM CHANNEL 1 P7 12 I O PWM CHANNEL 2 P8 13 I O TTL232 RX2 TTLRX channel 2 P9 14 I O TTL232 TX2 TTLTX channel 2 P10 15 I O 1 P11 16 I O PWM CHANNEL 6 P12 17 IO PWM CHANNEL 7 P13 18 I O PWM CHANNEL 8 P14 19 I O P15 20 I O P16 25 I O AD CHANNEL 0 P17 26 IO AD CHANNEL 1 P18 27 I O AD CHANNEL 2 2 P19 28 1 0 AD CHANNEL 3 P20 29 1 0 AD CHANNEL 4 P21 30 1 O AD CHANNEL 5 P22 31 1 0 AD CHANNEL 6 P23 32 IO AD CHANNEL 7 P24 33 IO Co processor SCL 1 P25 34 IO Co processor SDA 1 P26 35 IO Co processor INT 1 3 P27 36 1 0 PWM3 P28 37 1 O PWMA INTO P29 38 1 O PWM5 INT1 P30 39 1 O INT2 P31 40 IO INT3 1 Communication line for connecting to co processor Please try to save these pins for future co processor communication ports 52 Block Name Pin I O Function Explanation P32 45 IO AD CHANNEL 8 P33 46 IO AD CHANNEL 9 P34 47 IO AD CHANNEL 10 4 P35 48 IO AD CHANNEL 11 P36 49 IO AD CHANNEL 12 P37 50 IO AD CHANNEL 13 P38 51 IO AD CHANNEL 14 P39 52 IO AD CHANNEL 15 P40 60 I O SCL CUNET clock pin P41 59 IO SDA CUNET data pin P42 58 I O RX1 TTLRX channel 1 5 P43 57 IO TX1 TTLTX channel 1 P44 56 IO P45 55 IO P46 54 I O HCNTO High Counter 0 P47 53 I O HCNT1 High Counter 1 P48 65 IO P49 66 IO P50 67 IO
51. PSTN lara ide chan 42 ANREP ca de 124 B Backup Battery 418 BASE BOard mnt 35 BASIC interpreter 34 battery backup 47 51 baudrate secere 193 BCD2BIN eene 127 BOXCEEAR atacadas 267 BOX llano 267 A taranii nnii 79 BYTIEIN 5 decode 133 BATEO Tian 134 DYECS recede nee Reed 87 C CAS mute cic dad 403 CB220 ta nea ee 41 AA imeem reete 44 CB280 relays s 359 CB280CS isch rs 57 CB290 24 1 terrre dee 47 51 CB290 relays sese 360 CheckBf eeeeeeeeee 135 Chipset sender el 57 CURA 2a deii inet eitis De e ized 122 CIRCLE saan ee ee eet 268 CIRCLEFIEL oct 268 CECD T 250 CLCD command table 255 CLCD DIP switch 254 CLEAR iiie ote eres 260 o Bc UR MD ES 253 260 CMODE uo 266 COLOR arc isi eE ninia 273 COMPAriSONS oococcoconconcnnonnnss 386 CONS a 90 constant arrays oocomcononconcnnon 91 Constant sees 90 Contact A ies eere ree rne 361 Contact B 361 CONTRAST een 263 eo E 110 COUNT eite renun 137 COUNTRESET 136 139 CSG Dip switch 282 CSG module 281 CSGDEC Lees 284 CSGNPUT nennen 283 CSGXPUT T aiaa 284 OO isis 253 CSROFF pec isa 260 SEO e ise IIR UE cotta tee kee 253 CSRON a a 260 ADA E ATATEN 383 en i 383 CUBLOC I O ports 176
52. ST2 OK Y Check if ST1 is same as ST2 Operators used in our BASIC language may slightly differ with actual Math operators Please refer to the below table Operator Math Basic Example Add t 344 5 6 A Subtract 5 10 3 63 B Multiply X 2 4 A 5 Division 1234 3 3843 A To the power of 53 5 3 A 2 MOD Remainder of mod 102 mod 3 In CUBLOC BASIC a slash is used in place of division sign Please make sure to use parenthesis appropriately for correct calculations 1 5 1 2 5 gt y T P 5 3 4 2 6 2 6 3 4 3 4 94 Operator Priority When multiple operators are used the following operator priority is used 1 Operator inside parenthesis 2 Negative Sign 3 0 4 Multiplication Division Remainder MOD 5 Addition Subtraction 6 Left Shift Right Shift lt lt gt gt 5 344 5 3 4 Ie 2 lt a E LJ 4 A B C D B X G H DEMO PROGRAM a CUBLOC studio d cubloc_test math1 cul File Edit Device Run Setup Help Bag ABAJA gt nI Bis FI BASIC F2 LADDER Ladder Mnemonic Const Device CB280 Dim A As Integer Dim B As Integer Dim C As Integer d Jas A 10 Baud Rate Party Data Bits T B 3 en yw COM v 115200 v None Y ls T RX C 123 HB A Debug Dec C Cr c 123 B A Debug Dec C Cr E Fix
53. Temperature s 325 Text Editor 64 text layer size ess 258 BIME grrr ua 235 240 Time Chart Monitoring 353 TIMESET cuicos 242 TO cia 382 TON E ca reum 381 TOUCH Pad rre 424 Turbo Scan Time 367 U UDELAY icra eese 244 331 UDP ni a 31 UP Counter eren 383 UP DOWN Counter 384 Usepin iiitide enis 245 363 WSEPIN 2 stesstiecdsceetetattn ee 156 UIMAX irent 246 V Y 121 VALSNG eeenm HH 121 VAR islas 80 MB vita eid das 54 W WADD untada 394 WAITDRAW eeennm 423 WATTS deriv uis 248 WAND e torva eere terere es 399 458 WXCHG aora 390 WXOR cette carteles 398 X MOOR Tika acne 31
54. Turbo Scan Time Mode eseeseeen He 367 Things to Remember in LADDER eeeeeen mH 368 ladder instructions LOAD LOADN OUT NOT ANDIOR cer SETOUT RSTOUT 1 eoe fate paa enlvneea den ght ai DIEUDIEDZ neri riim eet dao niri de MCS MCSCLR nnn STIEPSET x erp iraia STEPOUT irri TON TAON EE TORRE ELO doter tea e a A LE NIE ERE Comparison Logic How to store Words and Double Words eese 387 Binary Decimal HexadeciMal coccoccncnccncnnnnconnnnnnnnnnnnnnrnnnnnonennnnnnns 388 WMOV DWMOMW acticsitedivdecsdsatteadedvadbsetessinbetedentiasscndeededeansecstoteds 389 WINC DWINC WDEC DWDEC eee 393 WADD DWABDD 3 eh ires terapie einer Ere o rvegr e der decal nine ne Dive Dr NR Ea 394 WSUB DWSU B testen iet exeo ds 394 WMUEZLDWMUL reote extera a aaa 395 WDM DWDIV RR iar 396 WOR DW OR 2 2 rende ve saevus eese pere eere evertere aureas ze Re vaa 397 WXOR DWXOR 5 2 err RRr erunt ion a r aao a aaaea Ainiin He e RE PER pA 398 WAND DWAND a t eoex nnt cetero e cetera sio Eyes ds Rei dee 399 WROL pio 400 WROR DWROR eiue tree tip 401 GOTO LABE ER 402 CALI SSBRT RET nerea a nates ate en a a a a a a N Nai 403 INTON e EET 404 TIN DE EPI c E IEEE 405 Special Registers acit A a eurer ue E tm tae ends 406 io ndo llo MERERETUR 409 What s GUTOUGCHE tiet treo eter ind 411 CUTOUCH Specifications inrer oen iret hacia cid 412 Hardware R
55. Variable A BYTEl amp HAB Store amp hab in byte 1 of A LONG BYTE3 BYTE2 BYTE1 BYTEO LOWBYTE Word To specify certain Word of a variable the below names can be used A Word is 16 bits LOWWORD WORDO Word 0 of variable WORD1 Word 1 of variable A WORD1 amp HABCD Store amp habcd in word 1 of A LONG LOWWORD Tips Need to access 5 bits of a variable Try NewVariable Variable and Ox1F This will mask the last 5 bits of the variable 88 DEMO PROGRAM CUBLOC studio d cubloc_test longbyte cul DAR Ele Edt Device Run setup Help Debug Terminal Bez d 88 a gt att Miro BoudRote Porty DolaBie grx py F1 BASIC F2 LADDER Ladder Mnemonic com rs200 E tone s PRX Const Device CB280 Dim A As Long A amp H12345678 Debug Hex A BYTEO Cr Debug Hex A BYTE1 Cr Debug Hex A BYTE2 Cr Debug Hex A BYTE3 Cr A WORD1 amp hABCD Debug Hex A Cr I Fix Right Side 89 Constants Constants can be used to declare a fixed value at the beginning of the program By doing this readability and debuggability of the source code will be easier 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 PI 3 14159
56. Word values and DWOR is for Double Word Values Usable P M F S C T D Constants Registers si O O Oo O s2 O O Oo O d O O O START WMO 1200H DD H 1 WMOV 34H D1 1 ACTION WOR D0 D1 D2 1 The result of above ladder diagram DO D1 D2 397 WXOR DWXOR WXOR si s2 d DWXOR si s2 d Store result of s1 XOR s WXOR is for logical operation XOR in WORD units whereas DWXOR is for DOUBLE WORD units Usable P M F S C T D Constants Registers si O O O 9 s2 O O O 9 d O O O START WMO 1234H D0 C 1 WMOV OFFH D1 1 ACTION WXOR D0 D1 D2 1 The following is result of above LADDER DO 1234H D1 OFFH D2 12CBH When you want to invert specific bits you can use XOR logical operation 398 WAND DWAND WAND si s2 d DWAND si s2 d Store result of si AND s2 WAND is for logical operation AND in WORD units whereas DWAND is for DOUBLE WORD units Registers that P M F S T D Constants may be used si O O O O s2 O O O O D O O O START WMOV 1234H D0 1 WMO OFFH D1 C 1 ACTION WAND D0 D1 D2 1 The results of execution of LADDER above You can use AND operation when you want to use specific bits only 399 WROL DWROL WROL d DWROL d Rotate the value on Register d 1 double word to the left The value left gets stored in the Carry flag WROL moves o
57. Z O W OE co 3 O Q O Q lt gt ZDDV DN nN wo S O o D oo zl ofa TISISEI SG AG alaala 200 lu O0 aade ors I II rz II Iii Ii jc tit ji pa a a 0 a a sl Ir rrriinrIiiriirir O H A a in w m o aj lt X M O Q wy ie O FIN om SF LEO OoN CO GD lt al OF O wy ie ojojojojojojojojojo dS QO SG a a ao adap mS mm alal alal Al ala 438 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 causes download error in CUBLOC Studio Please short or take out the extra capacitor connected to the DTR of the board as shown below CB220 has a this capacitor on the chip itself Short here VIN VSS RES VDD P15 P14 P13 P12 P11 P10 P9 P8 VIN VSS RES VDD P15 P14 P13 P12 P11 P10 P9 P8 439 Appendix C Using Output Port on the CB290 CT1720 Warning CB290 rev A CT1720 rev A Output ports Please be aware of the following when using CB290 rev A or CT1720 rev A with output ports 24 through 55 When using CB290 or CT1720 with a backup battery CB290 Proto Board Baseboard 64M and CT1720 the data memory is saved during power OFF Even the output on the I O ports are saved to memory When powered ON the output ports will recover from the status it was in at power OFF This is to let the modules be able to continue
58. addst stl st2 Cr Delay 200 Print loc 0 0 st2 If In 4 1 Then Puta2 3 aal a 80 10 Do While In 4 1 Loop Endif If In 10 1 Then Puta2 3 aa2 a 80 10 Do While In 10 1 Short Cut 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 64 Debugging amp CUBLOC studio d WsourceWcublocstudioWtestsourceW DER ile Edit Device Run Setup Help Si des Ga a gt m dii FI BASIC F2 LADDER Ladder Mnemonic Const Device CB280 Delay 10 Debug Hello Debug Terminal Port Baud Rate Parity Data Bits ary a com x 115200 None fe z em Fix Right Side As you can see in the above example DEBUG command can be used to debug 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 to use LADDER Monitoring Another option is to use the command Set Debug Off which will turn OFF the DEBUG feature 65 Menus Eie Edit Device Run Setup Help File Menu Open Ctri 0 Ladder Import Save Ctrl S Save As Save Object Print Ladder Print BASIC Print Setup Download from object file BASIC Section Ladder Section C Cubloc_Test c290exouttest cul CiWCubloc TestWBCDTEST cul C
59. be less than 100 while CO must be larger or equal to 99 386 How to store Words and Double Words Byte is 8 bits Word is 16 bits and Double Word is 32 bits 1 BYTE P d TT in aR A 1 WORD DOUBLE WORD There are 2 ways to store Word of Double Word size of 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 stored in Memory Address O and 12345678H is stored in Memory Address 5 In every Memory Address 1 byte of data is stored O0OONXJDOONAAO0ON 0 The Registers C T D are in units of Words To store a Double Word data 2 Word spaces will be required meaning two Register spaces Below is an example of store a Double Word data 12345678H D1 gets 1234H and DO gets 5678H DO 5678 D1 1234 D2 D3 D4 387 Binary Decimal Hexadecimal To program well we need to know binary decimal and hexadecimal numbers The 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 9 1001 9 10 1010 A 11 1011 B 12 1100 C 13 1101 D 14 1110 E 15 1111 F In CUBLOC s Ladder Logic we express binary and hexadecimal numbers in the following manner B
60. be shorted If using pin 8 and 9 directly please leave all jumpers to open state 295 About I2C CUBLOC provides easy set of commands to communicate using I2C 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 command SET I2C before using I2C commands I2C s START STOP When SCL Clock and SDA Data are HIGH I2C is in idle state If START command is executed during idle state I2C begins When SCL and SDA are both LOW I2C is in busy state If STOP command is executed during busy state I2C stops There is also a Repeated Start in I2C If START command is executed during busy state I2C Restarts LAE I er Pe s i Bu l i i i i 1 NS START Repe ted STOP Start o o v 296 Using EEPROM through I2C We will go through an example showing I2C communication between CUBLOC and EEPROM 24LC32 The following is a picture taken from the EEPROM s data sheet It shows how to send data to the EEPROM R W S CONTROLBYTE O A HIGHADDRESS A LOWADDRESS A DATA A P S Start A Acknowledge P Stop The first bit is for Start command The 4 upper bits of CONTROL BYTE must be 1010 and the 3 lower bits are for selecting the Chip s address Th
61. buffer 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 COUNT compare p When high counter value reaches a set target point the processor will set an I O Port to Low or High If Targetstate is set to 1 and when the Target number of pulses have been received the Port will output logic HIGH Likewise if the Targetstate is set to O and when the Target number of pulses have been received the Port will output logic LOW Channel Compare Range HCOUNT Channel 0 0 to 255 HCOUNT Channel 1 O to 65535 The high counter itself supports upto 32 bits but the COMPARE command is limited since this command was designed to not affect the overall multi tasking 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 Set Count0 On Compare 0 10 61 1 Do i Count 0 Debug Goxy 0 0 dec4 i Cr Delay 100 Loop The above uses High Counter Channel O with target of 10 When the Counter O value becomes 11 Port 61
62. character ascii code Same as GETSTR command except it will stop reading data at the StopChar even if there are data left to read set by the Length 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 GOSUB command can call a sub routine RETURN command must be used at the end of the sub routine GOSUB ADD_VALUE ADD_VALUE A A 1 RETURN Goto GOTO command will instruct the current Program to jump to 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 If I 2 Then Goto LAB1 End If LAB1 I 3 About Label A Label can be set with character to set a point for GOTO or GOSUB to jump to ADD_VALUE LINKPOINT A label cannot use reserved constants numbers or included a blank space Below are some not to do examples Ladder Reserved constant 123 Number Aboot 10 Blank space 165 HEAP Memory Access The HEAP memory access is a special feature only available on the CB405 module The new CUBLOC CB405 has a HEAP memory The user may use this memory from address O through 56831 in byte units or O through amp HDDFF in hex There s about 55KB of memory You can store large data for graphics temperature tables etc etc With a backup battery the HEAP memory can be used similar to an EEPROM memory 55K bytes 0000 4K byt
63. counter O uses the same resources as Pwm as shown below please be careful Not to use PWM at the same time COUNTERO PWMO TIMERA Mi PWM2 TIMERB PWM4 TU TU lt w v a i Measure frequency from pulse output PWM 0 channel Const Device CB280 Dim A as Integer Input 15 Low 5 Freqout 0 2000 Low 0 On Timer 100 Gosub GetFreq Do Loop GetFreq A Count 1 Debug goxy 10 2 Debug dec5 A Countreset 1 Reverse 0 Return 138 Countreset COUNTRESET channel Channel Counter Channel 0 to 1 Reset the specified Counter Channel to 0 Countreset 0 Clear Channel 0 Countreset 1 Clear channel 1 139 Dcd Variable DCD source Variable Variable to store results No String or Single Source source value This command DCD is opposite of NCD command It will return the bit position starting at LSB bit 0 of the highest bit that is a 1 T DED 15 result de 3 ekes 15 Melia lt 2 CUBLOC studio d cubloc_test unary cul File Edit Device Bun Setup Help Baf g amp ESCA dA gt m d FI BASIC F2 LADDER Ladder Mnem Baud Rate Parity Data Bits re Const Device CB280 EX 115200 gt none fe RK Dim A As Long 4 10 Debug Dec A Cr hod s Terminal A Not 1 Debug Dec A Cr A Ned 4 Debug Dec A Cr A Ded 15 Debug Dec A Cr Close Fix Right Side 140 Debug DEBUG data data data to send to PC CU
64. drawing lines circles and etc Set the layer OFF when drawing and set the layer ON when you are finished drawing everything 261 GLayer GLAYER layernumber Layernumber Set the graphic layer 0 1 2 There are 3 layers of GHLCD GHB3224 series One of the layers may be used as graphic layer Graphic commands such as LINE CIRLCLE and BOX can be used for the layer set a the graphic layer Normally Layer 1 is used for text while Layer 2 is used for graphics Layers 2 and 3 have slight different characteristics We recommend Layer 2 for graphics that require a lot of erasing Layer 1 can also be used as graphic layer In this case you can even erase text characters with graphic commands To set Layer 3 to graphic layer use command LAYER to turn Layer 3 ON to use Layer 3 Overlay OVERLAY overmode overmode Logical Mode 0 or 1 and 2 xor This command Overlay determines the logic mode between Layer 1 and Layer 2 Layer 1 is text and Layer 2 is graphics By using this command the user can decided what to do 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 To no invert you can set this to OR state 262 Contrast CONTRAST value value Contrast Value 1 to 1024 Control the contrast of the LCD with CONTRAST command Contrast 450 Light LIGHT value value Back light O OFF 1 ON Turn back light ON and O
65. gt gt Left Shift Right Shift Logic lt gt lt gt Less than Compare Larger than Less or Equal to Larger or Equal to lt gt Same Different Compare AND XOR OR AND XOR OR Logic Lowest Please refer to the above table for checking priority of operator used In the rows the highest priority is calculated from the left to right You can use operators as conditions like below IF A 1 10 THEN GOTO ABC Whole numbers and floating point numbers can be mixed The final result follows the type of variable it will be stored in DIM F1 AS SINGLE DIM A AS LONG F1 1 1234 A F1 3 14 A gets 3 even though result is 3 525456 Please make sure to include a period when using floating point numbers F1 3 0 4 0 Write 3 4 as 3 0 4 0 for floating values Fl 200 0 FLOOR A 12 0 SQR B 200 as 200 0 12 as 12 0 AND XOR OR is used for logical operations and as Bit operators IF A 1 AND B 1 THEN C 1 if A 1 and B 1 Logical Operation IF A I OR BEI THEN C21 4f Ael or Bel Logical Operation A B AND amp HF Set the upper 4 bits to zero Bit Operation A B XOR amp HF Invert the lower 4 bits Bit Operation A B OR amp HF Set the lower 4 bits to 1 Bit Operation 93 Strings can be compared with the sign ASCII values are compared for Strings DIM ST1 AS STRING 12 DIM ST2 AS STRING 12 ST1 COMFILE ST2 CUBLOC IF STI ST 2 THEN
66. has maximum of 1948 bytes of Data Memory Please make sure to have at least 100 bytes of free Data Memory for safety A Sys 6 Store the current Data Memory Address in A 238 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 Tadin is similar to Adin It returns the average of 10 ADIN converted value When working under noisy environments using Tadin could help in obtaining more precise results Tadin is pre made system s functions program function tadin num as byte as integer dim ii as integer ta as long ta 0 HO A TO O ta ta Adin num Next TADIN TA 10 End Function 239 Time Variable TIME address Variable Variable to store results No String or Single address Address of time value 0 to 6 CUBLOC module CB290 has an RTC chip internally You can use 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 alive even when module powers off through use of its backup battery 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
67. iodio 0 amp h8e 8 Shiftout ioclk iodio 0 0 8 Low iorst Delay 1 High iorst Shiftout ioclk iodio 0 amp h80 8 Shiftout ioclk iodio 0 amp H50 8 Low iorst Do High iorst adr amp h81 Shiftout ioclk iodio 0 adr 8 i Shiftin ioclk iodio 4 8 336 Debug Hex i cr Low iorst Delay 1000 Loop The above code will read ADDRESS 0 second s 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 nooness 0 cee os ADDRESS 1 min o 10 MIN MIN L x L L L 10 ADDRESS 2 hour waf o Arp HR E ORION ADDRESS 3 date o o 10DATE DATE f L ADDRESS 4 mon o o o vox EBEN monessa gt Soo o maa 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 337 NOTE 8 MCP3202 12 Bit A D Conversion The CUBLOC has a 10 bit A D converter Without a separate chip you can get up to 10 bits of A D conversion But for greater resolution meaning greater precision you can use a chip like the MCP3202 MCP3202 is a 12 bit A D converter that supports SPI protocol Here we will show you how to implement this 12 bit A D converter into your project o 3 TIT e i s MCS3202 T Pin Function I O Direction Expl
68. motor will move to a location set by pulse and duty value and will hold its position By being able to control the exact angles at which the RC servo stops we can control the RC servo as freely as we want 1mS 1 5mS 2mS 4 _ bal w 9 45 45 333 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 specification 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 outputted from port number 5 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 outputted from port number 5 RC servo will position itself to 45 degrees As you can see by simply change the duty value of PWM command 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 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 END 334 NOTE 6 DS1620 Digital Thermometer The DS1620 is a digital thermometer The chip internally has a temperature conversion table so the user does not have to make a se
69. not to be used for future firmware updates we ADVISE NOT to use them 306 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 1 00 2 Start Address LO 0X14 1 14 2 Length HI 0X00 1 00 2 Length LO 0X25 1 25 2 Error Check CRC 2 LRC 2 Ending Code CR LF 2 LRC is the 2 s complement of 8 bit sum of all values except Colon CR and LF For the table above 0x03 0x01 0x13 0x25 Ox3C To fin d the 2 s complement of 0x3C we can write it in binary first 0011 1100 Then we can invert the bits 1100 0011 Then add one which is 1100 0100 0xC4 LRC 0xC4 ASCII H 0 3 0 1 0 0 1 3 0 0 2 5 c 4 CR LF Hex 3A 30 33 30 31 30 30 31 33 30 30 32 35 43 34 13 10 307 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 OX1B 1 1B 2 Error Check CRC 2 LRC 2 Ending Code CR LF 2 If you look at the response to the query you can see that bit 20 through 27 make
70. of spending hours and hours in front of a computer flash programmer target board target board MCU engineer s desk CUBLOC engineer s desk 33 CUBLOC s Internal Structure BASIC processor Ladder processor BASIC Program Memory 1 BASIC LADDER Data Memory Data Memory The BASIC interpreter contains a Flash memory for user s BASIC programs LADDER processor also has a Flash memory for user s LADDER program I O ports are shared among BASIC and LADDER allowing free access to both BASIC data Memory can only be accessed by BASIC interpreter while LADDER data memory can be accessed by both BASIC Interpreter and LADDER Processor BASIC program memory 1 and LADDER 2 share the same Flash Memory The total available memory space is 80KB BASIC can use the whole memory or LADDER may use the whole memory As long as the BASIC and LADDER program total is within 200KB the user is free to program as he she wills CB2XX series allow 80KB I O ports 5 can be used both by BASIC and LADDER The user must specify I O ports to use in LADDER and BASIC All I O ports can be used in LADDER or BASIC 34 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 SB Series Base boards for CUBLOC SB series are especially g
71. of Bits 0 0 NONE 0 0 O 5 bit 1 Stop Bit 0 1 Reserve 1 0 1 6 bit 2 Stop Bits 1 0 Even 1 0 7 bit 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 Opencom 1 19200 3 30 20 Open Rs232 channel 1 Set RES Ml N52 00S Change Baudrate Parity 228 Set Rs485 Set Rs485 Channel PortNumber Channel RS232 Channel 0 to 3 PortNumber Transmit Enable Port Number RS485 allows you to daisy 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 either use a chip such as the SN75176B or use a RS232 to RS485 converters 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 following circuit schematic for connecting TTL signals from CB280 to RS485 chip SN75176B 560 CUBLOC CB280 SN75176B 485 560 The RS485 communication needs a Transmit Enable signal to signal when the device is sending and 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 Slave Adr 01 S
72. only use BASIC as part of Ladder Logic we are not fully using BASIC to its maximum performance The third point has to do with I Os BASIC language s execution of I Os can create unwanted collisions with LADDER The reason is that Ladder Logic I Os are updated while in BASIC I Os are directly 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 simultaneously without causing collision between the each other 26 With just BASIC you will be able to create many devices In comparison to other BASIC processor on the market today CUBLOC s BASIC clearly has faster processing speed and the upper hand on the main features If Ladder Logic is not necessary the user may use just BASIC In the case of I Os the user can specifically control the I Os used by BASIC and LADDER thereby eliminating I O collision problems CUBLOC uses BASIC as its main language We recommend controlling LADDER from BASIC For example there is a MASTER CONTROL feature in Ladder Logic allowing the user to set Control Zones Control Zones are sections within the Ladder Logic that the user can set entire sections of the control circuit With the MASTER CONTROL feature the user can enable disable Ladder Logic s Control Zones easily IfA 1 THEN M 1 2 1 If B 1 THEN _M 1 0 MCSCLR 0 In BASIC the user may read or write to Ladder Logi
73. or the mouse to control the red box After moving to the desired position you can use keys F3 to F12 to put the desired symbol You can also enter text for those required symbols 346 E PUES F3 to make a contact yai ron 3 1 461 SF aL 7_ p Heel F5 FB F F8 Fg Fil Fl2 NOT END 1 2 2 Type START and press ENTER Lt Tr z I T a X61 T C 7 Em F3 ES Ea i Ee E ES AGA SE ZO NOR REND mo 1 2 3 Press F5 couple times and you will see that it creates a line in VEE IL e al alles A ak v4 3 ES A E E ES AA SET T ANOTA REND START 1 4 Press F7 and type RELAY AF 4r 1 o i1d iC1l T L Y Hed lt 3 lt 5 lt gt F3 F4 F5 F6 F F8 FQ F11 F12 NOT END Insert Delete Undo E 3p 5 Go to the next rung line and press END alle Ghia t gl 1 zm al al e ee F3 F4 F5 F5 Fit F12 NOT END Insert Delete Undo START RELAY 1HI C 2 Ea Please press the ENTER key at the end of entering TEXT At the very end of the Ladder Logic you must put an END command 347 Editing LADDER Text Editing Text To edit an existing TEXT please place the cursor in the desired location and press ENTER Now you can edit the TEXT freely as you like START TON T1 100 1 mr 1 Erasing a Cell START 1 1 ES Enter SPACE key START 1 Erasing a Rung one line START RELAY E j a d END A rung is a row in Lad
74. point 266 Box BOX x1 y1 x2 y2 Draw a box with diagonal positions of X1 Y1 and X2 Y2 BOX 10 20 200 100 Draw box H Boxclear BOXCLEAR x1 y1 x2 y2 Clear the box with diagonal positions of X1 Y1 and X2 Y2 o iim BOXCLEAR 10 20 200 100 Clear box E 239 Boxfill BOXFILL x1 y1 x2 y2 logic logic O OR 1 AND 2 XOR Draw a box with diagonal positions of X1 Y1 and X2 Y2 and fill according to specified logic 0 OR will display all overlapped areas 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 267 Circle CIRCLE x yr Draw a circle with center of circle at x y and r as radius CIRCLE 200 100 50 Draw circle Circlefill CIRCLEFILL x y r Draw a circle and fill with center of circle at X y and r as radius CIRCLEFILL 200 100 50 Draw and fill circle 268 Ellipse ELLIPSE x y r1 r2 Draw an ellipse with center of circle at x y and r1 as horizontal radius and r2 as vertical radius ELLIPSE 200 100 100 50 Draw ellipse EIfill ELFILL X y r1 r2 Draw an ellipse and fill with center of circle at x y and rl as horizontal radius and r2 as vertical radius ELFILL 200 100 100 50 Draw and fill ellipse 269 Glocate GLOCATE x y Locate new position for the graphic layer GLOCATE 128 32 locate new position Gprint CUTOUCH Gprint G
75. 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 Oz Normal 2 or 3 Bold inverse O Normal 1 Inverse underline O Normal 1 Underline Sys Variable SYS address Variable Variable to store results No String or Single address Address 0 to 255 451 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 USEPIN I O In Out AliasName I O I O Port Number 0 to 255 In Out In or Out AliasName Alias for the port Optional 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 O FAST 1 SLOW 452 ARC COS esis e xao reper neve 110 Arc Sine isisisi nadine 110 Are Tal uscite ata ds 110 AMAS Hen 86 ASQ ORE er a 122
76. 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 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 All CUBLOC I O ports support both input output You have many options in setting the Port status to input or output By default all I O Ports are set to HIGH Z at power ON When 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 for 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 as default at power ON High Impedance means that the value of resistor is so high that it s neither HIGH nor LOW INPUT 8 Set Port 8 to HIGH Z input state 178 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 This command
77. table from the maker of the thermistor The following is a diode type 10K Ohm 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 7 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 325 16 14485 7 14994 4 15506 9 17 13839 6 14318 9 14801 5 18 13225 9 13677 7 14132 2 19 12642 8 13068 7 13496 9 20 12088 7 12490 3 12893 6 21 11561 9 11940 6 12320 7 22 11061 0 11418 2 11776 4 23 10584 6 10921 6 11259 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 the Zener diode must be used 1Kohm 196 NTC TH 5 1V ZENER DIODE 0 47uF CUBLOC A D CHANNEL O As you can see in the circuit diagram we will be using A D Analog to Digital converter to read the current voltage flowing through the sensor The A D converter will convert the current voltage into a value be
78. the week Timeset 5 amp H6 Month Timeset 6 amp H5 Year Do I Time 6 Debuge Year 7 200l Hex Ty tas I Time 5 Select Cass I Case 0 Debug January Case IT Debug February Case 2 Debug March Case 3 Debug April Case 4 Debug May Case 5 Debug June 242 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 WP UH I Time 4 Select Case I Case 0 Debug Sunday Case 1 Debug Monday Case 2 Debug Tuesday Case 3 Debug Wednesday Case 4 Debug Thursday Case 5 Debug Friday Case 6 Debug Saturday End Select Debug cr I Time 2 Debug Hex2 I I Time 1 Debug Hex2 I I Time 0 Debug Hex I cr Delay 1000 Loop Debug Terminal Screenshot Print date ES ae Terminal Baud Rate Party DataBits gry 4 EZ v 115200 v None y fe em Friday Friday 243 Udelay UDELAY time time interval 1 to 65535 A more specific delay function 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 dela
79. their existing processes in case of power outage Please be aware that when there are unknown values and battery backup is used there can be garbage values at power ON meaning unknown values outputting on the output ports Please use regular I O ports if you need to make sure that the output needs to be OFF at power ON Using Output ports on the CB290 CT1720 Rev B The CB290 CT1720 Rev B output ports P24 P55 are in high impendence High Z state in order to prevent garbage values outputting at power ON You must use Set OUTONLY ON command to set the CB290 CT1720 output ports to output status Set Outonly On 440 Appendix D CUBLOC 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 bcdvalue Variable Variable to store results Returns LONG bcdvalue BCD value to convert to binary Bclr BCLR channel buffertype channel RS232 Channel 0 to 3 buffertype O Receive 1 Send 2 Both Beep BEEP Port Length Port Port number 0 to 255 Length Pulse output period 1 to 65535 Bfree Variable BFRE
80. will ouput logic HIGH Debug Terminal Baud Rate Parity Data Bits eTx A Port com 115200 y none je gt ar J Fix Right Side This command is supported for CUBLOC STUDIO 2 0 X and above 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 to input before use of this command Up to 32bits can be counted Byte Integer Long Maximum 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 counter will count reliably CUBLOC has 2 Counter inputs Counter Channel 0 uses same resources as PWMO 1 2 and cannot be used together But you are free to use Counter Channel 1 as freely as you d like To use Counter Channel 0 SET COUNTO command must be used beforehand Channel 1 requires no additional settings VIN VSS RES VDD P15 COUNT 1 P14 lt COUNT 0 P13 P12 P11 P10 P9 P8 Dim R As Integer Input 15 Set port 15 as input Counter Channel 1 R Count 1 Read current Counter value Set Count0 On Activate Counter Channel 0 PWM0 1 2 becomes deactivated Input 14 Set port 14 as input Counter Channel 0 R Count 0 ea current Counter value 137 Since
81. x1 1 y1 2 x2 3 y2 When you need to find the current status of Menu buttons set by Menuset command you can use Menu function to return the current status O will read x2 1 will read y1 2 will read x2 and3 will read y2 It s as though the MENU is accessed as 2 dimensional array If Menu 0 1 100 THEN If Menu button 0 s Yl is less than 100 422 Waitdraw WAITDRAW This command will wait for a drawing command to finish before resuming execution ELFILL 200 100 100 50 Fill an ellipse WAITDRAW Wait until drawing is finished This command is especially useful for animations and when you have trouble displaying graphics because of the speed CUTOUCH has an internal buffer for receiving graphic commands from CUBLOC If this buffer fills up and data is sent to it the 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 avoid situations where the LCD might get blurry or received noise This command can only be used with CUTOUCH 423 Touch Pad Input Example You can use SET PAD ON PAD and GETPAD commands to find out which menus were pressed from the user All PAD commands are geared for receiving and processing touch input We can use ON PAD interrupts to receive touch inputs The following is an example program tha
82. 0 10 1O F3 F4 F5 F6 F F8 rg FH F12 NOT END Insert Delete Undo Copy Wizard P31 Mo M2 WORK_OFF TOGLE M2 MI WORK ON TOGLE MPG ON INPUT M3 MPG ON OFF TOGLE M5 MPG ON LED P40 gt zl Modified Program 154 Bytes 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 351 Monitoring CUBLOC STUDIO supports real time monitoring of Ladder Logic Click Here Bel S xa3uau EM 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 value of 5 for the monitoring speed CUBLOC studio c Wcubloc testWu3 1018 cul File Edit Device Bun Setup Help Bab Gg BE 4 miu Bu FI BASIC F2 LADDER Ladder Mnemonic i i J y Monitoring Stop TON T0 50 t m1 M301 M301 LI JOG HI SPEED PULS F2 2 SPEED LOW END TIME TON T1 20 al c mus 3 XM 97 Modified Program 9602 By
83. 0 ce 70 se 9e 110 10 120 130 140 150 160 e e is O i9 O 2 02 e 23 2 e 25 e 26 e e 28 e 29 e 3o 031 32 VDD vss RES NIC P16 P17 P18 P19 P20 INTO P21 INT1 p22 INT2 P23 4 NT3 P15 P14 P13 P12 Set external interrupt to TX RX1 AVDD Nic P24 P25 P26 P27 P47 P46 P45 P44 P43 P42 P41 P40 be on 330 340 350 36 9 70 380 30 100 410 20 130 10 150 46 e 47 48 e the Falling Edge 49 50 5 52 53 54 55 56 57 58 59 60 61 62 63 64 TTLTX1 TTLRX1 AVREF P48 P31 P30 P29 P28 P32 P33 P34 P35 P36 P37 P38 P39 215 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 such minimal BASIC code for Ladder logic Const Device CB280 Device Declaration Usepin 0 In START Port Declaration Usepin 1 In RESETKEY Usepin 2 In BKEY Usepin 3 0ut MOTOR Alias MO RELAYSTATE Aliases Alias M1 MAINSTATE Set Ladder On Start Ladder Do Loop BASIC program will run in infinite loop 216 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 MODBUS protocol MODBUS can connect to RS232 Channel 1 To enable MODBUS slave mode please use the Set modbus command This command set modb
84. 000 60 80 P55 WOND ROrAMTHOR ooo9959955959595 OrOLaNOOrmooY00r SESRSNIERE RO Go ocacaoaaoonao 1 zo en ER zz zz ES oo a ITI TXE RXE AVdd Vdd ADC8 _ P32 ADC9_P33 ADC10_P34 ADC11_P35 ADC12_P36 ADC13_P37 ADC14_P38 ADC15_P39 HCNT1_P47 HCNTO_P46 P45 TUTXE TURXE AVref Vss P48 P49 P50 P51 PWM9 P52 PWM10 P53 PWM11 P54 P55 P63 P62 P61 Sout Vdd Sin Vss Atn RES Vss VBB SS P0 P16 ADCO EEBSGESSPI P17_ADC1 MOSI P2 P18_ADC2 L MISO P3 P19_ADC3 P4 P20_ADC4 PWMO P5 P21 ADCS PWM1 P6 P22_ADC6 PWM2_P7 P23_ADC7 RX2 P8 P24 TX2 P9 P25 P10 P26 PWM6_P11 PWM7_P12 PWM8_P13 P14 P15 P27_PWM3 P28_ PWM4_INTO P29 PWM5_INT1 P30_INT2 P31_INT3 TXi RX1 L CUNET SDA _ CUNET SCL _ P44 P43 P42 P41 P40 609680 P60 P59 P58 P57 TX3 P56 RX3 Warranty Comfile Technology provides 1 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
85. 0295 nnnnnnnnnnnmnnnn 9 58 88 588589589 voo O41 48 P35 Rxo O2 47 P36 TXo O3 46 P37 pis Ha 45 P38 pwm3 P19 O5 44 P39 Pww INTO P20 Oje m 43 P48 PWN6 INT1 P21 Si CLUBLOC 42 P4T VDD a 8 vss Nr2P22 Os 4 P46 NT3P23 O9 CB 2 80C S 40 P45 RS e piconets 7 RO ssPo C410 i i 39 P44 een Ou Main Chip 38 P43 Ros Sub Chip oS R1 os P2 C12 37 P42 R3 4 5 R2 MiSO P3 13 36 P41 P4 a 35 P40 PWMo Ps 15 34 P11 PWM1 Pe C16 33 P10 gt 9 RN RR X amp RRR ARGA uuuuuuuuuuuuuuuu RERPpoorzeo cono yo E e zz E T Pi Main chip pin out Pin Port Function Desc 1 VDD Power Supply 2 RXO DOWNLOAD RX RS232 RX 3 TXO DOWNLOAD TX RS232 TX 4 P18 O port 5 P19 PWM3 O port 6 P20 PWM4 INTO O port Fi P21 PWM5 INT1 O port 8 P22 INT2 O port 9 P23 INT3 O port 10 PO SS O port 11 P1 SCK O port 12 P2 MOSI O port 13 P3 MISO O port 14 P4 O port 57 15 PS PWMO I O port 16 P6 PWM1 I O port 17 P7 PWM2 1 O port 18 P16 I O port 19 P17 I O port 20 RESET Reset Low active 21 VDD Power supply 22 VSS Ground 23 XTALOUT Xtal output 24 XTALIN Xtal input 25 P8 CUNET SCL I O port 26 P9 CUNET SDA I O port 27 RX1 RS232 CH1 RX RS232 Channel 1 Rx 28 TX RS232 CH1 TX RS232 Channel 1 Tx 29 P12 I O port 30 P13 I O port 31 P14 HCOUNTO I O port 32 P15 HCOUNT1 1 O port 33
86. 1 AS STRING 12 ST1 CUBLOC DEBUG MID ST1 2 4 UBLO is printed Debug Terminal Port Baud Rate Parity Data Bits ary e lt 2 CUBLOC studio d cubloc_test stringfunc cul cont y fasza File Edit Device Run Setup Help af m nx Be dx AR mE m F1 BASIC F2 LADDER Ladder Mnemonic Const Device CB280 Dim stl As String 12 stl CUBLOC Debug Left sti1 4 Cr Debug Right stl 4 Cr Debug Midfst1 2 4 Cr p 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 ST1 AAAAA is printed 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 Debug Terminal Baud Rate Parity Data Bits rx Ei Port lt CUBLOC studio d cubloc_test stringfunc cul comi 415200 gt Nene y 8 z em Eile Edit Device Run Setup Help j gei dx3mG e m0 8 5 FI BASIC F2 LADDER Ladder Mnemonic Const Device CB280 Dim stl As String 12 sti CUBLOC Debug Dec Len stl Cr stl String amp sh41 5 Debug stl Cr stl s
87. 1 Rising Edge 2 Changing Edge Set SET ONGLOBAL On Off Onglobal Set SET ONINTx On Off onint Set SET ONLADDERINT On Off onladderint 450 Set SET ONPAD On Off onpad Set SET ONRECVO On Off onrecv SET ONRECV1 On Off SET ONRECV2 On Off SET ONRECV3 On Off Set SET ONTIMER On Off Ontimer Shiftin Variable SHIFTIN clock data mode bitlength Variable Variable to store results No String or Single Clock Clock Port 0 to 255 Data Data Port 0 to 255 Mode 0 LSB First Least Significant Bit First After Rising Edge 1 MSB First Most Significant Bit First After Rising Edge 2 LSB First Least Significant Bit First After Falling Edge 3 MSB First Most Significant Bit First After Falling Edge 4 LSB First Least Significant Bit First Before Rising Edge 5 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 Steppulse STEPPULSE Channel Port Freq Qty Channel StepPulse Channel 0 or 1 Port Output Port Freq Output Frequency Up to 15kHz Qty of
88. 24 There for to get the A D value you must multiply result V by 204 8 You can easily make a chart by using an excel spreadsheet to enter these formulas END 329 NOTE 4 Sound Bytes In this application note I will be showing you simple ways to create key touch sound musical notes and alert sound An I O port or a PWM Channel of CUBLOC can be used for sound With a PWM Channel you have the advantage of creating different tones of sounds L souT VIN O SIN VSS O ATN RES VSS VDD B PO P15 B P1 P14 O Pa P13 Speaker 0 047uF EX P12 P4 P11 i P5 P10 P6 P9 der Psp um The above example shows PWM Channel O of CB220 being used with Freqout command to produce a sound isa Const Device cb280 Dim PLAYSTR As String Low 5 Fregout 0 5236 Create a sound with frequency of 440Hz Delay 500 Delay Pwmoff 0 Stop Sound by turning off PWM With commands like Freqout and Delay simple sounds can be created Filename playcdec cul gt Const Device CB280 Low 5 Freqout 0 4403 Delay 200 Eredgout 0 3703 Delay 200 Freqout 0 3114 Delay 200 Freqout 0 2202 Delay 200 Pwmoff 0 330 By changing 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 C D E F G A B C D E F G H I J K L M N To express one note you can use 2 characters The first character is for the note and second charact
89. 2cread 0 2cstop Print Results Debug Hex a cr 24LC32 CB280 Delay 500 Loop AO A1 SCL ji P2 A2 SDA P3 TEC Debug VErron I mr Do Loop 299 More About I C Advanced I C is a common protocol used by many industrial controllers today CUBLOC uses I C as one of its main communication protocols CuNET is built on the 12C protocol The main advantage of CuNET is that it s hardware controlled for LCD displays Not CSG modules or I O ports I C commands such as I2CWRITE and I2CREAD are software commands The advantage of I2C commands is that it does not require receive interrupts like serial communications This allows the CUBLOC to multi task not letting any situations where the processor can freeze indefinitely As a result a CUBLOC CB280 module can interface with almost 24 separate I2C buses That s buses you can add multiple I2C device per I C bus The CUBLOC simulates a Master I C device Since it can only simulate a Master 12C device the I C devices connected must be Slave I C devices The main advantage of I C protocol is that it does not cause any delays as CUBLOC is the Master I C devices CUBLOC can simply request for data when it wants to it does not have to wait for the I2C Slave device to respond Note The I O port used for I2C communication must be an Input Output port not Input Only or Output Only 5V 5V SCL SDA Slave Ad
90. 31 Hints for traditional PLC User cseseee mH 32 Hints for Micro Controller User occoccoccnoconcconcnncnnannnconconrnnanonnnnnannns 33 CUBLOC s Internal Structure comico caia aaea 34 CUBEOC Peripherals 7 tic iia dnd 35 CHAPTER 2 HARDWARE ccsscsccsssssscsssssssssssossssssscsssssnnssssossssssecssssssnnssssoesssececssssnnsessoooesseese 39 Hardware Features iasant a di 40 BL caustics on e a N E E EE 41 Supplying power to the CB220 00ccoccoccnncnnconanonconcananonnoncnnnannronanans 43 CBE ES 44 How to supply power to the CB280 seseeseeen ee 46 CB290 EE 47 A A e ERENT 51 How to connect Battery to CB290 CB405 sese 54 DIMENSIONS ii u a a a E S E a EE E 55 CUBLOC Chipset CB280CS ayinin tette ad 57 CHAPTER 3 CUBLOC STUDIO EDITOR COMPILER eee 61 CUBLOC STUDIO Basics 5 5 eti te a es kx wei sarees 62 Creating BASIG 5 Leu REIR EMIT 64 DEDO 65 MAA O ANO 66 CHAPTER 4 CUBLOC BASIC LANGUAGE ccsssssssssssscsssssssssssssosssssessssssnssssssssssssees 69 CUBLOC BASIC Feat tes 1 2 rat cecteebentva 70 Simple BASIC POD Ain oa 72 SUDAN FUNCION utes dre SUI eot d pudo ed reet 73 Variables ua aa aaa 79 cgi cH AE 81 About Variable Memory Space ssseeee een 85 10 Bits and Bytes Modifiers 2 2 ccececceeeeeeececeeeceeeseeeeeeeeeeeeeeeeeeeseeeeensenedes 87 Constante E E ouest Leo lenes fence ir une oe server dus 90 Constant AFraysS intestine hai
91. 32 to 39 OUTPUT Block 4 8 Output Ports P40 to 47 OUTPUT Block 5 8 Output Ports P48 to 55 OUTPUT Block 6 8 Output Ports P56to 63 INPUT Block 7 8 Input Ports JA P64 to 71 INPUT Block 8 8 Input Ports P72to 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 416 There are extra RS232 connectors as shown below so you have the flexibility to be able to access CUTOUCH when in an enclosed area O ea _ IT COMPLE Technology 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 TD RD Download Monitoring GND TD RD RS232 Channel 1 PC SIDE 417 Backup Battery CUTOUCH will maintain data in its data memory after power OFF by using its backup battery If backup is not needed the program must clear the memory at the beginning of the progra
92. 54 I y dis 187 455 M MCP3202 rp 338 Occ 377 MESGBR cti ds 377 UCA 105 MEMADR 20 e 184 MENU buttonS cooccoccnnconcoo 420 MENUCHECKoooccocccnccnccnnconos 422 MENUREVERSE se 422 MENUSE Tse coincide 421 MENUTITLE cccoccnccnncnncnnncnncos 421 MID aii 118 MODBUS eee 438 monitoring eese 352 multi tasking sssee 26 N loop 185 NOD ist eei e ic 186 Normally Closed 361 Normally Open 361 NOT 2 ns 374 NTC thermistor 325 O OFFSET deer 272 ON INT ideata eiii ibid ten 187 ON LADDERINT eee 188 ON PAD cian 190 ON RECV iiri 191 ON TIMER axis ni 192 Oriz Chips i3 eiiis daa 28 OPENCOM nsee 193 229 operators cococcnconcnccnnoncnconannono 93 ORS isaac ee ei laren 374 per 196 OUTPUT i i uideret vetrine 197 OU TS TAT Sisi eru Einb 198 456 P PAIN Ticos 274 PAUSEZ eue 198 PO 105 PEER i lote RENNES 199 PLC Setup Wizard 356 PLC Micro computer 29 Poke iie eds 105 POKE ener in 199 power regulator 43 PRI Tita 253 261 proto boards occooccoccnnnnncons 35 cl pae RE 273 PULSOUT tai 200 PUT Sieve niente toca Bee 201 PUTA we irte eror 202 203 PUTSTR iios ade utro Stree 204 PM ocre 205 PWMOFF socio std 206 R RAMCLEAR ese 85 207 RC Servo motor 333 Real Time Clock 336 re flashe
93. 56 I O ADC4 AD Channel 4 P29 55 I O ADCS AD Channel 5 P30 54 I O ADC6 AD Channel 6 P31 53 I O ADC7 AD Channel 7 P32 57 I O P33 58 I O P34 59 I O P35 60 1 0 Block 4 P36 61 I O P37 62 I O P38 63 I O P39 64 I O P40 48 I O P41 47 I O P42 46 I O P43 45 1 0 Block 5 P44 44 I O P45 43 I O P46 42 I O P47 41 I O P48 52 I O VDD 17 IN Power 4 5V to 5 5V VSS 18 IN GROUND RES 19 IN RESET Input LOW signal resets Normally HIGH or OPEN TX1 33 RS232 Channel 1 12V Data Output RX1 34 RS232 Channel 1 12V Data Input AVDD 35 ADC Power TTLTX1 49 RS232 Channel 1 5V TTL level Data Output TTLRX1 50 RS232 Channel 1 5V TTL level Data Input AVREF 51 ADC Reference Voltage 45 How to supply power to the CB280 The CB280 does not have a 5V regulator you must provide your own 5V power like shown below DC5V gt 10 17 voo TX TTLTX4 20 vss RX1 TTLRX1 30 19 RES AVDD AVREF 140 02 NC NIC P48 5 021 r 6 P24 P31 60 22 P17 P25 P30 70 23 pis P26 m 80 924 P19 P27 P28 90 25 P20 P4T P32 100 26 p21 P46 P33 10 27 p22 Pas P34 120 28 P23 P44 P35 130 29 P15 P43 P36 140 930 P14 P42 P37 150 31 P13 P41 P38 160 32 P12 P40 48 64 P39 Pin 20 and 36 are not used please DO NOT CONNECT anything 46 CB290 CB290 is in a 108 pin module package of which 91 pins can be used as I O ports It has a battery backup able 28KB of data memory and RTC C
94. 7 AD Channel 7 47 P16 83 IO CUNET SCL P17 84 I O CUNET SDA P18 85 I O INT Channel 2 P19 86 1 0 Block 2 INT Channel 3 P20 97 1 O P21 98 I O P22 99 I O High Count Channel 0 P23 100 I O 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 P64 33 Input P65 34 Input P66 35 Input P67 36 Input Block 8 P68 37 Input P69 38 Input P70
95. 7 Hex 1B 7 NONE 1 2 7 EVEN 1 18 Hex 12 7 ODD 1 26 Hex 1A OPENCOM 1 19200 3 30 20 Set to 8 N 1 193 The user can set the send and receive buffer size The send and receiver buffers take up space in the data memory Although you can set each buffer up to 1024 bytes it will take up that much of the data memory The number of variables you use may decrease We recommend receive buffer size from 30 to 100 and send buffer size from 30 to 50 For CB220 module port 1 and 2 can be used for Channel 0 Port 10 and 11 can be used for RS232C Channel 1 CHANNEL O TX sour f1 Y_ zh vin RX SiN 2 230 vss ATN F3 2210 RES vss 04 210 voD po Os 20H P15 P1 ge 49D P14 P2 o7 180 P13 P3 ge 17 pig CHANNEL 1 P4 Ho 160 P11 gt TX P5 10 150 P10 4 RX Pe O11 140 P9 P7 012 13H P8 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 one time 12V 12V 33e e s RX1 3e 50 AVDD 359 e 5 NC 36 52 P24 37 53 P25 38 e 54 P26 39 e 55 P27 400 e 56 P47 41 e 57 P46 420 e 58 P45 43 e 59 P44 44 60 P43 45 e P2 46 e 62 Pai 47 e 63 eec TILA AVREF Pas Pat P30 P29 P28 Paz P33 Pas P35 P36 Par P38 P39 mx gt 5 12V 12V
96. 7600 6 123 ON mae 115200 7 CuNET or RS232 280 GHB3224 DIP Switch number 4 is not Either Seven Segment Display CSG Series The seven segment display can be used to display numbers 8 LEDs are used for most seven segment displays as shown below To incorporate a seven segment display into products in the past people had to create a dynamic display method that is very complicated for the average user To simplify the matter we have developed an easy to use seven segment display called the CSG module Mn m In 7 01 1 E gt GHD 5V SCL SDA S csG 4s 0 amp O COMFILE As you can see above the front has 4 digit seven segment display and the back has two I2C connections After connecting the CSG to CUBLOC you can use the commands in the below table to easily and quickly display numbers you want Command Explanation Example Usage CSGDEC SlaveAdr Data Output decimal value CSGDEC O 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 281 Csgdec Use CSGDEC command to print decimal values to the SGN Const Device cb280 SIN cS must be used before csgdec command b 8 Do Esgdec 07b csgdec command Delay 100 Io Jo sp db If b 0 Then b 200 Loop To use C
97. 79 P 63 20 40 60 80 P55 PWM4 P90 95 ee 81 N C t 2 9 10 Port Blocks 50 CB405 CB405 is in a 80 pin module package of which 64 pins can be used as I O ports It has a battery backup able 55KB of data memory CB405 does not have an internal 5V regulator PWM6 P11 PWM7 P12 PWM8 P13 P14 P15 P27 PWM3 P28 PWM4 INTO P29 PWM5 INT 1 P30 INT2 P31 INT3 TtITXE TtIRXE AVref AD10 P34 P50 AD11 P35 P51 PWM9 AD12 P36 P52 PWM10 AD13 P37 P53 PWM11 AD14 P38 AD15 P39 P55 HCNT1 P47 P63 HCNTO P46 P62 SCL P40 60 e 80 P56 RX3 The pin numbers below are categorized by features not by pin numbers Name Pin I O Explanation SOUT 1 OUT DOWNLOAD SERIAL OUTPUT SIN 2 IN DOWNLOAD SERIAL INPUT ATN 3 IN DOWNLOAD SERIAL INPUT VSS 4 22 64 POWER IN 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 TTLTXE 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 is I O Ports explained in PortBlocks Block Name Pin I O Function Explanation PO 5 I O SPI SS Pi 6 Input SPI SCK Input Only
98. A amp HAA amp HAA amp HAA amp HAA amp HAA amp HAA amp HAA print CHR amp HDB30 Bmp BMP x y filenumber layer X y x y position to display BMP Filenumber BMP File number Layer Layer to display BMP GHB3224has FLASH memory to store BMP files Use the BMP Downloader to download BMP files Once BMP files are stored in the LCD you can simply use this command BMP to print to the LCD The GHB3224 has 102 400 bytes of Flash memory space to store BMP files You can store about 10 of 320x240 full screen size files 275 Graphic Data PUSH POP Commands On the GHB3224 series there is a separate stack for storing graphic data You can push and pop 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 similar to text editors 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 how the stack works gt eG 90 276 Gpush GPUSH x1 y1 x2 y2 layer Push x1 y1 to x2 y2 box to the stack GPUSH 10 20 200 100 2 Gpop GPOP x y layer logic logic 0 OR logic 1 AND logic 2 XOR logic 3 Clear screen then pop Pop from s
99. B280 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 Port Baud Rate COMA y 115200 mg m EIS DER ex Hu Fix Right Side e DAD Terminal Baud Rate n Data Bits di IM ML I Fix Right Side 155 Freepin FREEPIN I O VO O PORT Number Free I O Port set to LADDER using Usepin back to BASIC Use with CUBLOC STUDIO V2 0 X and above 156 Freqout FREQOUT Channel FreqValue Channel PWM Channel 0 to 15 FreqValue Frequency value between 1 and 65535 Output desired frequency to the desired PWM channel Please make sure to specify the PWM channel not I O port number For CB220 and CB280 ports 5 6 and 7 are PWM Channel 0 1 and 2 respectively The following is a basic chart showing the different FreqValues and corresponding frequencies 1 is for the highest possible frequency and 65535 is for the lowest possible frequency 0 does not produce any output FreqValue Frequency 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 also calculate the FreqValue to use by using the following formula Fre
100. B290 does not have an internal 5V regulator Of the I O ports 32 ports are Output only 32 ports are Input only and rest can be set as desired by the user 410061 TUTX1 420062 TIIRX1 430063 Avref 44 0064 450065 460066 470067 48 0 068 490069 500070 510071 520072 530073 5400714 550075 560076 570077 580078 590079 600080 SCL CUNET 98 6 84 P17_SDA CUNET INT3 INT4 0106 87 P72 97 83 P16 99 85 P18 00 86 P19 02 88 P73 03 e e 89 P74 0496 90 P75 05 e 91 P80 06 e e 92 P81 07 e e 93 P82 08 00 94 P83 o N a E z o P20 P21 P76 P77 P78 P79 P84 P85 P86 P87 PWM5_P91 96 82 P89_PWM3 PWM4 P90 9500 81 N C HCNTO P22 The pin numbers below are categorized by features not by pin numbers Port Pin IO 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 IO SPI SS Pi 6 Input SPI SCK P2 7 IO SPI MOSI P3 8 1 0 Block 0 SPI MISO P4 9 I O P5 10 I O PWM Channel 0 P6 11 I O PWM Channel 1 P7 12 IO PWM Channel 2 P8 25 I O ADCO AD Channel 0 P9 26 I O ADC1 AD Channel 1 P10 27 I O ADC2 AD Channel 2 P11 28 IO Block 1 ADC3 AD Channel 3 P12 29 I O ADC4 AD Channel 4 P13 30 I O ADC5 AD Channel 5 P14 31 I O ADC6 AD Channel 6 P15 32 I O ADC
101. BLOC supports DEBUG command by allowing the user to insert DEBUG commands as he wishes during the execution of a program The results of DEBUG commands inserted in the source code is displayed on the DEBUG Terminal DIM A AS INTEGER uaa ini xl _ Data Bits ary n n y a y ES e Rx DEBUG DEC A Use DEC or HEX to display numbers Without DEC or HEX the numbers will be printed as ASCII codes Please use DEC or HEX for variables to see the actual values If you insert question mark before DEC or HEX the variable s name will be printed together e TE Terminal iB x DEBUG DEC A CR Baud Rate Data Bits en 9 m DEBUG HERT fy CR zm y 115200 mn le lor 141 You can also use numbers to limit the number of decimal places to print DEBUG HEX8 A e a Terminal anl x Baud Rate Parity Data Bits en zm 115200 y Nore fe y RX 1 through 8 can be used with HEX HEX8 will print as 8 digit hexadecimal number 1 through 10 can be used with DEC You are free to mix strings numbers and etc DEBUG CHECK VALUE HEX A CR mixi Baud Rate DataBits_ grx 3n zm 115200 y io y fe y RK CHECK VALUE A 7B 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 displayed on the DEBUG Terminal 142 If you insert a DEBUG command to a c
102. Duty Value must be less than the Width Period Maximum of 65535 Pwmoff PWMOFF Channel Channel PWM Channel 0 to 15 449 Ramclear RAMCLEAR Reverse REVERSE Port Port I O Port Number 0 to 15 Set SET DISPLAY type method baud buffersize display type OZ Rs232LCD 1 GHLCD GHB3224 2 CLCD Method Communication Method O CuNET 1 COM1 baud Baud rate CuNET Slave address Buffersize Send Buffer Size Set SET DEBUG On Off debug Set i2c SET I2C 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 returninterval return 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
103. E PC 18T1 24v Ave b d LOAD 24V How to Connect a NPN TR Output This circuit diagram shows a NPN TR photocoupler separating 5V from the LOAD 24V CuBLOC 1 O Port 10K yak AM 194128 LOAD PC 18T1 Ses 24V How to Connect DC24V Input Use a double polarity photocoupler to convert 24V signals to 5V When input is received CUBLOC will receive a HIGH 5V signal 2 2K 1W CuBLOC 0 1uF 47K VO Port D T AM Ye i T 680 EE am a ji _ ge e 22K KPC714 no O DX ES TIT 5v 287 How to connect AD Input To connect an AD input to the CB280 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 inputted to AVREF pin O to 5V input voltage will be converted and if 3V is inputted to AVREF pin 0 to 3V input voltage will be converted DC5V DC5V TTLTX1 TTLRX1 AVREF P48 P31 P30 P29 P28 P32 P33 P34 P35 P36 P37 P38 P39 The CB220 s AVDD and AVREF are internally connected to 5V The following is the simplest type of AD input circuit using a Volume knob When you turn the knob the input will be converted by the CUBLOC ADC to a value from 0 to 1023 5V 10Koh
104. E 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 Blen Variable BLEN 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 Bmp BMP x y filenumber layer X y X y position to display BMP Filenumber BMP File number Layer Layer to display BMP 441 Box BOX x1 y1 x2 y2 Boxclear BOXCLEAR x1 y1 x2 y2 Boxfill BOXFILL x1 y1 x2 y2 logic logic O OR 1 AND 2 XOR Bytein Variable BYTEIN PortBlock 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 Circle CIRCLE x y r Circlefill 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 Cls CLS Clear CLEAR layer Cmode CMODE value value 0 BOX type 1 Underline type Compare COMPARE channel target port targetstate Channel High Counter channel Targe
105. E3 My Pictures File name Files of type CUBLOC Source file cul y Cancel idi 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 recovered When you press the RUN button or IMPORTANT CTRL R Save Compile gt CUBLOC module supports Code Download gt Execute are protection By encrypting automatically processed download data others can not LADDER and BASIC both are compiled with one RUN button If error is found during compilation the screen will move to where the error occurs simply read part of the chip s memory to access the source code 63 Creating BASIC You can create BASIC code as shown below CUBLOC Text Editor is similar to most text editors and supports Coloring of certain commands lt Cubloc Studio D _Tpc_test outofram cul Elle Edit Device Run Setup Help S Cui d ABE A mu E m FI BASIC F2 LADDER Ladder Mnemonic Const Device CB405 stl As String st2 As String aal As String aa2 As String E programmer Chr 10 2 timer Chr 10 comfile tech 2 cubloc amp cutouch controller Display 2 0 0 50 Opencom 3 115200 3 100 100 On recv3 Gosub aaa Set Until 3 100 10 Cls Do Debug stl Cr Debug
106. 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 every 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 406 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 407 408 Integrated Touch Screen Controller CUTOUCH User Manual Everything for Embedded Control COMPILE TECHNOLOGY Comfile Technology Inc www comfiletech com 409 Preface
107. FF Default is ON 263 Font FONT fontsize efontwidth fontsize O to 8 Font Selection efontwidth 0 fixed width 1 variable width GHB3224 has 4 different size and 2 different width Font Type Font 0 1 10 x 16 2 3 4 5 16 x 16 6 7 24 x 24 8 48 x 48 Const Device CB290 ETS 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 EOE O Glocate 10 120 GPrint FONT 0 ABCDEFGHIJKLMN nomi Glocate 10 140 GPrint FONT 2 ABCDEFGHIJKLMN Font 6 Glocate 10 160 GPrint FONT 6 ABCDEFGHIJ Font 8 Glocate 10 185 GPrint FONT 8 1 264 Style STYLE bold inverse underline bold O Normal 2 or 3 Bold inverse O Normal 1 Inverse underline O Normal 1 Underline You can use STYLE command to add Bold Inverse or Underline to your fonts Ja BOLD MAX INVERSE bem UNDERLINE 265 Cmode CMODE value value O BOX type 1 Underline type Choose the type of cursor to use Default is the Underline type Me 0 BOXx Type 1 UnderLine Type Line LINE x1 y1 x2 y2 Draw a line from x1 y1 to x2 y2 LINE 10 20 100 120 Draw line MQ Lineto LINETO x y Draw line from the last point to x y LINETO 200 50 Ew Continue drawing line from the last
108. GY can not be used inside the String ST COMFILE TECHNOLOGY can not be used inside the String ST COMFILE TECHNOLOGY can not be used 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 LCD Print Chr amp H22 COMFILE TECHNOLOGY Chr amp H22 Print Chr amp H27 COMFILE TECHNOLOGY Chr amp H27 Apostrophe 81 To connect multiple Strings you can use a comma as shown below onm 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 Debug Terminal Port Baud Rate Parity Data Bis grx a S lt CUBLOC studio d cubloc_test string cul com v 115200 None le T enx Ele Edit Device Run Setup Help Bang XGA mmi FI BASIC F2 LADDER Ladder Mnemonic Const Device CB280 Dim 81 As String COMFILE TECHNOLOGY Dim 82 As String 10 OREA SOCC 81 COMFILE TECHNOLOGY s2 KOREA SOCCER Debug 81 Cr Debug 82 Cr Fix Right Side 82 Merge Multiple Strings To merge multiple strings together use amp as shown below Dim al As String 30 Dim a2 As String 30 al Comfile a2 Technology ul e cul se mum se Y a Debug al cr The above program will show Comfile Technology
109. HB3224 DIP Switch 280 INTON Mr 404 GH seitens 37 257 GLAYER aiii is 262 K GLOCATE een 270 GMOV eee 392 Ms 385 GOSUB en 165 KCTUs a 385 GOTO osses 165 402 KEVIN Neoteo 179 GPASTE seeen 278 KEYINH teretes 180 GPOP rica re aa X A EROXRE 277 KEYPAD eee 181 GPRINT eee 270 KTAON dettes 381 GPUSH coonconnnnnoonannnnanonnnnnnons 277 KTON vaca irrita 381 H L l2 ee aai aa ses 112 NoYes 165 HIGED tiesa ida coat 170 PABE ees 62 dt md EK 402 HIGH Z wiciscvesdenieeestenseveswecves 176 LADDER LOGIC 24 344 TP Sti in o 116 LADDERSCAN eee 182 HPaste tins ecc rentes 279 UN 261 APO oras 279 LCD displays eee 36 HPUSH eene 279 left cabecera 118 Hyperbolic Cos 110 LEN siio rere is 119 Hyperbolic Sin 110 IGHT s cider ot rnt 263 Hyperbolic Tan 110 UNE Sun va dera 266 LINESTYLE aiii cas 273 LINETO acuso iia 266 Mi 110 I O ports A A 42 LOAD o dia a enei ep aaa a 373 I2 ia 296 EOADN ds 373 I2CREAD nee 172 173 LOCATE nerves 253 260 I2CSTART eee mme 171 Ke CNET aguveane 110 I2CSTOP unicidad 171 LOG LO iia lidia 110 I2CWRITE eene 174 Long 12 ecce ut ae 79 If Then Elseif Else EndIf 175 LOW sche acties ediceceterestla settles 183 IN sica adan 176 TRIM ii dados tics 120 INCR 1 iaa 177 INPUT onduten ono rere n ininda 178 input only pin seeren
110. IC F2 LADDER Ladder Mnemonic Const Device CB280 Dim A As Byte Dim As Integer B Dim C As Long D As Single Debug Terminal Port Baud Rate Parity Data Bits COM Y 15200 None y B hd A 123 B 5000 C 32999000 D 3 14 Debug Dec A Cr Debug Dec B Cr Debug Dec C Cr Debug Float D Cr Fix Right Side 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 ST1 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 Sering 12 10 Declare String Array 80 String A String size can be set up to 127 bytes When size is not set default value of 64 bytes will be used as the String size Dim SI As Sta TD SEN 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 COMFILE TECHNOLOGY LOGY do not fit here In CUBLOC BASIC must be used for String An apostrophe may not be used ST COMFILE TECHNOLO
111. IC as necessary The user is able to debug easier by having two processes work together instead of grudging through lines of BASIC codes DIM A AS INTEGER H IF IN 0 0 THEN OUT 2 LADDER LOGIC S Cubloc Studio D _Tpc_test BMPDOWN cul Ele Edit Device Run Setup Help ieu g XBA MA mu BE m FI BASIC F2 LADDER Ladder Mnemonic Print 27 BWBWRT pages gpg EE ex Delay 500 amp CUBLOC studio c tcubloc_testWu3 1018 cul 1 m Fils Edit Device Bun Sep Help Put RS232CH Asc K 1 g gGxmBua m uE m F1 Basic F2 LADDER Ladder Mnemonic For J 1 To pagesize Pie ae E e 55 ajag TE 4 OJO tro iro Wizard F3 Fa rs fe Fr Fe Fo Fi F Nor END hser Delete Undo Cony P5 F2 A XCCW Loop Until Blen RS23q TOUCH SENS INPUT PSI MB XCW TOUCH Geta R8232CH dt 256 F2 Bclr RS232CH 0 gamma For I 0 To 127 Step TOUCH SENS INPUT PSI MSEXCCW TOUCH Print dt I Print dt I 1 S PB F2 E3 1H 4 Delay 5 7 d Next TOUCH SENS INPUT P3I M10 YCW TOUCH Delay 100 For I 128 To 255 p p Print dt I Y H Print dt I 1 TOUCH SENS INPUT P91 MTI YCCW TOUCH Delay 5 H iB CCW FLSYN Next 31 PH F2 Delay 100 HH PR g TSENS ZCW Zccw eine MI2 Pe TOUCH SENS INPUT P91 M12 2CW TOUCH Delay 100 aa OL xl Put RS232CH Asc K Program 9602 Bytes Data 101
112. IM B 200 AS INTEGER Declare Integer array DIM C 200 AS LONG Declare Long array DIM D 20 10 AS SINGLE 2 dimensional Single array DIM ST1 10 AS STRING 12 i Declare String array COD A 3 6 A 3 3 6 CUBLOC supports multi dimension arrays including character arrays Up to 8 D arrays are supported 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 4 10 20 800 Bytes of Data Memory DIM D 20 10 AS SINGLE 86 Bits and Bytes modifiers A variable s bits and bytes can individually be accessed by using the commands shown below DIM A AS INTEGER DIM B AS BYTE A LOWBYTE amp H12 Store amp H12 at A s lowest byte LOWBIT Variable s bit 0 BITO to 31 Variable s bit 0 through 31 A BIT2 1 Make bit 2 of Al O 4o 4 gt N OS Iu y s BYTE LOWBIT Nibble A Nibble is for 4 bits By using Nibbles the user has more flexibility to manipulate the data LOWNIB Variable s NIBBLE O NIBO to 7 Variable s NIBBLE O to 7 A NIB3 7 Store 7 in Nibble 3 of A cono AAA A boa c bio c ns NIB7 NIB6 NIB1 NIBO LOWNIB 87 Byte To specify certain bytes of a variable the below names can be used A Byte is 8 bits LOWBYTE BYTEO BYTE 0 of Variable BYTE1 BYTE 1 of Variable BYTE2 BYTE 2 of Variable BYTE3 BYTE 3 of
113. Inc on the debug screen DEMO PROGRAM Debug Terminal Port Baud Rate Parity Data Bits ar 38 1 io dw c testistring c SS CUBLOC studio d cubloc_test string cul com 115200 None s x Cus El Edt Devre Rin Setup Help 3397 88 44 m mr EN ul ri DASIC F2 LADDER Ladder Mnemonic Const Device CE290 Dim al As String 30 Dim a2 As string 30 Comfile Technology Inc al Comfile az Technology al al a2 Inc Debug al 83 How to Access Individual Characters within a String You can use strings like an array Simply append _A after the name of your string variable like shown here M DIM STI AS STRING 12 SIM ago ST1 A 0 ASC A Store A in the first character of ST1 STI A Array is created at the same time When you declare Dim Sti as String 12 Sti 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 CUBLOC studio d cubl test stri T Port Baud Rate Parity Data Bis SC studio d cubloc_test string cu COMM 115200 N f File Edit Device Run Setup Help one S cuj 4458 gt ait Hu FI BASIC F2 LADDER Ladder Mnemonic Const Device CB280 Dim A As Integer Dim st As String 30 EID E st COMFILE dun
114. LADDER But you will need the most basic BASIC code 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 M1 RELAY1STATE 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 Interrupt An interrupt can occur during the main program to process immediate needs of some sort 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 RETURN command is used to return back to the main program INTERRUPT ROUTINE MAIN PROGRAM External Key input can be pressed and RS232 serial 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 CUBLOC possesses one of the most flexible interrupts in the world While an interrupt routine is running another interrupt request of the same type is
115. LC s can remotely control the status of its Registers in units of multiple bits The following is an example showing Slave Address 3 s P20 through P30 being turned ON OFF through this function code Query Field Header Slave Address Function Code Start Address HI Start Address LO Length HI Length LO Byte Count Data 1 Data 2 Error Check Ending Code Below table shows how the DATA in the above query is divided can be set to zero RTU 0X03 OXOF 0X00 0X14 0X00 0X0B 0X02 OXD1 0X05 CRC Bytes NJ HGB H oH p pH H d B mp ASCII colon P27 is placed in the MSB of the first Byte send and P20 is placed in the LSB of the first Byte There will be total of 2 bytes sent in this manner Left over bits Bit 1 T 0 1 0 0 0 1 0 0 0 0 0 1 0 1 Reg P27 P26 P25 P24 P23 P22 P21 P20 P30 P29 P28 Response Field RTU Bytes ASCII Bytes Header colon 1 Slave Address 0X03 1 03 2 Function Code OXOF OF 2 Start Address HI 0X00 1 00 2 Start Address LO 0X14 1 14 2 Length HI 0X00 1 00 2 Length LO OXOB 1 OB 2 Error Check CRC 2 LRC 2 Ending Code CR LF 2 312 Function Code 16 Preset Multiple Registers PLC s can remotely control the status of its Registers in units of Multiple Words at a time through this function code The following is an example showing Slave Address 3 s DO through D2 being written Query
116. LS vidus SO A SNO 2 CONST BYTE DATA2 31 25 102 34 1 0 65 64 34 O EAS 4473 OF i239 Strings can be used as shown next 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 Only 1 dimensional array is 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 S CUBLOC studio d cubloc_test constarray cul Eile Edit Device Run Setup Help BS d 488 4 gt mu Eu FI BASIC F2 LADDER Ladder Mnemonic if Const Device CB280 i Const Byte DATA 31 25 102 34 1 0 0 0 0 0 65 64 34 12 123 94 200 0 123 44 39 120 239 132 13 34 20 101 123 44 39 12 39 Debug Dec DATA1 3 Cr Debug Dec DATA1 6 Cr Debug Dec DATAl 1 Cr Debug Terminal Port Baud Rate Parity Data Bits COMI 115200 one 8 l Fix Right Side 92 Operators When using many logical operators the below priority table is used to determine which operator is operated on first Operator Explanation Type Priority To the power of Math Highest MOD Multiply Divide MOD Math Add Subtract Math lt lt
117. OC module CB405 you need to use CublocStudio v 2 0 X and above 1 New functions for the CB405 New Functions Commands Use the following commands for OPENCOM RS232 Channel 0 through 3 SET RS232 GET GETA GETSTR PUT PUTA PUTSTR BLEN BFREE CHECKBF BCLR ON RECV SET ONRECV WAITTX Use the AD commands from Channel 0 ADIN TADIN through 15 Use PWM commands from Channel 0 PWM PWMOFF through 11 2 Heap Access for the CB405 The HEAP memory access is a special feature only available on the CB405 module 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 Preface Comfile Technology has been developing PLC and BASIC controllers since 1997 With our past knowledge of this field we are giving you a brand new product that is more powerful flexible and has the best features of both BASIC controllers and PLCs Programmable Logic Controllers After experiences developing and selling TinyPLC a
118. P10 I O port 34 Pil I O port 35 P40 I O port 36 P41 I O port 37 P42 I O port 38 P43 I O port 39 P44 I O port 40 P45 I O port 41 P46 I O port 42 P47 1 O port 43 P48 I O port 44 P39 I O port 45 P38 I O port 46 P37 I O port 47 P36 I O port 48 P35 I O port 49 P34 I O port 50 P33 I O port 51 P32 I O port 52 VDD Power supply 53 VSS Ground 54 P31 ADC7 I O port 55 P30 ADC6 I O port 56 P29 ADC5 I O port 57 P28 ADC4 1 O port 58 P27 ADC3 I O port 59 P26 ADC2 I O port 60 P25 ADC1 I O port 61 P24 ADCO I O port 62 AREF Ref for ADC 63 VSS Ground 64 AVDD Power supply for ADC Please refer to Appendix F for detailed CB280CS specification 58 CB280CS Application Schematic to PC DOWNLOAD OF x2 5V Dr 5v poa A sh o DALE q2 6p q p ds gt sh Mud qs I 2p de x np 5V OF g7 op e ds N sh SERS FSSR 88888888 pl ust tice SS Tenn S eSRkSERRSESERS Ss 25 9722202225522 Kam x2 nrnnnnnmnnnnmnrnnrnrnr G HU o 8 ERBER 8 5 8G S8 m 9 Supervisor vwo i090 48 3 Pss Ky O A 2rxo a P36 3 OQ 3rxo 46 P37 Sa pig Q4 45 F3 pas gt 3 PWM3 P19 O 5 44 L3 P39 Lid E PWM4 NTO P20 6 43 O Ps PWMS IN Tt P21 O 7 l IBLOI E 42LJ Pa INT2P22 O 8 ap pas NT3P23 Q 9 CB 280CS 40 3 Pas ss po O 10 M 39 3 P44 pii Main Chip Q 11 SCK P1 38 3 Ps Mos P2 O 12 ATMEGAT128 18A app Pe MisO P3 g 3 36 Pat
119. P45 430 59 P34 PWM2_P7 P23 INT3 P44 44 60 P35 CUNET SCL P8 P15 HCNT1 P43 45 6 P36 CUNET SDA P9 P14 HCNTO P42 460 62 P37 P10 P13 P41 47 63 Pas P11 P12 P40 486 64 P39 CB280 The pin numbers below are categorized by features not by pin numbers Port Pin I O 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 IO SPI SS P1 6 Input SPI SCK P2 7 IO SPI MOSI P3 8 1 0 Block 0 SP MISO P4 9 IO P5 10 I O PWM Channel 0 P6 11 I O PWM Channel 1 P7 12 I O PWM Channel 2 P8 13 IO CuNET SCL P9 14 IO CuNET SDA P10 15 IO P11 16 1 0 Block 1 P12 32 IO P13 31 IO P14 30 I O High Count Channel 0 P15 29 I O High Count Channel 1 P16 21 IO P17 22 IO P18 23 IO P19 24 1 0 Block 2 PWM Channel 3 P20 25 I O PWM Channel 4 INT Channel 0 P21 26 I O PWM Channel 5 INT Channel 1 P22 27 I O INT Channel 2 P23 28 I O INT Channel 3 44 P24 37 I O ADCO AD Channel 0 P25 38 I O ADC1 AD Channel 1 P26 39 I O ADC2 AD Channel 2 P27 40 1 0 Block 3 ADC3 AD Channel 3 P28
120. PLC Embedded computer CUBLOC User Manual Version 2 5 Everything for Embedded Control COMPILE TECHNOLOGY Comfile Technology Inc www comfiletech com Copyright 1996 2006 Comfile Technology Blank Page SOUT CB220 2 VIN 5 5V 12Vinput vss CUBLOC ATN Y RES Core Module vss r VDD Pinout SS ADCO PO P15 HCNT1 Input only SCK_ADC1_P1 C P14_HCNTO MOSI_ADC2_P2 P13 MISO_ADC3_P3 P12 ADC4_P4 P11_TX1 PWMO_ADC5_P5 J P10_RX1 PWM1_ADC6_P6 P9_SDA CUNET PWM2_ADC7_P7 J P8_SCL CUNET SOUT 17 voD o TTLTX1 SIN O 18 vss RX1 e TTLRX1 CB280 mio on res woo se 51 VREF vss 020 Nc NIC e P48 SS PO 821 Pie ADCO P24 e P31 ADC7 Input only SCK P1 22 P17 ADC1_P25 o P30_ADC6 MOSI P2 023 P18 ADC2_P26 e P29_ADC5 MISO_P3 024 P19 PWM3 ADC3_P27 e P28_ADC4 P4 0 25 P20_PWM4_INTO P47 e P32 PWMO P5 26 P21 PWMS INT P46 o P33 PWM1_P6 27 P22 INT2 P45 e P34 PWM2_P7 0 28 P23 INT3 P44 e P35 CUNET SCL P8 29 P15 HCNT1 P43 P36 CUNET SDA P9 30 P14 HCNTO P42 e P37 P10 31 P13 P41 e P38 P11 32 P12 P40 e P39 TtTX1 TtlRX1 AVref Vss P32 P33 P34 P35 P36 P37 P38 P39 P48 P49 Vdd Vss RES VBB P8_ADCO P9 ADC1 P10_ADC2 P11 ADC3 P12_ADC4 P13_ADC5 P14_ADC6 P15_ADC7 P64 P65 CB290 SCL CUNET 84 P17_SDA CUNET INT3 INT4 PWM3 P66 ogoroowprooruo P50 P67 Zoooooooooooo0 P51 P68 KAM THOR DODONA p52 P69 ERES P53 P70 P54 200040 P71 90009000000
121. PRINT string Print String on the graphic layer You have more freedom in the graphic layer as you can use GLOCATE to specify exact position Then you can use this command GPRINT to print a string at that location GPRINT CUBLOC IS FASTER CR Print String and go to next line CR 270 CUTOUCH CUBLOC IS FASTER Dprint DPRINT string DPRINT is similar to GPRINT except it will over write the current graphics DPRINT WE LOVE CUBLOC CR Print String and go to next line 0 319 WE LOVE CUBLOC This command will allow a much faster printing speed as it will simply overwrite the background When trying to display animations or numbers that change rapidly such as moving ball or current time Dprint will allow smooth transitions Dprint can only be used with X Axis that is multiple of 8 For example you can use Glocate 8 2 or Glocate 16 101 271 Offset OFFSET xy You can set offset for the printed strings 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 239 OFFSET 3 3 Set x and y offset to 3 0 319 CUBLOC IS FUN COMFILE TECHNOLOGY 239 After the command the strings will automatically adjust to the new offsets 272 Pset PSET x y Place a dot on x y PSET 200 100 Place a dot Color COLOR value Set the color of LCD 1 is black and 0 is white Default value is O COLOR 0 Set col
122. Please be aware that the software may be upgraded often Please check www comfiletech com to download the latest version of CublocStudio Please do Setup gt Firmware Download after installing new version of CublocStudio as firmware of the modules is upgraded along with our software Firmware is comes automatically along w your new version of CublocStudio Please check www comfiletech com often for latest Manual Please make sure to insert the CUBLOC module correctly as inserting it upside down can cause damage to the chip Please be aware that our 1 Year Warranty only covers defective items Special thanks goes to Alexandre Braun amp Lextronics for applications on the Forum Batman for applications on the Forum Mauro Russo amp Uniplan Software srl Italy for User Manual Revisions Steve Yang amp Mr Bill Ebert for Modbus RTU Spence for website links and website bugs Table of Contents CHAPTER 1 CUBLOC GETTING STARTED 1Z eerte tttttttesenen 19 Mhat is CUBEOGC eene oie ette dee i eec desk bike aid 20 CUBLOC Specifications ooncocconcnncnnnnoncnnronanonnnnnnnnnnnnnnnrnnronrenannnnnns 21 Ladder Logic and BASIC i irern ii dci 24 Multi tasking of Ladder Logic and BASIC eee 26 Advantages of On Chip PLC Embedded Computer 28 Development Environment eren nennen nnne nre 30 Download and Monitoring through the Internet ccooccocccncnncnnnnnnconos
123. Q4 21H VDD p1 6 022 Pr P25 38 54 P30 AD INPUT Po g5 200 P15 p2 7 23 Pis P26 39 55 P29 PORT P16 190 P14 P3 80 24 P19 eat pis P2 7 180 P13 PA 9 25 P20 FAT ax AD INPUT P3 8 170 P12 P5 100 26 P21 TAS Hd P6 10 27 p22 P45 430 O 59 P34 PORT PRES i16 PM er 12 26 P23 Pas 44 60 P35 P5 10 15H P10 ps 120 29 Pis P43 45 61 P36 P6 O11 14H P9 P9 140 O 30 Pia pa2 par P7 12 13H P8 P10 150 O 31 P13 P41 P38 P11 160 32 P12 P40 48 64 P39 Please refer to the table below for AD channels CB220 CB280 CB290 CT17X0 CB405 A D channel 0 1 0 0 T O 24 1 0 8 1 0 0 T O 16 A D channel 1 T O 1 I O 25 I O 9 IO1 I O 17 A D channel 2 T O 2 I O 26 T O 10 T O 2 I O 18 A D channel 3 1 O 3 T O 27 T O 11 1 0 3 T O 19 A D channel 4 T O 4 T O 28 I O 12 T O 4 T O 20 A D channel 5 IO5 I O 29 I O 13 I O5 T O 21 A D channel 6 I O6 I O 30 I O 14 1 0 6 I O 22 A D channel 7 1 0 7 I O 31 I O 15 1 O 7 T O 23 A D channel 8 I O 32 A D channel 9 I O 33 A D channel 10 I O 34 A D channel 11 I O 35 A D channel 12 I O 36 A D channel 13 I O 37 A D channel 14 I O 38 A D channel 15 I O 39 ADIN command only converts once upon execution In comparison TADIN returns the average of 10 conversions there by giving the user more precise results If you need more precision we recommend the use of TADIN instead of ADIN 125 Alias ALIAS Registername AliasName Registername Register name such as PO MO TO Do n
124. R Ladder Mnemonic 3E el sel Monitoring Stop P56 P30 JOG LOW MODE MI7 JOG X INPUT C M18 JOG Y INPUT O MIS JOG Y INPUT O JOG Z INPUT M20 C Met JOG Z INPUT O M22 P30 P56 P30 JOG HI MODE JOG HI MODE tat Hal M23 0 X8 Y 82 Modified Program 9602 Bytes Data 101 Please be aware that it s two APOSTROPHES not a QUOTATION MARK 354 Options Window olx Ladder Style Size 1w e LADDER size adjust Line Space jg LADDER line space adjust Boarder Color Black White LADDER background color Monitoring Speed LADDER monitorring speed setting Fast Slow r uto Execute mode gt v Auto Run when download Auto run when download If you select to use 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 355 PLC Setup Wizard To use Ladder Logic in CUBLOC you must create the most basic BASIC code Although very simple this can be hard for first timers You can use the PLC Setup Wizard
125. Return IMPORTANT Please pay caution when creating the interrupt routine It must be less than the interval itself If interval is set at 10ms the interrupt routine from the label to its return must be within 10 ms About 360 instructions lines Otherwise collisions can occur within the program 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 Opencom must be declared beforehand CUBLOC has 2 or 4 channels for RS232C communication Channel O is used for Monitor Download but the user can use it for RS232 communication if she he wishes to forego monitoring Download will still work fine 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 Parity Stop Bit Bit of Bits 0 0 NONE 0 1 Stop Bit 0 0 5 bit 0 1 Reserve 1 2 Stop Bits 0 1 6 bit 1 0 Even 1 0 7 bit 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 2
126. Right Side 95 Expressing Numbers in Bits 3 ways of bit representation of numbers are possible with CUBLOC Binary 2 bit Decimal 10 bit and Hexadecimal 16 bit can be used Examples of how to Binary Decimal Hexadecimal 96 amp B10001010 0b1001001 amp B10101 0b1100 10 20 32 1234 amp HA amp H1234 amp HABCD OxABCD 0x1234 1234 SABCD Similar to C Similar to Assembly Language The BASIC Preprocessor The BASIC preprocessor is a macro processor that is used automatically by the compiler to transform your program before compilation It is called a macro processor because it allows you to define macros which are brief abbreviations for longer constructs 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 INCLUDE MYLIB cub For files in other directories you will need to include the full path name like shown here INCLUDE c mysource CUBLOC lib mylib cub By using include files you can store all of your sub routines in a separate file Please make sure to use pre processor directive include at the very end of your program After End for subroutines define name constants By using defi
127. SET pin 3 to SCL and pin 4 to SDA This 4 pin connector will be used as standard for CNET 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 CUBLOC while in idle state CuNET operates in a Master Slave mode Slave cannot start communication with the master For this type of communication you must use PAD communication PAD can receive inputs from other devices Please refer to ON PAD command for detailed information 292 CuNET device s connector s pin 2 connects to 5V of the main module Power GND SCL SDA MAIN GND SCL SDA CuNET Module CuNET device s connector s pin 2 connects to RESET of the main module when power is supplied to the CUNET device causes CUBLOC to reset Power GND SDA Active LOW to RESET Power GND RESET SDA MAIN CuNET lines can be used within 3 feet CuNET Module For longer communications up to about 1mile you can use Phillips I2C Long distance interface chip P82B96 or P82B715 293 CUBLOC STUDY BOARD Circuit Diagram Study board is especially for first timers and developers of CUBLOC Simple experiments including switches LED RS232 communication I2C piezo ADC toggle switch
128. SG commands SET I2C command must be used beforehand Slave Address Set the slave address of the CSG module at the back O0 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 n m 9 123 ata 1 123 m n 2 123 ON aii 3 eas Fn i ses sin 120 282 To display more than 4 digits use 2 CSG modules like shown below and set different slave addresses for each NE m n A El m a M Li L1 L1 a T L1 L1 LI Csgnput CSGNPUT slaveaadr 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 to the specified CSG module DATA most upper bit is for setting the DOT of the CSG You can use amp H30 to 39 and amp H41 to amp H46 only 283 Csgxput CSGXPUT slaveadr digit data slaveadr CSG module Slave Address digit Position 0 to 3 data Data Set the LED ON at the specified position When displaying anything other than numbers this command can be used to control each position of the LED itself A emi G LI mum D Bit 7 6 5 4 3 2 1 0 LED H G F E D C B A To print character L positions D E
129. Setup Help AS GARB A gt mimi m LFI BASIC F2 LADDER Ladder Mnemonic Const Device CB280 Dim A As Long A H1234 Debug Hex A Cr Debug HEX8 4 Cr Debug HEXS 4 Cr Debug Terminal ort Baud Rate Parity Data Bits gp com rs200 rore gt f E RK Fix Right Side 112 DEC Converts the variable to a decimal 10 bit DEC8 means to convert to 8 decimal places 1 to 11 can be used for decimal places DEBUG DEC A If A is 1234 1234 is printed DEBUG DEC10 A If A is 1234 bbbbbb1234 is printed b is a blank space in this case DEBUG DEC3 A IFA is 1234 234 is printed first character is cut S lt CUBLOC studio d cubloc_test format cul File Edit Device Run Setup Help Bud 428 A gt m4 Bs Parity Data Bits am F1 BASIC F2 cee Ladder Mnemonic cow liso mil mile Const Device CB280 Dim A As Long A 523478 Debug Dec A Cr Debug DEC10 A Cr Debug DEC3 A Cr Debug Dec A Cr 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 Strin
130. Syntax Features SET RS485 SET RS485 Channel Port Set Port Number for automatic control of TE Transmit Enable signal for RS485 converter Comfile RS485 Converter GETCRC GETCRC Variable Array Length Calculate the CRC VALHEX Variable VALHEX String Variable Convert hexadecimal String number to a decimal variable FREEPIN FREEPIN Port Free I O Port set to LADDER using Usepin back to BASIC FP FP Single Variable Whole Number Convert Floating Point variable Digits Fractional Number Digits to a formatted String COMPARE COMPARE Channel Set point When high counter value PortNumber PortStatus reaches a set point set an I O Port to Low or High I2CREADNA Variable IZCREADNA 0 I2CREAD command without acknowledgement 2 Modbus RTU Slave Mode SET MODBUS mode slaveaddress returninterval mode O ASCII 1 RTU slaveaddress Slave Address 1 to 254 returninterval return interval value 1 to 255 default value is 1 3 Pulse Control Command Function Syntax Features STEPPULSE STEPPULSE Channnel Output a set of number of PortNumber Freqency Number of pulses at a set frequency up Pulses to 15kHz STEPSTOP STEPSTOP Channel Stop Pulse Output Channel immediately STEPSTAT Variable STEPSTAT Channel Return number of pulses outputted since last STEPPULSE command 4 RS232 Receive and Send Commands Added Function Syntax Features PUTA2 PUTA2 Channel ArrayNam
131. Using the include file you will be able to save lots of time and be able to make changes to your menus without making it a big copy and paste hassle The following program is exactly same as SAMPLE4 except we use include file for the virtual keypad lt Filename CT005 CUL gt 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 NUMKEY Execute the Sub routine in INCLUDE file I 0 Do Loop GETTOUCH TX1 Getpad 2 TY1 Getpad 2 If Menucheck 0 TX1 TY1 1 Then lt lt 4 Pulsout 18 300 seif Menucheck 1 TX1 TY1 Then i lt lt d dom Pulsout 18 300 seif Menucheck 2 TX1 TY1 Then i lt lt 4 SIM NES Pulsout 18 300 seif Menucheck 3 TX1 TY1 Then cg e d ral E E 434 4 Pulsout 18 300 Elseif Menucheck 4 TX1 TY1 Then lt lt 4 a Pulsout 18 300 Elseif Menucheck 5 TX1 TY1 Then lt lt 4 6 Pulsout 18 300 Elseif Menucheck 6 TX1 TY1 Then lt lt 4 sry Pulsout 18 300 Elseif Menucheck 7 TX1 TY1 Then lt lt 4 g Pulsout 18 300 Elseif Menucheck 8 TX1 TY1 Then x E Pulsout 18 300 Elseif Menucheck 9 TX1 TY1 Then lt lt 4 Pulsout 18 300 Elseif Menucheck 10 TX1 TY1 1 Then 0 Pulsout 18 300 End If Locate 3 3 Print HEX4 I Return End INCLUDE CT005 INC We must include include command at the end of th
132. WMs DACs bit PWMs DACs PWMs DACs PWMs DACs Analog Configurable Frequency Configurable Frequency Outputs Configurable Fre Configurable Fre 35hz to 1 5Mhz 35hz to 1 5Mhz quency 35hz to quency 35hz to 1 5Mhz 1 5Mhz External None 4 Channels 4 Channels 4 Channels Interrupts High 2 Channel 32 bit 2 Channel 32 bit F 2 Channel 32 bit 2 Channel 32 bit oppend MT up to M up to Counters up to 2Mhz Counters up to 2Mhz Power 5 to 12V 40mA 5V 40mA ports 5V 70mA ports 5V 50mA ports ports unloaded unloaded unloaded unloaded Data Memory None None Optional Optional Back up Operating Temperat 40 C to 120 C 40 C to 120 C 40 C to 120 C 40 C to 120 C ure 24 pin DIP m x Package 600mil 64 pin Module 108 pin Module 80 pin Module 1 2 L x 0 6 W x 1 4 Lx 1 W x si 0 4 H 0 4 H 2 4 L x 1 9 W x 0 5 H 2 4 L x 1 9 W x 0 5 H Ize 30 x 15 3 x 11 35x 25 4 x 11 59 4 x 47 8 x 13 mm 59 4 x 47 8 x 13 mm mm mm 21 The main advantage of CUBLOC over other PLCs 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 Another advantage over other BASIC processors is that CUBLOC is able to separate the amount of work and programming between Ladder Logic and BAS
133. act B Normally Closed OUT Output NOT NOT Inverse the result STEPSET Step Controller Output Step Set 1 1 STEPOUT J Step Controller Output Step Out MCS Master Control Start t1 MCSCLR Master Control Stop t1 DIFU Set ON for 1 scan time when HIGH signal L received DIFD Set ON for 1 scan time when LOW signal received SETOUT Maintain output to ON t1 RSTOUT Maintain output to OFF T END End of Ladder Logic t1 GOTO Jump to specified label T LABEL Label Declaration T CALLS Call Subroutine 1 1 SBRT Declare subroutine RET End Subroutine TND conditional exit command 371 High level instructions Command Parameter Explanation Data Transfer Commands WMOV s d Word Data Move DWMOV s d Double Word Data Move WXCHG s d Word Data Exchange DWXCHG s d 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 Decrement 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 Opera
134. ame 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 PUTA command except it will stop transmission upto a set character in the array StopChar will be the last character to be send 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 Send String data to RS232 Channel OPENCOM 1 19200 0 50 10 PUTSTR 1 COMFILE TECHNOLOGY DEC I CR Similar to 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 Use PWM to Output desired PWM frequency When using this command please be aware that PWM Channel Number is different from I O port number For CB280 Ports 5 6 and 7 are used for PWM 0 1 and 2 respectively Before using PWM please make sure to set the Ports used to OUTPUT mode According to the set value of Period a maximum of 16 bit precision PWM signal is created When Period is set to 1024 it will be a 10 bit PWM When Period is
135. an be set to sense input on the Rising edge Falling Edge and 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 ON LADDERINT GOSUB command is used then the processor will jump to the routine specified by On Ladderint command This can be used when LADDER part of the program needs to jump to BASIC code Please use the SETOUT and DIFU command to write 1 to the Register F40 When 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 signs 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 i itl Byteout 1 i Delay 200 Loop msgl_rtn Locate 0 0 Print ON Ladderint Dec i Reverse 1 Return 1 SETOUT F40 1 When PO turns ON it will turn on F40 and when Register F40 turns ON msgi_rtn interrupt routine in BASIC will be executed In the interrupt routine a string is
136. an use Peek and Poke to read the data directly The following is how we would accomplish that 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 Peek command to directly access the memory and write 4 bytes We store that value in EEPOM Conversely 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 SRAM 105 Sharing Data CUBLOC has individual BASIC and LADDER data memory BASIC DATA MEMORY Variable Variable Variable Variable Variable Variable LADDER data memory can be accessed from BASIC easily by using system By using these system variables data can easily be read or variables written from and to LADDER LADDER DATA MEMORY System Variable Access Units Array 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 31 M Register Word Access B Words T 0 to T 99 T Register Timer E 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 an
137. anation 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 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 i h1111 Channel 1 Sh Bomber ecl eod d ad Shiftin ioclk iodo 3 12 High iocs Debug Dec ad cr Delay 100 Loop 338 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 inputted to the MCP320 CHO and CH1 pins must not be greater than the voltage supplied to the MCP3202 The result of A D conversion is displayed to the DEBUG window E TM Terminal 0 xj Baud Rate ex T E y 115200 y mm y b H RX Close T Fix Right Side lt END gt 339 NOTE 9 Read and write to the EEPROM With the EEPROM you can store between 0 5 to 64 KB of data Data is retained even after powering off allowing it to act almost as a small hard drive If you want to retain a temperature setting for a temperature controller you can simply store the value of the temperature in the EEPROM in case of power outs CUBLOC has an internal EEPROM of 4KB For small and simple data you may use this internal EEPROM In the case of
138. 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 slaveaar data slaveadr CSG Slave Address data Data Print decimal value to the CSG Csghex CSGHEX slaveaar data slaveadr CSG Slave Address data Data Print hexadecimal value to the CSG 284 Chapter 8 Interface Input Output Circuits How to connect LEDs Please connect the LED as shown below and output HIGH to the connected I O port to turn the LED ON 330 ohm T CuBLOC I O Port How to connect push switches Please connect the push switch as shown below and set the connected I O port to INPUT mode When the switches in pressed CUBLOC will read HIGH and when LOW otherwise puc CuBLOC I O Port 10Kohm How to connect Volume knob Please connect the Volume knob as shown below to a A D I O port and use ADIN command to read the input value of the Volume knob 10Kohm O CuBLOC O Port The CUBLOC core module uses 5V power When using larger voltage please use appropriate voltage converter or regulator 286 How to Connect a Output Relay The following diagram shows how to connect a 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 24V RELAY VO Port 1N4148 ex r1 ES Ea
139. and setup the I Os you will be using and create the BASIC source automatically PLC SETUP WIZARD Fil BAS F2 LACDER alle si I poset e oe r3 r4 r5 G pr RE r9 rii EM PLC Setup Wizard Ladder environment edit Output BASIC code review Device Select 1 0 maps A D convertor CB220 xl F Use all IN all OUT all IV AD channel 0 gt DIO W AD channel 1 gt D11 TF AD channel 2 gt D12 FT AD channel 3 gt D13 AD channel 4 gt D14 I AD channel 5 gt D15 I AD channel 6 gt D16 TF AD channel 7 gt D17 g 8 High Count gt D39 Out el Out GlRelayout Out Glsoloutt Alias Nick Name Out Motor Example Out Cl Papis E 2 Out el MO SubRelay Out el MED ot el IM2 FELAYT od E MS KOREA Out el ou el High Count gt D38 C PWM 0 1 2 lt D26 PWM 3 4 5 lt D29 iv use MODBUS on CHI I XI XI I XI XI I 000090009 115200 None 8 1 F Use Fast Scantime Load Save AS Replace Basic Code Cancel 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 356 EE PLC Setup Wizard Ladder environment edit Const Device CB220 om L120 300 20
140. aracter arrays DIM A 100 10 20 AS BYTE 70 Hardware RS232 Communication are Supported CUBLOC supports hardware RS232 communication meaning it does not conflict with real time processing 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 GHLCD Drawing boxes lines circles and graphic commands are easily implemented in few lines of code Various Communication Protocols are supported CUNET Display Peripherals such as LCD RS232 4 channel MODBUS HMI and Touch screen Protocol I2C I2C commands supported I2CREAD I2CWRITE SPI SPI commands supported SHIFTIN SHIFTOUT PAD Keypad touchpad supported Advanced Basic Language is Comparable to C Language 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 7i Simple BASIC program Below is an example of simple BASIC program with Do Loop statement Dim A As Byte Do Byteout 0 A A A 1 Loop This program outputs to Port PO P7 an increasing value of A 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 sepa
141. ather than IN which will remove the bouncing effect by software lt Filename keyinhinput cul gt 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 O 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 For the industrial field there can be a lot of noisy environments where it can affect the switch signals In order to block noise the user 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 noise from affecting the switch DC24V DC5V e 2 2Kohm Me wk ri e CUBLOC I O PC 18T1 10Kohm MRE AW END 321 NOTE 2 Keypad Input Application note 2 will cover a 4 by 4 Keypad by taking its input and outputting the results to a 4 digit 7 segment module CSG module CB280 I1 LI P8 ILL LI P9 PO P1 P2 P3 P4 PS P6 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 mE mE T LI Ci D Gl EE CSG 4S 103 lt Filename csgprint cul gt Const Device CB280 Set I2c 9 8 Dim I As Byte Do Csgdec 0 I
142. atically keep sending the data in send buffer until it s empty If the send buffer is full when PUT command is executed the PUT command will not wait for the buffer to flush In other words the data to send 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 PUL bos END IF BFREE checks for how much space the 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 On Recv interrupt routine for receiving data using the hardware serial buffer 201 Puta PUTA channel ArrayName bytelength channel RS232 Channel 0 to 3 ArrayName Array Name Bytelength Bytes to Send 1 to 65535 The command Puta can be used to send a Byte Array Simply put name of the array and number of bytes to send 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 ArrayN
143. ault value Counter Normal Operation Maintain status after MCS turned OFF Other Normal Operation Stop Operation Commands 377 The following screenshot shows MCS used within another MCS i Mo MCS 0 l LHH E 1 i P P5 HI bo uses Dee ce nnm MCST 73 I HI t 31 I P1 i PB i uH I A T MCSCLR i i C 1 1 Ma MET ENEDE NONU I l MCSCLR 0 l t 1 I I I I llle ERES 4 MCS t 1 l I l I l I I MCSCLR 0 I i 1 I I l I 378 Step Control S Register are used for step control The following is the correct format for step control Relay 0 15 20 0 255 S7 126 In Step Control there s normal step and reverse step For normal step we can simply use the STEPSET command STEPSET PO STEPSET 80 1 t 1 P1 STEPSET S0 2 t 1 P2 STEPSET 80 0 t 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 SO 1 is turned ON S0 1 is turned OFF When P2 turns ON S0 0 is turned ON and other steps are turned off S0 0 or step O is used for reset Otherwise STEPSET will move in order po E P1 pe Fl S0 0 S0 1 S0 2 379 STEPOUT This command STEPOUT will only 1 step to be enabled at all times The last step to be tur
144. ble 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 This function is for calculating 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 D N Il NFOWN o 0 3 Getcrc 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 be String and length of data is not limited 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 CUBOS Cr Do While In 0 1 Loop Loop GOTDATA A Getstr 1 8 Debug A Return C B280 TTLRX TTLTX e 9 9 163 Getstr2 Variable GETSTR channel length stopchar Variable String Variable to store results channel RS232 Channel length Length of data to receive StopChrar Stop
145. c s data memory In the above example you can access Register M1 as _M 1 and write to it from BASIC As you can see CUBLOC supports BASIC and LADDER multi tasking simultaneously through data memory sharing 27 Advantages of 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 When using these PLCs an external case and cabinet must be used in addition to other mind bogging wiring requirements When using just a couple of sets this might not present a big problem But when mass producing such PLCs labor cost for assembling the PLCs and faulty parts could lead to many problems Most importantly the overall design of you final product will be bigger and will cost more to produce CUBLOC CORE MODULE 28 CUBLOC is an On Chip PLC allowing 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 allow the product to be one of a kind The following table shows differences between a traditional PLC and On Chip PLC Micro computer CUBLOC Traditional PLC CUBLOC Picture Production Din Rail Attachment Din Rail or PCB Labor Costs High Low Mass Difficult Easy Production Final Product High Low Cost
146. ce Address The above table 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 Address after 40000 are word registers meaning you can access 16 bits at one time Please refer to the below Device Address when using MODBUS with CUBLOC or CUTOUCH Device Address here is shown in decimals Earlier Modbus Addresses were in hexadecimals Bit Access 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 the Device Addresses within the available number of registers in the module used For example the CUBLOC CB280 has data registers from DO through D99 There can only exist Device Addresses from 40001 to 40099 The rest of 400100 through 41000 the floating device addresses are
147. ces to 10 If A is 1234 bbbbb1234 will be displayed b stands for blank spaces DEBUG DP A 10 1 If A is 1234 0000001234 will be displayed anales Debug Terminal Baud Rate Parity Data Bits eT bo Port com 115200 Mone cw e RX a CUBLOC Studio D CUBLOC_Test FORMAT cul File Edit Device Run Setup Help BASH GABE a gt at Bs FI BASIC F2 LADDER Ladder Mnemonic Const Device CB280 j Dim A As Integer A 1234 Debug Dp A 8 Cr Debug Dp A 10 1 Fix Right Side 115 HP Variable Decimal Places ZeroPrint This command HP converts Variable into hexadecimal String representation If ZeroPrint is set to 1 zeroes are substituted for blank spaces Y 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 Y Y Y DEBUG HP A 4 1 If A is ABC OABC will be displayed a 2 ee Terminal Z CUBLOC Studio D CUBLOC_Test FORMAT cul Baud Rate Parity Data Bits Tx bil File Edit Device Run Setup Help COM ce 115200 None aemexmA wai im cie zl lem F1 BASIC F2 LADDER Ladder Mnemonic Const Device CB280 Dim A As Integer A amp habl2 Debug Hp A 4 Cr Debug Hp A 8 1 I Fis Right Side 116 FP Value Whole Number Digits Fractional Number Digits Convert Floating Point variables in
148. d nes 363 Relay Expression 359 Relay numbers 364 representation of numbers 96 RET irte re iones 403 RETURN Littere 165 REVERSE iiit iesin 208 A e ri 118 RND denn ia etaient snp inaa 209 RSTOUT 2 nidi saves 375 RIRIM 2 einen bots aces eene iode 120 RT 315 316 317 SO Toro ds 403 Select Case niisiis 210 SET DEBUG we inis 211 SET DISPLAY 1c 251 SET I2G 4 ide 214 SERIA raci n 215 SET LADDER On 216 Set Modbus eeese 217 SET MODBUS enne 5 SET ONGLOBAL 218 SET ONINTX eeeeene 219 SET ONLADDERINT 220 SET ONPAD een 221 SET ONRECV eene 222 SET ONTIMER ee 223 Set Outonly On 50 SERPAD cerei 225 Set Rs232 diia 228 SEL UN TE 231 SETOU Mitin aii 375 Seven Segment display 37 Sharing Data 106 SHIFTIN rire 232 SHIFTOUT nasip issida iaiia 233 SIM ore a ae a piia 110 SIN 42 Single crees 79 Sounds E 330 SOU ruere tesa en pene 42 special relays 406 SORS ETA 110 step control sees 379 STEPOUT hietaa 380 STEPSET e e itinere 379 SUNG s eoo reete 81 STRING rris 119 Study board sess 36 SU VE idle eI iens 265 Kc 238 T TADIN ione 125 239 Tani zi Dnus 110 TAO Foios 382 TAON pta 381 JD entere enel eive Dues ie vere iret 31
149. d collision among the two the I Os used in BASIC and LADDER should be specified One a port is declared with USEPIN command it can only be used in LADDER and cannot be accessed in BASIC USEPIN O IN 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 363 Use of Aliases When creating Ladder Logic using Register numbers such as PO P1 and MO the user can use alias to help simplify their programs PD P5 i C P1 Ab STARTKEY MAINMOTOR Swi HH In order to use alias you need to declare them in BASIC You can simply use ALIAS command to use ALIAS for Registers you desire to use LIAS MO MAINMOTOR LIAS M2 STATUS1 LIAS M4 MOTORSTOP gt DD You have an option of either using USEPIN or ALIAS command to use aliases in LADDER 364 Beginning of 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 consistently within the specified scan time of 10 milliseconds If you do not use SET LADDER ON command Ladder Logic will not be executed SET LADDER ON Declare devices to use You must declare the device to be used so the compiler knows The following are examples of how to use the CONST DEVICE command CONST DEVICE CB220 Use CB220 or CONST DEVICE CB280 Use CB280 This command must be placed at th
150. d on KCTU and KCTD commands can be used in place of CTU and CTD commands in order to make use of this KEEP timer and KEEP counter Please refer to KCTU KCTD commands for detailed information 419 Menu System Library CUTOUCH supports extra commands for easy to use menus These commands make for easy creation and manipulation of the menus With the menu system library a menu system shown in the below picture can be made in less than 5 minutes Comfile Automobile gas pressurizer Select gas coo Auto type Gas left Initialize Total cost MENU Commands CUTOUCH has memory space for about 100 MENU buttons Use MENUSET command to set the x and y axis positions and the style of the MENU Then MENUTITLE command can be used to name the MENU When touch input is received 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 positions and style by using MENUSET command The only restriction is that up to 100 button can be inputted at time in one screen But the user is free to reset each button to another usage after each screen allowing infinite buttons 420 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 Index value mu
151. d the rest of the 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 represents PO through P15 The following is an example program D 0 1234 _D 1 3456 _D 2 100 FOR I 0 TO 99 _M I 0 NEXT IF P 3 1 THEN M 127 1 For example _WP 0 Reversely accessing BASIC variables from Ladder is not possible but you can use Ladder interrupts to get around this 106 Use Ladder pins in BASIC using ALIAS command ALIAS command can be used to set aliases for Registers all except D used in LADDER Both BASIC and LADDER may freely use these set aliases Usepin 0 In START Usepin 1 Out RELAY Alias MO MOTORSTATE Alias M1 RELAY1STATE Alias T1 SUBTIMER RELAY 0 Sete pone TITO LOW MOTORSTATE 1 Sie IN seo tL Same as MOR iL A RELAYISTATE Store M1 status in variable A B SUBTIMER eStore Tr 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 A SIN B Return Sine value A COS B Return Cosine value A TAN 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 A ASIN B Return Arc Sine value A ACOS B Return Arc Cosine value A ATAN B Return
152. der You can press CTRL D to erase a rung This actually moves the rung to a buffer START RELAY 1 HH END 2 t 1 348 Rung Recovery To recover an erased rung press CTRL U START RELAY 1 Hl Ine C OUT2 2 HI END 3 t 1 Cell Insert and Delete START TON T0 100 1 1 If you press DEL button from current position the cell is erased and items on the right are pulled one cell to the left HE TON T0 100 1 e FL 1 If you press INS button from the current position a blank cell is inserted and items on the right are moved one cell right START TON T0100 m Rung Copy When 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 T0 100 1 HI c 1 oH F 349 Comments You can enter comments by adding an apostrophe THIS IS SAMPLE PROGRAM PO P3 u C You can use a semi colon to display to the next line For example This is Sample Program Date 24 Sep 2007 Comfile Technology THIS IS SAMPLE PROGRAM DATE 24 SEP 2007 COMFILE TECHNOLOGY Po P3 C 350 LADDER BLOCK COPY and PASTE You can make a selection of a block to copy and paste to different parts of the LADDER CUBLOC studio c Ycubloc testYu3 1018 cul File Edit Device Run Setup Help Bod d A28 4 gt att 8 El F1 BASIC F2 LADDER Ladder Mnemonic PLC ETE I ES ES a ES Z4 41 10 1
153. dress 497 Slave Address 34 Slave Address 42 Slave Address 02 Slave Address 04 Even though maximum range for typical I2C 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 P82B96 can also be used as buffer to protect the I2C devices in case of electrical surges and interferences 300 N C VCC LX LY LX LY Buffered Bus LDA or LCL SX P82B715 SY SX SY 12C Bus SDAor SCL GND N C Extend up to about of 3 4 mile using the P82B715 SDA SCL P82B715 CUBLOC P82B715 12C DEVICE By using the P82B96 ground and power can be isolated on the device ends SDA VCC SDA p RX SCL lt RX P82B96 TX RY sc gt Ty GND TY lt RY P82B96 12V 12V 5V T T 5V LONG CABLE SDA gt SDA lt SCL il yt q1 gt ti ScL p lt gt lt P82B96 P82B96 Please refer to Phillips website for more information on the specific chips discussed here http www standardics nxp com 301 If you are using I C interface within 12 feet we recommend to use the following protection circuit If the I2C devices are connected with no buffers electrical interference can cause damage to either CUBLOC or the I C Slave device By using diodes as sh
154. e StopChar Length Same as PUTA command except it will stop transmission upto a set character in the array StopChar will be the last character to be send GETA2 GETA2 Channel Array name ByteLength StopChar Same as GETA command except it will stop reading data at the StopChar even if there are data left to read set by the Length If StopChar is not found then it will operate just like a GETA command GETSTR2 String Variable Length StopChar GETSTR2 Channel Same as GETSTR command except it will stop reading data at the StopChar even if there are data left to read set by the Length If StopChar is not found then it will operate just like a GETSTR command StopChar is read from the buffer but not stored into the String Variable 5 RTC using the system timer for CUBLOC without RTC This command will allow you to use the system timer of CUBLOC as an RTC You can use TIME and TIMESET functions to access the following addresses address Returning Value Range 10 Seconds 0 to 59 11 Minutes 0 to 59 12 Hours 0 to 65535 13 Continuous Seconds 0 to 65535 NEW CUBLOC Module CB405 The new CUBLOC Module CB405 has more program and data memory with additional 2 RS232 serial channels over older CUBLOC modules Core Module Features CB405 RS232 Channels 200KB Program memory 110KB Data memory 64 I Os 4 To use the CUBL
155. e 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 software can be downloaded on our website under Download gt Integrated amp ASS Pixel Studio lt gt Source Code Type Starting CHR Code 8H DB30 base sHDB30 indent O te DEFCHR 8HDB30 8H00 8H00 8HO0 8HOO 8H3C 8H00 8H06 8H00 _ HO 8HO0 8H00 8HCO 8HOF HCO amp HOB AHED 8HO8 8H70 8HO7 5HDO 8HO3 8HTO 8HOO SHIO 8H07 amp H1 8 8H01 2HF8 2H00 2H00 2H00 400 Copy To Clipboard Save To Fie BASIC 3E LADDERZE SAM SE SIEIH 2 EZAN FSS Mo somoe PQ es tt Hey 414 X Numkey cvs CuCANVAS File Edit Generate Tools View Help RECERCA Numkey Use tab key to select neiahoa r ones 116250 reser x cal el J1 CT1720 33 32 2 82 J2 CUTOUCH I O Ports High Counter Input or I O Other I Os CT1720 shown here Model Name PPAe e PPA 04 e e 8d PPAe e PPA Zd e e 6d Zd e e Old d e e lid fd e Zid SSA e e SSA Sd e e ld SSA e e SSA 9d e e tid SSA e e SSA id e e Sid XS ossi e e ssn poaters O or T ssh e e SSA sspe e nud D al a o m al E ME vzde e Ord 99d e e zld E Side Lpd LSd e
156. e user may change the EEPROM chip s address by configuring the chip For a read 1 can be written for R W and for a write O can be written for 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 are sent Stop command can be sent It takes about 5ms of time for EEPROM write The following is a write EEPROM sequence in CUBLOC s BASIC code Set I2c 8 9 t Set P8 as SDA P9 as SCL T2eStart If I2cwrite amp H10100000 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 If I2cwrite 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 297 R W Repeated Start R W NoAck y y M y S CONTROLBYTE 0 A HIGHADDRESS A LOWADDRESS A S CONTROLBYTE 1 A DATA X P S Start p A Acknowledge Read Point P Stop Read Point is where the actual DATA will be read from the EERPOM The front part of the command is for setting the address to read data get I20 8 9 I2cstart If I2cwrite amp H10100000 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 esta
157. e Ne Ne px AN 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 like DO Loop it can enhance the speed of Ladder program more than 10 ms per scan time If using this command as shown below you will not be able to use BASIC at the same time 182 Const Device CB280 Usepin 0 In START Usepin 1 In RESETKEY Usepin 2 In BKEY Usepin 3 0ut MOTOR Alias MO RELAYSTATE Alias M1 MAINSTATE Do LadderScan Loop Device Declaration Port Declaration Aliases 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 OV When a port is set to High the port is internally connected to VDD whereas if it s set to Low the port is internally connected to VSS 183 Memadr Variable MEMADR TargetVariable Variable Variable to store results No String or Single TargetVariable Variable to find physical memory address Like C language you can use pointers in BASIC By using pointers you will be able to find the physical memory address of RAM and use it to store or read data
158. e code This is slightly different from other languages such as C CUCANVS can download at www comfiletech com CUCANVAS is free ware 435 436 APPENDIX Appendix A ASCII CODE char Code char Code char Code Code char EE i a oJ lo ola o c x El clo oi oo 5 gt Z x X ni H AY A I I I III I II I I IT I I I III Xj xp x Ll Ll LPL LPL L L L L III O A Ni OO SH LO WO BN olol lt al O A wy ie Oj FIN mM t LN wor oc BD LC a O O wie O WO O tO O WO O WO XO O 6 tO 6 o o tO mM mM mR mR m mM NMMPMNPNMMSPNPSNSPMNPM P G lt olol o wl alol I la xu E zo a Ol o H l gt Z x gt N A lt x xx LPL LL ij VL L L LL rj Xl xXx LPL LPL LPL L L L L Ll a Oj a NN MO SF LO WO RN o aj lt al Oj CQ wy it Ol I A OO t LEO O RN CO aj LC a OF A wy ie SPSL SPS A SEL SEE SE SE SE SE SE ty te SE LA LA to LO LO LO tO LO LO LO LA LA LO LO LO LO Ww Hl le 3 AS ale dna i O A Ni mM LN WO IN CO O J Vi I Aya I I II II II II LL L L LL cry I I I III I II I I I I I III oO A Nim in GNI olal lt al Ol O wy ie O AIAN ml F LO O NR ol ol lt a al Ol OQ wy ie NINININI NI NINI OE NINI NN A NN NI MA ea ca en a a cA am A a a a A mm mm JA Z x xl e O x uir w oisxizimiz mio DOJE Ol
159. e treten e 91 G ol rele RP 93 Expressing Numbers in Bits cconconccnccncnnnnnncnncnnnnnnnnonconconcnnaronnenannnos 96 The BASIC Preprocessor iis deer rece enge or pere dne setae oen eroe nde ia 97 Conditional 2 22 ota coil ita latina luar io dls 5 dla 99 To use EADDER ONLY iaa a ia de 102 To Use BASICONE eiia ina ia 102 Int rruptss ie naaa bore etuer had yb ean ia a 103 More about Interrupts eerie eerte ae EE aa e SRETNES 104 Pointers using Peek Poke and Memadr eese 105 Shiaring D ta deri ee e rere rai 106 CHAPTER 5 CUBLOC BASIC FUNCTIONS eee tttttteeenn 109 Math Fufictiors riore net er ze Saepe tenent diia 110 Type CONVE a aso 112 String FUNCION So 115 CHAPTER 6 CUBLOC BASIC STATEMENTS amp LIBRARY 123 pun 124 AliaS ciere REID t E MEE sete PUEDE REM 126 A EE TEE aa aaa 127 fe ES 128 BOC yee eise eecosa E 129 Bfree oen ote ed eee buie dtes 130 BINZDCO eS 130 Bin2Dcd A three lure nut etfi toes 131 Blen dict caia 132 O o 133 ByteOUE rain a de AAA AAA 134 GhieckBf Jeera taena E en cerise eaea ene adesse din rr cea Bunfea 135 COMPAS ide 136 COME PEEL EE 137 COUNTERS Cte a ias 139 Di A a 140 Deba a on og fue Ot ad Made 141 DeCs ct ia Ia E EAS 144 Delay A a ea a aa aa 145 DOs LOOP eee E a A 146 Divis coy TOEIC 148 12 EAGIA cis cae anna na eat aia Eeread d A es i ap a ias O sese O Getstr2 Gos b Ret tin
160. e very start of the program 365 To Use Ladder Only without BASIC 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 0ut MOTOR Alias MO RELAYSTATE Aliases Alias M1 MAINSTATE Set Ladder On Start Ladder Do Loop BASIC program will run in infinite loop 366 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 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 ims are possible Const Device CB280 Device Declaration Usepin 0 In START Port Declaration Usepin 1 In RESETKEY Usepin 2 In BKEY Usepin 3 0ut MOTOR Alias MO RELAYSTATE Aliases Alias M1 MAINSTATE Do 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 FIG PO Below is an example of a conditional case where Turbo Scan Time is used Only when Register
161. eared for the industrial field applications Simply attach our Plug N Play relays to the output ports for implementing solenoids magnetic switches and etc With 24V input ports and DIN RAIL Mount Brackets the user does not have to re invent the wheel by using CUBASE 35 STUDY BOARD Study board is geared for first timers and experienced developers to CUBLOC Peripherals for simple experiments including switches LED RS232 communication I2C piezo ADC toggle switches and LCDs are included We recommend the Start Kit for first timers which includes this 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 I2C protocol With one line commands PRINT CLS etc you can easily start printing to the LCD without hassling with complex lines and commands COLD mema k cmd CUNET is especially engineered for CUBLOC displays therefore we recommend to use CUNET supported LCDs for quick and easy development Our Graphic Display GHLCD allows you to download Black and White BMP images from your computer and store it in its memory 36 7 Segment Display Modules CSG Series 7 Segment display modules can be easily implemented using CUBLOC s I2C protocol and native commands n m m hn LI EJ L1 EJ CUTOUCH Series CUTOUCH is an integration of our graphic LCD touch panel and CUBLOC co
162. ecial Register F FO to F127 1 bit System Status Timer T TO to T255 16 bit 1 Word For Timers Counter C CO to C255 16 bit 1 Word For Counters Step Enable S SO to S15 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 1 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 WPO reis PO WP1 es WP2 eo WP3 res 360 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 ig ge ele JE A Normal Open B Normal Close Input Output Register Symbol Input Output Registers are the most basic symbols among the Registers in Ladder Logic ContactA Po PI P2 dl 11 Contact B Output Relay Function Registers Function Registers include timers c
163. ed This one command accomplishes same functions as shown below OPENCOM 1 19200 0 100 50 PUTSTR 1 ILOVEYOU CR DO WHILE BFREE 1 1 49 Wait until all data have been sent LOOP By using WaitTx the process of sending data becomes 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 248 Chapter 7 CUBLOC Display Library With CUBLOC you can easily control LCD through Comfile LCD products such as the GHLCD or CLCD Drawing lines circles boxes and printing strings can be done with single line of code Below are some of our LCD specifications that will aid the user in understanding the basics Character LCD CLCD CLCD is a blue screen LCD that can print characters and numbers A control board that receives serial data and outputs to the LCD is attached to the back of the CLCD CLCD receives data through the I2C communication protocol 250 Set Display SET DISPLAY type method baud buffersize type O RS232LCD 1 GHB3224 2 CLCD Method Communication Method O CuNET 1 RS232 CH1 baud Slave Address when Method 0 Baudrate when Method 1 Buffersize Send Buffer Size up to 128 This command SET DISPLAY can be used to set the settings for display It can only be used once All displays
164. ed 1 No Acknowledgement data data to send Byte value 0 to 255 Send one byte of data through I2C This command creates Acknowledge pulse and returns O if there is acknowledgement and 1 if there isn t If there is no acknowledgement it could mean two things Either I2C lines are not connected properly or power is not supplied correctly In case this happens please setup an error processing function such as below IF I2CWRITE DATA 1 THEN GOTO ERR PROC When you don t need to check for acknowledgement you can just use any variable to receive the acknowledgement as shown below A I2CWRITE DATA One byte of data transfer takes approximately 60 micro seconds Please refer to Chapter 8 About I2C for detailed I2C communications description 174 If Then Elseif Endif You can use If Then Elseif Else EndIf conditional statements to set conditions for your program If Conditionl Then Expressionl Expression2 Elseif Condition2 Then Expression3 Else Expression4 End If Usage 1 If A 10 Then B 1 Usage 2 If A 10 Then B 1 Else C 1 Usage 3 If A 10 Then When using more than 1 line of if B do not put any Expressions after Then End If Usage 4 If A lt 10 Then B Else End If Usage 6 lt Usage 5 If pes Then Ew Then Elseif A lt 20 Then C 1 aired Se E Elseif A 40 Then C 2 Bn ute Else D 1 End If 175 In Variable IN Port Variable The variable to store
165. emperature Integrated Touch screen Panel w Integrated Touch screen Panel w Package 2mm Headers and 2mm Headers and 2 5mm RCABLE Headers 2 5mm RCABLE Headers 7 17 x 5 17 x 0 98 7 17 x 5 17 x 0 98 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 412 Hardware Requirements To use CUTOUCH the user may use a Windows XP 2000 or 98 operating system equipped computer If you would like to use it in Linux Unix Macintosh environment you will need to install a virtual machine software of some type such as VMware etc that allows 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 with the PC When CUTOUCH is disconnected from the PC it goes into a STAND ALONE state The main program is stored in CUTOUCH s flash memory and will be retained even with no power The user may download new programs and erase them as many times as he or she wishes COMFILE TECHNOLOGY Above Picture of CUTOUCH ready for programming 413 Software Development Environment CUTOUCH uses CublocStudio as its main development environment graphics we have automatic code generating GUI Graphic User Interface software called CuCANVAS and PixelStudio CublocStudio is used for BASIC and Ladder Logic programming on th
166. equirements seeee emen 413 Software Development Environment eeeeen ne 414 CUTOUCH I O PORRES vaciadas 415 Backup Battery EP ME PH 418 KEEP Timer and KEEP Counter eee 419 Menu System Library eeeeseeeeen Henn 420 MENU amp omrriands iei neti ete cents terre roe Rest axe Lo e Ther uus 420 MIU A iaa 421 Saisie 421 MEN E 422 MenuUre Vers sanan iiai aaa ee Ea EAE an Ea AA aaea Te anian 422 MOU Ji aa 422 E A 423 Touch Pad Input ExaMple sisir in renan a aadorin 424 CUTOUCH Sample ProgramMS sssssssrsrrsrrsrsrrnrnrnnrnrnnrnrnurrnnnrnnennnnren 426 APPENDIX oe IRURE IE EET ES EIS INIRE NEAR IE E IEEE 437 Appendix A ASCIE CODE et cet sds cael etna aaa 438 Appendix B Note for BASIC STAMP users eeeeen m 439 Appendix C Using Output Port on the CB290 CT1720 440 Appendix D CUBLOC BASIC Command summary e 441 18 Chapter 1 CUBLOC Getting started What is CUBLOC CUBLOC is different from the traditional PLCs that you may associate with Traditional PLCs have cases and connections like the picture below but CUBLOC is an On Chip PLC Industrial Controller meaning you have more freedom and flexibility to the final product size and design CUBLOC Modules are similar to traditional PLCs in that Ladder Logic can be used But its small size allows developers to design custom PCBs just like a microcontroller
167. er 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 amp H41 Freqout CH PLAYTABLE CHAR CHAR Asc Mid NOTE PL 1 1 amp H30 Delay CHAR 100 Next Pwmoff CH End Sub When using PWM port for other purposes Freqout command no longer becomes 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 331 lt Filename playport cul gt lt END gt 332 NOTE 5 RC Servo Motor RC Servo Motors are used by many hobbyist to make remote control cars planes and etc In the recent years it has been used for robot arms legs and other body parts With CUBLOC you can use the PWM to easily implement an RC Servo motor into your project There are 3 wires to the RC servo motor The black wire is ground and red wire is for power The other yellow wire is for inputting PWM signal For PWM signal you can input about 60 pulses per second to enable the RC servo Black GND The RC Servo
168. er 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 whereas when set to OUTPUT the pin ether outputs LOW or HIGH The maximum current coming out of the output ports is 25mA The user is free to choose which I O ports he she will use for which purpose such as AD PWM etc 42 Supplying power to the CB220 CB220 has an internal 5V power regulator that accepts anything between 5 5 to 12V of power It will produce a stable 100mA 5V When using the internal regulator voltage can be inputted to pin 24 and 5V will output on pin 21 If 5V is used for power the user may simply connect to pin 21 If your application requires more than 100mA of current that can be supplied by the internal regulator please use a separate power supply Method 1 DC5 5 12V ny Method 2 DC5V 43 CB280 CB280 is in a 64 pin module package and 49 of those pins can be used for I O The CB280 does not have a 5V internal regulator souT 16 17 voD Y TX1 33 e 49 TTLTX1 sin 20 18 vss RX1 34 amp 50 TTLRX1 ATN RES AVDD 35 51 AVREF vss NIC N C 36 e e 52 P48 SS PO P16 ADCO P24 37 53 P31_ADC7 Input only JSCK P1 P17 ADC1_P25 38 54 P30_ADC6 MOSI P2 P18 ADC2 P26 39 55 P29 ADCS MISO P3 P19 PWM3 ADC3_P27 40 56 28 ADC4 P4 P20_PWM4_INTO P47 410 57 P32 PWMO P5 P21 PWMS INT1 P46 42 58 P33 PWM1_P6 P22 INT2
169. er to the below table Mode Value Bit Diagram Pattern LSB First amp H20 0010 XXXX MSB First amp HOO 0000 XXXX SCK Low amp HO8 xxxx Edge 1xxx Triggered SCK High Edge amp HOO xxxx Triggered Oxxx Sampling amp H04 Xxxx after SCK x1xx ie Sampling amp HOO xxxx o f t qu 1 1 before SCK x0xx 226 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 amp H 0 0 Sample MSB Bit6 Bit5 Bit4 Bit3 Bit2 Biti LSB SCK amp H 0 4 Sample MSB Bit6 Bit5 Bit4 Bit3 Bit2 Bit LSB amp H 0 8 Sample MSB Bit6 Bit5 Bit4 Bit3 Bit2 Bit LSB amp H 0 C Sample MSB Bit6 Bit5 Bit4 Bit3 Bit2 Bit LSB 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 227 Set Rs232 Set Rs232 channel baudrate protocol channel RS232 Channel 0 to 3 Bauarate 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 Parity Stop Bit Bit
170. ertain part of the program and the DEBUG Terminal displays the values during execution it proves that the program has executed to that point By using these DEBUG commands you will be able to find bugs in your program and monitor variables change in real time If you enter character in the white part of the Debug Terminal it will be sent to the DOWNLOAD port of CUBLOC We have added this feature for future advanced development Warning DEBUG command may not be used while monitoring in Ladder Logic Likewise Ladder Logic monitoring can not be used while debugging using DEBUG commands The following is a chart of commands that can be used with the DEBUG command You can control the DEBUG screen just like a real LCD Command Code Explanation Example Usage CLR 0 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 CLRDN 12 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 in line with the DEBUG command Debug Goxy 5 5 Dec I Deb
171. es amp HDDFF amp HFFF Heap Memory EEPROM Memory There are 5 types of 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 of bytes to read constant or variable 1to4 Read data from the HEAP memory address You can read up to a maximum of 4 bytes at a time Hwrite HWRITE Address Data ByteLength Address HEAP memory address Data Constant or Variable with data whole numbers only ByteLength of bytes to write Write data in HEAP memory address DIM A AS INTEGER DIM B AS INTEGER A 100 HWRITE 0 A 2 Write integer A to address 0 B HREAD 0 2 Read from address 0 and store in B 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 ba
172. es and LCDs are included Communication protocol CuNET I2C and LCD connections are also provided 1 RS232 CH1 O Contact 2 CB280 TX RX Contact Reset Switch Contact LED S Ws 3 ALCD Connector 1 0 Ports Contact CuNET 4 CuNET Jumper Bread Board DC 9V INPUT RS232 CHANNEL 1 POWER S W When 9V is inputted 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 294 Cubloc Study board 1 Schematic 5V VDD Nit GND VSS cH 234511 BACK B gu uL TTLTX LED AID TOGGLE PUSHS W ALCD VO PORTS POT 01234567 891111110 15 1517 18192021222 CUN er PH TOGGLE D 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 2 For CB280 connect RS232 Channel 1 as shown below Tx rx RX JRX 3 For using CuNET all jumpers must
173. g Comfile Technology Inc 410 What is CUTOUCH CUTOUCH is different from the traditional Touch screens you may associate with Traditional Touch screens are not a complete integrated solution to your application They are usually Touch screen panels that will only process graphics and touch input In other words most Touch screens can not be used as a industrial controller as well as graphic LCD and touch input CUTOUCH is complete integration of a traditional PLC with a Touch screen graphic LCD By integrating user input display output and control developers now can put one Touch panel as a control system i RUL TOUCH PANEL PLC CUTOUCH 411 CUTOUCH Specifications Processor CUTOUCH CT1720 CUTOUCH CT1721 Microprocessor Dual Core Atmega128 18 432Mhz Dual Core Atmega128 18 432Mhz Program Memory Flash SOKB SORE Mena RAI 24KB BASIC 4KB Ladder Logic 24KB BASIC 4KB Ladder Logic EEPROM 4KB EEPROM 4KB EEPROM Program Speed 36 000 sec 36 000 sec General Purpose I O 82 I O lines ALL 5V TTL 33 input only 32 output only 17 input output configurable 82 1 0 lines TTL amp 24V DC 1 TTL input 32 24V opto isolated inputs 32 24V TR outputs 17 TTL input output configurable Serial Ports for Communication 2 High speed hardware independent serial ports Channel 0 amp 1 RS232C 12V Configurable Baud rates 2400bps to 230 400 bps 2 Hig
174. g Const Device cb280 Dim F1 As Single Fl 3 14 Debug Float Fl cr Print 3 14000 Dim ST As String 15 ST Float F1 First store in a String ST Left ST 3 Convert to 3 decimal places Debug ST V Print 3 14 2 CUBLOC studio d cubloc_test format cul File Edit Device Run Setup Help BSD g 5C 44 gt mu E m ROREM s FI BASIC F2 LADDER Ladder Mnemonic Baud Rate Parity Data Bits Const Device CB280 _ Em 115200 None E Y RX Dim Fl As Single F1 3 14 Debug Float F1 3 140000 Close I Fix Right Side You can also store into a string before printing debug statements or displaying to the LCD amp CUBLOC studio d cubloc_test format cul File Edit Device Run Setup Help B de o ES GA dA gt i mms LFI BASIC F2 LADDER Ladder Mnemoni yore ne ETE Baud Rate Parity Data Bits Const Device CB280 j Dim F1 As Single En gt 15200 gt None zie PRK Dim 81 As String 12 Fl 3 14 Float F1 Debug sl Close I Fis Right Side 114 String Functions String Ructions are provided to assist the user in accessing data within the String DP Variable Decimal Places ZeroPrint The command DP converts Variable into decimal String representation If ZeroPrint is set to 1 zeros are substituted for blank spaces Dim A as Integer DEBUG DP A 10 0 Convert A into decimal String representation Set display decimal pla
175. graphic on 3 different layers Unlike our CLCD the GHLCD supports many different commands for easy drawing of lines circles and boxes There are also commands such as copy cut paste and a graphic software CuCanvas for downloading BMP images to the GHLCD The GHB3224 model is a black and white STN type LCD with 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 Layer1 257 The text layer size is 40x15 as you can see in the below grid Each character size is 8 by 16 For graphics 320 by 240 pixels are provided for the GHLCD series 0 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 With the graphic layer you have a complete control over where to display graphics over the 320 x 240 pixels 258 With the text layer you can display text over the specified text pixels of 40 by 15 We recommend to draw the background in the graphic layer and to print characters in the text layer GHB3224C supports CuNET GHB3224C model support CuNET When using CUBLOC please use the GHB3224C model as you have one more RS232 port free to use for something else GHB3224C CuNET setup settings Set Display 1 0 1 50 GHLCD CUNET Set Address to 1 Send buffer to 50 Warning CUNET S
176. h speed hardware independent serial ports Channel 0 amp 1 RS232C 12V Configurable Baud rates 2400bps to 230 400 bps Analog Inputs 8 channel 10 bit ADCs Input Voltage Range 0 to 5V 8 channel 10 bit ADCs Configurable Voltage O to 5V OR O to 10V Analog Outputs 6 Channel 16 bit PWMs DACs Output Voltage Range O to 5V Configurable Frequency 35hz to 1 5Mhz 6 Channel 16 bit PWMs DACs Output Voltage Range 0 to 5V 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 DC Current Consumption w ports Current Consumption w ports unloaded unloaded Power 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 Q 12V w Backlight ON 340mA 12V w Backlight OFF 130mA 12V w Backlight OFF 130mA RTC Real Time Clock Yes Yes Timers 1 User Configurable Timer Configurable Interval Units 10ms 1 User Configurable Timer Configurable Interval Units 10ms Data Memory Back Yes a 1 Farad rechargeable Super Yes a 1 Farad rechargeable Super 4 5 x 3 4 5 6 diagonal up Capacitor is included Capacitor is included Operating 0 C to 70 C 0 C to 70 C T
177. hat requires SPI communication this command can be used 232 After Rising After Falling Edge Edge Before Rising Edge DIM A AS Byte A SHIFTIN 3 4 0 8 Port 3 is Clock Port 4 ds Data Mode 0 8 bit received CLK DATA Ji LIE 0 1 1 0 0 1 0 0 26H LSB MSB 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 I2C variable Variable to store data up to 65535 bitlength Bit Length 1 to 16 This command Shiftout sends shift output There are 3 modes Mode 2 is for I2C protocol In I2C communication there requires an acknowledgement ACK signal for every 8 bits SHIFTOUT 3 4 0 amp H55 8 Port 3 Clock Port 4 Data Mode 0 send 0x55 bitlength 8 bit ex JU U UD UU UL sad O LLL 1 0 1 0 1 0 1 0 55H LSB MSB 233 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 Output a set of number of pulses at a set frequency up to 15kHz FREQOUT and PWM can also output pulses but user cannot control the number of pulses and must use the PWM ports With STEPPULSE the user can use any of the output p
178. heck Syntax Menu Run Reset Ladder Monitor on BASIC Debug Terminal Time Chart Monitor Ctrl F7 Explanation 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 CUBLOC Module Start Ladder Monitoring Open BASIC Debug Terminal Window This window opens automatically when there s a DEBUG command in the source code View Time chart monitor window Clear CUBLOC s Flash Clear CUBLOC s Flash Memory Memory Write enable fuse off View Register Usage Check Syntax Setup Menu Menu PLC Setup Wizard PC Interface Setup Editor Environment Setup Environment Options Firmware Download This will turn off 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 BUT you will be able to download again after a new Firmware Download After Compiling View Register usage of Ladder Logic Check Syntax Explanation Automatic BASIC source code generation for Ladder Logic Setup the RS232 COM PORT for Download Monitor Select COM1 through COM4 Setup Editor Environment options for BASIC text editor CUBLOC Studio Options Download Firmware to CUBLOC CORE Please use this to download firmware to CUBLOC CORE man
179. 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 for an interrupt On Pad Create interrupt when Pad receives data 103 More about Interrupts The CUBLOC and CUTOUCH have RTOS which controls interrupt events This is slightly different from 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 mal function 4 There is no limit on the number of interrupts and how long an interrupt routine may be 5 Delay Pulsout commands can be used during an interrupt BUT De
180. inary 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 In BASIC it 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 388 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 F S C T D Constants s Source O O O O d Destination O O O START WMOV 100 DO HL 1 INO DWMO 1234H D2 1 When input START turns ON DO will get 100 When INO turns ON D2 will get 1234H 389 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 is for exchanging Double Word Usable P M F S C T D Constants Registers s O 9 O d O O O START WMOY 100 DO 1 WMOV 123 D1 1 B WXCHG DO D1 r 1 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 Di 100 D2 U w 390 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 cleari
181. ing 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 lt 2mm 78 74 mil 18 415mm 725 mil 55 59 4mm 2338 mil 49 53mm 1950 mil A Y CB290 CB405 36 83mm 1450 mil AAA A III XIII 000 gt 2mm 78 74 mil 47 8mm 1882mil e0000000000000 seseseececeeo v gt lt 2mm 78 74 mil 10 8mm 425 mil 14 0 14 9mm 551 586mil CB290 CB405 9 5mm 374mil Please refer to the above picture for PCB design The numbers are Offsets based on location 0 0 X 150 X 2100 Y 1600 Y 1600 Unit 1 1000 Inch Mil 56 CUBLOC Chipset CB280CS The CB280CS has exactly the same features as a regular CB280 chip except it s in a chipset format By using the CB280CS the user is able to solder the chipset directly on to their PCB This will lower your overall production cost while integrating CB280 into your product seamlessly Since this chipset has same features as a regular CB280 we recommend you develop your applications on the CB280 before going into production with the chipset version The CB280CS includes Main Chip Sub Chip S exRSRRRSEB SERBS 202222000
182. ion it is considered to be a Local variable The Local Variables 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 LOOP1 A A 4 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 Global Variable and K is declared as 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 Sub you do not need parenthesis around the parameters For multiple parameters use a comma to separate them The example shows how this is done Y 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
183. ith the CB405 EADIN command can only be used with Channel 0 through 7 Please refer to the following table for AD Channel and its corresponding Port Number according to your CUBLOC module or CUTOUCH Channel CB220 CB280 CB290 CT17X0 CB405 ADCO 1 00 I O 24 1 0 8 I OO0 T O 16 ADC1 O1 I O 25 1 09 I O 1 I O 17 ADC2 1 O 2 I O 26 I O 10 o2 I O 18 ADC3 I O 3 I O 27 I O 11 1 03 I O 19 ADC4 1 04 I O 28 I O 12 o4 I O 20 ADC5 O5 I O 29 I O 13 1 05 T O 21 ADC6 I O 6 I O 30 I O 14 1 06 I O 22 ADC7 1 0 7 I O 31 I O 15 O7 I O 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 e 100 EEWRITE 0 A 2 Store A in Address 0 B EEREAD 0 2 i Read from Address 0 and store in B 151 Eewrite EEWRITE Address Data 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 Dim A As Integer Dim B As Integer A 100 Eewrite 0 A 2 Store A in Address 0 B EKeread 0 2 Read from Address 0 and store in B When writing to the EEPROM it takes about 3 to 5 milliseconds When reading from the EEPROM it takes less than 0 milliseconds There is a physica
184. iuo Bole eee ivre ee ea eye ves pea ds e voa due eed aed ees Hread A eecivtetetr denter eed ier eere e ek eaa mds HWE caia dead POSTO a a EUER eread A A EE n T2Creadna E EC EP I2Cwrite If Then Elseif Endif On Pad Gosub On ReCVX iic ecl Re I Unc Y Led De eub cec M Beg eue ced dich tances OMSTIMOR A A Ea e A aaie AEEA EE OOO a A a A nm Rid a eta titads Select Case Set DeODUG E Debug Command How to seen 211 SeUT26 i ec eese E A 214 Set Insieme AA akon EE ded 215 Set Eadder on Off 5 2 abi 216 Set Modbus ss Set Onglobal Set ONIME EU Set OnLadderint SE SOON A A qa SeWOMUIMEN ica ci cid Set Outonly ccceeeeeeeeeeee eee Set Pad eene Set Rs232 neus Set RS485 ecos Set Uritil 2 oticc dicet opus dee Shack pda docete Do One s Env EON CERO uma stout liinda chius SHiftOUCh ec o A oases fetta dsc 14 Overlay Contrast Circlefill a o i e CE zl UIDERI THEME EHE Linestyle eese ID o s r4 eR EE EIER HER Hpaste 5 3 2c nee EL D eeivt ee ae ia Input O tp t Circuits cia dee Le eres tee eor cl a rey Does e cen ead ene 286 RS232 3HOWTO linee rei enc MAR PRIMUS 290 np ES 292 CUBLOC STUDY BOARD Circuit Diagram een 294 About I2 Gidin a deii nei epe Lee tegere pendeat 296 More About I C Advanced e
185. l ae 22 Model Output only port CB290 P24 to P55 CT1720 CT1721 P24 to P55 224 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 the PAD communications you must use 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 signals avd HONOL TOUCH PAD BL CONTROLLER CUBLOC I O ports PO through P3 can be used for PAD communications 225 TTLTX1 TTLRX1 AVREF P48 Packet is for size of packet that will cause an interrupt For example the touchpad require 4 bytes to be received before an interrupt is called Here the size of the packet is 4 Buffersize is the total size of the receive buffer The buffer size must be at least 1 greater than packet size buffersize packet 1 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 ref
186. l limit of around 100 000 writes to the EEPROM If you are using EEPROM for data acquisition or data that requires a lot of writes we rather recommend use of the data memory with backup battery included modules such as the CB290 The following is a table showing comparisons betweens SRAM and EEPROM Type Battery Backup SRAM EEPROM Life of Data 3 Months to 1 Year 40 Years Depending on Battery Capacity Maximum Writes Infinite About 100 000 Writing Time 0 ms 3to 5 ms General use Backup Necessary Equipment Small amount of data to in the case of power outage record Example Production Line Long data life requirement Counter Example Product Serial Number 152 Ekeypad Variable EKEYPAD portblockln portblockOut Variable Variable to store results Returns Byte Portblockin Port Block to receive input 0 to 15 PortblockOut Port Block to output 0 to 15 This command EKEYPAD extends KEYPAD to read up to 64 key inputs Two Port Blocks can be used to read up to 64 key inputs Input Port Block and output Port Block must be selected separately For ports not used within the input Port Block a resistor must be connected to 5V This Port may not be used for other purpose when using this command For ports not used within the output Port Block they can be left in OPEN state This Port also may not be used for other purposes The following is an example of using Port Block 0 as input and P
187. larger data you can use an EEPROM like 24LC512 to store up to 64KB of data Here we will show you how to access the 24LC32 4KB EEPROM through I2C protocol The serial EEPROMs usually support either SPI or I2C I2C EEPROMs name starts with 24XXXX and SPI EEPROMs name starts with 93XXX Filename eeprom cul gt Const Device CB280 Dim adr As Integer Dim data As Byte Dim a As Byte data amp ha6 adr amp h3 eH cS Do I2cstart If I2cwrite s b10100000 1 Then Goto err proc a I2cwrite adr bytel a I2cwrite adr lowbyte 340 a I2cwrite data 2cstop Delay 1000 2cstart a I2cwrite amp b10100000 a I2cwrite adr bytel a I2cwrite adr lowbyte 2cstart a I2cwrite amp b10100001 a I2cread 0 2cstop Debug Hex a cr ADR ADR 1 DATA DATA 1 Loop enu DEOS Delos Majors 1 Do Loop This example program will write a number to 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 341 MEMO 342 Chapter 12 Ladder Logic WARNNING If you do not use SET LADDER ON command Ladder Logic will not be executed 343 LADDER Basics The following is an example of one switch and a lamp If you take out the power the following results F If you express the above circuit diagram as Ladder Logic the f
188. lave Adr 02 Slave Adr 03 229 The SET RS485 command allows 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 TTLTX 7 l j l P48 When using the SET RS485 command the Port being used may not be used 560 1 Please refer to the diagram on the left when connecting multiple CUBLOCs or CUTOUCH using RS485 SN75176B Please use a 120 Ohm terminating resistor for the device at the end SN75176B The two 560 Ohm Pull Up and Pull Down resistors are required for proper communication SN75176B 230 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 there 1 byte of data received this command Set Until can be used to set when the interrupt will be called When the specified character is received or length of bytes received has exceed the set packetlength value then ON RECV will jump to the specified interrupt routine This way you can cont
189. lave address and Display Slave address must match Display Slave address can be set with the DIP switch 259 Cls CLS Initialize the LCD and clear all layers Set a little bit of delay for the LCD to initialize CLS 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 if OFF Csroff CSROFF Turn Cursor OFF Locate LOCATE x y X X axis position of LCD Y Y axis position of LCD Set the position of the text layer After the CLS command the LCD defaults to position 0 0 LOCATE 1 1 Mover cursor to 1 1 PRINT COMFILE 260 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 GPRINT command can be used LOCATE 1 1 Move to position 1 1 PRINT COMFILE DEC I PRINT Layer LAYER layer1mode layer2 mode layer3 mode Layer1mode Set Layer 1 mode O off 1 0n 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 if OFF when LCD is first turned ON Use this command to hide the process of
190. lay and Pulsout time may be affected by other interrupts that occur during its execution To protect against such situations 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 actual increase the execution speed of CUBLOC or CUTOUCH by setting all interrupt 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 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 Bclr command can be used in case the user does not want to process another On Recv Interrupt 8 If you declare an interrupt twice the last one called will be in effect 104 Pointers using Peek Poke and Memadr Following is an example that uses EEWRITE command and EEREAD command to read floating point data Const Device CB280 Dim f1 As Single f2 As Single f1 3 14 Eewrite 0 f1 4 f2 Eeread 0 4 DebugaElostet2ncm When you run this code the debug window will show 3 00000 instead of 3 14 The reason is that EEWRITE command automatically converts floating point values to whole numbers In order to store floating point values we c
191. le Variable to store results No String or Single channel RS232 Channel number 0 to 3 buffertype O Receive Buffer 1 Send Buffer 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 plenty of receive buffer size should be used 132 Dim A As Byte Opencom 15 1920050 1 00 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 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 the I O Port Block 8 I O ports are collectively called as a Port Block Port O to 7 is Block O and Port 8 to 15 is Block 1 Depending on the model of CUBLOC the Port Block number can vary When using this command all I 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 following is how Port Blocks are set according to the CUBLOC model souT 1 Y 24 VIN SIN 2 23H vss ATN 3 22H RES vss 4 2117 VDD Po gs5 20H P15 P16 19D p14
192. m O CUBLOC I O Port 288 The following is AD input that receives 4 to 20mA of input You can use a 230 Ohm and 20 Ohm resistors in serial instead of a 250 Ohm resistor 4 20mA CUBLOC 1 O Port 2500hm For O to 10V of input use 2 resistors as shown below This is also called a voltage divider 1Kohm 0 10V CUBLOC O Port 1Kohm How to use PWM as Digital to Analog converter CUBLOC has 6 PWM ports If you use the simple circuit shown below you can make a D A converter T 10Kohm OUTPUT CUBLOC PWM Port 47uF d 289 RS232 HOWTO Pin 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 12V sour g Y ah vn sin O 23H vss ATN g3 22H RES 12V vss Q 210 vob Po g P1 O P2 g EEEE IT m P3 g TD P12 5V P4 jo 160p 88 gt Ps 10 150 P10 4 Peri mm 140 P9 GND P7 12 130 Pa For CB280 there is are 5V and 12V signals for RS232C Channel 1 12V 12V 12V 33 e 49 rre 5V 34 s 12V The reason for two 5V and 12V signal level exist is as follows Since PC uses RS232 12V signals we will need to make a separate circuit for converting to 5V signals for CUBLOC But si
193. m 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 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 add up to 5 years of backup depending on the battery capacity For adding backup battery please connect to the pins labeled External Battery under the super capacitor DEMO FOR CUTOUCH Const Device CT1720 Dim TX1 As Word TY1 As Word TX1 0 TY1 0 Clear just this variable RAMCLEAR Clear all RAM For LADDER all Registers S M C T and D are backed up by the backup battery Register P is cleared at power ON by default If you only want to clear parts of the 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 Jun Next Set Ladder On Most traditional PLCs have KEEP memory for storing and restoring data in case of power down CUTOUCH also has this feature by using a super capacitor which recharges itself and acts as a backup battery You also have the option of using larger capacity capacitor or an actual battery 418 KEEP Timer and KEEP Counter KEEP timer will retain its data values when powered off and restart from the data values when power is turne
194. mmands Exit Do Loop Until Condition DO UNTIL will infinitely loop until condition in UNTIL is met 146 DEMO PROGRAM Debug Terminal Port Baud Rate Parity Data Bits lt 2 CUBLOC Studio D CUBLOC_Test SELECT cut comi 115200 none fa File Edit Device Run Setup Help Baz d XARA p mm M FI BASIC F2 LADDER Ladder Mnemonid Const Device CB280 Dim A As Integer A 4 Do While A lt 10 Debug Dec A Cr Incr A Loop T Fix Right Side Debug Terminal Port Baud Rate Parity Data Bits amp 7 CUBLOC Studio D CUBLOC_Test SELECT cul com y 115200 None gt e x Ele Edt Device Run Setup Help gau d cmce smsu FI BASIC F2 LADDER Ladder Mnemonic Const Device CB280 Dim A As Integer A 4 Bo Debug Dec A Cr Incr A Loop Until A 9 T Fix Right Side 147 Dtzero DTZERO variable Variable Variable for decrement No String or Single Decrement the variable by 1 When variable reaches 0 the variable is no longer decremented 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 is used for a more precise AD conversion CUBLOC has an internal OPAMP When using ADIN command the OPAMP is not used By using this command EAdin the user can utilize the OPAMP for more precise results ADC
195. ms and embeddable applets for downloading and monitoring your CUBLOC module You may use this program to manage thousands of devices MAXPORT module MaxPORT Downloader v 1 2 8 Search Local Area Network LAN for XPORTs Select for CUBLOC Firmware 192 168 0 4 Port 59004 MAC 00 20 44 85 32 9D CB280 y CUBLOC Object File Downloader CUBLOC Firmware Downloader MaxPORT Firmware Downloader via TFTP Search Status Monitor Use This IP Set IP Address Set all to ZERO for Automatic IP via DHCP 0 0 0 0 Set IP ln Set Debug ON Monitoring Download Server Program for multiple MAXPORTs 31 Hints for traditional PLC User 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 By having the option of using the BASIC language even the PLC user may be able to incorporate new features to the final product by making use of BASIC which has much powerful capability and flexibility in communicating with other devices than PLCs To use CUBLOC the user 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 t
196. n When return value is not declared Long will be used as return value Y Exceptions includes using arrays as parameters Function ARRAYUSING A 10 AS Integer 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 subroutines parameters are Call by value meaning the values are only used as reference Even if the parameter value is changed within a subroutine it will not affect the actual variable used as a parameter like shown here 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 WS Ws 10 A does not change when V is changed ADDATEN V End Sub 77 In contrast there is 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 like shown here ST COMFILE TECHNOLOGY ST COMPILE _ TECHNOLOGY Comments Use an apostrophe to add comments Comments are discarded during compile meaning it will not take up extra Program Memory ADD VALUE B 1 Add 1 to B Comment Nested subroutines Nes
197. n Master Mode simply n communication using commands like CUBLOC s GET and PUT eeds to be able to use RS232 data 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 DIMAS ASP Ola Dim Port As Integer Opencom 1 115200 3 80 80 On Recvl Gosub GETMODBUS Set Wrote wel 1760710 Do For Port 2 To 4 BitWrite Port Delay 100 Next For Port 2 To 4 BitWrite Port Delay 100 Next Loop GETMODBUS End TE aldea 10 E 10 Then A Blen 1 0 Debug GOT RESPONSE B Getstr 1 A Debug B End If Return Sub BitWrite K As Integer Dim LRC As Integer RUES EE sO S05 cesa T lao dio 10 Data Receive Interrupt routine When Ending Code 10 on Channel 1 is discovered create an interrupt 1 Turn PO Pl P2 ON 0 Turn P0 P1 P2 OFF Uo If buffer empty then Store the buffer length in A Store received data in B D As Integer 315 If D 0 Then Putstr 1 0000 LRC 3 5 K Bytel K Byte0 Calculate LRC Else usura 1 MON LRC 3 5 K Bytel K Byte0 0xFF LRC End If Putstr 1 Hex2 LRC 13 10 Send End Sub MODBUS ASCII Slave Mode Y 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 TX RX RS232 P2 m CH1 RX TX PR P4 GND GND CB280 When the Slave finishes
198. nc cul com y riszoo none s GRX Elle Edit Device Run Setup Help sog gxm A w nwm FI BASIC F2 LADDER Ladder Mnemonic Const Device CB280 Dim stl As String 12 Dim i As Integer St 1238 i Val stl Debug bec i Ur Dim f1 As Single stl 3 14 fl Valsng stl Debug Float f1 Cr VALHEX String variable Return a converted hexadecimal value of the String DIM ST1 AS STRING 12 DIM I AS LONG ST1 ABCD123 I VALHEX ST1 amp HABCD123 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 ST1 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 ST1 AS STRING 12 DIM 1 AS INTEGER STi 123 I ASC STI amp H31 is stored in variable I ASCII code of 1 is amp H31 or 0x31 Caution 1 A variable must be used when using string functions DEBUG LEFT INTEGER 4 ST1 INTEGER DEBUG LEFT ST1 4 A string by itself cannot be used A string must be stored as a variable first a Terminal Baud Rate Parity Data Bits gr S CUBLOC studio d cubloc_test c cob 115200 M PS RUE Ruso Tus Gum Re E El zl ons EE z LIU PEME ES CLRAE E Fi BASIC Fa LADDEN Ladder Mnemonic Search Const Device CHZ80 Dim stl As Stri
199. nce there are 12V signal outputs the user doesn t have to worry about making a separate circuit For downloading to CUBLOC it is very easy since you can connect a PC cable directly to pins 1 and 2 For RS422 and RS485 conversions 5V signals are provided for RS232 Channel 1 290 For CB280 12V signals are provided for RS232 communication Please be careful to use only one of the 5V or 12V connections at one time The following shows a simple circuit diagram of RS232 conversion from 12V to 5V signal using a MAX232 chip cECXVIN CuBLOC RX CuBLOC TX MAX232 is a very useful chip for converting between 5V and 12V of RS232 signals 16 15 14 Rs232c OUTPUT 1 3 RS232C INPUT 12 TILOUTPUT OJAN 11 TTL input RS232C OUTPUT 7 10 rr eur RS232C INPUT B 9 TTILOUTPUT 291 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 style protecting against outside noise It automatically removes pulses less than 50ns VIN VSS RES VDD P15 GND P14 5V RESET P13 SCL P12 SDA P11 P10 P9 P8 4 7Kohm x2 For using CuNET the 4 pin connector s pin 1 must be connected to ground pin 2 to 5V or RE
200. nd PicBASIC which are chip based PLCs and BASIC controllers we have been able to improve our engineering efforts every year CUBLOC is able to adapt to the user s strengths whether that be BASIC or LADDER Unlike other products you can simply use CUBLOC as a BASIC controller or as a PLC controller Ladder Logic which is the traditional way of programming PLCs for its outstanding control sequence is neither sufficient nor easy to use for graphic interface and other modern technology that require complex programming In comparison the BASIC language proves to be simple yet easy to implement those modern devices CUBLOC is able to handle both BASIC and Ladder Logic through on chip multi tasking By sharing memory data it s able to integrate both BASIC and LADDER efficiently and become a new type of controller by itself CUBLOC is created for beginners and advanced users in mind Its basic purpose is to cut design time for those who are just entering the field of microcontrollers engineers from other backgrounds such as Chemical or Mechanical and anyone who would like to make something that they envision quickly and get a head start on their project With our Plug N Play displays development boards and relay boards you will be able to put something 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
201. ne you can define constants before compiling define motorport 4 low motorport For the example above motorport will be compiled as 4 You can also just use CONST for such examples like this CONST motorport 4 low motorport The following example uses define for replacing a line of command 97 define FLAGREG1 2 define f led FLAGREG1 BITO define calc 44 1 256 f led e 1 Set FLAGREG1 s bit zero to 1 IF f led 1 then f led 0 Make it easier to read j calc Calculations can be simplified define will not differentiate uppercase and lowercase letters They will all be processed as uppercase character For example define ALPHA O and define alpha 0 are both considered the same DEMO PROGRAM Debug Terminal E ES lt CUBLOC studio d cubloc_test abc cul ES Data Bts we Tx ial Port File Edit Device Run Setup Help com zl 115200 gt one gt E gt SRK Bad d m mu Em FI BASIC F2 LADDER Ladder Mnemonic Const Device CB280 define Rep Debug Dec Dim A As Integer A 123 rep A Cr 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 or both simultaneously using the special defined operator Here are some reasons to use a conditional W A program may
202. ne word whereas DWROL moves double word Registers that P M F S C T D Constants may be used d o o lo E d BKEY WROL DO 1 If DO has 8421H the following results DO 0843H pip O 400 WROR DWROR WROR d DWROR d Rotate the value on 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 that P M F S E T D Constants may be used d O O O BKEY WROR D1 jj f 1 If D1 has 8421H the following results gt S O D1 OC210H 401 GOTO LABEL GOTO label LABEL label The command GOTO will jump to the specified label Label is for declaring labels START GOTO SK 1 1 BEKY TON 10 100 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 HE GOTO SKI 1 402 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 Ecl yel a E E eh rae ere Main Program j pros START CALLS CHK RTN I l t 1 l I RET E 1 RETmust be used when l i there are sub routines SBAT CHK RTM 4 Start of sub routine I I BKEY TON T0100 i I
203. ned ON will be the step to be enabled at any given moment PO STEPOUT S0 1 t 1 PI STEPOUT 50 2 t 1 p2 STEPOUT S0 0 c 1 When P1 turns ON S0 2 turn ON When PO turns on SO 1 turns ON A step will be kept on until another step is turned ON Po OOO pr EmN 9 po soo ESA 50 1 50 2 380 TON TAON When input turns ON timer value is decremented and output turns on when timer is done second units and another that works in 1 second units There are two kinds of timers one that works in 0 01 Type of Timer Time units Maximum Time TON 0 01 sec 655 35 sec TAON 0 1 sec 6553 5 sec START TON 10 100 1 START TAON T1 100 Hr 1 There are 2 parameters with commands TON TAON For the first parameter you can choose between TO to T99 and for the second parameter you may use a number or a data memory such as DO Usable P M F S T D Constants Registers TON TAON O O O O In the above LADDER diagram when START turns ON TO Timer will start from zero to 100 When 100 is reached TO will turn on Here 100 is equal to 1 second for TON and 10 seconds for TAON 1sec stant _L _ TO When START turns OFF the timer is reset to original set value of 100 and TO turn off too TON TAON commands will reset its timer values upon powering OFF To use the features of battery backup you can use KTON KTAON which
204. 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 W 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 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 4 endif block will be compiled otherwise statements will be discarded Const Device CB280 Delay 500 Device only returns the decimal number If Device 220 Debug CB220 module used tendif The above example shows how depending on the module of CUBLOC CUTOUCH you can decided to include a command in the final compilation of your program By using conditional directives you will be able to manage multiple modules of your CUBLOC CUTOUCH with just one source code 99 By using preprocessor directive elseif or else you can create more complex if 4endif blocks Const Device CB220 Delay 500 Device only returns the decimal number If Device 220 Debug CB220 module used elseif device 280 Debug CB220 module used elseif device 290 Debug CB290 module used elseif device
205. ng 12 stl Chr amp h41 Debug stl Cr sti 123 Debug Hex Asc stl Cr Close Fix Right Side 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 ADC to convert analog to digital signals or use PWM to convert digital to analog signal ADIN command reads the analog signal value and store the result in a variable Depending on the model the number of AD ports may vary For the CB280 there are 8 AD ports P24 to P31 The AD port must be set to input before use When voltage between 0 and AVREF in inputted that voltage is converted to a value from 0 to 1023 AVREF can accept voltage between 2 to 5 V Generally 5V is used 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 5y Input voltage Dim A As Integer Input 24 Set port to input A Adin 0 Do a A D conversion on channel 0 and Y store result in A 124 The following is AD input ports shown for CB220 and CB280 souT 1 Y zah vin PN je bi vss s ae ring sINO2 23H vss ATN 30 19 RES p r AVREF sudan lp uolens rasiote vss
206. ng both BASIC and Ladder Logic in your designs 24 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 daring task for 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 that BASIC has is that its language is very similar to the English language IF GOTO etc allowing the beginners and the developers to learn in matter of hours instead having to deal with months of learning curves 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 seque
207. ng memory Usable P M F S C T D Constants Registers S O O O d O O O n O sTaRT WMOV 100 DO t 1 ACTION FMOV D0 D1 5 a t 1 Below is result of LADDER execution Notice Please Set n less than 255 391 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 Constants Registers S O O O d O O O n 9 ACTION GMOV DD D10 5 t l Below is result of LADDER execution DO D1 D2 D3 D4 D5 D6 D7 D8 D9 D10 Dii D12 D13 D14 D15 D16 Notice Please Set n less than 255 392 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 P S C T D Constants Registers d O O 9 START WMOV 100 DO 1 ACTION WINC DO 1 Below is result of LADDER execution DO a al pl Bl 393 WADD DWADD WADD si s2 d DWADD si s2 d Add s1 and s2 and store 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 si O O O 9 s2 O O O 9 d 9 O O
208. ntial language both have its advantages over each other Ladder Logic is able to process what couldn t be done with BASIC On the other hand BASIC can easily process what is either hard to do or couldn t be done in Ladder Logic That is why we created CUBLOC which 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 costs 25 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 Je UR FUNC 1 PO P1 Print Setting Mode I FUNC 1 ARARA B B 1 RETURN The first weakness is that based on the execution time of BASIC Ladder Logic also gets affected If the BASIC code is made up of an infinite 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 can only be used as part of Ladder Logic BASIC is a powerful language by being able to process complex algorithms But if we can
209. nu 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 447 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 Ncd Variable NCD source Variable Variable to store results No String or 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 On recv ON RECV1 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 I O Port number 0 to 255 Value Value to be outputted to the I O Port 1 or 0 Output OUTPUT Port Port I O 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
210. o overcome the deficiencies and disadvantages of traditional PLCs by being able to use both BASIC and LADDER language DISPLAY KEYPAD Bl B We provide many BASIC libraries for user interfaces which you can simply copy amp paste to achieve the user interface structure desired PC INTERFACE 32 Hints for Micro Controller User MCU Micro Controller Unit is programmable micro computers such as PIC AVR and 8051 For mass production MCUs can cut costs and reduce the overall product size But the main disadvantage of MCUs is that it is hard to develop and takes a long time For simple projects this might be a good route Even those experienced engineers feel that MCU programming is time consuming and not a simple task To make a final product it takes many hours programming and debugging with an MCU Even after development if bugs arise it becomes almost impossible to update the MCU In comparison Comfile s CUBLOC will cut the users development time as much as 20 times and provide a MCU like chip that is upgradeable through RS232 cable or even through the internet by using an XPORT By being able to provide a way to upgrade the final product the value of your final product is much more than what you thought If you have experience programming with MCUs we guarantee you that development of your final product will be much easier You will be able to spend more time designing the features of your final product instead
211. ollowing results H P9 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 and etc The following is an OR and AND connection in Ladder Logic PO P2 P9 344 In this circuit diagram PO and P2 and connected in logical combination of AND PO and P3 are ORed Which mean either PO or P3 has to be on If you express the above circuit diagram in Ladder Logic it will be as follows Po P2 Pg 9 P3 In CUBLOC STUDIO the right side is not shown In the Ladder Logic of CUBLOC PO P1 P2 are called Registers 345 Creating LADDER The below screen shows you how Ladder Logic is created in CUBLOC STUDIO amp CUBLOC studio c Wcubloc_testWu3 1018 cul T Eile Edit Device Run Setup Help B aud 468 4 gt miu Bu Fi BASIC F2 LADDER reel talte d PLC 4b HE Wizard H Eb ms ts P eol Fil fa NOT END to ES E s P62 P63 P86 MO P72 EA HH C Pel Pez P83 PB Pe Mo HHHH C MI WORK ON TOGLE MI M2 WORK_OFF TOGLE M2 t C MPG ON INPUT M3 F P4 P62 MPG ON OFF TOGLE M5 MPG ON LED P40 gt xl Modified Program 154 Bytes Data 1001 The red box shown above is the cursor for Ladder Logic You may use the keyboard up down left and right keys
212. or to 0 Linestyle LINESTYLE value Set line style using this command You can make dotted lines by increasing the value The default value is 0 a straight line LINESTYLE 1 Use dotted lines Dotsize DOTSIZE value style Set the dot size Value is the size of the dot and style can either be O for rectangular or 1 for circular dot DOTSIZE 1 1 Set dot size to 1 and dot type to circle 273 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 r start end Draw an arc with x and y as the center Start and end are the values between O and 360 degrees ARC 200 60 100 10 20 Draw an arc from 10 to 20 degrees 274 Defchr DEFCHR code data Code Custom character code amp hdb30 to amp hdbff Data 32byte bitmap data Create custom characters using this code 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 DPRINT Total of 207 custom characters can be stored in the memory At power off the characters are not preserved DEFCHR amp HDB30 amp HAA amp HAA amp HAA amp HAA amp HAA amp HAA amp HAA amp HAA _ amp HAA amp HAA amp HAA amp H55 amp HAA amp HAA amp HAA amp HAA amp HAA amp HAA amp HAA amp HAA amp HAA amp HAA amp HAA amp HAA amp HA
213. ort Block 1 as output 36 44 52 60 i e 37 45 53 61 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 amount of times For Variable Starting Value To Ending Value Incremental Step Commands Exit For Next In the below example Incremental Step is not set FOR NEXT loop will increment 1 every loop as default Dim K As Long For K 0 To 10 Debug Dp K CR Next For K 10 To 0 Step 1 i Debug Dp K CR Negative Step step from 10 to 0 Next EXIT FOR command can be used within the FOR NEXT loop to exit any desired moment 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 choosing a variable to use for FOR NEXT loop please make sure the chosen variable is able to cover desired range Byte variables can cover from 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 negative STEP please choose LONG as it can handle negative numbers 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 Ws Debug Dec A Debug Debug Dec 3 A Cr Next Const Device C
214. orts and control the number of pulses at a desired frequency Depending on the core 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 CB220 280 290 1 0 Channel 0 PWM 3 4 5 CT17XX CB405 2 Oorl Channel 0 PWM 3 4 5 Channel 1 6 7 8 STEPPULSE uses the CUBLOC processor s PWM counters meaning when using this command PWM3 PWM4 and PWM5 cannot be used For 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 You can use any of the available output I O ports on the CUBLOC When the STEPPULSE command is executed that Port is automatically set to ouput state Even after the output of pulses have finished the Port remains in output state Output Frequency can be set from 1hz to 15000Hz or 15kHz Number of pulses can be set from 1 to 2147483647 This command will run in the background independently so the user may use system resources for other tasks 234 Stepstop STEPSTOP Channel Channel StepPulse Channel 0 or 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 man
215. ot use D area AliasName An Alias for the Register chosen up to 32 character Aliases may be made up for Registers like PO MO CO With Aliases the user will be able to write more clear and easy to read code Alias MO Rstate Alias MO Kstate Alias PO StartSw 126 Bcd2bin Variable BCD2BIN bcdvalue Variable Variable to store results Returns LONG bcdvalue BCD value to convert to binary This command does the exact opposite of BIN2BCD command Dim A As Integer A Bcd2bin amp h1234 Debug Dec A C rint 1234 127 Bclr BCLR channel buffertype channel RS232 Channel 0 to 3 buffertype O Receive 1 Send 2 Both Clear the specified RS232 Channel s buffer Buffer type can be chosen ile 11 0 Clear RS232 Channel 1 s rx buffer ECU Clear RS232 Channel 1 s tx buffer ele 1 2 Clear RS232 Channel 1 s rx amp tx buffers 128 Beep 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 Piezo or a speaker can be connected to the Port A short beep will be outputted This is useful for creating Key touch 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 OL cm 129 Bfree Variable BFREE channel buffertype Variable Variable to store results No String or Single channel RS232 Channel numbe
216. ounters and other math operation Registers t 1 e PO TON 70 100 Function Relay 361 Internal Register Internal Register M only operates within the program Unless connected to an actual external port it is only used internally You may use M Register as input or output symbol ACTION MO D WMOV 100 00 1 P Registers that are not used as I O ports CUBLOC supports P Registers from PO to P127 P Register is 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 362 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 I O 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 OUT 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 I O ports into P Registers INPUT REFLASH Y LADDER SCAN y 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 avoi
217. own 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 24LC32 SCL SDA CUBLOC 302 Chapter 9 MODBUS About MODBUS MODBUS is a protocol developed by MODICON to help interface peripherals for their PLCs It is usually used with devices like Touch screens HMI devices and SCADA software A lot of Touch screen panels HMI and SCADA software now days support MODBUS In MODBUS there is Master and Slave mode The Master provides data while the Slave receives the data The slave can only respond to master and cannot communicate on its own Each slave has a unique address called Slave Address The Master using those Slave Addresses can talk to one of the slaves 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 Error Checksum codes Slave receives a Frame and analyzes it When responding to the Master Slave also sends in Frames In other words MODBUS send and receive can be seen as composed of Frames that are sent and received There are two types of MODBUS ASCII and RTU RTU type can be implemented by using less bytes in the communication ASCII use LRM for error checking and RTU uses CRC The next is how ASCII and RTU are used
218. parate conversion table Temperature range between 55 and 125 degrees Celcius can be obtained by the DS1620 in units of 0 5 Degrees SOUT VIN SIN vss ATN RES vss VDD Po P15 P1 P14 P2 P13 P3 P12 P4 PH P5 P10 P6 P9 P7 PB CB220 A me Doa VDD bei rH A rst T LO meno com mr 091620 Filename ds1620 cul gt Const Device CB280 Const iorst 7 Const ioclk 6 Const iodq 5 Dim I As Integer Delay 100 High iorst init ds1620 Shiftout toclk Ioda 0 1278 Shutter Lociki iodo Orano Low iorst Do High iorst Shiftout ioclk iodq 0 amp haa 8 i Shiftin ioclk iodgq 4 9 i i debug dec i cr Low iorst Delay 100 Loop The final value received can be divided into 2 to obtain the current temperature END 335 NOTE 7 DS1302 RTC DS1302 RTC Real Time Clock is a chip that will acts 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 in this note TW 32768Hz DS1302 Pin Function I O Direction Explanation RST Reset Input Data transfer when High SCLK System Clock Input Clock signal I O Data Input Data input output Input Output Output Filename ds1302 cul gt Const Device CB220 Const torse T Const iodio 6 Const ioclk 5 Dim I As Integer Dim adr As Byte High iorst Shiftout ioclk
219. pattern of random values are generated Thus this function is not a true random number generator 209 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 Statement 1 Case Value Value Statement 2 Case Else Statement 3 End Select Select Case A 1 Case B 0 Case 2 B 2 Case 3 4 5 6 Use Comma for more than 1 value B 3 Case Is lt 1 Use lt for logical operations B 3 Case Else Use ELSE for all other cases B 4 End Select Select Case K Case Is lt 10 If less than 10 R 0 Case Is lt 40 If less than 40 R21 Case Is 80 R22 Case Is 100 R23 Case Else R24 End select 210 Set Debug SET DEBUG On Off Set Debug is set to On by default You can use this command to turn OFF and turn ON the DEBUG window in BASIC When you don t need DEBUG feature you can use this command to turn off DEBUG feature instead of erasing all the code with Debug code When this command is used all DEBUG commands are not compiled in effect 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 also do other tasks to help save development time 1 How to Check if program is being re
220. pc 5 Debug A stl A Cr Close Fix Right Side 119 LTRIM String variable Cut all blank spaces on the left side of the String and return the value DIM ST1 AS STRING 12 ST1 COMFILE 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 ST1 AS STRING 12 ST1 COMFILE ST1 RTRIM ST1 DEBUG ST1 TECH COMFILETECH is printed Blank spaces on the right are removed se Terminal Baud Rate Parity Data Bis g dx amp CUBLOC studio d cubloc_test stringfunc cul En 115200 none la rx File Edit Device Run Setup Help a5 3 e 39 Rh m ur 5 5 FI BASIC F2 LADDER Ladder Mnemonic Const Device CB280 Dim stl As String 12 st1 2 CUBLOC s Debug Ltrim stl Core Cr Debug Rtrim st1 Core Cr 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 ST e 3 14 F VALSNG ST1 3 14 is stored in variable F as a floating point number Debug Terminal Baud Rate Parity Data Bits GTH Port CUBLOC studio d cubloc_test stringfu
221. pecified length of data to the RAM Address Const Device CB280 Dim F1 As Single F2 As Single F1 3 14 Eewrite 10 Peek Memadr F1 4 4 Poke Memadr F2 Eeread 10 4 4 Debug Float F2 CR 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 output 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 give you about 23mS pulse LOW 2 HIGH 2 PULSOUT 2 100 23mS HIGH Pulse PULSOUT 2 100 23mS LOW Pulse Pulsout is pre made system s sub program sub pulsout pt as byte ln as word dim dll as integer reverse pt for dii 0 to In 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 String please use Putstr command instead OPENCOM 1 19200 0 50 10 IMPORTANT DIM A AS BYTE The command A amp HAO PUT 1 A 1 Send amp HAO 0xA0 to RS232 Channel 1 OPENCOM must be used beforehand Within CUBLOC the data is first stored in the send buffer CUBLOC BASIC Interpreter will autom
222. 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 WMOV 3 00 m Ta 2 1 SETOUT F40 c 1 P2 WMOV 2 00 1 c 1 SETOUT F40 1 When PO turns ON DO gets 3 and interrupt routine is executed If P2 turns ON DO gets 2 and 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 If D 0 3 Then Locate 0 0 Print ON Ladderint Dec i End If If D 0 2 Then Locate 0 0 Print TEST PROGRAM Dec i End If Return For short version of above LADDER commands the user can use 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 D0 F c 1 PI INTON 2 D0 F c 1 189 On Pad Gosub ON PAD GOSUB label You can set the packet size using SET PAD command The ON PAD interrupt will jump to the label when the buffer amount is equal to the set packet size Please make sure to use RETURN command after the label Const Device Ct1720 Dim TX1 As Integer TY1 As Integer Contrast 450 Set Pad 0 4 5 On Pad Gosub GETTOUCH Do Loop GETTOUCH TX1 Getpad 2 TY1 Getpad 2 oce S19 UT SI aL 110 Pulsout 18 300 Return 190 On RecvX ON RECVO ON RECV1 ON RECV2 ON RECV3 When data
223. processing the Data sent by the Master the Slave will jump to the label GETMODBUS We can use SET UNTIL command to check for ending code LF 10 Then Getstr command is used to store all received data in RDATA The data in RDATA can be analyzed to verify if the communication was achieved soundly or not When the slave is not connected the program will never jump to GETMODBUS 316 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 crctable inc E Open serial port for MODBUS n Set Baudrate as 115200bps and 8 N 1 with d receive buffer of 200 bytes and send buffer of 100 bytes Opencom 1 115200 3 200 100 Y Data Receive Interrupt routine On Recvl Gosub GETMODBUS y Clear All Buffers lla 12 t User Timer for MODBUS Timeout On timer 1 Gosub MyClock Debug MODBUS FloatingPoint Value Write RTU Example Micra 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 2 3 33 Debug Writing multiple Single values to address 0 Cr writemultiplesingle 1 0 3 Do Loop
224. put Status Debug Debug ty current Goxy 16 3 Debug Goxy 30 5 Debug Counter Dec5 A Incr A pere Terminal E Use the command BaudRate Party DataBis grx E Debug CLR to clear oo gif mee E the Debug window At any time during development you can disable and also not incude Debug POWER M TEM MONIT EEN E statement during Compiling by using the command Set COUNTER 11417 Debug Off INPUT COMFILE TECH Close Fix Right Side 213 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 I2C communication Once this command is executed both Ports become to OUTPUT HIGH state Please use Input Output Port for I2C and use two 4 7K resistors as shown below SCL L_ spa 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 214 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 edge or changing edge SET INTO 0 SOUT SIN ATN vss Po P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 10 20 30 40 5
225. qValue 2304000 Desired Frequency Before using this command please set the specified PWM Port to output mode To stop PWM you can use the command PWMOFF The following is an example Const Device cb280 Dim i As Integer y Low 5 Set Port 5 to low and output i 1 Fregout 0 10 Produce a 209 3Khz wave Do Infinite loop Loop Since Freqout uses the same resources as PWM there are a couple of restrictions you must be aware of PWM Channel 0 1 and 2 use the same timer If PWM Channel 0 is used for Fregout command channel 0 1 and 2 all cannot be used for PWM command 157 Likewise PWM Channel 3 4 and 5 act the same If you use Freqout on PWM Channel 3 PWM Channels 3 4 and 5 cannot be used for PWM command You can product different frequencies on PWM Channel 0 and 3 To sum up the user may produce two different frequencies at one time and when using the Freqout command the PWM command cannot be used The following is a chart that shows corresponding FreqValue to the music 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 c 17613 8806 4403 2202 Db 16624 8312 4156 2078 D 15691 7846 3923 1961 Eb 14811 7405 3703 1851 E 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 0 5236 Note A in Octave 4 440Hz F
226. r Slave Address Function Code Start Address HI Start Address LO Length HI Length LO Error Check Ending Code The response shows that the data was entered correctly You MUST use FF 00 and 00 00 to turn ON OFF Registers simply be ignored Response Field Header Slave Address Function Code Start Address HI Start Address LO Length HI Length LO Error Check Ending Code 310 RTU 0X03 0X05 0X01 0X00 OXFF 0X00 CRC RTU 0X03 0X05 0X01 0X00 OXFF 0X00 CRC Bytes NRRRRR PCR Bytes N H B oH oH H B o H HH ASCII colon ASCII colon Bytes NNNNNNNNNRA other values will Bytes NNNNNNNNR Function Code 06 Preset Single Registers PLC s can remotely control the status of its Registers 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 ASCII 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 CR LF 2 Response Field RTU Bytes ASCII Bytes Header colon 1 Slave Address 0X03 1 03 2 Function Code 0X06 1 06 2 Start Address HI 0X70 1 01 2 Start Address LO 0X01 1 70 2 Length HI 0X12 1 12 2 Length LO 0X34 1 34 2 Error Check CRC 2 LRC 2 Ending Code CR LF 2 311 Function Code 15 Force Multiple Coils P
227. r 0 to 3 buffertype O Receive Buffer 1 Send Buffer This function will return the number of free bytes that either receive buffer or send buffer has currently For sending data this command can be used to avoid overflowing the buffer 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 binary value to BCD code BCD code is a way of expressing binary values as decimals For example 3451 in binary is as shown below 3451 0000 1101 0111 1011 0 D 7 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 to be representable in a device such as the 7 segment display i 123456 j bin2bcd i Debug Hex j Print 123456 131 Blen Variable BLEN channel buffertype This function Blen returns current number 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 Variab
228. r 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 step 237 Sys Variable SYS address Variable Variable to store results No String or Single address Address 0 to 255 Use command Sys to read the status 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 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
229. ram will display RESET button and will increment number shown every time the button is pressed 3241 RESET Filename CT002 CUL Const Device Ct1720 Dim I As Integer Dim TX1 As Integer TY1 As Integer Contrast 550 Set Pad 0 4 5 On Pad Gosub GETTOUCH Menuset 0 2 120 155 195 200 Menutitle 0 20 14 RESET Do Locate 15 6 Print DECS I Iper T Delay 200 Loop GETTOUCH TX1 Getpad 2 TY1 Getpad 2 If Menucheck 0 TX1 TY1 1 Then Pulsout 18 300 I 0 End If Return SET PAD command activates touch input ON PAD command is used to jump to a label when touch input is received MENUSET command is used to set the desired touch input area and MENUTITLE command is used to set the name of the button itself PULSEOUT outputs BEEP sound to the piezo 427 SAMPLE 3 Draw a circle where your finger touches Filename CT003 CUL gt Const Device Ct1720 Dim TX1 As Integer TY1 As Integer Contrast 550 Set Pad 0 4 5 On Pad Gosub GETTOUCH Do Loop GETTOUCH TX1 Getpad 2 TY1 Getpad 2 eximere fab MUT STATES ale Pulsout 18 300 Return 428 SAMPLE 4 Make a virtual keypad and accept numerical values Filename CT004 CUL gt 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 Menutit Menuset Menutit Menuset Menutit Menuset Menutit Menuset Menutit Menuset Menutit Menuset
230. rating A A 1 to a function the user will be able to separate one big program into small chunks As you can see here the main program ends when END comes and functions are added afterwards MAIN PROGRAM End SUB FUNCTION Sub Program SUB 72 Sub and Function For sub routines you can either use Sub or Function Sub does not return any values whereas 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 End Function Exit during sub routine To return values using Function simply store the final value as the name of the Function like shown here Function ADD VALUE B As Byte As Byte ADD VALUE B 1 Return BH End Function DEMO PROGRAM Debug Terminal PER Bouse Perty DB an A sao gt none gt nx Tat com 2 CUBLOC studio d cubloc_test functest cul Ele Edit Device Run Setup Help S ud X204 mu HB m p FI BASIC F2 LADDER Ladder Mnemonic Const Device CB280 Dim A As Byte A 0 Do Delay 100 Debug Dec A Cr A ADD VALUE A Close T Fix Right Side Function ADD VALUE B As Byte As Byte ADD VALUE B 1 End Function 73 Global and Local Variables When you declare variables inside a Sub or Funct
231. re Repeated Start If I2cwrite amp H10100001 1 Then ERR PROC Read command DATA I2cread 0 Result store in DATA I2cstop And now we will look at how to read multiple data from the EEPROM Without using the STOP command we can keep reading from the EEPROM since it automatically increments its address In this way we can set the address to read from only once and then read the rest of the data much faster set 120 8 9 Mes bast If I2cwrite amp H10100000 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 I2cstart Repeated Start If I2cwrite amp H10100001 1 Then ERR PROC Read command Ror IL 0 To 10 ADATA I I2cread 0 Read 10 bytes continuously ADATA is an array Next I2cstop 298 I2c example The following example shows CB280 and EEPROM 24LC32 connected A value will be written to a specified address of the EEPROM and then read back to display on the DEBUG window of CUBLOC Studio Const Device cb280 Dim adr As Integer Dim data As Byte Dim a As Byte data amp hal adr amp h3 Set 120 3 2 Do Write 1 Byte Diosa f I2cwrite amp b10100000 1 Then Goto err proc a I2cwrite adr bytel a I2cwrite adr lowbyte a I2cwrite data 2cstop Delay 1000 Read 1 Byte 2estart a I2cwrite amp b b10100000 a I2cwrite adr byte1 a I2cwrite adr lowbyte 2estart a I2cwrite amp b10100001 a I
232. re module With BASIC you can control the GHLCD touch panel With Ladder Logic I O 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 comfiletech com often for these updates 37 MEMO Chapter 2 Hardware Hardware Features CUBLOC have the following features BASIC and Ladder Logic 80KB or 200KB Flash Memory BASIC Execution Speed 36 000 Instr sec LADDER Execution Speed 10ms Scan time Turbo Mode 100 Micro Second Data Memory for BASIC 2 to 51KB Data Memory for LADDER 1 to 4KB EEPROM Memory 4KB 16 to 91 I O pins Ports 10 bit 16 Channel ADC 8 to 16bit 3 to 12 Channel PWM DAC UART H W RS232C ports 4 Channels RS232C port PC interface RTC chip included CB290 Model Comparison Chart Feature CB220 CB280 CB290 CB405 Program 80KB 80KB 80KB 200KB Memory Data Memory BASIC 2KB BASIC 2KB BASIC 24KB BASIC 51KB LADDER 1KB LADDER 1KB LADDER 4KB LADDER 4KB HEAP 55KB Battery N A N A Available Available Backup EEPROM 4KB 4KB 4KB 4KB T O ports 16 49 2 914 2 64 2 Package 24 pin DIP 64 pin Module 108 pin Module 80 pin Module ADC 8 Channel 8 Channel 8 Channel 16 Channel PWM 3 Channel 6 Channel 6 Channel 12 Channel RS232 2 Channel 2 Channel 2 Channel 4 Channel External None 4 4 4 Interrupt HIGH COUNT 2 Channel 2 Channel 2 Channel 2 Channel INPUT RTC
233. ren RIRs 300 CHAPTER 9 MODBUS About MODBUS s eurn rire iia 304 MODBUS ASCII Master Mode ceeseeene mH 315 MODBUS ASCII Slave Mode eeeeeee HH 316 MODBUS RTU Master Mode eseseeeen Hen 317 CHAPTER 10 APPLICATION NOTES 000 ccccssssssssssssosssssscccssssnsssssooessssecesssssnnssssoossseees 319 NOTED Switch Input iore e iaa 320 NOTE 2 K ypad InpU t eiie hne des oases dipan AES 322 NOTE 3 Temperature Sensor esseeeeee enn 325 NOTE 4 Sourid Bytes a rers tao tania tal rer Ropa ier ce 330 CHAPTER 12 LADDER LOGIC 16 NOTE 5 RC Servo Motor cococcccccccononnnononcnnonennnnnononcnnonnnnnononnanenannnnns 333 NOTE 7 DS1302 RIG cil ceva cia rec Teboe adeb deg Da Rete Deb eve 336 NOTE 8 MCP3202 12 Bit A D Conversion eene 338 NOTE 9 Read and write to the EEPROM ceeeeennnn nnnm 340 LADDER BaSS e eb D rt Creating LADDER Editing LADDER Text tdeo A ah aede ae ae ie MOMIEOMING EET PET TP Time Chart Monitoring 2 2 dla de a Done Ere n WATCEHPOIN Taiana Register Expression Ladder symbols Using OS 5s cire ertt Use of AllaseS vein eee eee ere A NY ee ea e Pes ans y avs Beginning of LADDER eese nenne rne Declare devices to use cococconcoronenncanoncnnononcancaronccncorenccncnrenenacanoss To Use Ladder Only without BASIC eseeenen He 366 Enable
234. reqout 0 1469 CH D F 4156 3703 3144 Note G in Octave 5 G Ad 2774 2471 C D 2078 1851 C D E F G A B 4403 3923 3495 3299 2939 2618 2333 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 RS232 port This command Get actually reads from the receive buffer If there is no data in the receive buffer it will quit without waiting for data 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 one For receiving a Long type data it would be 4 For larger data please use GETSTR TIPS Use SYS 1 after GET or GETSTR to verify 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 Recv1 Gosub GOTDATA Do Do while In 0 0 Loop Wait until press button Connect P0 Put asc H ju Put esc y Putas hd Pur Ll aso UL A T ione I ese v d PUG al 115 3E HELLO Chr 13 Chr 10 Bue dip 110 11 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
235. riable 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 I O Port number Hpaste HPASTE x y layer 445 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 I2cstart I2CSTART I2cstop I2CSTOP I2cread Variable I2CREAD dummy Variable Variable to store results No String or Single dummy dummy value Normally 0 I2creadna Variable I2CREADNA dummy Variable Variable to store results No String or Single dummy dummy value Normally 0 I2cwrite Variable I2CWRITE data Variable Acknowledge O 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 I O Port number 0 to 255 Incr INCR variable Variable Variable for increment No String or Single Input INPUT Port Port I O Port number 0 to 255 Keyin Variable KEYIN Port debouncingtime Variable Variable to s
236. rol 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 ESSERE MEO OPENS As you can see above the packet size is 99 bytes In other words if character S is not received within 99 bytes interrupt will occur SET UNTIL 1 5 The user may also just set the packet size and not set the character as shown above The character may also be written in decimal as shown below SET UNTIL 1 100 4 231 Shiftin Variable SHIFTIN clock data mode bitlength Variable Variable to store results No String or Single Clock Clock Port 0 to 255 Data Data Port 0 to 255 Mode 0 LSB First Least Significant Bit First After Rising Edge 1 MSB First Most Significant Bit First After Rising Edge 2 LSB First Least Significant Bit First After Falling Edge 3 MSB First Most Significant Bit First After Falling Edge 4 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 command can be used to communicate with SPI MIcrowire and similar communication protocols When using EEPROM ADC or DAC t
237. ry backup CB290 In comparison CTD command will lose its count value when the module is powered off KCTU KCTD must be used with modules that support Battery Backup such as the CB290 385 Comparison Logic Compare 2 Words 16 bit or 2 Double Words 32 bit values and turn on Output when the conditions are satisfied Comparison Data Types Explanation Command S1 s2 Word 16 bit When s1 and s2 are same Output turns ON lt gt s1 s2 Word 16 bit When s1 and s2 are different Output turns ON gt s1 s2 Word 16 bit When s1 gt s2 Output turns ON lt s1 s2 Word 16 bit When s1 lt s2 Output turns ON gt S1 s2 Word 16 bit When s1 gt s2 Output turns ON lt s1 s2 Word 16 bit When s1 lt s2 Output turns ON D s1 s2 DWord 32 bit When s1 and s2 are same Output turns ON D lt gt s1 s2 DWord 32 bit When si and s2 are different Output turns ON D s1 s2 DWord 32 bit When s1 gt s2 Output turns ON D s1 s2 DWord 32 bit When s1 lt s2 Output turns ON D gt s1 s2 DWord 32 bit When s1 gt s2 Output turns ON D lt s1 s2 DWord 32 bit When s1 lt s2 Output turns ON DO TI MO You can mix different comparisons as shown below DO TI gt CO 88 MO E SS lt D1 100 When either DO T1 or D1 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
238. s command is a DOWN Counter When input is received the counter is decremented 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 1 c RESET R 100 pulse purse MANN Ann reserH COT C1 383 UP DOWN COUNTER Below is a simple way of how UP Counter can be used to make a UP DOWN Counter PO CTU CO 100 1 C PI R P2 WDEC CO e 1 PO is for counting UP P2 is for counting DOWN and P1 is for resetting the COUNTER When Counter reaches 100 CO turns ON eo DHL AMM pao MM mn co COUNT co OD 384 KCTU This command is exactly same as CTU command except this command will be able to remember counter value when module is powered off The module used for this command MUST support battery backup CB290 In comparison CTU command will lose its count value when the module is powered off PI KCTU CO 100 i i n3 100 pulse PO P1 e Use RESET to set the counter to 0 atthe Power off amp on beginning When using this command for the very first time please use the RESET signal to reset the counter value Otherwise counter will start at the last value it was set random if not set before KCTD This command is exactly same as CTD command except this command will be able to remember counter value when module is powered off The module used for this command MUST support batte
239. s 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 left over bits can just be disregarded 308 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 colon 1 Slave Address 0X03 1 03 2 Function Code 0X03 1 03 2 Start Address HI 0X70 1 70 2 Start Address LO 0X00 1 00 2 Length HI 0X00 1 00 2 Length LO 0X03 1 03 2 Error Check CRC 2 LRC 2 Ending Code CR LF 2 1 Word is has 2 bytes so we are going to get 6 bytes total as response Response Field RTU Bytes ASCII Bytes Header colon 1 Slave Address 0X03 1 03 2 Function Code 0X03 1 03 2 Byte Count 0X06 1 06 2 Data 1 LO 0X03 1 03 2 Data 1 HI OXE8 1 E8 2 Data 2 LO 0X01 1 01 2 Data 2 HI OXF4 1 F4 2 Data 3 LO 0X05 1 05 2 Data 3 HI 0X33 1 33 2 Length LO 0X03 1 03 2 Error Check CRC 2 LRC 2 Ending Code CR LF 2 309 Function Code 05 Force Single Coil PLC s can remotely control the status of its 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 Heade
240. set 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 as shown below Const Device CB280 Debug Terminal DEAR Debug Port Baud Rate Parity Data Bits eTx i com 115200 None je ar Reset Do High 0 Delay 200 Low 0 Delay 200 Loop Fix Right Side 211 2 How to check if a particular point of the program is being executed Simply insert a Debug command where you would like to tell if that part of the program is being executed like shown here e S Terminal BAE Const Device CB280 Baud Rate Parity Data Bis g 7x Du High 0 Delay 200 Low 0 Delay 200 Loop Debug This Part E T Fix Right Side The debug statement above will never execute as the program stays in the Do 212 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 locate a particular location on the LCD like shown here amp CUBLOC studio d icubloc_testidebuscreen cul Ele Edt Device Run Setup Help Bal GAG A gt m ur E FI BASIC F2 LADDER Ladder Mnemonic Dim A As Integer Debug CLR Debug Goxy 1 1 Debug POWER METER SYSTEM MONITOR SCREEN Debug Goxy 2 3 Debug Input Status Debug Goxy 2 5 Debug Out
241. set to 65535 it will be a 16 bit PWM Please set the Duty to be less than the Period Duty can be 50 of Period to create a square wave PWM is independently hardware driven within CUBLOC Once the PWM command is executed it will keep running until PWMOFF command is called 200 1024 LOW 5 Set port 5 output and output LOW signal PWM 0 200 1024 Output 10 bit PWM with duty of 200 and Width of 1024 IMPORTANT PWM 0 1 and 2 must used the same value of Period since they share the same resources Their duty values can be different PWM Channel 3 4 and 5 also must use the same value of Width since they share the same resources Their duty values can be different 205 Pwmoff PWMOFF Channel Channel PWM Channel 0 to 15 Stop the PWM output Following is available PWM channels according to the models sour Q 1 24 7 VIN SIN 2 23D vss ATN 3 22H RES vss Q4 21B vob Po js 20H P15 P1 ge 190 P14 p27 18H P13 P3 g8 170 P12 PA jo 16H P11 PWMO P5110 150 P10 PWM1 4 P6 01 14H Pa PWM2 p7 12 130 P8 For CB220 3 PWM channels are provided on the Ports P5 P6 and P7 sour 1 617 voo ma 33 e 49 TTLTXt sin 2 18 vss RX1 TTLRX1 AVREF P48 pat P30 P29 P28 9 RES AVDD 20 N C Nic 21 P146 P24 2 PIT Pag 23 P18 P26 4 p19 gt PWM3 P27 25 p20 gt PWM4 Bar 26 P21 gt PWMS PAS 42 p22 Pag 28 P23 Pag 29 P15 P43 P14 Paz P13 pat P12 P40
242. ssed a beep will sound from the piezo and the button will be inversed abc DEMO FOR CUTOUCH Const Device CT1720 Dim TX1 As Integer TY1 As Integer Dim k As Long Contrast 550 Set Pad 0 4 5 On Pad Gosub abc Menuset 0 2 8 16 87 63 Menutitle 0 13 13 STE 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 Tx Getpad 2 amete fe EET TYI 10 f Menucheck 0 TX1 TY1 Then Menureverse 0 End If f Menucheck 1 TX1 TY1 Then Menureverse 1 Pulsout 18 300 End If f Menucheck 2 TX1 TY1 Then Menureverse 2 Pulsout 18 300 End If Return Pulsout 18 300 Send out beep to piezo Start End Restart 425 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 Filename CTOO1 CUL gt Const Device Ct1720 Dim I As Integer Contrast 550 LCD CONTRAST SETTING Do Locate 15 6 Print DECS T TASE 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 a adjustable knob on the back of CUTOUCH In this case you have the option to set the contrast manually 426 SAMPLE 2 The following example prog
243. st 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 showed box 1 0 1 2 x1 y1 x2 y2 are the x and y axis positions of the left upper and lower right corners When this command is executed the set part of the screen becomes part of the button s area 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 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 421 Menucheck Variable MENUCHECK index touchx touchy Variable Variable to store results 1 if selected O if unselected Index Menu Index Number Touchx Touch pad x axis point Touchy Touch pad y axis point Use this command Menucheck to see which menu is selected 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 Selected menu box is inverted Initialize Total cost Menu Variable MENU index pos Variable Variable to store results 1 selected O unselected Index Menu Index pos Position 0
244. sults No String or Single mux AD input Port Combination MUX 0 to 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 4095 Data Data to write to EEPROM up to Long type values ByteLength Number of Bytes to write 1 to 4 443 Ekeypad Variable EKEYPAD portblockIn portblockOut Variable Variable to store results Returns Byte PortblockIn Port Block to receive input 0 to 15 PortblockOut Port Block to output 0 to 15 Ellipse ELLIPSE x y ri r2 EIfill ELFILL x y r1 r2 Freepin FREEPIN I O I O I O 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 Getcrc 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 calc
245. t 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 value Contrast Value Count Variable COUNT channel Variable Variable to store results No String or Single Channel Counter Channel number 0 to 1 442 Countreset COUNTRESET channel Channel Counter Channel 0 to 1 Csroff CSROFF Csron CSRON Dcd 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 Dtzero DTZERO variable Variable Variable for decrement No String or Single Eadin Variable EADIN mux Variable Variable to store re
246. t CUBLOC and CUTOUCH are one of the most versatile BASIC PLC hybrid chip on the market today Another analogy to real life would be to automobiles Do you have a very small fast car Or do you have a monster truck How would it be to use an SUV Yes CUBLCC is sort of like an SUV in the automobile world You have the best of the worlds Although it s not as fast as a raw MCU you can take advantage over the overall savings in development cost and time using our Plug N Play peripherals 23 Ladder Logic and BASIC The biggest advantage of Ladder Logic is that all circuits are processed in Parallel meaning they are all processed at the same time Po P2 Pg A P3 P5 P6 P8 sC HH As you can see above both A and B circuits are in a waiting state ready to turn 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 B As Integer A 0 Jump Again For B 0 to 10 Debug DECA CR A A 10 Loop Next 1 Goto Again ________ These 2 types of programming languages have been used in different fields for a long time Ladder Logic is used in automation controllers such as PLCs On the other hand BASIC and other programming languages such as C and Assembly have been used in PCs and MCUs Whether you are an experienced MCU or PLC user you will be able to benefit by integrati
247. t uses the touch pad DEMO FOR CUTOUCH Const Device CT1720 Dim TX1 As Word TY1 As Word Set Pad 0 4 5 1 Activate Touch PAD Input On Pad Gosub abc 2 Declare pad interrupts Do Loop abc TX1 Getpad 2 3 Interrupt Service routine TY1 Getpad 2 CirorefiTi AA AO 4 Draw a circle where it y was touched Return 1 SET PAD 0 4 5 This command will activate the PAD inputs Syntax SET PAD mode packet size buffer size CUTOUCH has a separate touch controller that will sense touch input and send back to the CPU through SPI protocol This touch controller will create a 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 1 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 interrupt service routine When PAD input occurs this is part of the code until return will be executed 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 you will be able to see that wherever you press on the screen a circle will appear Please use this program as a skeleton for your touch programs The following is MENU command and ON PAD command example When 424 button is pre
248. tack and display on the specified layer at position x y with specified logic GPOP 120 20 2 0 277 Gpaste GPASTE x y layer logic logic 0 OR logic 1 AND logic 2 XOR logic 3 Clear screen then pop Paste from 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 there is further need to use the current item in stack 278 Hpush HPUSH x1 y1 x2 y2 layer HPUSH HPOP HPASTE commands are similar to GPUSH GPOP and GPASTE except that the columns can only be multiple of 8 as shown below The 320 pixels have been divided by 8 there are only 40 columns each 8 pixels wide 11111111112222222222333 012345678901234567890123456789012 239 HPUSH 6 20 12 100 2 Hpop HPOP x y layer Same as GPOP except x value is 0 to 39 HPOP 10 20 2 0 Hpaste Hpaste x y layer Same as GPASTE except x is between 0 and 39 279 GHB3224C DIP Switch Settings On the back of the GHB3224B there are DIP switches to set the RS232 baud rate and I2Cslave address used Please choose one communication method to use at a single time DIP Switch RS232 Baud Rate I2C Slave Address 123 ON TT 2400 0 123 ON mm 4800 1 12 3 on E m 9600 2 123 ON EE 19200 3 123 ON E Em 28800 4 123 ONE E a 38400 5 123 ON i NI 5
249. ted subroutines are supported in CUBLOC A FLOOR SQR F Do Floor on SQR F Colons Colons may not be used to put append commands in CUBLOC BASIC Pals hal a GSL Toortst A 1 Correct B 1 C 1 78 Variables There are 5 types of variables in CUBLOC BASIC BYTE 8 bit Positive Number 0 to 255 e INTEGER 16 bit Positive Number O to 65535 eo 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 L For storing negative numbers please use LONG or SINGLE Use 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 STI 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 lt CUBLOC studio d cubloc_test variable cul File Edit Device Run Setup Help Bag xi mu E FI BAS
250. tes Data 101 Please make sure to stop monitoring before editing or downloading 352 Time Chart Monitoring Click He re B amp ul d ABM gt m ur EH El 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 Time Chart Monltor aferran erm emen m Pad ew Sampling Time ie Cursor Move Tof control icon Zoom control 7 Relay select Use Unuse Time interval display X position To use the Time Chart Monitor you must set Debug off in Basic To do this simple add Set Debug Off command at the very beginning of your code Set Debug Off While using Time Chart Monitor Ladder Monitoring may not be used either 353 WATCH POINT When you want to watch the status of Registers and timers outside the current Ladder Monitoring screen you can use 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 CUBLOC studio c Weubloc_testWu3 1018 cul File Edit Device Run Setup Help BS d XS wt Be ef FI BASIC F2 LADDE
251. tion 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 372 LOAD LOADN OUT LOAD is for Normally Open Contacts and LOADN is for Normally Closed Contacts Registers that P M F S C T D Constants can be used LOAD 0 O 0 O 0 O LOADN OUT O 9 373 NOT AND OR NOT Symbol PO P5 f C Po PI P5 FI 0 PO P5 C i EN AND OR 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 The following is an example of BLOCK AND and BLOCK OR BLOCKAND PU P Jl P5 FAI C 7 Ld Po p P5 HA PI P3 HA BLOCK OR 374 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 r J P1 RSTOUT P5 C J Registers that P M F S C T D
252. to a formatted String with user defined whole and fractional number digits Dim A as Single A 3 14 DEBUG Float A 8 1400000 Prints all digits DEBUG FP A 3 2 Y 3 14 Print user defined digits By using 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 Cubloc Studio d cubloc_test fptest cul ETE Cd mde m er Uu 27 Cubloc Studio d cubloc_test fptest cu File Edit Device Run Setup Help COMA ay 15200 Wudl None m Bal SiG A m m NI F1 BASIC F2 LADDER Ladder Mnemo Const Device CB28D Dim A As Single AS 3 14 3 140000 Debug Float A Cr 3 14 Debug FP A 3 2 Cr Close Fis Right Side CUBLOC Floating Point Values are in accordance with the IEEE724 format The values of FP and Float may differ but the value stored in the variable will be the same 117 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 ST1 AS STRING 12 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 ST
253. tore results No String or Single Port Input Port 0 to 255 deboucingtime Debouncing Time 1 to 65555 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 65555 446 Keypad Variable KEYPAD PortBlock Variable Variable to store results Returns Byte No String or Single PortBlock Port Block 0 to 15 Layer LAYER layerimode layer2 mode layer3 mode Layerimode Set Layer 1 mode 0 off 1 0n 2 flash Layer2mode Set Layer 2 mode 0 off 1 0n 2 flash Layer3mode Set Layer 3 mode O off 1 0n 2 flash Ladderscan LADDERSCAN Light LIGHT value value Back light O OFF 1 ON Line LINE x1 y1 x2 y2 Linestyle LINESTYLE value Lineto LINETO x y Low LOW Port Port I O 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 02x1 1 y1 2 x2 3 y2 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 O if unselected Index Menu Index Number Touchx Touch pad x axis point Touchy Touch pad y axis point Me
254. ttery EEWRITE command takes about 5mS 4KB 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 Clear all 55KB of HEAP memory to 0 Heap Variable HEAP Address Variable Variable to store results Address HEAP memory address Heap function returns 1 byte of data from the 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 Heap memory address HEAP Memory Address The HEAP memory is divided into byte unit addresses When a LONG variable is stored 4 bytes is stored and 4 memory addresses are used HWRITE 0 amp H1234ABCD 4 0 CD 1 AB 2 34 3 12 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 The above example will overwrite HEAP memory address 1 Please be careful to not overwrite your data DEMO PROGRAM Const Device CB405 Dim A As Byte Dim I As Long J As Long I amp HABCD1234 Heapclear Hwrite 0 1 4 Do Heapw 56830 100 Heapw 56831 123 Debug Dec Heap 56830 Cr Debug Dec Heap 56831 Cr
255. tween 0 and 1024 The most important part of this application note is the following table which converts the value of voltage to A D value between O and 1024 Only some of the temperatures are shown 165473 9 4 969965259 129831 7 4 961782976 102509 3 4 951695171 326 o oo oO o1 WIN O ui ei o1 o1 02 51 02 C2 C2 Co Co Co Co Co C9 C2 S2 IN INININININININ IN Je fe fe fe fe fede UTR WIN O io 0o 1 JO o1 S o o O vo JOIN O o1 S 0o N O ojo 4 O o1 S fu IN RE JO 46970 5 _ 4 895769279 1003 4540 6 4 890207868 1002 a2250 5 4 884394522 1000 4091 5 4 878320427 oo9 l38055 4 4 871976604 _ 998 361344 4 865353924 oo6 4321 5 amp 858443112 pos 32610 0 4 851234752 994 30993 7 4 8437193 992 9466 8 4 835887094 po0 8023 9 4 827728362 989 6660 0 4 819233234 987 25370 2 a 810391755 o85 4150 1 4 801193902 83 2995 7 479162959 o81 1903 1 4 781688696 p79 20868 5 4 771361072 977 9888 7 4 760636561 975 i9960 5 4 749505017 p73 s080 8 4 737956327 p70 7246 9 a 725980424 o68 6456 1 4713567319 pes 5706 0 4 700707114 963 l1ag94 4 4 68739003 aso 14318 9 4 673606431 o57 3677 7 4 amp 659346849 o54 3068 7 4 644602011 p5i 12490 3 4 629362861 o48 1940 6 4 613620595 p45 1418
256. ually 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 CONST DEVICE CB220 Use CB220 This should be the first line at the start of your program When this command is not used CB220 model will be chosen as default CONST DEVICE CT1720 Use CT1720 CONST DEVICE CB280 Use CB280 69 CUBLOC BASIC Features Interface PC with RS232C Port CUBLOC uses RS232 port to interface with the PC You also have option of using it to connect to MAXPORT and use monitoring downloading via the internet CUBLOC BASIC supports functions and sub routines Like C language the user is able to create sub routines and functions to lessen the complexities of their programs By being able to use sub routines and functions it is now possible to simple copy amp paste for new programs instead of starting everything from scratch Function SUM A As Integer B As Integer As Integer Dim RES As Integer RES A B SUM RES End Function Calculations can be done within conditional statements such as If While etc IF A 1 100 THEN GOTO ABC IF A 1 100 AND B 100 20 ORC 3 THEN GOTO ABC Multi dimension arrays are supported CUBLOC supports multi dimension arrays including character arrays Maximum of 8 D arrays are supported and only 1 dimensional array is allowed for ch
257. ug Clr TEST PROGRAM 143 Decr DECR variable Variable Variable for decrementing No String or Single Decrement the variable by 1 similar to A in C language Decr A Decrement A by 1 144 Delay DELAY time Time interval variable or constant up to Long type Delay for the specified time in milliseconds Delay should be only used for slight delays in getting something to work We recommend not using it for time measurements and time specific applications Delay 10 Delay about 10 ms Delay 200 Delay about 200 ms Delay is pre made system s sub program sub delay dl as long dll var long dl2 var integer for dl1 0 to dl for d12 0 to 1 nop nop nop next next end sub 145 Do Loop DO LOOP will loop the commands within itself unless DO WHILE or DO UNTIL is used to set a condition in which DO LOOP can be terminated EXIT DO command can also be used within the DO LOOP to exit from the loop Do Commands Loop Dim K As Integer Do K Adin 0 Read AD input from channel 0 Debug Dec K Cr Delay 1000 Loop In the above example the program will loop infinitely within DO and LOOP 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 condition in WHILE is met Do Until Condition Commands Exit Do Loop Do Co
258. ulate 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 Length 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 to 65535 444 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 to 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 20 OR logic 21 AND logic 22 XOR logic 3 Clear screen then pop Gprint GPRINT string Gpush GPUSH x1 y1 x2 y2 layer Gpop GPOP x y layer logic logic 20 OR logic 21 AND logic 22 XOR logic 3 Clear screen then pop 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 Va
259. us is to enable the MODBUS slave It must come after OPENCOM command and only runs on RS232 Channel 1 Baudrate 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 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 217 Set Onglobal SET ONGLOBAL On Off At power On Set Onglobal is ON by default This command turns on or off the ability to receive 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 218 Set Onint SET ONINTx On Off
260. ut Register PO to P127 1 bit Interface w P External devices Internal Registers M MO to M511 1 bit Internal Registers Special Register F FO to F127 1 bit 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 SO to S15 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 located in the MSB of the WPO commands like WMOV PO is located in the LSB of WPO and P15 is These Registers are very useful to use with PO MO FO TO co C49 T99 P127 F127 16bit bu d bow d 16bit tbit 1bit M511 E DO D99 16bit 359 CB290 CB405 Registers The following is a chart that shows CB290 Registers T and D Registers than CB220 and CB280 CB290 has more M C 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 Sp
261. ven after this command ESC S 1B 53 2 Cursor ON Default ESC s 1B 73 2 Cursor OFF ESC B 1B 42 2 Backlight ON Default ESC b 1B 62 2 Backlight OFF ESC H 1B 48 2 LOCATE 0 0 ESC L X Y 1B 4C xx yy 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 1 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 maximum baud rate settings for 12V 4 pin level is 38400bps For TTL 5V level 3 pin up to 115200bps can be used The following is an example code when using the CB280 to connect to the CLCD module through CUNET protocol When you execute this program CLCD will display increment of numbers Const Device Cb280 Set Display 2 0 1 50 Set the SLAVE ADDRESS to 1 by manipulating the DIP switch Dim i As Integer Delay 100 Delay for start up of CLCD els Delay 200 Delay for initializing and clearing CLCD 255 The slave address of CLCD and SET DISPLAY command should match 256 GHLCD Graphic LCD GHB3224 Series GHLCD is able to display characters and
262. will communicate using method set here Please choose the type of LCD the method baud rate and buffer size CLCD will use Method O Method 1 RS232 Channel 1 Use RS232 Channel 1 for display For the CB220 port 11 TX is used CHANNEL 0 TX sour di Y_ zh vin RX gt siN D2 231 vss ATN O3 221 RES vss 04 21H voD Po Q5 20H P15 P1 ge 19H Pra P2 07 18H P13 P3 D8 17h P12 CHANNEL 1 Pa Do 16H P11 gt TX P5 Q10 150 P10 lt RX Pe O11 im 1410 Pe P7 12 13H P8 For the CB280 pin 33 or pin 49 can be used Pin 49 outputs 12V level signal and 33 outputs 5V level signal CHANNEL 1 CHANNEL O CHANNEL 1 TX sou 10 017 voo TX 10 33 e 49 mi RX gt sin 20 018 vss RX gt RX 34 50 TTLRX1 4 ATN 30 0 19 RES AVDD 35 5 AVREF vss 4 20 wc Nic 36 e 52 P48 Po 5 21 Pis P24 37 e 53 P31 p1 6 22 P7 P25 38 54 P30 p2 70 02 Pia P26 39 55 P29 p3 8 24 Pio PWM3 P27 40 56 P28 P4 90 25 P20 gt PWM4 P47 41 57 P32 Ps 10 26 P21 gt PWM5 P46 42 58 P33 P6 11 27 P22 Pas 43 59 P34 P7 120 28 P23 Pas 44 60 P35 Ps 130 29 Pis P43 45 61 P36 P9 14 0 30 P14 P42 46 62 P37 P10 i50 031 Pra Par 47 e 63 P38 pit Mee 32 P12 Pao 48 64 P39 251 The possible Baud Rate settings are as follows 2400 4800 9600 14400 19200 28800 38400 57600 76800 115200
263. will maintain its values when powered OFF Below is an example of how to reset TAON Fl MO TAON TO 100 Y ps TO mo T Lj C 381 TOFF TAOFF When input turns ON output turns ON immediately When the input turns OFF the output is kept ON until 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 1 START TAOFF T1 100 1 There are 2 parameters with commands TOFF TAOFF For the first parameter you can choose between TO to T99 and for the second parameter you may use a number or a data memory such as DO Usable P M F S E T D Constants Registers TOFF TAOFF O O O O In the above LADDER diagram when START turns ON TO Timer will immediately turn ON After START turns OFF timer will start decreasing from 100 to O When 0 is reached TO will turn OFF Here 100 is equal to 1 second for TON and 10 seconds for TAOFF 1sec lt gt sTART M To D 382 CTU This command is an UP Counter When input is received the counter is incremented 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 C0 100 C RESET R 100 pulse puse HOM Anno RESET E co CTD Thi
264. y is unpressed which will return a scancode of 255 This is to let the processor stop reading input while a key is pressed Otherwise the processor might receive multiple key inputs since execution time of 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 quick END 324 NOTE 3 Temperature Sensor In our world today there are countless number of devices that senses temperature Refrigerator heater air conditioner automobiles and many other devices that uses temperature sensors Therefore this is one of the very basic components we must know What types of temperature sensors are there There is PT100 NTC PTC thermistor and other chip type sensors such as the DS1620 Today we will dive into the NTC thermistor and figure out how to connect and use it with CUBLOC The NTC thermistor can be comparable to a very 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 Among NTC thermistors the ceramic types can sense around 20 to 130 degrees Celcius temperature There is an NTC thermistor that resembles a diode With this thermistor we can sense between 30 and 250 degrees Celcius temperature 4D You can acquire R T Resistance Temperature conversion
265. y pulses have been outputted since the last STEPPULSE command STEPSTAT will return double the number of pulses remaining to be outputted 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 outputting pulses _F 56 will be logic HIGH 1 When Channel 1 is outputting pulses _F 57 will be set to logic HIGH 1 If no pulses are outputting at the moment the F registers will be set to logic LOW 0 STEPPULSE CHO F56 bo STEPPULSE CH1 IS 235 DEMO PROGRAM Cubloc Studio d cubloc_test steppulse cul DER Ele Edt Device Run Setup Help Bei d xsS8u 4 miuB x FI BASIC F2 LADDER Ladder Mnemonic Func Script Const Device CB280 Do Do While In 0 0 Loop Steppulse 0 5 5000 300 Do While In 0 1 Loop When Port 0 switch is pressed Port 5 or P5 will output 300 pulses at the speed of 5kHz The following is a circuit diagram for the above code CB280 sv Po rs Ss M 5KHz 130 Pulses 15KHz 300 Pulses OR 236 You can connect a stepper motor and stepper motor driver such as below to control a stepper motor DRIVER CONTROLLER POWER GROUND 24 TO 80 VDC 5 VDC S PWR GND SIGNAL GN alo gt DISABLE DIRECTION STEP 5 VDC CURRENT SET CURRENT SET SIGNAL GNI Y GND Connect 3 I Os of CUBLOC to the stepper motor drive
266. y when using this command To not get affected by LADDER or BASIC we recommend stopping LADDER and all interrupts before using this command Y Udelay 100 Delay about 1630 micro seconds 244 Usepin Usepin I O In Out AliasName 1 O VO Port Number 0 to 255 In Out In or Out AliasName Alias for the port Optional This command Usepin is used to set the I O Port status and alias name for LADDER program Please use this command to set the I O Ports before using them in LADDER Usepin 0 IN START Usepin 1 OUT RELAY Usepin 2 IN BKEY Usepin 3 OUT MOTOR 245 Utmax UTMAX variable Variable Variable for decrement No String or Single Increment the variable by 1 When maximum is reached the variable is no longer incremented The Maximum here refers to the variable s maximum value In the case with Byte the maximum would be 255 and in the case with Integer the maximum would be 65535 Utmax A Increment A by 1 246 Wait Wait time Time interval variable or constant mS unit 10 to 2147483640 Wait for the specified time in milliseconds This command will delay using the system clock This delay function is accurate to 10ms units Wait 10 Delay 10 ms Wait 15 Delay 10 ms Wait 110 Delay 110 ms Wait 115 Delay 110 ms Use with CUBLOC STUDIO 2 0 H and above 247 WaitTx WAITTX channel channel RS232Channel 0 to 3 This command WaitTx will wait until the send buffer is flush

Download Pdf Manuals

image

Related Search

Related Contents

愛の手スクエア取説 10式取一般-SQ-2型-HP  Louisiana Medicaid Management Information System (LMMIS)  Indesit IWDE 7125 S  Das tanzende Alphabet  

Copyright © All rights reserved.
Failed to retrieve file