C-Control Pro IDE © 2013 Conrad Electronic
I C-Control Pro IDE Table of Contents 2 Part 1 Important Notes 1 Introduction ................................................................................................................................... 2 2 Reading ................................................................................................................................... this operating manual 2 3 Handling .......................................................................................................................
Inhalt II 3................................................................................................................................... LCD Matrix 127 Part 3 IDE 129 1................................................................................................................................... Projects 130 1.1 ................................................................................................................................... Create Projects 130 1.2 ............................
III C-Control Pro IDE 2................................................................................................................................... CompactC 170 2.1 ................................................................................................................................... Program 170 2.2 ................................................................................................................................... Instructions 171 2.3 ......................................
Inhalt IV 5.4 ................................................................................................................................... CAN_Init 242 5.5 ................................................................................................................................... CAN_Receive 243 5.6 ................................................................................................................................... CAN_MObSend 243 5.7 ...........................................
V C-Control Pro IDE 11.7 ................................................................................................................................... ETH_CloseListenUDP 264 11.8 ................................................................................................................................... ETH_DisconnectTCP 264 11.9 ................................................................................................................................... ETH_GetIPInfo 265 11.10 ...........
Inhalt VI 16.2 ................................................................................................................................... Integer 297 17 ................................................................................................................................... OneWire 298 17.1 ................................................................................................................................... Onewire_Read 298 17.2 .............................................
VII C-Control Pro IDE 21.2 ................................................................................................................................... SDC Return Values 328 21.3 ................................................................................................................................... SDC_FClose 328 21.4 ................................................................................................................................... SDC_FOpen 329 21.5 ......................
Inhalt VIII 25 ................................................................................................................................... Threads 354 25.1 ................................................................................................................................... Thread_Cycles 356 25.2 ................................................................................................................................... Thread_Delay 357 25.3 .....................................
Part 1
Important Notes 1 2 Important Notes This chapter deals with important information's to warranty, support and operation of the C-ControlPro hardware and software. 1.1 Introduction The C-Control Pro Systems are based on the Atmel AVR32 and the Atmel Mega Series (Mega 32, Mega 128, AT90CAN) resp. These Microcontrollers are used in large numbers in a broad variety of devices from entertainment electronics through household appliances to various application facilities in the industries.
3 1.4 C-Control Pro IDE Intended use The C-Control Pro Unit is an electronic device in the sense of an integrated circuit. It serves the programmable controlling of electric and electronic equipment. Construction and operation of this equipment must be in conformance with the valid European licensing principles (CE). The C-Control Pro must not be galvanically connected to voltages exceeding the directed Extra Low Protective Voltage.
Important Notes 1.6 4 Service Conrad Electronic provides you with a team of experienced service technicians. If you have any question with regard to our C-Control Pro Unit you can reach our Technical Service by letter, telefax or e-mail. By letter Conrad Electronic SE Technical Inquiry Klaus-Conrad-Straße 2 D-92530 Wernberg-Köblitz Fax-Nr.: E-Mail: 09604 / 40-8848 webmaster@c-control.de Please preferably use e-mail communication.
5 1.9 C-Control Pro IDE History Version 2.31 from 09/20/2013 New Features AVR32 support Ethernet Support (AVR32Bit) Webserver (AVR32Bit) Tab Interface for Editor new Communication routines direct access to COM Port in Toolbar turn on/off COM Ports in Toolbar Error Corrections Documentation Update Partly wrong incrementation of Clock Variable in Interrupt context corrected error in type recognition of constants fixed error in Onewire_Read wrong definitions PORT_ON and PORT_OFF corrected Version 2.
Important Notes Floats in tables now work Corrected negative values in tables Fixed constant expressions in parentheses Corrected function calls made in return statements "#pragma Warn" is now "'#pragma Warning" Wrong editor undo after save fixed Fixed bug in Serial_IRQ_Info Fixed bug in serial program transfer Problem in Servo-Routines corrected External Interrupt Acknowledge now in correct order Wrong upper limit at some TimerXTime() functions fixed Clear all Breakpoints now works every time Fixed problem
7 C-Control Pro IDE Addition und Subtraction of Pointers Optimized Port OUT, PIN and DDR Access Direct Atmel Register Access Formatted String Output with Str_Printf() convert ASCII strings in numerical values ++/-- for BASIC Port toggle functions RC5 Send and Receive Routines Software Clock (Time & Date) with Quartz correction factor Servo Routines mathematical Round Atmel Mega Sleep Function Error Corrections Initialization Timer_T0FRQ corrected Initialization Timer_T0PWM corrected Initialization Timer_T1
Important Notes 8 New FTDI driver Error Corrections Global For-Loop counter variables in BASIC work now correct Char variables work now correct with negative numbers "u" after an integer now defines unsigned number Project names now can contain special characters Thread_Wait() now supports thread parameter return command in CompactC without return parameter was working wrong Corrected swapped error messages when called functions with pointers Corrected error message at assignment, when function had no ret
9 C-Control Pro IDE Thread_Kill() worked erroneous when called from the main thread read accesses from globally defined floating point arrays were faulty The second serial interface was not working correctly EEPROM write accesses that used illegal addresses could overwrite reserved data in EEPROM There was a chance with a very low probability that the LCD display content could get corrupted Version 1.
Important Notes Version 1.39 from 06/09/2005 New Features BASIC Support CompactC and BASIC can be mixed in a project Extended Documentation Loop Optimizing for For - Next in BASIC ThreadInfo Function New Demo Programs Error Corrections Compiler does no longer break down at German Umlauts (ä, ö, ü) Internal Byte Code of command StoreRel32XT corrected Offset in String Table improved Version 1.
Part 2
Hardware 2 12 Hardware This chapter gives a description of the hardware coming into operation with the C-Control Pro series. The Modules C-Control Pro Mega32 and C-Control Pro Mega128 will be described. Further chapters will comment on construction and function of the accompanying application boards and LCD modules as well as the keyboard. 2.1 Mega Series 2.1.1 Installation In this chapter the installation of hardware and software of the C-Control Pro Mega is described. 2.1.1.
13 C-Control Pro IDE tion Board Mounting Orientation of Module MEGA32 The connector of Module Mega32 has been designed in such a way that faulty insertion of the Module is not possible. The dismounting of the Module is performed by carefully lifting it from the socket by use of a suitable tool. In order to avoid bending the contacts the lifting of the Module should take place from various sides. 2.1.1.
Hardware From here select "Install software from a list or other source" and click "Next"..
15 C-Control Pro IDE Then type in the path to the driver’s directory. If the software has been installed to "C:\Programs" it will be path "C:\Programs\C-Control-Pro\FTDI USB Driver".
Hardware 16 The message "C-Control Pro USB Device has not passed the Windows Logo Test ...." will normally appear. This does not mean that the driver has failed during the Windows Logo Test. It merely means that the driver has not taken part in the (quite costly) Redmond Test. Here click "Continue Installation". The USB driver should then be installed after a few seconds. In the PC software click on IDE in menu Options and select the area Interfaces. Here select the communication port "USB0".
17 C-Control Pro IDE SPI Switch Off (only Mega128) A signal on the SPI interface during switch on can activate USB communication. In order to avoid this PortG.4 (LED 2) can be set LOW during switch on. The SPI interface will then not be activated. The SPI interface can also be manually be switched off by the Interpreter later on using SPI_Disable ().
Hardware 18 means that measured voltages can be represented by integral numbers from 0 through 1023. The reference voltage for the lower limit is GND level, i. e. 0V. The reference voltage for the upper limit can be selected by the user: 5V Operating Voltage (VCC) Internal Reference Voltage of 2.56V External Reference Voltage e. g. 4,096V generated by a Reference Voltage IC.
19 C-Control Pro IDE It is important to closely study the pin assignment of M32 and M128 prior to programming since important functions of the program design (e. g. the USB interface of the application board) will apply to specific ports. If these ports are re-programmed or if the matching jumpers on the application board are no longer set then it may happen that the design platform can no longer transfer any programs to the C-Control Pro.
Hardware 20 Environmental Conditions Range of admissable ambient temperature Range of admissable ambient relative humidity Power Supply 0°C … 70°C 20% … 60% Range of admissable supply voltage Power reqirement of the module without external loads 4,5V … 5,5V appr. 20mA Clock Clock Frequency (Quartz Oscillator) Mechanics Overall measurements less pins, appr. Weight Pin pitch Number of pins (two rows) Distance between rows 14.7456MHz 53 mm x 21mm x 8 mm appr. 90g 2.54mm 40 15.24mm Ports Max.
21 C-Control Pro IDE 32K Bytes of In-System Self-Programmable Flash Endurance: 10,000 Write/Erase Cycles In-System Programming by On-chip Boot Program 1024 Bytes EEPROM 2K Byte Internal SRAM Peripheral Features: Two 8-bit Timer/Counters with Separate Prescalers and Compare Modes One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture Mode Four PWM Channels 8-channel, 10-bit ADC 8 Single-ended Channels 2 Differential Channels with Programmable Gain at 1x, 10x, or 200x Byte-oriented Two-w
Hardware 20 PD6 PortD.6 30 ICP LED1 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 PD7 PC0 PC1 PC2 PC3 PC4 PC5 PC6 PC7 PortD.7 PortC.0 PortC.1 PortC.2 PortC.3 PortC.4 PortC.5 PortC.6 PortC.7 31 16 17 18 19 20 21 22 23 SCL SDA LED2 EXT-SCL EXT-SDA 7 6 5 AVCC GND AREF ADC7 ADC6 ADC5 PA7 PA6 PA5 PortA.7 PortA.6 PortA.5 RX_BUSY TX_REQ KEY_EN 36 PA4 PortA.4 4 ADC4 LCD_EN 37 PA3 PortA.3 3 ADC3 EXT_SCK 38 PA2 PortA.2 2 ADC2 EXT_DATA 39 40 PA1 PA0 PortA.1 PortA.
D C B 1 SCHUTZHAUBE-DIL40 * X1 R1 20K * VCC GND VCC C3 10NF/16V * D1 BAS70 * GND X1 40 41 42 43 44 1 2 3 9 10 11 12 13 14 15 16 PB0 PB1 PB2 PB3 PB4 PB5 PB6 PB7 PD0 PD1 PD2 PD3 PD4 PD5 PD6 PD7 4 2 AGND PA0 (ADC0) PA1 (ADC1) PA2 (ADC2) PA3 (ADC3) PA4 (ADC4) RESET PA5 (ADC5) PA6 (ADC6) PB0 (XCK/T0) PA7 (ADC7) PB1 (T1) PB2 (AIN0/INT2) PB3 (AIN1/OC0) PB4 (SS) PB5 (MOSI) PC0 (SCL) PB6 (MISO) PC1 (SDA) PB7 (SCK) PC2 (TCK) PC3 (TMS) PC4 (TDO) PD0 (RXD) PC5 (TDI) PD1 (TXD) PC6 (TOSC1) PD2 (INT0) P
Hardware 24 responding socket strips must be organized in the following pitch format: In the graph the socket strip X1-X4 and then the first two pins of the socket strip can be seen. Pin 1 of strip X1 corresponds to terminal X1_1 (see Mega128 Pinzuordnung). Module Memory The C-Control Pro 128 Module provides 128kB FLASH, 4kB EEPROM and 4kB SRAM. A supplementary EEPROM with an 8kB memory depth and an SRAM with a 64kB memory depth is mounted on the application board.
25 C-Control Pro IDE Clock Generation Clock generation takes place by a 14.7456MHz Quartz Oscillator. All time dependent actions within the controller are derived from this clock frequency. Reset A Reset initiates the return of the Micro Controller system to a defined starting condition. In gerneral the C-Control Pro Module knows two reset sources: Power-On-Reset: is automatically executed after the operating voltage is switched on.
Hardware 26 Timer_3 with 16 bits each. They can be used for D/A conversion, to control servo motors in pattern making and to output audio frequencies. A pulse length modulated signal has a period of N so called "Ticks". The duration of one tick is the time base. If the output value of a PLM port is set to X then the port will hold high level for X ticks of one period and will then for the balance of the period drop to low level. For programming of the PLM channels see Timer.
27 C-Control Pro IDE Ports Max. admissible current from digital ports Admissible current total on digital ports Admissible input voltage on port pins (digital and A/D) Internal pull-up resistors (disconnectable) 2.1.4.1 ± 20 mA 200mA –0.5V ... 5.5V 20 - 50 kOhm CPU The Micro Controller Atmega128 originates from the AVR family by ATMEL. It is a low-power Micro Controller with Advanced RISC Architecture.
Hardware 28 7 Differential Channels 2 Differential Channels with Programmable Gain at 1x, 10x, or 200x Byte-oriented Two-wire Serial Interface Dual Programmable Serial USARTs Master/Slave SPI Serial Interface Programmable Watchdog Timer with On-chip Oscillator On-chip Analog Comparator Special Microcontroller Features Power-on Reset and Programmable Brown-out Detection Internal Calibrated RC Oscillator External and Internal Interrupt Sources Six Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-do
29 C-Control Pro IDE X2_6 X2_3 X4_10 X4_12 PG4 X2_9 X2_10 X2_11 X2_12 X2_13 19 20 21 22 23 24 25 26 27 28 29 6 52 PD0 PD1 PD2 PD3 PD4 3 3 3 3 3 24 25 26 27 28 TOSC1 RESET VCC GND XTAL2 XTAL1 INT0 INT1 INT2 INT3 IC1 X2_14 X2_15 X2_16 30 31 32 PD5 PD6 PD7 3 3 3 29 30 31 XCK1 T1 T2 X2_7 X2_8 X4_8 X4_7 X4_6 X4_5 X4_4 X4_3 X4_2 X4_1 X2_4 X3_16 X3_15 X3_14 X3_13 X3_12 X3_11 X3_10 X3_9 X4_10 X4_12 X3_8 X3_7 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 PG0 PG1 PC0 PC1 PC2
Hardware 2.1.4.3 30 Connection Diagram 14 16 15 14 13 12 9 8 7 6 5 4 3 2 1 15 11 16 10 X3 The shown connection diagram shows the planned C-Control Pro Module with CAN Bus interface. This Module has not been built. Inside the C-Control Pro 128 Module is working a Mega 128 processor, and not a AT90CAN128 like shown in this diagram. Therefore there is also no ATA6660 CAN-Bus Transceiver inside the C-Control Module.
31 C-Control Pro IDE In the graph the socket strip X1-X4 and then the first two pins of the socket strip can be seen. Pin 1 of strip X1 corresponds to terminal X1_1 (see Mega128 Pinzuordnung).
Hardware 32 Clock Generation Clock generation takes place by a 16MHz Quartz Oscillator. All time dependent actions within the controller are derived from this clock frequency. Reset A Reset initiates the return of the Micro Controller system to a defined starting condition. In gerneral the C-Control Pro Module knows two reset sources: Power-On-Reset: is automatically executed after the operating voltage is switched on.
33 C-Control Pro IDE There are three timers available for PLM. These are Timer_0 with 8 bits and Timer_1 as well as Timer_3 with 16 bits each. They can be used for D/A conversion, to control servo motors in pattern making and to output audio frequencies. A pulse length modulated signal has a period of N so called "Ticks". The duration of one tick is the time base.
Hardware 34 Ports Max. admissible current from digital ports Admissible current total on digital ports Admissible input voltage on port pins (digital and A/D) Internal pull-up resistors (disconnectable) 2.1.5.1 ± 20 mA 200mA –0.5V ... 5.5V 20 - 50 kOhm CPU AT90CAN Overview The Micro Controller AT90CAN originates from the AVR family by ATMEL. It is a low-power Micro Controller with Advanced RISC Architecture.
35 C-Control Pro IDE • 10-bit Prescaler • External Event Counter • Output Compare or 8-bit PWM Output 8-bit Asynchronous Timer/Counter-2 • 10-bit Prescaler • External Event Counter • Output Compare or 8-Bit PWM Output • 32Khz Oscillator for RTC Operation Dual 16-bit Synchronous Timer/Counters-1 & 3 • 10-bit Prescaler • Input Capture with Noise Canceler • External Event Counter • 3-Output Compare or 16-Bit PWM Output • Output Compare Modulation 8-channel, 10-bit SAR ADC • 8 Single-ended Channels • 7 Differe
Hardware 36 Pin Assignment for Application Board Mega128 CAN Module M128 Port Port PortBit # 1 X1_16 2 PE0 4 32 X1_15 3 PE1 4 33 X1_14 4 PE2 4 34 X1_13 5 PE3 4 35 X1_12 6 PE4 4 36 X1_11 7 PE5 4 37 X1_10 8 PE6 4 38 X1_9 9 PE7 4 39 X1_8 10 PB0 1 8 X1_7 11 PB1 1 9 X1_6 12 PB2 1 10 X1_5 13 PB3 1 11 X1_4 14 PB4 1 12 X1_3 15 PB5 1 13 X1_2 16 PB6 1 14 X1_1 17 PB7 1 15 X2_5 18 PG3 6 51 X2_6 19 PG4 6 52 X2_3 20 X4_10 21 X4_12 22 23 24 X2_9 25 PD0 3 24 X2_10 26 PD1 3 25 X2_11 27 PD2 3 26 X2_12 28 PD3 3 27 X2_13 29
37 C-Control Pro IDE X3_13 X3_12 X3_11 X3_10 X3_9 X4_10 X4_12 X2_14 47 48 49 50 51 52 53 54 PA4 PA3 PA2 PA1 PA0 0 0 0 0 0 4 3 2 1 0 PF7 5 47 AD4 AD3 AD2 AD1 AD0 VCC GND ADC7 X3_7 55 PF6 5 46 ADC6 X3_6 56 PF5 5 45 ADC5 X3_5 57 PF4 5 44 ADC4 X3_4 X3_3 X3_2 X3_1 X4_11 X4_12 X4_9 X4_13 X4_14 58 59 60 61 62 63 64 PF3 PF2 PF1 PF0 5 5 5 5 43 42 41 40 ADC3 ADC2 ADC1 ADC0 AREF GND AVCC CAN-L CAN-H A/D SRAM A/D SRAM A/D SRAM A/D SRAM A/D SRAM TDI-JTAG in CAN Modul exchanged with X3
Hardware 2.1.5.3 38 Connection Diagram The connection diagram shows the new C-Control Pro Mega128 CAN module with CAN bus.
39 C-Control Pro IDE © 2013 Conrad Electronic
Hardware 2.1.6 40 Mega32 Application Board USB The "C-Control Pro Application Board MEGA 32" (Conrad Item no. 198245) provides a USB interface for the program’s loading and debugging. Because of the high data rate of this interface data transmission times are considerably shorter compared to the serial interface. Communication takes place through a USB Controller by FTDI and an AVR Mega8 Controller. The Mega8 provides its own Reset push button (SW5).
41 C-Control Pro IDE consists of a monochrome matrix of 5x7 pixels. A flashing cursor below any one of the characters will indicate the current output position. The operating system provides a simple software interface for output on the display. This display is connected to connector X14 (16 poles, double row). By means of a mechanical protection a faulty connection and thus the confusing of poles is avoided. The LCD module used is of type Hantronix HDM08216L-3.
Hardware 42 ity of 125mA it is not recommended for use in devices consistently battery operated. Please see the note on short time breakdowns of the power supply (see Reset Characteristics). If you turn the application board to a position where the interface connectors (USB and serial) show to the upper side, the leftmost column on the breadboard is GND and the rightmost column is VCC.
43 C-Control Pro IDE Testing Interfaces The 4 pole pin strip X16 is to be used for testing purposes only and will not necessarily be armed with components of any kind on every application board. For the user this pin strip is of no importance. One further testing interface is the 6 pole pin strip (two rows at 3 pins each) at JP4. This pin strip too is only meant for internal use and may likely no longer be fitted with components in future board series.
Hardware 44 nected to the module while the left side connects to the components of the application board. If any jumper is pulled then the connection to the application board is suspended. This may lead to obstructions of USB, RS232, etc. on the board. JP1 and JP2 These jumpers are assigned to push buttons SW1 and SW2. There is the possibility to operate the push button against both GND or VCC. In the basic setting the push buttons are switching to GND.
45 C-Control Pro IDE JP6 When using the displays the LED back lighting can be switched off by use of JP6. PAD3 PAD3 (to the right of the module, below the blue inscription) is required as ADC_VREF_EXT for functions ADC_Set and ADC_SetInt.
RESET VCC H2 H3 TL36W000050 D3 1N4007 H4 6 5 GND VCC SCL SDA IC2 D4 1N4007 7 1 2 3 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 GND VCC GND C6 100NF/50V GND VIN VOUT IC3 LM78M05 JP4 1 2 3 JUMPER 3 C7 10NF/50V GND 1 L1 VCC GND 3 GND GND VCC GND PAD2 PAD1 C13 10UF/35V VREG C9 100NF/50V C15 100NF/50V VUSB LD3 GND LD2 LD1 R3 390E VCC R2 390E VCC R1 390E VCC C32 100NF/50V LED1 LED2 GND BLM21A 102SPT AREF PAD3 AREF C14 100NF/50V VCC AVCC A
KEY-E LCD-E EXT-SCK EXT-DATA KEY-E LCD-E R23 1K GND GND 8 EXT-SCK 7 9 15 1 2 10 7 9 15 1 2 10 9 1 2 EXT-DATA VCC Q7 Q7 CE PL CP DS IC9 Q7 Q7 CE PL CP DS IC8 VCC D0 D1 D2 D3 D4 D5 D6 D7 3 4 5 6 10 11 12 13 GND 74HC165 D0 D1 D2 D3 D4 D5 D6 D7 KEY03 KEY06 KEY09 KEY02 GND KEY02 KEY09 KEY06 KEY03 KEY12 KEY05 KEY01 VCC KEY11 KEY04 KEY10 KEY08 KEY07 11 12 13 14 3 4 5 6 KEY08 KEY10 KEY04 KEY11 KEY07 KEY01 KEY05 KEY12 GND 74HC165 D0 D1 D2 D3 D4 D5 D6
4X1 1 2 3 4 X16 0E R11 27E GND XF1 2K2 R19 XF2 33PF/16V C27 28 Q2 6.
49 2.1.6.
Hardware 2.1.7 50 Mega128 Application Board USB The "C-Control Pro Application Board MEGA 128" (Conrad Item no. 198258) provides a USB interface for the program’s loading and debugging. Because of the high data rate of this interface data transmission times are considerably shorter compared to the serial interface. Communication takes place through a USB Controller by FTDI and an AVR Mega8 Controller. The Mega8 provides its own Reset push button (SW5).
51 C-Control Pro IDE An LCD module can be plugged onto the application board. It displays 2 lines at 8 characters each. In general also differently organized displays can be operated through this interface. Each character consists of a monochrome matrix of 5x7 pixels. A flashing cursor below any one of the characters will indicate the current output position. The operating system provides a simple software interface for output on the display.
Hardware 52 I2C Interface Through this interface serial data can be transmitted at high speed. To do this only two signal lines are necessary. Data transmission takes place according to the I2C protocol. To effectively use this interface special functions are provided (see Software Description I2C). I2C SCL I2C SDA I2C Bus Clock Line I2C Bus Data Line PortD.0 PortD.1 Power Supply (POWER, 5 Volt, GND) Power is provided to the application board by means of a 9V/ 250mA Mains Plug-in Power Supply.
53 C-Control Pro IDE Never connect the serial transmission outputs of two devices directly together! Transmission outputs can usually be identified by their negative output voltage in quiescent condition. Testing Interfaces The 4 pole pin strip X16 is to be used for testing purposes only and will not necessarily be armed with components of any kind on every application board. For the user this pin strip is of no importance.
Hardware 54 To deactivate the SRAM the jumper JP7 has to be moved to the left side (orientation: serial interface shows to the left), such that the left pins of JP7 are connected. 2.1.7.2 Jumper Application Board Jumper By use of jumpers certain options can be selected. This applies to several ports which are provided with special functions (see Pin Assignment Table for M128). E. g. the serial interface is realized through Pins PortE.0 and PortE.1.
55 C-Control Pro IDE JP1 and JP2 These jumpers are assigned to push buttons SW1 and SW2. There is the possibility to operate the push button against both GND or VCC. In the basic setting the push buttons are switching to GND. JP4 JP4 serves to toggle the operating voltage (Mains Plug-In Power Supply or USB). The application board should be operated using Plug-In Power Supply and voltage control (Shipping Condition).
Hardware Connection Diagram MOD3 X6 X6A 13 4 14 3 15 2 16 1 MOD4 4 12 5 13 6 14 7 15 8 16 11 7 9 8 PG0 PG1 PG2 PG3 PG4 4 5 6 7 8 3 b0805j GND 4 1 5 2 47k EXT-A2 b0805j 3 3 4 4 BLM21A GND C6 VCC VUSB 100nF C32 b0805j 10nF b0805j 3 GND 4 X5A 1 1 2 2 3 3 4 4 5 5 6 6 7 7 EXT-RXD0 EXT-TXD0 EXT-T1 TX-REQ EXT-T2 EXT-DATA 8 X2 1 1 PA0 PA1 PA2 PA3 PA4 PA5 PA6 PA7 2 3 4 5 6 7 8 2 3 4 5 6 7 8 Project: MEGA128app_V2 PCB-Design: MEGA Appl.
57 C-Control Pro IDE VCC b0805j 390R R9 b0805j 390R R8 b0805j 390R 0R b0805j SIWU LD6 $splname LD4 R27 0R 0R b0805j b0805j 2 GND $splname $splname LD5 4 3 R7 X16 2 1 LL4148 RES_FT R13 sod80 D5 R42 VCC VCC b0805j 22k R18 VCC 7 5 R17 27R b0805j 27 XTIN b0805j Q2 33pF 12 2 EEDATA GND R19 2 17 D6 D7 PB3 PB4 PB5 VCC AREF AGND 21 GND PC0 23 PD1 PC1 24 32 PD2 PC2 25 PD0 1 PD3 2 PC3 26 PD4 9 PD5 PC4 27 PD6 PC5 28 10 11 PD7 D0
Hardware 2.1.7.
59 2.1.8 C-Control Pro IDE Mega32 Projectboard The C-Control Projectboard PRO32 (Conrad Item no. 197287) provides a economic alternative to the application board MEGA32 (Conrad-Order no. 198 245). Compared to the C-Control Pro application board, it's range of functions is significantly limited, and is used mainly for own hardware developments related to the MEGA32 UNIT. The Projectboard includes the most important components needed to operate the MEGA32 UNIT.
Hardware 60 totype area are no longer energized when using USB operation. This supply is used only for test applications, when there is no external power supply available. The appropriate COM port (serial port) must be selected in the C-Control Pro IDE software. Also the programming via USB is made through the serial interface of the C-Control PRO32 UNIT. Prior to that check, when necessary, the Windows device manager, which COM ports are available, or which was installed by the RS232-USB converter.
61 2.1.9 C-Control Pro IDE Mega128 Projectboard The "C-Control PRO 128 Projectboard" (Conrad Item no. 197313) provides a economic alternative to the "Application-Board MEGA128" (Conrad-Order no. 198258). Compared to the C-Control Pro application board, it's range of functions is significantly limited, and is used mainly for own hardware developments related to the "MEGA128 UNIT" and the "MEGA128CAN UNIT".
Hardware 62 Attention! A maximum current of 100mA through USB should not be exceeded! The switch S3 and the power supply pin headers J17/J18 and the pins for Vcc / GND on the prototype area are no longer energized when using USB operation. This supply is used only for test applications, when there is no external power supply available. The appropriate COM port (serial port) must be selected in the C-Control Pro IDE software.
63 C-Control Pro IDE Max continuous current from the stabilized 5V voltage: 100 mA (without cooling) Prototype area: 2.54 mm Range of the permissible ambient temperature: 0 ° C to +70 ° C Admissible relative humidity environment .. 20 - 60% non-condensing Dimensions: 160 x 100 x 23 mm (including "MEGA128 UNIT" or "MEGA128CAN UNIT) 2.2 AVR32Bit 2.2.1 Installation In this chapter the installation of hardware and software of the C-Control Pro AVR32Bit is described.
Hardware 2.2.1.2 64 USB Driver Installation Now connect the Unit with the supplied mini-USB cable to the PC (the cable is enclosed the Applicationboard or Mainboard). The PC is trying to install a driver for a "C-Control Pro AVR32" device. You can find the appropriate driver in the directory USB Driver\ AVR32 USB Driver in the installation directory of the C-Control Pro IDE. If all the connections are made, start the IDE. In the IDE the corresponding COM port (virtual serial port) must be selected.
65 C-Control Pro IDE Now you can already transfer a program to the Unit. The demo programs can be found if you click in the IDE under "Help" on "Demo Programs". 2.2.2 Firmware The operating system of the C-Control Pro consists of the following components: Bootloader Interpreter Bootloader The boot loader is always available. It starts the interpreter or performs an upload when a new version of the interpreter is available.
Hardware 66 The library function ForceBootloader(), as well as a change in the "C-Control Configuration" AVR32Bit Unit options lead to an internal reset, where the Autostart behavior is ignored. This is done on purpose in order to make remote maintenance possible. In this case the user program can also be launched from the IDE, or a pressure on the reset button triggers Autostart again. On delivery, the Autostart jumper is set. Please remove, otherwise no program transfer is possible.
67 2.2.3 C-Control Pro IDE Module The C-Control Pro AVR32Bit UNIT (Conrad Order No.: 192573) is currently the fastest microcontroller unit of the C-Control Pro family (Atmel AT32UC3C1512C). The unit is equipped with a powerful AVR32 32-bit DSP microcontroller with FPU (Floating Point Unit) for the calculation of floating point numbers. This microcontroller has been specially designed for industrial and automotive applications, thus meeting a high standard of performance and reliability.
Hardware Scheme of the AVR32Bit Unit Picture UNIT (view from above) Picture UNIT (view from below) © 2013 Conrad Electronic 68
69 C-Control Pro IDE Jumper: J1: enables Autostart of user application J2: enables CAN 120Ohm terminator Pin layout of the Module Picture UNIT Pinout For a port list, see the chapter Pin Assignment. Power Supply The CON X1 Unit pins 3.3V and GND must be connected to a stabilized supply voltage.
Hardware 70 3.3V and the GND pins are connected to each other! The "POWER" LED indicates that the Unit is receiving power. The C-Control PRO UNIT has no inverse polarity protection, so the UNIT is destroyed by reversed polarity of the power supply! Picture UNIT Power Supply USB Through the mini-USB connector, the C-Control Pro AVR32Bit module is connected to the PC. The USB port is used for programming and debugging of user software. All C-Control Pro UNIT's have a debugger.
71 C-Control Pro IDE If the Autostart Jumper (J1) is inserted, the user program immediately restarts after a reset. On delivery, the Autostart jumper is set. Please remove, otherwise no program transfer is possible. Clock Generation The clock generation of the microcontroller is performed by a 12 MHz quartz crystal. In the controller the 12 MHz are clocked up to 66Mhz with a PLL-oscillator. All timings of the controller, as well as the 48Mhz of the USB subsystem are derived from this clock.
Hardware 72 Since the outputs of the AVR32Bit Unit can not be overly stressed, a small driver stage should always (see picture) be used downstream. In the example an LED is driven, according to consumer a corresponding FET or transistor must be used. This circuit is used for loads up to 100mA. For inductive loads a freewheeling diode must be connected in parallel to the load.
73 C-Control Pro IDE The following reference voltage sources are available: 0,6 * VDDANA internal (0,6 * 3.3V = 1,98V) internal reference voltage of 1V two external reference voltage inputs, e.g. 2.048V generated by reference-voltage-IC If "x" is a digital measurement value, calculate the corresponding voltage value "u" as follows: The resolution depends on the configuration of the ADC.
Hardware 74 Technical Data power supply VCC 3 to 3.6V Nominal 3.3V / >200mA (stabilized) maximum voltage at the pins -0.3V to 3.6V maximum voltage at all pins (sum) 120mA RPULLUP I/O 5 to 26 kOhm RPULLDOWN I/O 2 to 16 kOhm input Low-level voltage I/O 0.3 * VCC input high-level voltage I/O 0.7 * VCC output low-level voltage I/O -3.5 to -14mA dependent on configuration(1) output high-level voltage I/O 3.
75 C-Control Pro IDE output driver strength is programmable with the Port_Attribute() function. 2.2.3.1 Pin Assignment Port A through Port D are for direct pin functions (e. g. Port_WriteBit) counted from 0 through 127, see "PortBit". Pin Assignment for C-Control Pro AVR32Bit Unit and Application Board C-Control C-Control AVR32 Unit Name Module Pin Port Name TQFP 100 GPIO Function1 Function2 P1 X1.09 PA00 1 0 CAN1-TX P2 X1.10 PA01 2 1 CAN1-RX P3 X1.11 PA02 3 2 P4 X1.
Hardware P28 X1.36 PB20 43 52 TIMER0-B P29 X1.37 PB21 44 53 COUNTA-1 P30 X1.38 PB22 45 54 TIMER2-A P31 P32 P33 P34 P35 P36 P37 P38 P39 P40 P41 P42 P43 P44 P45 P46 P47 P48 P49 P50 P51 X1.39 X2.42 X2.41 X2.18 X2.17 X2.40 X2.39 X2.38 X2.37 X2.36 X2.35 X2.34 X2.33 X2.32 X2.31 X2.30 X2.29 X2.28 X2.27 X2.26 X2.
77 C-Control Pro IDE UNIT Pinout Hardwired Pins C-Control Module Pin TQFP 100 AVR32 Port Name X1.05, X1.06 X1.07, X1.
Hardware 39 40 41 53 54 82 83 VDDIN_33 VDDCORE GNDCORE VDDIO2 GNDIO2 VDDIO3 GNDIO 96 97 47 48 PB00 PB01 PB30 PB31 X2.03 X2.02 X2.01 34 35 36 VBUS DM DP X2.43 100 PB03 X2.
79 C-Control Pro IDE X1.46 CAN Driver CAN0_HI X2.07 X2.08 X2.09 X2.10 X2.11 X2.12 X2.13, X2.14 X2.15 PHY PHY PHY PHY PHY PHY PHY PHY LAN_RDLAN_RD+ LAN_TDLAN_TD+ LAN_LED_LNK LAN_LED_ACT +3.
Hardware 2.2.3.
81 C-Control Pro IDE © 2013 Conrad Electronic
Hardware 2.2.4 82 Applicationboard The C-Control PRO AVR32Bit Applicationboard (Conrad Order No.: 192587) is the standard development board for the C-Control PRO AVR32Bit UNIT. The application board contains all the components that are needed to operate the C-Control PRO AVR32Bit UNIT. In addition, the board has a very good and comprehensive peripheral equipment. The board offers the following features: 1x power supply (3.3V & 5V) 1x on/off switch 1x LAN connector (RJ45) 1x 2.
83 C-Control Pro IDE Installation / Commissioning The C-Control PRO AVR32Bit UNIT is attached that the mini-USB socket of the Unit shows in the direction of the on/off switch (see mark on Applicationboard). In base condition, the jumper (JP1 to JP7) for LED1, LED2 and keyboard are not plugged. The power supply of the Applicationboard occurs via a stabilized power supply or a laboratory power supply with an output voltage of 7.5V and a minimum current of 500mA.
Hardware 84 Connection Diagram cutout of I2C-LCD LC-Display contrast control The best visibility of the LCD character arises in frontal view. If necessary, the contrast needs to be adjusted. The contrast can be set with the trimmer R19 ("Contrast" to the left of the LCD screen). UNIT-BUS Pin Configuration I2C and UNIT-Bus The pins on the socket connector Y23 (Block 4) are permanently connected to the pins P34 (SDA) and P35 (SCL).
85 C-Control Pro IDE Exam plel connect LED3 and LED4 to P32 and P33 LED's The pins of the connector strips Y10 (10 pin) are permanently connected to the LED's LED1 to LED8. The LED's are driven via a high impedance FET (about 100K). So that the port can also be used for other purposes, and the LED's signal the port status in addition. The jumpers JP6 and JP7 wire the first two LED's LED1, LED2 to the pins of the UNIT P48 and P49.
Hardware 86 Exam ple connect reference voltage to ADCREF0 CAN Bus At clamp J6 the CAN bus (CAN0) is led out of the UNIT and can be used directly. It must be followed by no driver, since it is a driver already available on the UNIT. Audio Amplifier At the pins on the socket connector Y22 a PWM signal can be connected directly from the UNIT to the audio output. Headphones, small speakers (min. 8 Ohms) or an active speaker can be connected to the jack.
87 C-Control Pro IDE Exam ple connect trim m er to ADC0 and ADC1 w ith external reference voltage 2.048V Keypad For user inputs a 5-button keypad (key cross) is available. The pins on the socket connector Y11 (6 pin) are connected to the switches T1 to T5. Through the jumper JP1 to JP5 the buttons T1 to T5 can be connected directly to the pins of the UNIT (P41 to P45).
Hardware 88 Exam ple connect Relay to P54 FET driver The pins of the socket strip Y15 are connected to the open-drain FET driver. Hereby ohmic consumers (max. 12VDC / 2A) can be controlled directly. The OUTPUT CTRL pins can be connected directly to a port on the UNIT. It can also be used to control PWM signals. At pin header Y18 opendrain outputs are ready for usage. These outputs are connected to the consumers - power supply (+).
89 C-Control Pro IDE Exam ple FET driver w ith load controlled by P53 USB to UART Converter The pins on the socket connector Y5 (4 pin) are connected to the UART to USB converter (Silabs CP2104). At the USB connector (type B) the board is connected to the PC. The converter is used for serial data output from the Unit to the PC. Install the driver first before making a connection. The drivers for the converter module can be found at: http://www.silabs.com/PROducts/mcu/Pages/USBtoUARTBridgeVCPDrivers.
Hardware 90 Exam ple connect USB-UART converter to UART0 RS232 to UART Converter The pins on the socket connector Y6 (4 pin) are connected to the RS232 converter (MAX3232). At the 9-pin SUB-D connector the board is connected to the PC or a RS232 device. The converter is used to convert the 3.3V of the UNIT to the standard level of the RS232 serial interface (+/-12V). Through this interface data can be send data to a PC or a another RS232 device (e.g. meter).
91 C-Control Pro IDE Exam ple connect RS232 to UART0 This product complies with the applicable national and European requirements. The "I2C bus" is a registered trademark of Philips Semiconductors. All other company and product names mentioned are trademarks of their respective owners. All rights reserved.
Hardware © 2013 Conrad Electronic 92
93 2.2.4.
Hardware © 2013 Conrad Electronic 94
95 2.2.5 C-Control Pro IDE Mainboard The C-Control PRO AVR32Bit Mainboard (Conrad Order No.: 192702) is a compact experimental and development board for the C-Control PRO AVR32Bit UNIT. The C-Control PRO AVR32Bit Mainboard contains all the components required for the operation of the C-Control PRO AVR32Bit UNIT. In addition, the board has a good basic set of peripherals.
Hardware 96 The board offers the following features: 1x 1x 1x 1x 2x 1x 1x 1x 2x 1x power supply (3.3V & 5V) LAN connector (RJ45) 2.048V external reference voltage signal generator (Buzzer) CAN connector LCD-PORT for connection to the I2C LCD's (Conrad Order No.: 192602) I2C-BUS connector 1-Wire connector I/O-PORT with 26 pins UNIT-Bus (3.
97 C-Control Pro IDE UNIT-BUS Pin Configuration Reference Voltage The jumper JP3 connects the external 2.048V reference voltage to the ADCREF0 (P8) pin of the UNIT. CAN Bus At the clamp with the marking "CAN" the CAN bus (CAN0) is led out of the UNIT and can be used directly. It must be followed by no driver, since it is a driver already available on the UNIT. On the socket connector J10 the second CAN bus (CAN1) is led out. This does not have a CAN driver and can be used as a normal input/output.
Hardware Matching connection cable pre-assembled (length 35cm) 98 Order No. 198876 1-WIRE At the screw clamp labeled "1WIRE" the pin P3 of the UNIT is led out. At this pin a 1-WIRE sensor such as a temperature sensor (Conrad Order No. 198284) can be connected. This pin can also be used as a normal digital input/output. PORT-1, PORT-2 At the 26-pin pin header connectors labeled "PORT 1" and "PORT 2" the free pins are brought out of the AVR32Bit UNIT. Here, the experiment board (Conrad Order No.
99 C-Control Pro IDE 3x Jumper Quick Guide © 2013 Conrad Electronic
Hardware 2.2.5.
101 2.2.6 C-Control Pro IDE UNIT-BUS Exp. Board The C-Control PRO AVR32Bit UNIT BUS Exp. Board (Conrad Order No.: 192659) is designed to expand the functionality of the C-Control PRO AVR32Bit products. The product is designed as an open circuit board with six single 6-pin pin header sockets, and only determined for the UNIT-BUS of the C-Control PRO AVR32Bit and the C-Control I product family (extensions) and their sockets. The control of the individual modules is done via software.
Hardware 2.2.6.
103 2.2.7 C-Control Pro IDE LCD1602 Board The C-Control PRO AVR32Bit LCD1602 board (Conrad Order No. 192602) is designed to expand the functionality of the C-Control PRO AVR32Bit products. The product is configured as open circuit board. The module is equipped with a two-line 16 character LCD display with backlight and a 6-pin header connector, and is only determined for the C-Control PRO AVR32Bit Mainboard (Conrad Order No. 192702) .
Hardware 104 PCB Rear View Is the base address of the LCD used (equal to the application board), the jumper must be removed on the LCD board. See also LCD_SetDispAddr. LCD Port Connectors The Mainboard is connected to the LCD1602 Board via a 6-pin ribbon cable with pin header connector (female). Since the cable may vary according to the application, we offer these components for self-assembly using the following order numbers: Ribbon cable RM1.27 0.05mm²: Pin header connectors 2x3 RM:2.
105 C-Control Pro IDE The I2C address jumpers JP1 and JP3 are located on the back of the LCD1602 module. With the use of multiple LCD modules (max. 8), the jumper must be set according to the desired address as follows (Jumper JP1 = points to IC): JP3 JP2 JP1 address - - - Hex 27 - - x Hex 26 - x - Hex 25 - x x Hex 24 x - - Hex 23 x - x Hex 22 x x - Hex 21 x Hex 20 x x x=Jumper set / - = not set Attention: Other I2C bus modules use the same I2C expander chips (PCA8574).
Hardware current consumption with backlight 13mA weight 55g © 2013 Conrad Electronic 106
107 2.2.7.
Hardware 2.2.8 108 Port-Ext-Board The Port-Ext-Board (Conrad Order No. 192615) is constructed to expand the functionality of the CControl PRO AVR32Bit Mainboard (Conrad Order No. 192702). The product is designed as an open breadboard experimental circuit board with a pitch of 2.54mm. It is equipped with two single 26-pin header connectors and suitable only for the port outputs (PORT-1/PORT-2). The board serves to build your own circuits in conjunction with the C-Control PRO AVR32Bit Mainboard.
109 C-Control Pro IDE Port-Extension-Board Overview © 2013 Conrad Electronic
Hardware CAD Technical Data: dimensions 110mm x 90mm x 13mm (LxWxH) pin header pitch 2.54mm breadboard pitch 2.
111 2.2.9 C-Control Pro IDE REL4-Board The C-Control PRO AVR32Bit REL4 Board (Conrad Order No. 192631) is designed to expand the functionality of the C-Control PRO AVR32Bit products. The product is configured as open circuit board. The board is equipped with 4 relays for switching loads, and is intended only for C-Control PRO products.
Hardware 112 exceed 2m, since this will cause communication errors. However, when longer lines are needed, it is helpful to put an I2C power driver (Order No. 198280) in-between. The RELBUS-Board is supplied by the screw clamp "VREL" with power. The UNIT-BUS is used in this module only as a communication interface, and for the supply of the digital electronic part of the circuit.
113 C-Control Pro IDE x x x x=Jumper set / - = not set x x x x Hex 22 Hex 21 Hex 20 Attention: Other I2C bus modules use the same I2C expander chips (PCA8574). Therefore the maximum number of modules with this IC is limited to 8! CAD Info: The REL4-Board can be mounted on a DIN rail by Phoenix Contact DIN rail carrier of the series "UMK". Technical Data dimensions 76mm x 72mm x 18mm (LxWxH) pin header pitch 2.54mm relay NC/NO, max.
Hardware operating voltage 12V current consumption 120mA weight 70g © 2013 Conrad Electronic 114
115 2.2.9.
Hardware 116 2.2.10 RELBUS-Board The C-Control PRO AVR32Bit RELBUS-Board (Conrad Order No. 192645) is designed to expand the functionality of the C-Control PRO AVR32Bit products. The product is configured as open circuit board. It is equipped with 8 open source switching stages (high-side switch) to switch 8 consumers with small loads such as relay and intended only for the C-Control PRO UNIT-BUS.
117 C-Control Pro IDE RELBUS-Board overview The RELBUS-Board has two UNIT-BUS connections that are mutually connected 1:1. Thus, e.g., one of the connectors can be plugged to the Applicationboard or Mainboard, and the second port can be used as a junction that connects to another UNIT-BUS module. The cable length must not exceed 2m, since this will cause communication errors. However, when longer lines are needed, it is helpful to put an I2C power driver (Order No. 198280) in-between.
Hardware 118 Beispiel Verbraucheranschluss an Ausgang Q1 Attention: Other I2C bus modules use the same I2C expander chips (PCA8574). Therefore the maximum number of modules with this IC is limited to 8! Addressing: The I2C address jumpers J1 to J3 are located on the front of the RELBUS-Board.
119 C-Control Pro IDE x x x=Jumper set / - = not set x Hex 20 CAD Info: The RELBUS-Board can be mounted on a DIN rail by Phoenix Contact DIN rail carrier of the series "UMK". Attention: The outputs are not short-circuit proof and can be destroyed in a short to ground! Technical Data dimensions 42mm x 72mm x 22mm (LxWxH) pin header pitch 2.54 mm output implementation open-source (high-side switch) output load max.
Hardware 2.2.10.
121 C-Control Pro IDE 2.2.11 UNIT-BUS Ext-Board The C-Control PRO AVR32Bit UNIT BUS Ext board (Conrad Order No. 192673) is designed to expand the functionality of the C-Control PRO AVR32Bit products. The product is designed as an open breadboard experimental circuit board with a pitch of 2.54mm. It is equipped with two 6-pin header connectors and is intended only for the C-Control UNIT-BUS. The board serves to build your own circuits.
Hardware 122 Tip: The pin header connectors can be easily pressed together with a small vise. Cut the cable to proper length and straight it in the plug (guide grooves in the plug), and then clamp between the two vise jaws, and turn it carefully until the connector clicks into place.
123 C-Control Pro IDE CAD Technical Data: dimensions 110mm x 90mm x 13mm (LxWxH) pin header pitch 2.54mm hole grid pitch (PCB) 2.
Hardware 124 2.2.12 USB-Board The C-Control PRO AVR32Bit USB-Board (Conrad Order No. 192688) is designed to expand the functionality of the C-Control PRO AVR32Bit products. The product is configured as open circuit board. It is equipped with a USB Type-B connector and a 3-pin header connector (pitch: 2.54mm) for connection to a 3.3V UART interface of the C-Control PRO AVR32Bit.
125 C-Control Pro IDE CAD Technical Data: dimensions 23mm x 25mm x 12mm (LxWxH) UART pin pitch 2.54mm USB Type-B operating voltage powered by USB port UART level 3.
Hardware 2.2.12.
127 2.3 C-Control Pro IDE LCD Matrix The complete datasheets are on the CD-ROM in the directory "Datasheets". CHARACTER MODULE FONT TABLE (Standard font) Character modules with built in controllers and Character Generator (CG) ROM & RAM will display 96 ASCII and special characters in a dot matrix format. Then first 16 locations are occupied by the character generator RAM. These locations can be loaded with the user designed symbols and then displayed along with the characters stored in the CG ROM.
Part 3
129 3 C-Control Pro IDE IDE The C-Control Pro User Interface (IDE) consists of the following main elements: Sidebar for Project Files Editor Window Compiler Messages C-Control Outputs Variables Window Here several files can be filed to form a project In order to edit files as many editor windows as necessary can be opened.
IDE 3.1 130 Projects Every program for the C-Control Pro Module is configured through a project. The project states which source files and libraries are being utilized. Also the settings of the Compiler are noted. A project consists of the project file with the extension ".cprj" and the appropriate source files. 3.1.1 Create Projects In the menu Project the dialog box Create Project can be opened by use of item New. Here a project name is issued for the project.
131 C-Control Pro IDE In menu Project the current project can be translated by the Compiler by use of Compile (F9). The Compiler messages are displayed in a separate window section. If errors arise during compilation then one error will be described per line. The form is: File Name(Line,Column): Error Description The error positions can be found in the source text by use of commands Next Error (F11) or Previous Error (Shift-F11). Both commands are found in menu item Project.
IDE 132 Project Files When files have been added to the project these can be opened by a double mouse click onto the file name. By use of a right click further options will appear: Up – The project file will move up the list (also with Ctrl - Arrow up). Down – The project file will move down (also with Ctrl - Arrow down). Rename – The name of the project file will be changed. Delete – The file will be deleted from the project. Options – The project options can be changed.
133 3.1.4 C-Control Pro IDE Project Options For each project the compiler settings can be changed separately. The items Author, Version, Commentary can be freely inscribed. They serve as memory support in order to better remember the project details at a later date. In "CPU" the target platform of the project is determined. Configure Libraries calls the Library Management.
IDE 134 Create Debug Code Creates Debug Code. If Debug Code is compiled the Byte Code becomes insignificantly longer. For each line in the source text which contains executable commands the Byte Code will be one Byte longer. Create Map File Generates a map file that shows the address and length of variables. Check Array Index Limits Code will be inserted code that checks the index of array accesses. Use only for testing, since the runtime is increased.
135 C-Control Pro IDE Only those files will be used for compilation whose CheckBox has been selected. The list can be altered by use of the path text input field "Library Name" and the buttons in the dialog: Add – The path will be added to the list. Replace – The selected entry in the list is replaced by the path name. Delete – The selected list entry is deleted. Update Library – Files present in the Compiler Presetting but not in this list will be added. 3.1.6 Thread Options Since version 2.
IDE 3.1.7 136 Todo Liste On the Project menu a simple todo list can be called. The content is stored together with the project. 3.2 Editor Several windows can be opened in the C-Control Pro Interface. Each window can be altered in size and displayed text detail. A double mouse click on the title line will maximize the window.
137 C-Control Pro IDE A mouse click in the area to the left of the text will there set a Breakpoint. Prior to this the source text must be compiled error free with "Debug Info" and in the corresponding line really executable program text must be placed (i. e. no commentary line o. e.). Functions Overview On the left side is an overview of all syntactically correct defined functions. The function names with parameters are expressed in this view.
IDE 138 Code Folding To maintain a good overview over the source code, the code can be folded. After the syntactical analyzer, that is built into the editor, recognizes a defined function, beams are drawn on the left side along the range of the function. A click on the minus sign in the small box folds the text, so that only the first line of the function can be seen. Another click on the small plus sign, and the code unfolds again.
139 C-Control Pro IDE Parameter Input Help Nach einer erfolgreichen Kompilierung werden auch die Parameter einer Function analysiert. Tippt man einen bekannten Funktionsnamen und Klammer auf "(", so wird in gelb die erwarteten Typen der Funktionsparameter angezeigt. After a successful compilation, the parameters of all function are analyzed. If you tap a known function name and a parenthesis "(", the expected types of the function parameters displayed in yellow. 3.2.
IDE 140 Search/Restore Dialog Text to find – Input field for the text to be searched for. Replace with – Text that will replace the text found. Case Sensitive – makes the distinction between upper and lower case writing. Whole words only – will find only whole words rather than part character chains. Regular expressions – activates the input of Regular Expressions in the search mask. Prompt on replace – prior to replacing the user will be asked for approval.
141 C-Control Pro IDE Print: Print Preview: Printer Setup: Page Setup: 3.2.
IDE Shift + Right Shift + Up Shift + Down Shift + Ctrl + Left Shift + Ctrl + Right Shift + PgUp Shift + PgDn Shift + Ctrl + PgUp Shift + Ctrl + PgDn Shift + Ctrl + Home Shift + Ctrl + End Shift + Home Shift + End Alt + Shift + Left Alt + Shift + Right Alt + Shift + Up Alt + Shift + Down Alt + Shift + Ctrl + Left Alt + Shift + Ctrl + Right Alt + Shift + PgUp Alt + Shift + PgDn Alt + Shift + Ctrl + PgUp Alt + Shift + Ctrl + Alt + PgDn Alt + Shift + Ctrl + Home Alt + Shift + Ctrl + End Alt + Shift + Home Alt +
143 C-Control Pro IDE Ctrl + K + B Ctrl + K + K Esc Ctrl + digit (0-9) Shift + Ctrl + (0-9) Ctrl + Space 3.2.4 Marks the beginning of a block Marks the end of a block Reset selection Go to Bookmark digit (0-9) Set Bookmark digit (0-9) Auto completion popup Regular Expressions The search function in the editor supports Regular Expressions. With this function character chains can highly flexible be searched for and replaced. ^ $ .
IDE 3.3 144 C-Control Hardware Under menu item C-Control all hardware relevant functions can be executed. These include transfer and start of the program on the hardware as well as password functions. 3.3.1 Interface Selection In the toolbar the COM interface that addresses the C-Control Pro module can be directly selected in a drop-down menu. In this list all interfaces are labeled COM, regardless of whether it really is a serial port or a USBconnected virtual comport.
145 3.3.2 C-Control Pro IDE Start Program Program Transfer After a project has been translated free of errors the Bytecode must first be transferred onto the CControl Pro module before it can be executed. This is done by use of the command Transfer (ShiftF9) in menu C-Control. After an update of the IDE, if necessary, not just the bytecode is transferred to the module, but also the latest version of the interpreter is sent to the C-Control module.
IDE 146 You can enter the current network settings, the UDP port of the bootloader and the MAC address. To avoid connection problems, the MAC address should be set to a new value before switching on the Ethernet support. To this end, its own MAC address is generated and supplied on a label for each C-Control Pro AVR32Bit. See Software Installation. Options Ethernet Support - Switches on Ethernet support. Allow Ping - ICMP echo requests are answered.
147 C-Control Pro IDE Currently, the Ethernet support is limited to program update. 3.3.5 Outputs For display of Debug messages there is an "Outputs" window section. Here is shown when the Bytecode Interpreter has been started and terminated and for how long (in milliseconds) the Interpreter was in operation. The operation time however is not very useful if the Interpreter has been stopped during Debug Mode. The Outputs window can also be used to display the user’s own Debug messages.
IDE 148 several Debug Functions. With a right mouse click in the Debug Outputs section the following commands can be selected: Delete – will delete the list of Debug outputs Copy to Clipboard – will copy all text messages onto the clipboard 3.3.6 PIN Functions Some solitary functions of the Interpreter can be protected by use of an alpha-numeric PIN. If an Interpreter is protected by a PIN normal operations are prohibited.
149 3.4 C-Control Pro IDE Debugger In order to activate the Debugger the project must first be compiled in Debug Code free of errors and then transferred to the Module. The file holding the Debug Code (*.dbg) must be present in the project list. In the Debugger menu all Debugger commands can be found. The Debugger ist started with Debug Mode (Shift-F10). If at this point of time no Breakpoint is set then the Debugger will stop at the first executable instruction.
IDE 3.4.1 150 Breakpoints The editor allows to set up to 16 Breakpoints. A Breakpoint is entered by a mouse click to the left of the beginning of a line (see IDE or Editor Window). The number of Breakpoints is limited to 16 because this information is carried along in RAM during operation of the Bytecode Interpreter. Other Debuggers on the Market will set Breakpoints directly into the program code.
151 C-Control Pro IDE In order to enter a variable into the list of monitored variables there are two possibilities. For one the cursor can be placed in the text editor at the beginning of a variable and then Insert Variable can be selected by a right mouse click. The other possibility is by use of the context menu in the variables list which can also be activated by a right mouse click. When Insert Variable is selected then the variable to be monitored can as text be entered into the list.
IDE 152 Under certain circumstances an error message is shown instead of a value in the list: no Debug Code wrong Syntax Function unknown Variable unknown not in Debug Mode no Context not actual No Debug Code has been generated During text entry invalid characters have been entered for a variable The Function Name is not known The Variable Name is not known The Debug Mode has not been activated Local variables can only be displayed while within this function The content of the variable has not been updat
153 C-Control Pro IDE The contents of an array window may at every stop of the Debugger or at every single step no longer be actual. If with each single step in the Debugger several array windows are newly brought up-todate then delays may occur since the data must always be loaded from the Module. For this reason there are three operating modes: Auto Actualize Actualize at Breakpoint Manually Actualize 3.
IDE 154 Terminal Window Received characters are directly shown in the terminal window. Characters can be send in two different ways. On the one hand the user can click into the terminal window and directly type the characters from the keyboard, on the other hand the text can be entered in to the ASCII input line and send with the Send button. Instead of ASCII the characters can be defined as integer values in the Integer input line.
155 C-Control Pro IDE You can change the attributes of the font, and the foreground- and background color. With Multiline border a colored border can be drawn around the highlighted strings. Also case changes can be made with the option Capitalization Effect.
IDE 156 Default, Line separator and Sub background are not used. Due to technical limitations, this dialog is always displayed in English! 3.5.2 Editor Settings Overwrite mode – Inserts text at the cursor overwriting existing text. Auto indent mode - Positions the cursor under the first non blank character of the preceding non blank line when you press Enter.
157 C-Control Pro IDE only the selected word is highlighted. Fixed line height - Prevents line height calculation. Line height will be calculated by means of Default Style. Persistent blocks - Keeps marked blocks selected even when the cursor is moved using the arrow keys, until a new block is selected. Overwrite blocks - Replaces a marked block of text with whatever is typed next. If Persistent Blocks is also selected, text you enter is appended following the currently selected block.
IDE 3.5.3 158 IDE Settings Separate aspects of the IDE can be configured. check for Transfer after Compilation – After a program has been compiled but not transferred to the C-Control Module then the user will be questioned whether or not the program should be started. Reopen last Project – The last open project will be re-opened when the C-Control Pro IDE is started. show Splash only for short time - The Splashscreen is only displayed until the main window opens.
159 3.5.3.1 C-Control Pro IDE Editor Editor Tabs - Different files are displayed in Editor Tabs. Multiline Editor Tabs - The Tabs are displayed as multiple-rows. open editor windows maximized – When a file is opened the editor window will automatically be switched to maximum size. spell check comments - The comments within the editor are checked for spelling errors. automatic correct reserved words - While writing all reserved words and known library functions the case is corrected.
IDE 3.5.3.2 160 Internet Update In order to check if any improvements or error corrections have been issued by Conrad Electronic the Internet Update can be activated. When the selection box "Update Check Every n Days" is selected then an update will be searched for in the Internet at an interval of n days at every start of the IDE. The parameter n can be set in the input field on the right. The button "Update Check Now" will immediately activate an update search.
161 3.5.3.3 C-Control Pro IDE Compiler Presetting In the Compiler Presetting the standard values can be configured which will be stored during creation of a new project. Presetting can be reached under Compiler in the Options menu. A description of the options can be found under Project Options. The selection box "Configure Library" is identical to the description in chapter Projects. 3.5.3.4 Terminal Here you can set the serial parameter for the built in terminal program.
IDE 3.5.3.5 162 Tools In the Tool settings the user can insert, delete and edit entries that defines external programs that can be executed fast and simple from the IDE. The names of the programs can be found in the Tools pulldown menu and can be started with a single click .
163 C-Control Pro IDE For each program that is inserted, the user can choose the name, the execution path and the parameters that are submitted. 3.6 Windows When there are several windows opened within the editor area they can automatically be arranged by use of commands in the Window Menu. Overlap – The windows will be arranged on top of each other with each successive window placed fractionally lower and more to the right than the preceding one.
IDE 3.7 164 Help Under menu item Help the Help file can be opened by use of Contents (Key F1). Menu item Program Version will open the window "Version Information" and will at the same time copy the contents onto the clipboard. These informations are important if a Support E-Mail needs to be sent to Conrad Electronic. Since these informations are automatically placed onto the clipboard when Program Version is called up the data can easily be added to the end of an E-Mail.
165 C-Control Pro IDE The command Context Help is also available in the editor window after a right mouse click.
Part 4
167 C-Control Pro IDE 4 Compiler 4.1 General Features This domain provides information on the Compiler’s properties and features which are independent of the programming language used. 4.1.1 Preprocessor The Gnu Generic Preprocessor used here provides some additional functions which are documented under http://nothingisreal.com/gpp/gpp.html. Only the functions described here however have also together with the C-Control Pro Compiler been thoroughly tested.
Compiler 168 If there is an optional #else instruction then the source text will be processed after #else if the symbol has not been defined. Insertion of Text #include path\file name By this instruction a text file can be inserted into the source code. Because of some restrictions in the Preprocessor a path within a #include instruction must not contain any blank characters! 4.1.1.
169 C-Control Pro IDE txt=__LINE__; Msg_WriteText(txt); Msg_WriteChar(13); txt=__FILE__; Msg_WriteText(txt); Msg_WriteChar(13); txt=__FUNCTION__; Msg_WriteText(txt); Msg_WriteChar(13); 4.1.2 // Issue Line Number // LF // Issue File Number // LF // Issue Function Name // LF Pragma Instructions By use of the #pragma instruction output and flow of the Compiler can be controlled. The following commands are authorized: #pragma Error "xyz..." #pragma Warning "xyz..." #pragma Message "xyz...
Compiler 170 Total Length: 4 bytes Function main() count n Total Length: 4 bytes 2 2 2 0 From this list can be seen that no global variables are being used. There are further the two functions "Pulse()" and "main()". Each one of these functions consumes a memory space of 4 Bytes on local variables. 4.2 CompactC One possibility to program the C-Control Pro Mega 32 or Mega 128 is offered by the programming language CompactC.
171 4.2.2 C-Control Pro IDE Instructions Instruction An instruction consists of several reserved command words, identifiers and operators and is at the end terminated by a semicolon (';'). In order to separate various elements of an instruction there are spaces in between the instruction elements which are called "Whitespaces". By “spaces“ space characters, tabulators and line feeds ("C/R and LF") are meant. It is of no consequence whether a space is built by one or several "Whitespaces".
Compiler 172 Identifier Identifier are the names of Functions or Variables . Valid characters are letters (A-Z,a-z), numbers (0-9) and the low dash ('_') An identifier always starts with a letter Upper and lower case writings are differentiated Reserved Words are not allowed as identifier The length of identifiers is unlimited Arithmetic Expressions An arithmetic expression is a quantity of values connected by Operators. In this case quantities can either be Figures, Variables and Functions .
173 C-Control Pro IDE In some cases expressions must be constant in order to be valid. E. g. also see Declaration of Array Variables . 4.2.3 Data Types Values always are of a certain data type. Integer values (integral values; whole numbered values) in CompactC are of the 8, 16 or 32 Bit wide data type, floating point values are always 4 byte long.
Compiler 174 tion is executed "signed". If one of the operands is of the float type then the result is also of the float type. If one of the two operands happens to be of the 8 Bit or 16 Bit data type then it will be converted into a float data type prior to the operation. 4.2.4 Variables Variables can take on various values depending on the Data Type by which they have been defined.
175 C-Control Pro IDE Floating Point Figures (data type float) may contain a decimal point and an exponent. float x,y; x=5.70; y=2.3e+2; x=-5.33e-1; sizeof Operator By the operator sizeof() the number of Bytes a variable takes up in memory can be determined. Examples: int s; float f: s=sizeof(f); // the value of s is 4 With arrays only the Byte length of the basic data type is returned. On order to calculate the memory consumption of the array the value must be multiplied by the number of elements.
Compiler 176 byte glob[10] = {1,2,3,4,5,6,7,8,9,10}; flash byte fglob[2][2]={10,11,12,13}; void main(void) { byte loc[5]= {2,3,4,5,6}; byte xloc[2][2]; xloc= fglob; } Because there is more flash memory than RAM available, it is possible with the flash keyword to define data that are written in the flash memory only. These data can be copied to a RAM array with same dimensions with an assignment operation. In this example this is done through "xloc= fglob".
177 C-Control Pro IDE Sequence Char/Value \\ \' \a \b \t \n \v \f \r \ ' 7 8 9 10 11 12 13 Strings cannot be assigned to multi dimensional Char arrays. There are however tricks for advanced users: char str_array[3][40]; char single_str[40]; single_str="A String"; // will copy single_str in the second string of str_array Str_StrCopy(str_array,single_str,40); This will work because with a gap of 40 characters after the first string there will in str_array be room for the second string.
Compiler 178 // x,y not accessable since local to function func1 } Global variables have a defined memory space which is available throughout the entire program run. At program start the global variables will be initialized by zero. Local Variables get not initialized at the begin of a function! Local variables will during calculation of a function be arranged on the stack. I. e. local variables exist in memory only during the time period in which the function is executed.
179 4.2.5.1 C-Control Pro IDE Arithmetic Operators All arithmetic operators with the exception of Modulo are defined for Integer and Floating Point data types. Modulo is restricted to data type Integer only. It must be observed that in an expression the figure 7 will have an Integer data type assigned to it. If a figure of data type float should be explicitly created then a decimal point has to be added: 7.
Compiler 16 >> 2 4.2.5.4 180 4 In- /Decrement Operators Incremental and decremental operators are only allowed for variables with Integer data types.
181 C-Control Pro IDE && 4.2.6 logical And || logical Or ! logical Not 1 && 1 5 && 0 0 || 0 1 || 0 !2 !0 1 0 0 1 0 1 Control Structures Control structures allow to change the program completion depending on expressions, variables or external influences. 4.2.6.1 Conditional Valuation With a conditional valuation expressions can be generated which will be conditionally calculated.
Compiler 182 { a=a*2; x=a; } while(a); The essential difference between the do .. while loop and the normal while loop is the fact that in a do .. while loop the instruction is executed at least once. break Instruction A break instruction will leave the loop and the program execution will start with the next instruction after the do .. while loop. continue Instruction When executing continue within a loop there will immediately be a new calculation of the Expression.
183 C-Control Pro IDE If a loop needs to be programmed with a different step width Instruction2 needs to be modified accordingly: for(i=0;i<100;i=i+3) { a=5*i; } // variable i does now increment in steps to 3 break Instruction A break instruction will leave the loop and the program execution starts with the next instruction after the for loop. continue Instruction continue will immediately initialize a new calculation of the Expression.
Compiler 4.2.6.5 184 if .. else An if instruction does have the following syntax: if( Expression ) Instruction1; else Instruction2; After the if instruction an Arithmetic Expression will follow in parenthesis. If this Expression is evaluated as unequal 0 then Instruction1 will be executed. By use of the command word else an alternative Instruction2 can be defined which will be executed when the Expression has been calculated as 0. The addition of an else instruction is optional and is not necessary.
185 C-Control Pro IDE case constant_2: Instruction_2; break; . . case constant_n: Instruction_n; break; default: // default is optional Instruction_0; }; The value of the Expression is calculated. Then the program execution will jump to the constant corresponding to the value of the Expression and will continue the program from there. If no constant corresponds to the value of the expression the switch construct will be left.
Compiler case 2: a++; 186 // is also executed at a value of a==1 case 3: a++; // is also executed at a value of a==1 or a==2 } In this example all three "a++" instructions are executed if a equals 1. 4.2.6.7 while With a while instruction the instructions can depending on a condition be repeated in a loop. while( Expression ) Instruction; At first the Expression is evaluated. If the result is unequal 0 then the Expression is executed.
187 4.2.7 C-Control Pro IDE Functions In order to structure a larger program it is separated into several sub-functions. This not only improves the readability but allows to combine all program instructions repeatedly appearing in functions. A program does in any case contain the function "main", which is started in first place. After that other functions can be called up. A simple example: void func1(void) { // instructions in function func1 . .
Compiler 188 } When calling up a function all parameters must always be stated. The following call up is inadmissible: func1(); func1(128); // func1 gets 2 parameters! // func1 gets 2 parameters! Return Parameters It is not only possible to pass parameters. A function can also offer a return value. The data type of this value is during function definition entered ahead of the function name. If no value needs to be returned the data type used will be void.
189 C-Control Pro IDE is only the reference (pointer) to the array variable text. Presently arrays can only be passed "by Reference"! Pointer Arithmetic In the current C-Control Pro software also arithmetic on a reference (pointer) is permitted, as the following example shows. The arithmetic is limited to addition, subtraction, multiplication and division.
Compiler 10 9 8 7 6 5 4 3 2 1 4.2.8.
191 C-Control Pro IDE ! logisches Nicht Bitoperatoren & | ^ ~ 4.2.8.
Compiler 4.3 192 BASIC The second programming language for the C-Control Pro Mega Module is BASIC. The Compiler translates the BASIC commands into a Bytecode which is then processed by the C-Control Pro Interpreter. The language volume of the BASIC dialect used here corresponds to a large extent to the industry standard of the large software suppliers.
193 4.3.2 C-Control Pro IDE Instructions Instruction An instruction consists of several reserved command words, identifiers and operators and is at the end terminated by the end of the line. In order to separate various elements of an instruction there are spaces in between the instruction elements which are called "Whitespaces". By “spaces“ space characters, tabulators and line feeds ("C/R and LF") are meant. It is of no consequence whether a space is built by one or several "Whitespaces".
Compiler 194 Arithmetic Expressions An arithmetic expression is a quantity of values connected by Operators. In this case quantities can either be Figures, Variables or Functions . A simple example: 2 + 3 Here the numerical values 2 and 3 are connected by the Operator "+". An arithmetic value again represents a value. In this case the value is 5. Further examples: a - 3 b + f(5) 2 + 3 * 6 Following the rule "Dot before Line" here 3 times 6 is calculated first and then 2 is added.
195 C-Control Pro IDE Data Type Char Byte Integer UInteger Word Long (no Mega32) ULong (no Mega32) Single Sign Range Bit Yes No Yes No No Yes -128 ... +127 0 ... 255 -32768 ... +32767 0 ... 65535 0 ... 65535 -2147483648 ... 2147483647 8 8 16 16 16 32 No 0 ... 4294967295 32 Yes ±1.175e-38 to ±3.402e38 32 Due to size restrictions of the interpreter, 32-Bit Integer are not available on the Mega32. Strings There is no explicit "String" data type. A string is based on a character array.
Compiler 196 Dim Name1, Name2, Name3 As Integer As types are allowed: Char, Byte, Integer, Word, Single Examples: Dim a As Integer Dim i,j As Integer Dim xyz As Single Integer variables may have decimal figure values or Hex values assigned to. With Hex values the characters "&H" will be placed ahead of the figure. Just as with CompactC it is also allowed to place the prefix "0x" ahead of the Hex values. Binary numbers can be created with the prefix "0B".
197 C-Control Pro IDE Dim f As Single s=SizeOf(f) ' the value of s is 4 With arrays only the Byte length of the basic data type is returned. On order to calculate the memory consumption of the array the value must be multiplied by the number of elements. Array Variables If behind the name, which in case of a variable definition is set in parenthesis, a figure value is written then an array has been defined. An array will arrange the space for a defined variable manifold in memory.
Compiler 198 Direct Access to flash Array entries With version 2.12 it is possible to access single entries in flash arrays: Flash glob(10) = {1,2,3,4,5,6,7,8,9,10} As Byte Sub main() Dim a As Byte a= glob(2) End Sub There is still one limitation: Only references to arrays that lie in RAM can be passed as function parameters. This is not possible with references to flash arrays. Strings There is no explicit "String" data type. A string is based on an array of data type Char.
199 C-Control Pro IDE Dim str_array(3,40) As Char Dim Single_str(40) As Char Single_str="A String" ' will copy Single_str in the second string of str_array Str_StrCopy(str_array,Single_str,40) This will work because with a gap of 40 characters after the first string there will in str_array be room for the second string. Visibility of Variables When variables are declared outside of functions then they will have global visibility. I. e. they can be addressed from every function.
Compiler 200 Sub func1() Static a As Integer End Sub In opposition to normal local variables will static variables still keep their value even if the function is left. At a further call-up of the function the static variable will have the same contents as when leaving the function. In order to have the contents of a Static variable defined at first access the static variables will equally to global variables at program start also be initialized by zero. 4.3.
201 C-Control Pro IDE - 4.3.5.2 Negative Sign -(2+2) -4 Example Result &H0f And 3 &Hf0 And &H0f 1 Or 3 &Hf0 Or &H0f &Hff Xor &H0f &Hf0 Xor &H0f Not &Hff Not &Hf0 3 0 3 &Hff &Hf0 &Hff 0 &H0f Bitoperators Bit operators are only allowed for Integer data types Operator And Description And Or Or Xor exclusive Or Not Bit inversion All these Operators work arithmetically: E.g. Not &H01 = &Hfe. Both values are evaluated to true in an If expression.
Compiler Operator Description variable++ first variable value, after access variable gets incremented by one (postincrement) first variable value, after access variable gets decremented by one (postdecrement) value of the variable gets incremented by one before access (preincrement) value of the variable gets decremented by one before access (predecrement) variable-++variable --variable 202 Example Result a++ a a-- a ++a a+1 --a a-1 These operators are normally not a part of a Basic dialect
203 C-Control Pro IDE Do Instructions Loop While Expression The instructions are being executed. At the end the Expression is evaluated. If the result is unequal 0 then the execution of the expression will be repeated. The entire procedure will constantly be repeated until the Expression takes on the value 0.
Compiler 204 Do While a<10 a=a+2 End While Do While a a=a*2 x=a End While Exit Instruction If an Exit instruction is executed within a loop than the loop will be left and the program execution starts with the next instruction after the While loop. Example: Do While 1 ' Endless loop a=a+1 If a>10 Then Exit ' Will terminate loop End If End While 4.3.6.3 For Next A For Next loop is normally used to program a definite number of loop runs.
205 C-Control Pro IDE For i=1 To 10 Step 3 If i>3 Then a=i End If a=a-1 Next 'Increment i in steps of 3 In this location please note again that arrays are in any case zero based. A For Next loop should thus rather run from 0 through 9. Exit Instruction An Exit instruction will leave the loop and the program execution starts with the next instruction after the For loop. Example: For i=1 To 10 If i=6 Then Exit End If Next 4.3.6.
Compiler 206 Instructions2 Else Instructions3 End If After the if instruction an Arithmetic Expression will follow. If this Expression is evaluated as unequal 0 then Instruction1 will be executed. By use of the command word else an alternative Instruction2 can be defined which will be executed when the Expression has been calculated as 0. The addition of an else instruction is optional and not really necessary.
207 C-Control Pro IDE End Case The value of the Expression is calculated. Then the program execution will jump to the first constant comparison that can be evaluated as true and will continue the program from there. If no constant comparison can be fulfilled the Select Case construct will be left. For constant comparisons special comparisons and ranges can be defined .
Compiler 208 Case >= 100 b=14 Case <> 25 b=15 Else b=b+2 End Case In CompactC the instructions will be continued after a Case instruction until a break comes up or the switch instruction is left. With BASIC this is different: Here the execution of the commands will break off after a Case, if the next Case instruction is reached. 4.3.7 Functions In order to structure a larger program it is separated into several sub-functions.
209 C-Control Pro IDE Sub main() Dim a As Word Dim f As Single func1(128,12.0) ' you can pass Numerical constants a=100 f=12.0 func1(a+28,f) ' or yet variables too and even numerical expressions End Sub When calling up a function all parameters must always be stated. The following call up is inadmissible: func1() func1(128) ' func1 gets 2 parameters! ' func1 gets 2 parameters! Return Parameters It is not only possible to pass parameters. A function can also offer a return value.
Compiler 210 Text="hello world" Len=StringLength(Text) End Sub In main the reference of text is presented as parameters to the function StringLength. If in a function a normal parameter is changed then the change is not visible outside this function. With references this is different. Through parameter str can in StringLength the contents of text be changed since str is only the reference (pointer) to the array variable text.
211 4.3.8.1 C-Control Pro IDE Operator Precedence Rank 10 9 8 7 6 5 4 3 2 1 4.3.8.
Compiler Xor Not 4.3.8.3 212 exclusive Or Bit inversion Reserved Words The following words are reserved and cannot be used as identifiers: And Char End If Next Select Sub Word 4.4 As Dim Exit Integer Not Single Then Xor ByRef Do False Lab Opc SizeOf To ULong Byte Else For Loop Or Static True Long Case ElseIf Goto Mod Return Step While UInteger Assembler With IDE Version 2.0 it is possible to integrate Assembler routines into a project. The used Assembler is the GNU Open Source Assembler AVRA.
213 C-Control Pro IDE // CompactC Source void proc1 $asm("tag1")(void); int proc2 $asm("tag2")(int a, float b, byte c); int glob1; void main(void) { int a; proc1(); a= proc2(11, 2.71, 33); } The procedures proc1 and proc2 must first be declared, before they can be called. This happens with the keyword $asm.
Compiler CLR ST R30 X,R30 214 ; the high byte is zero ret .endif In the second part of the assembler sources the passed parameters "a" and "c" are added as integers, and then the sum is returned. .
215 C-Control Pro IDE When the address of the global variable is in the X register pair (R26,R27), the desired value (in our example 42) can be written there: LDI ST CLR ST R30,LOW(42) X+,R30 R30 X,R30 ; the high byte of 42 is zero Parameter Passing Parameters are passed on the stack of the Bytecode Interpreter. The stackpointer (SP) lies in the register pair R10,R11. Are parameters passed, they are written one after another onto the stack.
Compiler 216 done to save bytecodes in the interpreter. Is the assembly routine declared as byte, a word must be a written as the return value, if the assembly routine is of type char, an int is required. In all other cases no change is needed. ; return a + c MOVW R30, R6 ADIW R30, 4 MOVW R6, R30 ST ST 4.4.
217 4.
Compiler 218 SUB 026 01A 00011010 Substitute ESC 027 01B 00011011 Escape FS 028 01C 00011100 File Separator GS 029 01D 00011101 Group Separator RS 030 01E 00011110 Request to Send, Record Separator US 031 01F 00011111 Unit Separator SP 032 020 00100000 Space ! 033 021 00100001 Exclamation Mark “ 034 022 00100010 Double Quote # 035 023 00100011 Number Sign $ 036 024 00100100 Dollar Sign % 037 025 00100101 Percent & 038 026 00100110 Ampersand ‘ 039 027
219 C-Control Pro IDE 6 054 036 00110110 7 055 037 00110111 8 056 038 00111000 9 057 039 00111001 : 058 03A 00111010 Colon ; 059 03B 00111011 Semi-Colon < 060 03C 00111100 Less Than = 061 03D 00111101 Equal > 062 03E 00111110 Greater Than ? 063 03F 00111111 Question Mark @ 064 040 01000000 AT Symbol A 065 041 01000001 B 066 042 01000010 C 067 043 01000011 D 068 044 01000100 E 069 045 01000101 F 070 046 01000110 G 071 047 01000111 H 0
Compiler U 085 055 01010101 V 086 056 01010110 W 087 057 01010111 X 088 058 01011000 Y 089 059 01011001 Z 090 05A 01011010 [ 091 05B 01011011 Left Opening Bracket \ 092 05C 01011100 Back Slash ] 093 05D 01011101 Right Closing Bracket ^ 094 05E 01011110 Caret DEC HEX BIN _ 095 05F 01011111 Underscore ` 096 060 01100000 a 097 061 01100001 b 098 062 01100010 c 099 063 01100011 d 100 064 01100100 e 101 065 01100101 f 102 066 01100110 g
221 C-Control Pro IDE q 113 071 01110001 r 114 072 01110010 s 115 073 01110011 t 116 074 01110100 u 117 075 01110101 v 118 076 01110110 w 119 077 01110111 x 120 078 01111000 y 121 079 01111001 z 122 07A 01111010 { 123 07B 01111011 Left Opening Brace | 124 07C 01111100 Vertical Bar } 125 07D 01111101 Right Closing Brace ~ 126 07E 01111110 Tilde DEL 127 07F 01111111 Delete © 2013 Conrad Electronic
Part 5
223 5 C-Control Pro IDE Libraries In this part of the documentation all attached Help functions are described which allow the user to comfortably gain access to the hardware. At the beginning of each function the syntax for CompactC and BASIC is shown. After that the description of functions and involved parameters will follow. 5.1 Internal Functions To allow the Compiler to recognize the internal functions present in the Interpreter these functions must be defined in library "IntFunc_Lib.cc".
Libraries 224 Parameter ms 5.2.2 wait duration in milliseconds ForceBootloader (AVR32Bit) General Functions Syntax void ForceBootloader(void); Sub ForceBootloader(); Description Jumps into the bootloader. After that, the unit is again available for commands, eg to update the software. Parameter None 5.2.3 Sleep (Mega) General Functions Syntax void Sleep(byte ctrl); Sub Sleep(ctrl As Byte) Description Using this function the Atmel CPU is set in one of the 6 different sleep modes.
225 C-Control Pro IDE 0 0 0 1 1 1 1 0 1 1 0 0 1 1 5.3 Analog-Comparator 5.3.1 Mega 1 0 1 0 1 0 1 ADC Noise Reduction Power-down Power-save Reserved Reserved Standby Extended Standby The Analog Comparator allows to compare two analog signals. The result of this comparison is returned as either "0" or "1". Voltages of between 0 and 5V can be compared at the positive and negative inputs. 5.3.1.
Libraries 226 // Mega32: Input (+) PB2 (PortB.2) bzw. band gap reference 1,22V // Input (-) PB3 (PortB.3) // Mega128: Input (+) PE2 (PortE.2) bzw. band gap reference 1,22V // Input (-) PE3 (PortE.3) // used Library: IntFunc_Lib.cc // // // // // // // // // The function AComp returns the value of the comparator. If the voltage on input PB2/PE2 is greater than the input PB3/PE3 the function AComp returns the value 1.
227 5.3.2.1 C-Control Pro IDE AC_Disable Analog Compare Functions Example Syntax void AC_Disable(byte ctrl); Sub AC_Disable(ctrl As Byte); Description Turns the specified Analog Comparator off. Parameter ctrl Analog Comparator (0 - 1) 5.3.2.2 AC_Enable Analog Compare Functions Example Syntax void AC_Enable(byte ctrl, byte in_pos, byte in_neg); Sub AC_Enable(ctrl As Byte, in_pos As Byte, in_neg As Byte); Description Turns the Analog Comparator on. The Atmel AVR32 has 2 Analog Comparators.
Libraries AC_AC0AN0 AC_AC0BP0 AC_AC1AP0 AC_AC1AP1 AC_AC1AN0 AC_AC1AN1 AC_AC1BP0 AC_AC1BP1 5.3.2.3 P20 P21 P25 P11 P24 P12 P26 P13 1 2 0 1 2 3 4 5 in_neg in_neg - 228 in_pos in_pos in_neg in_neg in_neg in_neg AC_InpHigher Analog Compare Functions Example Syntax byte AC_InpHigher(byte ctrl); Sub AC_Disable(ctrl As Byte) As Byte; Description Returns whether the voltage of in_pos is greater than the voltage of in_neg.
229 C-Control Pro IDE 5.4 Analog-Digital-Converter 5.4.1 Mega The Micro Controller has an Analog Digital Converter with a resolution of 10 Bit. I. e. measured voltages can be displayed as integral numbers from 0 through 1023. Reference voltage for the lower limit is GND level (0V). The reference voltage for the upper limit can be selected at will. External Reference Voltage AVCC with capacitor on AREF Internal Reference Voltage 2.56V with capacitor on AREF Analog Inputs ADC0 ...
Libraries 230 u = x * Reference Voltage / 512 / V 5.4.1.1 ADC_Disable ADC Functions Syntax void ADC_Disable(void); Sub ADC_Disable() Description This function disables to the A/D-Converter to reduce power consumption. Parameter None 5.4.1.2 ADC_Read ADC Functions Syntax word ADC_Read(void); Sub ADC_Read() As Word Description The function ADC_Read delivers the digitized measured value from one of the 8 ADC ports. The port number (0..7) has been given as a parameter in the call of ADC_Set().
231 C-Control Pro IDE Sub ADC_ReadInt() As Word Description This function is used to read the measurement value after a successful ADC-Interrupt. The ADC-Interrupt gets triggered after the AD conversion is completed and a new measurement value is available. See ADC_SetInt and ADC_StartInt. The function ADC_Read delivers the digitized measured value from one of the 8 ADC ports. The port number (0..7) has been given as a parameter in the call of ADC_Set().
Libraries 5.4.1.5 232 ADC_SetInt ADC Functions Syntax word ADC_SetInt(byte v_ref, byte channel); Sub ADC_SetInt(v_ref As Byte, channel As Byte) As Word Description The function ADC_SetInt initializes the Analog-Digital converter for interrupt usage. The reference voltage and the measurement channel number is selected and the A/D converter is prepared for the measurement. An interrupt service routine must be defined. After successful interrupt the value can be read with ADC_ReadInt().
233 5.4.2 C-Control Pro IDE AVR32Bit The microcontroller has an Analog-to-Digital converter with a selectable resolution of 8/10/12 bits. This means that measured voltages can be represented as whole numbers from -2048 to 2048, since the AD-converter always works differential. In addition, an ADC preamplifier gain of 1, 2, 4, 8, 16, 32, 64 can be set by software. The following reference voltage sources are available: 0,6 * VDDANA internal (0,6 * 3.
Libraries 234 offset); Sub ADC_Enable(mode As Byte, speed As ULong, ref As Byte, input_cnt As Byte, offset As Char) Description The ADC sequencer in the AVR32 can carry up to 8 A/D-conversions at the same time. An A/D-conversion can be a differential measurement between an ADC pin and GND, or a differential measurement between two pins. See ADC_SetInput. For the mode parameter various properties can be ORed (this of course only makes sense with one ADC resolution).
235 C-Control Pro IDE ADC_REF06VDD ADC_ADCREF0 ADC_ADCREF1 5.4.2.3 internal 0.6 x VDDANA Reference external ADCREF0 Reference external ADCREF1 Reference ADC_GetValue ADC Functions Syntax int ADC_GetValue(byte indx); Sub ADC_GetValue(indx As Byte) As Integer Description The function reads a measured value from the A/D-converter. The indx parameter corresponds to the entry in the inputs array in ADC_Enable().
Libraries values cnt 5.4.2.5 236 pointer to the 16-Bit array (0-7) number of values that are copied into the array ADC_SetInput ADC Functions Syntax void ADC_SetInput(byte indx, byte inp1, byte inp2, byte gain); Sub ADC_Enable(indx As Byte, inp1 As Byte, inp2 As Byte, gain As Byte) Description The ADC sequencer in the AVR32 can carry up to 8 AD conversion at a time. The function ADC_SetInput defines the ADC inputs between a differential measurement is carried out.
237 C-Control Pro IDE Sub ADC_Start() Description The built-in A / D converter starts to convert analog data. Parameter None 5.4.2.
Libraries 238 only used today in the automotive industry, but also in the areas of automation, aviation, aerospace and medical technology. The C-Control Manual cannot provide an introduction to the CAN standard, due to the complexity of the topic. Prior knowledge about the CAN standard and Full CAN message objects are assumed at this point. It is therefore recommended that beginner to embedded controllers will not work directly with the CAN bus.
239 C-Control Pro IDE Less than 125 kbit/s Up to 1000m The line lengths are highly dependent on the used cables and the number of participants. It is possible to use a "twist-pair cables with a characteristic impedance 108-132 Ohm. A maximum of 32 MEGA128CAN units can operate on a bus. It is best to start at the theoretical maximum speed for the used cable length, and to lower the transfer rate when there is no packet transfer at all or there occur too many packet errors.
Libraries 5.5.1 240 CAN Examples In this chapter some initialization examples are given to clarify the operation of the CAN Library. Initialization In any event, the CAN library must be initialized before use. This example is for the CAN bus at a speed of 1 mega bps, and for a FIFO RAM with 10 entries. byte fifo_buf[140]; CAN_Init(CAN_1MBPS, 10, fifo_buf); Reception 1. On MOb 2 messages of type CAN 2.0A are received, that have exactly an identifier of 0x123. CAN_SetMOb(2, 0x123, 0x7ff, CAN_RECV); 2.
241 C-Control Pro IDE byte data[8], i; for(i=0;i<8;i++) data[i]=i; CAN_SetMOb(1, 0x12345678, 0, CAN_SEND|CAN_EXTID); CAN_MObSend(1, 8, data); Automatic Reply MOb 4 is set to automatic reply. The data bytes provided with CAN_SetMOb () are sent when a CAN 2.0B trigger message is received with ID of 0x999. The number of transmitted data bytes depends on the DLC incoming trigger message.
Libraries 242 Returns information about the number of received CAN messages and CAN transmission errors. Parameter infotype selected CAN Bus information Return Parameter CAN Library information infotype parameter: Value 1 2 3 5.5.4 Definition CAN_MSGS CAN_ERR_RECV CAN_ERR_TRAN Meaning Number of already received CAN messages in the FIFO Number of CAN receive errors (max. 255) Number of CAN send errors (max.
243 C-Control Pro IDE 0 1 2 3 4 5 6 7 8 9 5.5.5 CAN_10KBPS CAN_20KBPS CAN_40KBPS CAN_100KBPS CAN_125KBPS CAN_200KBPS CAN_250KBPS CAN_500KBPS CAN_800KBPS CAN_1MBPS 10.000bps 20.000bps 40.000bps 100.000bps 125.000bps 200.000bps 250.000bps 500.000bps 800.000bps 1.000.
Libraries 244 Description A CAN message is sent over the bus. If, however, the CAN_REPL flag was set at CAN_SetMOb (), the data for the automatic reply will be saved and not sent immediately. Parameter mob len data 5.5.7 MOb Number (0-14) Length of the data to send Array in der CAN_SetChan (AVR32Bit) CAN Bus Functions Syntax void CAN_SetChan(byte chan); Sub CAN_SetChan(chan As Byte) Description Selects a CAN channel (CAN0 or CAN1) for further access.
245 C-Control Pro IDE Parameter mob ID maskID flag MOb Number(0-14) Identifier Identifier Mask Operation parameter for the Message Object (MOb) flag Parameter: Value (Hex) 01 02 04 08 10 20 40 5.6 Definition CAN_RECV CAN_RTR CAN_EXTID CAN_REPL CAN_IGN_RTR CAN_IGN_EXTID CAN_SEND Description Messages are received on this MOb The Remote Trigger Bit is set The CAN Message has a 29-Bit ID (V2.
Libraries Description All Date and Time values of the internal software clock can be read. The values of day and month are zero based, a one should be added when printing. Parameter indx index of date or time parameter #define CLOCK_SEC CLOCK_MIN CLOCK_HOUR CLOCK_DAY CLOCK_MON CLOCK_YEAR Index 0 1 2 3 4 5 Meaning Second Minute Hour Day Month Year Return Parameter requested time parameter 5.6.
247 5.6.3 C-Control Pro IDE Clock_SetTime Clock Functions Syntax void Clock_SetTime(byte hour, byte min, byte sec, char corr); Sub Clock_SetTime(hour As Byte, min As Byte, sec As Byte, corr As Char) Description Sets the time of the internal software clock. For a description of the correction factor refer to chapter Clock. The correction factor is unused in the AVR32Bit, you can specify any value there. Parameter hour min sec corr 5.
Libraries 28 29 - 34 35 36 - 41 42 - 44 45 - 49 50 - 57 58 248 Parity Minute Hour Parity Hour Day of the Month Weekday Month Year Parity Date This signifies that reception must be in progress for at least one full minute before time information can be provided. The information decoded during this minute is only secured by three parity bits. So two incorrectly received bits will already lead to a transmission error that can not be recognized in this way.
249 C-Control Pro IDE RTC (Real Time Clock) The RTC is controlled by a 10ms interrupt and runs in the background independent of the user program. The display on the LCD is updated every second. The display format is in the first line: Hour : Minute : Second, in the second line: Date of Day : Month : Year. LED1 flashes once per second. After program start the RTC begins with the set time. The date is set to zero and thus indicates that no DCF time adjustment has yet taken place.
Libraries 5.7.3 250 DCF_PULS DCF Functions Syntax void DCF_PULS(void); Sub DCF_PULS() Description Set DCF_Mode to 1 ("look for pulse"). Parameter None 5.7.4 DCF_START DCF Functions Syntax void DCF_START(void); Sub DCF_START() Description DCF_START initializes all variables and sets DCF_Mode to 1. From now on DCF time recording is working automatically. Parameter None 5.7.
251 C-Control Pro IDE void DCF_SYNC(void); Sub DCF_SYNC() Description Set DCF_Mode to 2 ("synchronize for frame beginning"). Parameter None 5.8 Debug The Debug Message Functions allow to send formatted text to the output window of the IDE. These functions are interrupt driven with a buffer of up to 128 Byte. I. e. 128 Byte can be transferred through the debug interface without the Mega 32 or Mega 128 Module having to wait for completion of the output.
Libraries 252 Sub Msg_WriteFloat(val As Single) Description The passed floating point number is displayed with a preceding decimal sign. Parameter val float value 5.8.3 Msg_WriteHex Debug Message Functions Syntax void Msg_WriteHex(word val); Sub Msg_WriteHex(val As Word) Description The 16bit value is displayed in the output window. The Output is formatted as a hexadecimal value with 4 digits. Leading zeros are displayed. Parameter val 16bit integer value 5.8.
253 C-Control Pro IDE val 16bit integer value 5.8.5 Msg_WriteText Debug Message Functions Syntax void Msg_WriteText(char text[]); Sub Msg_WriteText(ByRef text As Char) Description All characters of a character array up to the terminating null are sent to the output window. Parameter text pointer to char array 5.8.
Libraries 254 tions! 5.9.1 DirAcc_Read Direct Access Functions Syntax byte DirAcc_Read(byte register); Sub DirAcc_Read(register As Byte) As Byte Description A Byte is read from a Register of the Atmel CPU. Parameter register Register number (refer to chapter "Register Summary" in the Atmel Reference Manual) Return Parameter Value of Register 5.9.
255 C-Control Pro IDE 5.10.1 EEPROM_Read EEPROM Functions Syntax byte EEPROM_Read(word pos); Sub EEPROM_Read(pos As Word) As Byte Description Reads one byte out of the EEPROM at position pos. On the C-Control Pro Mega Units the first 32 byte are reserved for the system of the C-Control Pro. Therefore a pos value of 0 and higher accesses the EEPROM memory at position 32 and upwards. Parameter pos byte position in EEPROM Return Parameter EEPROM value 5.10.
Libraries 256 5.10.3 EEPROM_ReadFloat EEPROM Functions Syntax float EEPROM_ReadFloat(word pos); Sub EEPROM_ReadFloat(pos As Word) As Single Description Reads a floating point value out of the EEPROM at position pos. The value of pos describes a byte position in the EEPROM. This should be taken care of when using word or floating point accesses. On the C-Control Pro Mega Units the first 32 byte are reserved for the system of the C-Control Pro.
257 C-Control Pro IDE 5.10.5 EEPROM_WriteWord EEPROM Functions Syntax void EEPROM_WriteWord(word pos, word val); Sub EEPROM_WriteWord(pos As Word, val As Word) Description Writes one word into the EEPROM at position pos. The value of pos describes a byte position in the EEPROM. This should be taken care of when using word or floating point accesses. On the C-Control Pro Mega Units the first 32 byte are reserved for the system of the C-Control Pro.
Libraries 5.11 258 Ethernet (AVR32Bit) The C-Control Pro Unit AVR32Bit supports Ethernet hardware and protocols that follow the IEEE 802.3 standard. The associated PHY works with auto-negotiation and connects to a speed of 100Mbit or a 10Mbit, whatever speed the opposite side (eg a switch) offers. Power-over-Ethernet is not supported.
259 C-Control Pro IDE ton to initiate a complete system reboot. 5.11.2 TCP/IP Programming Open a TCP/IP connection: Create a receive buffer with ETH_SetConnBuf. The call of ETH_ConnectTCP establishes a connection and sets the internal state to ES_CONNECTING. With periodical calling of ETH_GetStateTCP the connection state is monitored. After ES_CONNECTING the state can change to ES_CONNECTED or ES_DISCONNECTED.
Libraries 260 byte tcp_buf[ETH_BUF(4000,6)], rbuf[1461]; void main(void) { word info[4], plen; char cmdtxt[50]; dword ip; byte id, state; ETH_SetConnBuf(tcp_buf, 4000, 6); id= ETH_ConnectTCP(IP_ADDR(192,168,0,1), 80); state= ES_CONNECTING; while(state == ES_CONNECTING) { state= ETH_GetStateTCP(id); } if(state == ES_CONNECTED) { cmdtxt= "GET / HTTP/1.
261 C-Control Pro IDE char text[10]; ETH_SetConnBuf(tcp_buf, 4000, 6); // 4000 byte buffer and allow 6 connections ETH_ListenTCP(23); // Listen Telnet port while(1) { ip= ETH_CheckReceiveBuf(info); if(ip) { plen= info[3]; // if(plen > 200) plen= 200; // limit to 200 bytes ETH_ReceiveData(rbuf, plen); txt= "Cmd:\n"; ETH_SendTCP(info[0], txt, 5); // send Cmd String } } } 5.11.3 UDP Programming UDP packets can directly be sent with ETH_SendUDP. The maximum size is 1460 bytes.
Libraries void SendSyslogMsg(dword ip, byte level, char text[]) { byte buf[100]; Str_Printf(buf, "<%d>%s", 16*8+level, text); ETH_SendUDP(ip, 514, buf, Str_Len(buf)); } void main(void) { while(1) { SendSyslogMsg(IP_ADDR(192,168,0,1), 3, "test message"); AbsDelay(1000); } } 2.
263 C-Control Pro IDE Description Opens a TCP / IP connection to a port. The 32-bit value of the IP address can be calculated with the macro IP_ADDR () from the accustomed notation: For example, IP_ADDR (192,168,1,1). When returning from ETH_ConnectTCP the connection is not established directly. You have to monitor the status of the connection with ETH_GetStateTCP. Parameter ip port IP-Address UDP Port Return Parameter sock_id (Socket Index), ff (Hex) in case of error 5.11.
Libraries info[0] info[1] info[2] info[3] socket index IP port of sender socket handle packet length 5.11.6 ETH_CloseListenTCP Ethernet Functions Syntax void ETH_CloseListenTCP(word handle); Sub ETH_CloseListenTCP(handle As Word) Description Closes a TCP listening socket that was created with ETH_ListenTCP. Parameter handle ETH_ListenTCP handle 5.11.
265 C-Control Pro IDE Sub ETH_DisconnectTCP(sock_id As Byte) Description Terminates an open connection. Parameter sock_id Socket Index 5.11.9 ETH_GetIPInfo Ethernet Functions Syntax void ETH_GetIPInfo(byte info, byte data[]); Sub ETH_GetIPInfo(info As Byte, ByRef data As Byte) Description Returns Ethernet information in a byte array. The length of the array must be sized to fit the values? . If ? DHCP is enabled and the IP address is currently 0.0.0.
Libraries 266 Description Informs about the status of the connection. Since the other party can cancel a TCP / IP connection at any time, the status of the program should be monitored periodically in the main loop. The sock_id parameter is returned either by ETH_ConnectTCP, or you get it as info [0] value of ETH_CheckReceiveBuf.
267 C-Control Pro IDE 5.11.12 ETH_ListenUDP Ethernet Functions Syntax word ETH_ListenUDP(word port); Sub ETH_ListenUDP(port As Word) As Word Description Opens a listening socket on a TCP port. Received packets are stored in the buffer that was initialized with ETH_SetConnBuf. Parameter port UDP Port Return Parameter handle to UDP listening Socket, 0 in case of error 5.11.
Libraries 268 Sub ETH_SendTCP(sock_id As Byte, ByRef buf As Byte, len As Word) As Byte Description Sends TCP data to an open TCP/IP connection. The sock_id parameter is returned either by ETH_ConnectTCP, or you get it as info [0] value of ETH_CheckReceiveBuf. Parameter sock_id buf len socket index address of TCP data buffer length of TCP data Return Parameter 0 if no error 5.11.
269 C-Control Pro IDE Sub ETH_SetConnBuf(ByRef buf As Byte, size As Word, TCP_conn As Byte) Description Creates an Ethernet receive buffer where received TCP/IP and UDP packets are stored. Parameter buf size 5.12 address of receive buffer size of buffer I2C The Controller provides an I2C Logic which allows effective communication. The Controller operates as an I2C Master (single master system). A slave operating mode is possible but not yet implemented in the current version. 5.12.1 Mega 5.12.1.
Libraries 270 The Bitrate can be calculated as follows: Bitrate = ((CPU_CLOCK / TARGET_I2C_SPEED) - 16) / 2 5.12.1.2 I2C_Read_ACK I2C Functions Syntax byte I2C_Read_ACK(void); Sub I2C_Read_ACK() As Byte Description This function receives a byte and acknowledges with ACK. Afterwards the status of the interface can be returned with I2C_Status(). Return Parameter value read from the I2C bus 5.12.1.
271 C-Control Pro IDE Description This function introduces communication with a starting sequence. Afterwards the status of the interface can be returned with I2C_Status(). Parameter None 5.12.1.5 I2C_Status I2C Functions Syntax byte I2C_Status(void); Sub I2C_Status() Description With I2C_Status the status of the I2C interface can be accessed. For the meaning of the return value please look inside the I2C status code table. Return Parameter current I2C Status 5.12.1.
Libraries 5.12.1.7 272 I2C_Write I2C Functions Example Syntax void I2C_Write(byte data); Sub I2C_Write(data As Byte) Description I2C_Write() sends a byte to the I2C bus. Afterwards the status of the interface can be returned with I2C_Status(). Parameter data data byte 5.12.1.
273 C-Control Pro IDE 40 48 50 58 5.12.1.
Libraries 5.12.2.1 274 I2C_Probe I2C Functions Syntax byte I2C_Probe(byte addr); Sub I2C_Probe(addr As Byte) As Byte Description I2C_Probe tries to address an I2C device and gives as result whether the attempt was successful. Parameter addr address of I2C device Return Parameter 1 = device has answered 0 else 5.12.2.
275 C-Control Pro IDE length number of bytes that are transferred (exclusive header) Return Parameter -1 = transmission error 0 = successful 5.12.2.3 I2C_SetSpeed I2C Functions Example Syntax void I2C_SetSpeed(dword I2C_BR); Sub I2C_SetSpeed(I2C_BR As ULong) Description This function sets the speed of the I2C interface. Parameter I2C_BR Indicates the bit rate as a 32-bit value.
Libraries 276 Sub I2C_Write(addr As Byte, hdr As ULong, hdr_len As Byte, ByRef mem_addr As Byte, length As Word) As Byte Description First, up to 4 bytes of header data are written to the I2C device with address addr (I2C 7-bit address). The header data is passed in hdr (dword), the number of bytes in hdr_len. The hdr_len may be zero, means that is there is no header data transferred. There are always the first high-order bytes of the header transmitted (big endian).
277 5.13 C-Control Pro IDE Interrupt The Controller provides a multitude of interrupts. Some of them are used for system functions and are thus not available to the user. The following interrupts can be utilized by the user.
Libraries INT_4 INT_5 INT_6 INT_7 INT_ADC INT_100Hz INT_TIMER0 INT_TIMER1 INT_TIMER2 INT_TIMER3 INT_TIMER4 INT_TIMER5 INT_CAN external Interrupt external Interrupt external Interrupt external Interrupt ADC 100 Hz Interrupt Timer 0 Timer 1 Timer 2 Timer 3 Timer 4 Timer 5 CAN 278 4 5 6 7 The corresponding interrupt has to receive the corresponding instructions in an Interrupt Service Routine (ISR) and also the interrupt has to be enabled. See Example.
279 C-Control Pro IDE 0: 1: a falling edge triggers the interrupt a rising edge triggers the interrupt Mode parameter for AVR32 0: 1: 2: 3: a low level triggers the interrupt a high level edge triggers the interrupt a falling edge triggers the interrupt a rising edge triggers the interrupt When 40 (Hex) is ORed to the parameter Mode (only AVR32) an internal pull-down is set, if 80 (Hex) is ORed an internal pull-up gets enabled. 5.13.
Libraries 280 The return value expresses how often a interrupt got triggered until the function Irq_GetCount() has been called. A value greater 1 shows that the interrupts are triggered more rapidly than the interrupt service routine is processed. 5.13.4 Irq_SetVect Interrupt Functions Example Syntax void Irq_SetVect(byte irqnr, dword vect); Sub Irq_SetVect(irqnr As Byte, vect As ULong) Description Defines an interrupt service routine for a specified interrupt.
281 C-Control Pro IDE int cnt; void ISR(void) { cnt=cnt+1; #if AVR32 Irq_GetCount(INT_100HZ); #else Irq_GetCount(INT_TIM2COMP); #endif } void main(void) { cnt=0; #if AVR32 Irq_SetVect(INT_100HZ, ISR); #else Irq_SetVect(INT_TIM2COMP, ISR); #endif while(true); // endless loop } 5.14 Keyboard (Mega) One part of these keyboard routines is implemented in the Interpreter, another can be called up after appending library "LCD_Lib.cc". Since the functions in "LCD_Lib.
Libraries 282 Parameter None 5.14.2 Key_Scan Keyboard Functions Syntax word Key_Scan(void); Sub Key_Scan() As Word Description Key_Scan scans sequentially the input pins of the connected keyboard and returns the result as a bit field with 16 bits. Bits that are set represent keys that have been pressed during the scan. Return Parameter 16 bits that represent the input lines of the keyboard 5.14.3 Key_TranslateKey Keyboard Functions (Library "Key_Lib .
283 5.15 C-Control Pro IDE LCD A part of these routines is implemented in the Interpreter, another part can be called up by appending library "LCD_Lib.cc". Since the functions in "LCD_Lib.cc" are realized through Bytecode they are slower when executed. Library functions however have the advantage that they can be taken from the project by omitting the library in case they are not needed. Direct Interpreter functions are always present, will however take up flash memory. 5.15.
Libraries None 5.15.1.3 LCD_WriteDataRegister LCD Functions (Library "LCD_Lib .cc") Syntax void LCD_WriteDataRegister(char x); Sub LCD_WriteDataRegister(x As Char) Description Sends a data byte to the display controller. Parameter x data byte 5.15.1.4 LCD_WriteCTRRegister LCD Functions (Library "LCD_Lib .cc") Syntax void LCD_WriteCTRRegister(byte cmd); Sub LCD_WriteCTRRegister(cmd As Byte) Description Sends a command to the display controller. Parameter cmd byte command 5.15.
285 C-Control Pro IDE Description Clears the display and enables the Cursor. Parameter None 5.15.3 LCD_CursorOff LCD Functions (Library "LCD_Lib .cc") Syntax void LCD_CursorOff(void); Sub LCD_CursorOff() Description Turns the cursor off on the display. Parameter None 5.15.4 LCD_CursorOn LCD Functions (Library "LCD_Lib .cc") Syntax void LCD_CursorOn(void); Sub LCD_CursorOn() Description Turns the cursor in the display on.
Libraries 5.15.5 LCD_CursorPos LCD Functions (Library "LCD_Lib .cc") Syntax void LCD_CursorPos(byte pos); Sub LCD_CursorPos(pos As Byte) Description Moves the cursor to position pos.
287 C-Control Pro IDE None 5.15.7 LCD_Locate LCD Functions Syntax void LCD_Locate(int row, int column); Sub LCD_Locate(row As Integer, column As Integer) Description Sets the cursor of the LCD display to given row and column. Parameter row column 5.15.8 LCD_SetDispAddr (AVR32Bit) LCD Functions (Library "LCD_Lib .cc") Syntax void LCD_SetDispAddr(byte addr); Sub LCD_SetDispAddr(addr As Byte) Description Sets a new destination address for the LCD output.
Libraries 5.15.9 LCD_WriteChar LCD Functions (Library "LCD_Lib .cc") Syntax void LCD_WriteChar(char c); Sub LCD_WriteChar(c As Char) Description Displays one character at the cursor position on the LCD display. Parameter c ASCII value of output character 5.15.10 LCD_WriteFloat LCD Functions Syntax void LCD_WriteFloat(float value, byte length); Sub LCD_WriteFloat(value As Single, length As Byte) Description Writes a floating point value with given length to LCD display.
289 C-Control Pro IDE Description LCD_WriteRegister divides the data byte y in 2 nibbles (4bit values) and sends the nibbles to the display controller. y data byte x command nibble 5.15.12 LCD_WriteText LCD Functions (Library "LCD_Lib .cc") Syntax void LCD_WriteText(char text[]); Sub LCD_WriteText(ByRef Text As Char) Description All characters of the char array up to the terminating zero are displayed. Parameter text char array 5.15.
Libraries 5.16 290 Math Mathematical Functions. 5.16.1 Floating Point In the following the mathematical functions are listed which the C-Control Pro is able to master with single floating point accuracy (32 bit). These functions are not contained in the C-Control Pro 32 since it would then not offer enough memory for user programs. 5.16.1.1 FPU (AVR32Bit) The AVR32Bit UNIT has an integrated floating point unit (FPU), that greatly accelerates floating point operations.
291 C-Control Pro IDE Description The mathematical arc sine (inverse sine) is calculated. Parameter val input value between -1 and 1 Return Parameter arc sine of the input value in the range [-Pi/2..Pi/2], expressed in radians 5.16.1.4 atan Floating Point Functions Syntax float atan(float val); Sub atan(val As Single) As Single Description The mathematical arc tangent (inverse tangent) is calculated. Parameter val input value Return Parameter arc tangent of the input value in the range [-Pi/2..
Libraries Return Parameter result 5.16.1.6 cos Floating Point Functions Syntax float cos(float val); Sub cos(val As Single) As Single Description The mathematical cosine is calculated. Parameter val input angle expressed in radians Return Parameter cosine of the input value between -1 and 1 5.16.1.7 exp Floating Point Functions Syntax float exp(float val); Sub exp(val As Single) As Single Description The exponential function e ^ val is calculated.
293 C-Control Pro IDE 5.16.1.8 fabs Floating Point Functions Syntax float fabs(float val); Sub fabs(val As Single) As Single Description The absolute value of the floating point number val is calculated. Parameter val input value Return Parameter result 5.16.1.9 floor Floating Point Functions Syntax float floor(float val); Sub floor(val As Single) As Single Description The smallest integer value of the floating point number x is calculated. Parameter val input value Return Parameter result 5.16.
Libraries 294 Sub ldexp(val As Single,expn As Integer) As Single Description The function val * 2 ^ expn is calculated (also used as internal help function for other mathematical functions). Parameter val multiplier expn exponent Return Parameter result 5.16.1.11 ln Floating Point Functions Syntax float ln(float val); Sub ln(val As Single) As Single Description The natural logarithm is calculated. Parameter val input value Return Parameter result 5.16.1.
295 C-Control Pro IDE The logarithm base 10 is calculated. Parameter val input value Return Parameter result 5.16.1.13 pow Floating Point Functions Syntax float pow(float x, float y); Sub pow(x As Single, y As Single) As Single Description The power function x ^ y is calculated. Parameter x base y exponent Return Parameter result 5.16.1.14 round Floating Point Functions Syntax float round(float val); Sub round(val As Single) As Single Description Rounding function.
Libraries result of the function 5.16.1.15 sin Floating Point Functions Syntax float sin(float val); Sub sin(val As Single) As Single Description The mathematical sine is calculated. Parameter val input angle expressed in radians Return Parameter sine of the input value between -1 and 1 5.16.1.16 sqrt Floating Point Functions Syntax float sqrt(float val); Sub sqrt(val As Single) As Single Description The square root of a positive floating point number is calculated.
297 C-Control Pro IDE 5.16.1.17 tan Floating Point Functions Syntax float tan(float val); Sub tan(val As Single) As Single Description The mathematical tangent is calculated. Parameter val input angle expressed in radians Return Parameter tangent of the input value 5.16.2 Integer Mathematical Integer Functions. 5.16.2.1 rand Integer Functions Syntax int rand(void); Sub rand() As Integer Description This function returns a pseudo random number between 0 and 32768.
Libraries 5.16.2.2 298 srand Integer Functions Syntax void srand(int seed); Sub srand(seed As Integer) Description Sets the seed for the pseudo random number generator. With the same seed the pseudo random number sequences can be reproduced. Parameter seed pseudo random number generator starting value. 5.17 OneWire 1-Wire or One-Wire is a serial interface that needs only one wire for signaling and power. The data is transferred asynchronously (without clock signal) in groups of 64 bit.
299 C-Control Pro IDE 5.17.2 Onewire_Reset 1-Wire Functions Syntax void Onewire_Reset(byte portbit); Sub Onewire_Reset(portbit As Byte) Description A reset is made on the One-Wire Bus. The port bit number for the One-Wire Bus communication is specified. Parameter portbit port bit number (see Port Table) 5.17.3 Onewire_Write 1-Wire Functions Syntax void Onewire_Write(byte data); Sub Onewire_Write(data As Byte) Description A byte is written to the One-Wire Bus. Parameter data data byte 5.17.
Libraries ret= OneWire_Reset(7); // PortA.7 if(ret == 0) { text= "no device found"; Msg_WriteText(text); goto end; } OneWire_Write(0xcc); // skip ROM cmd OneWire_Write(0x44); // start temperature measure cmd AbsDelay(3000); OneWire_Reset(7); // PortA.
301 C-Control Pro IDE End If OneWire_Write(0xcc) OneWire_Write(0x44) ' skip ROM cmd ' start temperature measure cmd AbsDelay(3000) OneWire_Reset(7) OneWire_Write(0xcc) OneWire_Write(0xbe) ' PortA.7 ' skip ROM cmd ' read scratch_pad cmd For i = 0 To 9 ' read whole scratchpad scratch_pad(i)= OneWire_Read() Msg_WriteHex(scratch_pad(i)) Next Msg_WriteChar(13) Text = "Temperature: " Msg_WriteText(Text) temp = scratch_pad(1) * 256 + scratch_pad(0) Msg_WriteFloat(temp * 0.
Libraries 302 input then the pull-up resistor (Reference Level VCC) is activated and the input is defined. Atmel AVR32Bit The Atmel AVR32Bit provides the ports A to D, which are each 32 bits in width. Each bit of every port can be configured as input or output. In addition, it is possible to enable a pullup, pulldown, and adjust the drive strength.
303 C-Control Pro IDE set PullDown minimum Drive Strength normal Drive Strength high Drive Strength maximum Drive Strength PORT_ATTR_PULL_DOWN PORT_ATTR_DRIVE_MIN PORT_ATTR_DRIVE_LOW PORT_ATTR_DRIVE_HIGH PORT_ATTR_DRIVE_MAX 08 00 10 20 30 To obtain more accurate values ? of the drive strength of a port please refer to the chapter "Electrical Characteristics" in the Atmel AT32UC3C datasheet. 5.18.
Libraries 304 Port Bit access is always significant slower than the normal Port access that transfers 8 Bit. If the desired values of all Port Bits are known, 8-Bit Port access is always preferable. Parameter portbit port bit number (see Port Table) val 0=Input, 1= Output 5.18.4 Port_Read (Mega) Port Functions Syntax byte Port_Read(byte port); Sub Port_Read(port As Byte) As Byte Description Reads a byte from the specified port.
305 C-Control Pro IDE Parameter portbit bit number of port (see Port Table) Return Parameter bit value (0 or 1) 5.18.6 Port_ToggleBit Port Functions Syntax void Port_ToggleBit(byte portbit); Sub Port_ToggleBit(portbit As Byte) Description The function Port_WriteBit inverts the value of a Pin that is configured for output. See Pin Assignment of AVR32, M32 and M128. Mega: Is a Pin configured as input, this will set an internal pull-up resistor on (bit = 1) or off (bit = 0).
Libraries port 306 port number (see Port Table) 5.18.8 Port_Write (Mega) Port Functions Example Syntax void Port_Write(byte port, byte val); Sub Port_Write(port As Byte, val As Byte) Description Writes a byte to the specified port. Only the Pins of port that are configured for output will show their value as port output on their bit position (see Pin Assignment of M32 and M128). Is a Pin configured as input, this will set an internal pull-up resistor on (bit = 1) or off (bit = 0).
307 C-Control Pro IDE ted. Parameter portbit val bit number of port (see Port Table) bit value (0 or 1) 5.18.10 Port Table Port Number Table Mega32 and Mega128 (CAN) Definition Value PortA PortB PortC PortD PortE (Mega128) PortF (Mega128) PortG (Mega128) 0 1 2 3 4 5 6 Portbits Table Mega32 and Mega128 (CAN) Definition Portbit Portbit Name PortA.0 ... PortA.7 PortB.0 ... PortB.7 PortC.0 ... PortC.7 PortD.0 ... PortD.7 0 ... 7 8 ... 15 16 ... 23 24 ... 31 PA0 ... PA7 PB0 ... PB7 PC0 ... PC7 PD0 .
Libraries Portbits Table AVR32 Definition Portbit Portbit Name PortA.0 ... PortA.31 PortB.0 ... PortB.31 PortC.0 ... PortC.31 PortD.0 ... PortD.31 0 ... 31 32 ... 63 64 ... 95 96 ... 127 PA00 ... PA31 PB00 ... PB31 PC00 ... PC31 PD00 ...
309 C-Control Pro IDE Port28 Port29 Port30 Port31 Port32 Port33 Port34 Port35 Port36 Port37 Port38 Port39 Port40 Port41 Port42 Port43 Port44 Port45 Port46 Port47 Port48 Port49 Port50 Port51 Port52 Port53 Port54 Port55 Port56 Port57 52 53 54 55 65 70 68 69 81 82 79 80 83 84 76 75 77 78 85 86 87 88 95 103 104 117 118 119 51 34 PB20 PB21 PB22 PB23 PC01 PC06 PC04 PC05 PC17 PC18 PC15 PC16 PC19 PC20 PC12 PC11 PC13 PC14 PC21 PC22 PC23 PC24 PC31 PD07 PD08 PD21 PD22 PD23 PB19 PB02 5.18.
Libraries 310 5.18.12 Port Example (AVR32Bit) All three program examples will light LED1 as long as button T1 is pressed. The examples differ in addressing the port name. If the button is not pressed, a "1" will be read from the port because each switch on the Applicationboard is connected to a pull-up resistor.
311 C-Control Pro IDE void main(void) { Port_Attribute(PC23, PORT_ATTR_OUTPUT | PORT_ATTR_INIT_LOW); Port_Attribute(PC20, PORT_ATTR_INPUT); while(true) // Endlosschleife { if(Port_ReadBit(PC20)) { Port_WriteBit(PC23, PORT_OFF); } else { Port_WriteBit(PC23, PORT_ON); } } } 5.19 RC5 A common used standard protocol for infrared data communication is the RC5 code, originally developed by Phillips.
Libraries Connection to C-Control Pro (Sender diode) Connection to C-Control Pro (Receiver) Pin assignm ent of TSOP1736 IR-Receiver © 2013 Conrad Electronic 312
313 C-Control Pro IDE Internal struture of receiver © 2013 Conrad Electronic
Libraries External circuit of receiver for connection to C-Control Pro 5.19.1 RC5_Init RC5 Functions Syntax void RC5_Init(byte pin); Sub RC5_Init(pin As Byte) Description The port pin is defined, that is connected to RC5 sender or receiver.
315 C-Control Pro IDE Parameter pin bit number of port (see Port Table) 5.19.2 RC5_Read RC5 Functions Syntax word RC5_Read(void); Sub RC5_Read() As Word Description Recognized RC5 datawords are received from the defined port pin. If there is no signal, the receive routine waits up to 130ms. This is because there is a 113ms gap between two repeated RC5 datawords. A return value of 0 means that no RC5 signal could be detected. This function will not recognize if a different format than RC-5 is used.
Libraries 5.20 316 RS232 There is a chance to miss received characters when using the polled serial routines, especially at high baud rates. If this is an issue, please use the interrupt driven serial routines with Serial_Init_IRQ() instead of Serial_Init(). Mega The serial interface can be operated at speeds of up to 230.4 kilo baud. With the functions for the serial interface the first parameter will indicate the port number (0 or 1).
317 C-Control Pro IDE divider = ( processor clock / baudrate / 16 ) -1 Example: 15 = (14745600 / 57600 / 16 ) -1 It is difficult to obtain the standard baudrates from the 16 MHz processor clock of the Mega128 CAN. Therefore are differences at higher baudrates between both divider tables. DoubleClock Mode If the High-Bit of the divider is set, the DoubleClock Mode is enabled. In this mode the divider value must be doubled. E.g.
Libraries 31 25 8022 (Hex) 12 6 3 SR_BDMIDI SR_BD38400 SR_BD57600 SR_BD76800 SR_BD125000 SR_BD250000 318 31250bps 38400bps 57600bps 76800bps 125000bps 250000bps 5.20.2 Serial_Disable Serial Functions Syntax void Serial_Disable(byte serport); Sub Serial_Disable(serport As Byte) Description The serial interface gets switched off and the corresponding ports can be used otherwise. Parameter serport interface number (0 = 1st serial port, 1 = 2nd serial port, ...) 5.20.
319 C-Control Pro IDE baudrate. This has the advantage that baudrates, that have no exact divider value can be represented. E.g. MIDI: The new value SB_MIDI (=803a Hex) lies much nearer at the correct value of 31250baud. An example for 19200 baud: The normal divider value for 19200 baud is 002f (Hex). If DoubleClock Mode is used, the divider must be doubled (=005e Hex). Then set the Hi-bit, and the alternative divider value for 19200 baud is 805e (Hex).
Libraries 320 serport interface number (0 = 1st serial port, 1 = 2nd serial port, ...) par interface parameter (see par table) baud baud rate table par definitions: Definition SR_5BIT SR_6BIT SR_7BIT SR_8BIT Function 5 Bit 6 Bit 7 Bit 8 Bit char length char length char length char length SR_1STOP SR_2STOP 1 stop bit 2 stop bit SR_NO_PAR SR_EVEN_PAR SR_ODD_PAR no parity even parity odd parity 5.20.
321 C-Control Pro IDE Please use Serial_ReadExt() if you work in serial IRQ mode. Serial_Read() only supports polled mode. Parameter serport ramaddr recvlen sendlen par divider interface number (0 = 1st serial port, 1 = 2nd serial port, ...
Libraries 322 SR_EVEN_PAR" means 7 bit character length, 2 stop bits and even parity (see Example). An example in BASIC Syntax: "SR_7BIT Or SR_2STOP Or SR_EVEN_PAR". The user supplied buffer must be available the whole time the serial interface is working. Since after leaving a function the local variables are no longer available, it is most times a good idea to provide the user supplied buffer as a global variable. Please use Serial_ReadExt() if you work in serial IRQ mode.
323 C-Control Pro IDE Parameter serport interface number (0 = 1st serial port, 1 = 2nd serial port ) info values: RS232_FIFO_RECV (0) RS232_FIFO_SEND(1) number of bytes received number of bytes written to he send buffer Return Parameter result in bytes 5.20.8 Serial_Read (Mega) Serial Functions Syntax byte Serial_Read(byte serport); Sub Serial_Read(serport As Byte) As Byte Description Reads one byte from the serial interface.
Libraries 324 Description Reads one byte from the serial interface. In opposite to Serial_Read() Serial_ReadExt() returns immediately even if there is no byte available in the serial port. In this case 256 (100 Hex) is returned. Please use Serial_ReadExt() if you work in serial IRQ mode. Serial_Read() only supports polled mode.
325 C-Control Pro IDE Parameter serport interface number (0 = 1st serial port, 1 = 2nd serial port ) text char array 5.20.12 Serial Example // string output on the serial interface void main(void) { int i; char str[10]; str="test"; i=0; // initialize serial port with 19200baud, 8 bit, 1 stop bit, no parity Serial_Init(0,SR_8BIT|SR_1STOP|SR_NO_PAR,SR_BD19200); while(str[i]) Serial_Write(0,str[i++]); // output string to serial port } 5.20.
Libraries 326 triggered. In the demo programs this part is commented out for the AVR32Bit Unit. SD-Card Support for C-Control Pro Mega 128 and Mega 128 CAN The C-Control Pro SD Card interface (Conrad Order No. 197220) is used for connecting a microcontroller, such as C-Control Unit 128 Mega (Conrad Order No. 198219) to a 3.3 SD card. The SD-card expansion features a level converter, which bidirectional converts the signals, allowing a direct connection of the SD card to a 5V microcontroller.
327 C-Control Pro IDE LED EN2 PB.7 PB.6 WP (Write Protect): high = write protected SD card low = access allowed CD (Card Detect): high = SD-Card not recognized low = SD-Card detected SPI- Interface: MISO MOSI SCK SS Other: LED -> User Led (5V level) Reset Circuit: En1 = Reset the SD-Card (low = running mode / high = reset) En2 = Supply SD-Card holder (low = off / high = on) The bottom diagram shows the performance of the hardware reset.
Libraries 328 5.21.1 FAT Support FAT Specification FAT support: FAT12, FAT16 and FAT32. Open files: Unlimited, depending on available memory. File size: Dependent from FAT Type (up to 4G bytes). Volume size: Dependent from FAT Type (up to 2T bytes at 512 bytes/sector) Cluster size: Dependent from FAT Type (up to 64K bytes at 512 bytes/sector) Sector size: Dependent from FAT Type (up to 4K bytes) The SD card functions support no long file names (LFN) under FAT.
329 C-Control Pro IDE Description Closes a previously opened file. Parameter fil_ramaddr address of the FILE buffer Return Parameter Success of the called SDC function. See SDC Return Values. 5.21.4 SDC_FOpen SDCard Functions Syntax byte SDC_FOpen(byte fil_ramaddr[], char path[], byte mode); Sub SDC_FOpen(ByRef fil_ramaddr As Byte, ByRef path As Char, mode As Byte) As Byte; Description Opens a file. For each open file a FILE buffer has to be created. For this we define a byte array of size 32.
Libraries 330 Mode Value (Hex) Description FA_OPEN_EXISTING FA_READ FA_WRITE FA_CREATE_NEW FA_CREATE_ALWAYS FA_OPEN_ALWAYS 00 01 02 04 08 10 Opens file. If file does not exist, then error File reading allowed File writing allowed Creates file, if file already exists, then error Creates file, if file already exists, then file is truncated Opens file. If file does not exist, then file is created 5.21.
331 C-Control Pro IDE Parameter fil_ramaddr address of the FILE buffer pos read / write position Return Parameter Success of the called SDC function. See SDC Return Values. 5.21.7 SDC_FSetDateTime SDCard Functions Syntax byte SDC_FSetDateTime(char path[], byte day, byte mon, word year, byte min, byte hours, byte sec); Sub SDC_FSetDateTime(ByRef path As Char,day As Byte,mon As Byte,year As Word, min As Byte, hours As Byte, sec As Byte) As Byte Description Set the date and time attributes of a file.
Libraries Read attributes of a file to a dword (ULong) array with 4 elements. Parameter path filinfo file path return array Return Parameter Success of the called SDC function. See SDC Return Values. Rückgabe Array: fileinfo[0] fileinfo[1] fileinfo[2] fileinfo[3] file length date time file attribute Coding date: Bits 0:4 - day: 1...31 Bits 5:8 - month: 1...12 Bits 9:15 - year begin with 1980: 0...127 Coding time: Bits 0:4 - seconds/2: 0...29 Bits 5:10 - minute: 0...59 Bits 11:15 - hour: 0...
333 C-Control Pro IDE Return Parameter Success of the called SDC function. See SDC Return Values. 5.21.10 SDC_FTruncate SDCard Functions Syntax byte SDC_FTruncate(byte fil_ramaddr[]); Sub SDC_FTruncate(ByRef fil_ramaddr As Byte) As Byte Description Delete the rest of the file from the current cursor position. Parameter fil_ramaddr address of the FILE buffer Return Parameter Success of the called SDC function. See SDC Return Values. 5.21.
Libraries 334 Return Parameter Success of the called SDC function. See SDC Return Values. 5.21.12 SDC_GetFree SDCard Functions Syntax byte SDC_GetFree(char path[], dword kbfree[]); Sub SDC_GetFree(ByRef path As Char, ByRef kbfree As ULong) As Byte Description Returns the number of free clusters on the SD Card. The number of free clusters is copied to the first element of the array kbfree. Parameter path kbfree path to the root of the disk.
335 C-Control Pro IDE Return Parameter Success of the called SDC function. See SDC Return Values. 5.21.14 SDC_MkDir SDCard Functions Syntax byte SDC_MkDir(char path[]); Sub SDC_MkDir(ByRef path As Char) As Byte Description Creates a directory on the SD card. Parameter path path to the directory Return Parameter Success of the called SDC function. See SDC Return Values. 5.21.
Libraries 336 Return Parameter Success of the called SDC function. See SDC Return Values. 5.21.16 SDC_Unlink SDCard Functions Syntax byte SDC_Unlink(char path[]); Sub SDC_Unlink(ByRef path As Char) As Byte Description Deletes a file. Parameter path file path Return Parameter Success of the called SDC function. See SDC Return Values. 5.21.
337 C-Control Pro IDE // Power on -> SD-Card Port_WriteBit(14,1); // EN2 (PB.6) +5V AbsDelay(50); // 50ms Pause // SD-Card Fat init SDC_Init (fat); // Create a new file folders SDC_MkDir("0:/CC-PRO"); // Does the file already exists? // If the file is not created res=SDC_FOpen(fil, "0:/CC-PRO/test.txt", FA_READ|FA_WRITE|FA_OPEN_EXISTING); if(res!=0)SDC_FOpen(fil, "0:/CC-PRO/test.txt", FA_WRITE|FA_CREATE_ALWAYS); // Writes to a text file buf= "Hallo...
Libraries 338 +5Volt ist the supply voltage of the servo, it must provide enough current to drive the servo. The ground of the servo and the ground of the C-Control Pro unit must be the same. The pulse for the servo is generated by the PWM signal of the C-Control unit. 5.22.
339 C-Control Pro IDE A 16-bit Timer is needed for the servo steering routines. Is the timer turned off, or is used for other purposes the servo routines will not work. Parameter servo_cnt servo_interval ramaddr timer number of possible servos (maximum 20) periodic length (0=10ms, 1=20ms) address of memory block 16-Bit Timer used for servo steering Mega32: 0 = Timer 1 Mega128 & Mega128 CAN: 0=Timer 1, 1=Timer 3 AVR32: all Timer (0 - 5) 5.22.
Libraries 340 AbsDelay(5000); Servo_Set(7, 1000); // Servo Portbit 7 1000µs AbsDelay(5000); Servo_Set(7, 0); Servo_Set(6, 0); Servo_Set(5, 0); // all Servos off } 5.23 SPI The Serial Peripheral Interface Bus or SPI bus is a synchronous serial data link standard named by Motorola that operates in full duplex mode. Devices communicate in master/slave mode where the master device initiates the data frame. Multiple slave devices are allowed with individual slave select (chip select) lines. 5.23.
341 C-Control Pro IDE 5.23.1.2 SPI_Enable SPI Functions Syntax void SPI_Enable(byte ctrl); Sub SPI_Enable(ctrl As Byte) Description The SPI interface is initialized with the value of ctrl (see SPCR register in Atmel Mega Reference Manual).
Libraries Return Parameter received byte from the SPI interface 5.23.1.4 SPI_ReadBuf SPI Functions Syntax void SPI_ReadBuf(byte buf[], word length); Sub SPI_ReadBuf(ByRef buf As Byte, length As Word) Description A number of bytes are read from the SPI interface into an array. Parameter buf length 5.23.1.5 pointer to byte array number of bytes to read SPI_Write SPI Functions Syntax void SPI_Write(byte data); Sub SPI_Write(data As Byte) Description One byte is send to the serial interface.
343 C-Control Pro IDE Sub SPI_WriteBuf(ByRef buf As Byte, length As Word) Description A number of bytes are sent to the SPI interface. Parameter buf pointer to byte array length number of bytes to be transferred 5.23.2 AVR32Bit 5.23.2.1 SPI_Disable SPI Functions Syntax void SPI_Disable(byte chan); Sub SPI_Disable(chan As Byte) Description The SPI interface is switched off and the associated ports can be used differently. Parameter chan 5.23.2.
Libraries 344 selected that meets the desired clock rate closest: divider = 66Mhz / speed. The actual speed is then 66Mhz / divider. As a result, baud rates less than 259000 may not be used. Parameter SPI channel (0 - 1) SPI baud rate (259000 - 66000000) number of data bits SPI mode chan speed bits mode 5.23.2.3 SPI Mode CPOL NCPHA 0 1 2 3 0 0 1 1 1 0 1 0 SPI_Read SPI Functions Syntax word SPI_Read(); Sub SPI_Read() As Word Description Data is read from the SPI interface.
345 C-Control Pro IDE less of whether the SPI interface is initialized with more bits. Parameter buf length 5.23.2.5 pointer to byte array number of bytes to read SPI_SetChan SPI Functions Syntax void SPI_SetChan(byte chan); Sub SPI_SetChan(chan As Byte) Description Selects an SPI interface (SPI0 or SPI1) for further access. Parameter chan SPI channel (0 - 1) 5.23.2.
Libraries 346 Sub SPI_WriteBuf(ByRef buf As Byte, length As Word) Description A number of bytes are sent to the SPI interface. The function works with 8 bits, regardless of whether the SPI interface is initialized with more bits. Parameter buf length 5.24 pointer to byte array number of bytes to be transferred Strings One part of these string routines is implemented in the Interpreter, another can be called up after appending library "String_Lib.cc". Since the functions in "String_Lib.
347 C-Control Pro IDE Remark The attribute smaller or greater is specified for the character difference at the first point of difference between both strings. 5.24.2 Str_Copy String Functions Syntax void Str_Copy(char destination[], char source[], word offset); Sub Str_Copy(ByRef destination As Char, ByRef source As Char, offset As Word) Description The source string (source) is copied to the destination string (destination).
Libraries 5.24.4 Str_Isalnum String Functions (Library "String_Lib .cc") Syntax byte Str_Isalnum(char c); Sub Str_Isalnum(c As Char) As Byte Description A character is tested if it is alphabetically or a digit. Parameter c tested character Return Parameter 1 if the character is alphabetically or a digit (upper- or lowercase) 0 else 5.24.5 Str_Isalpha String Functions (Library "String_Lib .
349 C-Control Pro IDE 5.24.6 Str_Len String Functions Syntax word Str_Len(char str[]); Sub Str_Len(ByRef str As Char) As Word Description The length of the string (character array) is returned. Parameter str pointer to string Return Parameter length of the string (without terminating zero) 5.24.7 Str_Printf String Functions Example Syntax void Str_Printf(char str[], char format[], ...); Sub Str_Printf(ByRef str As Char, ByRef format As Char, ...
Libraries 0 l padd with "0" 32-Bit Integer Format %[width]d %[width][.prec]u %[width]x %[width][.prec]f %[width]s %[width]c Description integer unsigned integer hexadecimal floating point string char 350 Parameter str format pointer to string pointer to format string 5.24.8 Str_ReadFloat String Functions Syntax float Str_ReadFloat(char str[]); Sub Str_ReadFloat(ByRef str As Char) As Single Description The value of a string representing a floating point number is returned.
351 C-Control Pro IDE Description The value of a string representing an integer number is returned. The number is recognized, even if there or other characters after the number. Parameter str pointer to string Return Parameter integer value of string 5.24.10 Str_ReadNum String Functions Syntax word Str_ReadNum(char str[], byte base); Sub Str_ReadNum(ByRef str As Char, base As Byte) As Word Description The value of a string representing an unsigned number is returned.
Libraries 352 is returned. Parameter source string that is searched search substring that is looked for Return Parameter position of the found substring -1 else 5.24.12 Str_WriteFloat String Functions Syntax void Str_WriteFloat(float n, byte decimal, char text[], word offset); Sub Str_WriteFloat(n As Single, decimal As Byte, ByRef text As Char, offset As Word) Description The floating point number n is converted to an ASCII string with decimal number of decimal digits after the period.
353 C-Control Pro IDE set of offset. The offset parameter is used to change a string after a specified number (offset) of characters and leave the beginning of the string intact. Parameter n integer number text pointer to destination string offset offset that is applied to the position where the string is copied If offset has the value STR_APPEND (ffff Hex) then the length of the destination string is assumed as offset. In this case the source string is copied behind the destination string. 5.24.
Libraries 354 5.24.15 Str_Printf Example // CompactC void main(void) { char str[80]; // Integer Str_Printf(str, "arg1: %d\r", 1234); Msg_WriteText(str); // Ouput of integer, floating point, string und hex number Str_Printf(str, "arg1: %8d arg2:%10.3f arg3:%20s arg4: %x\r", 1234, 2.34567, "hello world", 256); Msg_WriteText(str); Str_Printf(str, "arg1: %u arg2: %.2u\r", 65000, 0xff); Msg_WriteText(str);} } ' Basic Sub main() Dim str(80) As Char Str_Printf(str, "arg1: %08d arg2:%10.
355 C-Control Pro IDE active at all times even if no threads have explicitly been started. If the main program (thread "0") terminates, all other threads stop, too. The priority of threads can be influenced by changing the number of time cycles which one thread is allowed to execute until the next thread change takes place. The smaller the number of cycles until the change takes place, the lower the priority of the thread. Thread Configuration Before IDE version 2.
Libraries 356 tions Thread_Wait and Thread_Signal. A thread bound to wait will execute instruction Thread_Wait with a signal number. The condition of the thread is set on waiting. This means that the thread may be ignored at a possible thread change. If the other thread has completed its critical work it will send the command Thread_Signal with the same signal number the first thread had used for its Thread_Wait.
357 C-Control Pro IDE 5.25.2 Thread_Delay Thread Functions Example Syntax void Thread_Delay(word delay); Sub Thread_Delay(delay As Word) Description With this function a thread will set to "sleep" for a specified time. After this time the thread is again ready for execution. The waiting period is given in ticks that are created by Timer 2. If Timer 2 is set off or used for other purposes, the mode of operation of Thread_Delay() is not defined.
Libraries 358 5.25.4 Thread_Kill Thread Functions Syntax void Thread_Kill(byte thread); Sub Thread_Kill(thread As Byte) Description Terminates a thread. If 0 is given as thread number, the whole program will be terminated. Parameter thread (0-13) thread number 5.25.5 Thread_Lock Thread Functions Syntax void Thread_Lock(byte lock); Sub Thread_Lock(lock As Byte) Description With this function you can inhibit thread changes.
359 C-Control Pro IDE Description Returns the free memory that is available for the calling thread. Parameter None Return Parameter free memory in bytes 5.25.7 Thread_Resume Thread Functions Syntax void Thread_Resume(byte thread); Sub Thread_Resume(thread As Byte) Description If a thread has the state "waiting" it can be set to "inactive" with this function call. "Inactive" means that a thread is ready for activation at a thread change. Parameter thread (0-13) thread number 5.25.
Libraries 360 Parameter signal signal value 5.25.9 Thread_Start Thread Functions Example Syntax void Thread_Start(byte thread, dword func); Sub Thread_Start(Byte thread As Byte, func As ULong) Description A new thread gets started. Every function in the program can be used as starting function for the thread.
361 C-Control Pro IDE 5.25.
Libraries } 362 // after that the thread // sleeps for 200ms //----------------------------------------------------------------// main program // void main(void) { Thread_Start(1,thread1); // start new thread } 5.26 while(true) // endless loop { Thread_Delay(100); Msg_WriteText("Thread1"); } // the thread sleeps for 100ms // after that "Thread1" is displayed Timer 5.26.1 Mega In C-Control Pro Mega 32 there are two, in Mega128 are three independent timers available.
363 C-Control Pro IDE // Example: Pulse Counting with CNT1 Timer_T1CNT(); pulse(n); // generate n Pulses count=Timer_T1GetCNT(); 5.26.1.2 Frequency Generation To generate frequencies Tim e r_ 0 , Tim e r_ 1 and Tim e r_ 3 can be utilized as follows: Timer0 (8 Bit) 1. Example: // Square Wave Signal with 10*1,085 µs = 10,85 µs Period Duration Timer_T0FRQ(10, PS0_8) 2.
Libraries 364 Timer_T3FRQX(10,2,PS_8); 5.26.1.3 Frequency Measurement Timer_1 (16Bit) and Timer_3 (16Bit) (only Mega128) can be used for direct measurement of a frequency. The pulses per second are being counted, the result is then delivered in Hertz units. The maximum frequency is 64kHz and is yielded by the 16 bit counter. An example for this kind of frequency measurement can be found under "Demo Programs/FreqMeasurement". By shortening the measuring time also higher frequencies can be measured.
365 C-Control Pro IDE Timer_T1PWMX(255,128,128,PS_8); Timer_T1PWA(128); Timer_T1PWB(128); AbsDelay(1000); // set OC1B off Timer_Disable(1); Timer_T1PWM(255,128,PS_8); Port_DataDirBit(14,1); Port_WriteBit(14,0); } 5.26.1.5 Pulse & Period Measurement By use of Timer_1 or Timer_3 (only Mega128) pulse widths and signal periods can be measured. Here by use of the Input Capture Function (specific register of the Controller) the time between two signal slopes is measured.
Libraries while(PM_Value==0); 366 // Measure Pulse Width or Period Msg_WriteHex(PM_Value); // Output Measuring Value } For reason of better survey only a simplified version is shown here. Because of a collision on Pin B.4 Timer_0 is used for pulse generation with Mega128. The entire program can be found in directory PW_Measurement. 5.26.1.6 Timer Functions In C-Control Pro Mega 32 there are two, in Mega128 three independent Timer available.
367 C-Control Pro IDE Description This function disables the specified timer. Timer functions occupy I/O ports. If a timer is not needed and the corresponding I/O ports are used otherwise, the timer must be disabled. Parameter 0 = Timer_0 1 = Timer_1 3 = Timer_3 (only Mega128) 5.26.1.8 Timer_T0CNT Timer Functions Syntax void Timer_T0CNT(void); Sub Timer_T0CNT() Description These function initializes Counter0. Counter0 gets incremented at every positive signal edge at Input Mega32:T0 (PIN1).
Libraries period period duration PS prescaler Table prescaler: Prescaler Tickduration Mega32 PS0_1 (1) PS0_8 (2) PS0_64 (3) PS0_256 (4) PS0_1024 (5) Prescaler 135,6 ns 1,085 µs 8,681 µs 34,72 µs 138,9 µs Tickduration Mega128 PS0_1 (1) PS0_8 (2) PS0_32 (3) PS0_64 (4) PS0_128 (5) PS0_256 (6) PS0_1024 (7) 135,6 ns 1,085 µs 4,340 µs 8,681 µs 17,36 µs 34,72 µs 138,9 µs Tickduration Mega128 CAN 125 ns 1 µs 4 µs 8µs 16 µs 32 µs 128 µs 5.26.1.
369 C-Control Pro IDE void Timer_T0PW(byte PW); Sub Timer_T0PW(PW As Byte) Description This function sets a new pulse width for Timer0 without changing the prescaler. For the pulse width parameters do not use the value zero. See Pulse Width Modulation Parameter PW pulse width 5.26.1.12 Timer_T0PWM Timer Functions Syntax void Timer_T0PWM(byte PW, byte PS); Sub Timer_T0PWM(PW As Byte, PS As Byte) Description This function initializes Timer0 with given prescaler and pulse width, see table.
Libraries PS0_1 (1) PS0_8 (2) PS0_32 (3) PS0_64 (4) PS0_128 (5) PS0_256 (6) PS0_1024 (7) 67,8 ns 542,5 ns 2,17 µs 4,34 µs 8,68 µs 17,36 µs 69,44 µs 370 62,5 ns 500 ns 2 µs 4 µs 8 µs 16 µs 64 µs 5.26.1.13 Timer_T0Start Timer Functions Syntax void Timer_T0Start(byte prescaler); Sub Timer_T0Start(prescaler As Byte) Description The timer continues with the already set parameters. The prescaler must be given again. Parameter prescaler prescaler (see table) 5.26.1.
371 C-Control Pro IDE 5.26.1.15 Timer_T0Time Timer Functions Syntax void Timer_T0Time(byte Time, byte PS); Sub Timer_T0Time(Time As Byte, PS As Byte) Description This function initializes Timer_0 with a prescaler and a timer interval value, see table. After the timing interval is expired The Timer_0 Interrupt (INT_TIM0COMP) is triggered. There is an extended prescaler definition for the Mega128, see table.
Libraries 372 Description These function initializes Counter1. Counter1 gets incremented at every positive signal edge at input Mega32: PortB.1 (PIN2) Mega128: PortD.6 (X2_15). Parameter None 5.26.1.17 Timer_T1CNT_Int Timer Functions Syntax void Timer_T1CNT_Int(word limit); Sub Timer_T1CNT_Int(limit As Word) Description These function initializes Counter1. Counter1 gets incremented at every positive signal edge at input Mega32: PortB.1 (PIN2) Mega128: PortD.6 (X2_15).
373 C-Control Pro IDE period period duration PS prescaler Table prescaler: Prescaler Tickduration Mega32 + Mega128 Tickduration Mega128 CAN 135,6 ns 1,085 µs 8,681 µs 34,72 µs 138,9 µs 125 ns 1 µs 8 µs 32 µs 128 µs PS_1 (1) PS_8 (2) PS_64 (3) PS_256 (4) PS_1024 (5) 5.26.1.19 Timer_T1FRQX Timer Functions Syntax void Timer_T1FRQX(word period, word skew, byte PS); Sub Timer_T1FRQX(period As Word, skew As Word, PS As Byte) Description This function initializes Timer1 for frequency generation.
Libraries 374 Return Parameter counter value 5.26.1.21 Timer_T1GetPM Timer Functions Syntax word Timer_T1GetPM(void); Sub Timer_T1GetPM() As Word Description Returns the result of the measurement. Parameter None Return Parameter result of measurement To calculate the correct value, the 16bit result is multiplied with the entry of the prescaler Table that was passed in the call to Timer_T1PM. 5.26.1.
375 C-Control Pro IDE 5.26.1.23 Timer_T1PM Timer Functions Syntax void Timer_T1PM(byte Mode, byte PS); void Timer_T1PM(Mode As Byte, PS As Byte) Description This function defines if pulse width measurement or period measurement should be done. Then it initializes Timer_1 and sets the prescaler.
Libraries 376 5.26.1.25 Timer_T1PWM Timer Functions Syntax void Timer_T1PWM(word period, word PW0, byte PS); Sub Timer_T1PWM(period As Word, PW0 As Word, PS As Byte) Description This function initializes Timer_1 with given period duration, pulse width and prescaler, see table. The output signal is generated at Mega32: PortD.5 (PIN19), Mega128: PortB.5 (X1_3). There is an extended prescaler definition for the Mega128, see table. For the pulse width parameters do not use the value zero.
377 C-Control Pro IDE Parameter period PW0 PW1 PS period duration pulse width channel A pulse width channel B prescaler (see table prescaler) 5.26.1.27 Timer_T1PWMY Timer Functions Syntax void Timer_T1PWMY(word period, word PW0, word PW1, word PW2, byte PS); Sub Timer_T1PWMY(period As Word, PW0 As Word, PW1 As Word, PW2 As Word, PS As Byte) Description This function initializes Timer_1 with given period duration, prescaler, pulse width for channel A, B and C. The output signal is generated at PortB.
Libraries 378 Parameter prescaler prescaler (see table) 5.26.1.29 Timer_T1Stop Timer Functions Syntax void Timer_T1Stop(void); Sub Timer_T1Stop() Description The frequency generation gets stopped. The output signal can be 0 or 1, dependent on the last state. Only the clock generation is stopped, all other settings stay the same. Parameter None 5.26.1.
379 C-Control Pro IDE PS_1 (1) PS_8 (2) PS_64 (3) PS_256 (4) PS_1024 (5) 67,8 ns 542,5 ns 4,34 µs 17,36 µs 69,44 µs 62,5 ns 500 ns 4 µs 16 µs 64 µs 5.26.1.31 Timer_T3CNT Timer Functions Syntax void Timer_T3CNT(void); Sub Timer_T3CNT() Description These function initializes Counter3. Counter3 gets incremented at every positive signal edge at input PortE.6 (X1_10) Parameter None 5.26.1.
Libraries 380 5.26.1.33 Timer_T3FRQ Timer Functions Syntax void Timer_T3FRQ(word period, byte PS); Sub Timer_T3FRQ(period As Word, PS As Byte) Description This function initializes Timer3 for frequency generation. Parameters are period duration and prescaler, see table. The output signal is generated at PortE.3 (X1_13). The frequency generation is started automatically..
381 C-Control Pro IDE period skew PS period duration phase shift prescaler (table prescaler) 5.26.1.35 Timer_T3GetCNT Timer Functions Syntax word Timer_T3GetCNT(void); Sub Timer_T3GetCNT() As Word Description The value of Counter1 is read. If there was an overflow a value of ffff (Hex) is returned. Return Parameter counter value 5.26.1.36 Timer_T3GetPM Timer Functions Syntax word Timer_T3GetPM(void); Sub Timer_T3GetPM() As Word Description Returns the result of the measurement.
Libraries 382 5.26.1.37 Timer_T3PWA Timer Functions Syntax void Timer_T3PWA(word PW0); Sub Timer_T3PWA(PW0 As Word) Description This function sets a new pulse width (Channel A) for Timer3 without changing the prescaler. For the pulse width parameters do not use the value zero. See Pulse Width Modulation Parameter PW0 pulse width 5.26.1.
383 C-Control Pro IDE PS_1024 (5) 69,44 µs 64 µs 5.26.1.39 Timer_T3PWB Timer Functions Syntax void Timer_T3PWB(word PW1); Sub Timer_T3PWB(PW1 As Word) Description This function sets a new pulse width (Channel B) for Timer3 without changing the prescaler. For the pulse width parameters do not use the value zero. See Pulse Width Modulation Parameter PW1 pulse width 5.26.1.
Libraries PS_1 (1) PS_8 (2) PS_64 (3) PS_256 (4) PS_1024 (5) 67,8 ns 542,5 ns 4,34 µs 17,36 µs 69,44 µs 384 62,5 ns 500 ns 4 µs 16 µs 64 µs 5.26.1.41 Timer_T3PWMX Timer Functions Syntax void Timer_T3PWMX(word period, word PW0, word PW1, byte PS); Sub Timer_T3PWMX(period As Word, PW0 As Word, PW1 As Word, PS As Byte) Description This function initializes Timer_3 with given period duration, prescaler, pulse width for channel A and B. The output signal is generated at PortE.3 (X1_13) and PortE.
385 C-Control Pro IDE Parameter period PW0 PW1 PW2 PS period duration pulse width channel A pulse width channel B pulse width channel C prescaler (see table prescaler) 5.26.1.43 Timer_T3Start Timer Functions Syntax void Timer_T3Start(byte prescaler); Sub Timer_T3Start(prescaler As Byte) Description The timer continues with the already set parameters. The prescaler must be given again. Parameter prescaler prescaler (see table) 5.26.1.
Libraries 386 5.26.1.45 Timer_T3Time Timer Functions Syntax void Timer_T3Time(word Time, byte PS); Sub Timer_T3Time(Time As Word, PS As Byte) Description This function initializes Timer_3 with a prescaler and a timer interval value (16bit), see table. After the timing interval is expired Timer_3 Interrupt (INT_TIM3CMPA) is triggered.
387 C-Control Pro IDE Return Parameter time interval expressed in 10ms ticks Example void main(void) { word time; Timer_TickCount(); AbsDelay(500); // wait 500 ms time=Timer_TickCount(); // the value should be 50 } 5.26.2 AVR32Bit There are 2 timer with 3 channels available in the C-Control Pro AVR32Bit. These will show up in the library as 6 timer.
Libraries 388 word cnt; void count_irq(void) { cnt++; Irq_GetCount(INT_TIMER0); } void main(void) { cnt= 0; Irq_SetVect(INT_TIMER2, count_irq); Timer_ConfigCounter(2, COUNTA_1, CNT_RISING, 300); AbsDelay(10000); Msg_WriteWord(Timer_GetCounterVal(2)); Msg_WriteChar('\r'); while(1); } 5.26.2.2 Frequency Generation On each of the 6 timer channels a rectangular signal can be generated. In the following Example, a 50Hz signal is generated which (see Pin Assignment) is output on pin TIMER0-A and TIMER0-B.
389 C-Control Pro IDE 5.26.2.3 Pulse Width Modulation The C-Control AVR32Bit can output a pulse width modulated signal on up to 4 channels. The following Example 1 will produce a signal of 1.65 MHz period, and 50% duty on PWM channel 1. After 10 seconds, the PWM channel is switched off. The signal is output to pin PWMH_1 and PWML_1 (see Pin Assignment). Example void main(void) { PWM_Init(1, PWM_1, PWM_ENAB_HIGH|PWM_ENAB_LOW); PWM_Update(1, 40L, 20L, 0, 0); AbsDelay(10000); PWM_Disable(1); } 5.26.2.
Libraries 390 To create the mode parameter, the bit values from the table are ORed (see PWM_Example). For a more detailed description of PWMH_x, PWML_x and deadtime, please consult the AT32UC3C data sheet.
391 C-Control Pro IDE During operation the period (frequency), duty (latitude) and deadtime of the PWM signal can be specified. For the frequency, the following formula applies: Frq = 66,000,000 / prescaler / period. Permitted values for duty are 0 to period. A duty of 0 means that the signal is permanently off, wherein a duty of value period means the signal is permanently on. Therefore a duty of 50% is period / 2.
Libraries 5.26.2.8 392 Timer_CPUCycles Timer Functions Syntax dword Timer_CPUCycles(void); Sub Timer_CPUCycles() As ULong Description Measures the CPU cycles between two calls of Timer_CPUCycles () and returns the value at the second call of Timer_CPUCycles (). The return value of the first call can be ignored. Since the processor is clocked at 66Mhz, only periods of up to 65 seconds can be measured. Parameter None Return Parameter CPU cycles between two calls 5.26.2.
393 C-Control Pro IDE Sub Timer_GetCounterVal(timer As Byte) As Word Description Returns the 16-bit counter of a timer. Parameter timer number of timer (0 - 5) Return Parameter counter value 5.26.2.11 Timer_Set Timer Functions Syntax void Timer_Set(byte timer, byte PS, word period, word flags); Sub Timer_Set(timer As Byte, PS As Byte, period As Word, flags As Word) Description This function initializes the timer with the specified prescaler and period, see Table.
Libraries TIM_128 (4) 394 1,939 µs Table flags: Definition TIMFLG_IRQ TIMFLG_PINA TIMFLG_PINB Meaning Interrupts are generated signal is output on pin TIMERx-A signal is output on pin TIMERx-B 5.26.2.12 Timer_TickCount Timer Functions Syntax dword Timer_TickCount(void); Sub Timer_TickCount() As ULong Description Measures the time in 10ms ticks between two calls of Timer_TickCount() and returns the value at the second call of Timer_TickCount(). The return value of the first call can be ignored.
395 5.27 C-Control Pro IDE Webserver (AVR32Bit) The web server of the C-Control Pro AVR32Bit is started with WEB_StartServer. Any TCP/IP port may be selected for this. When the web server starts the number of dynamic variables is defined with whom you want to work. The dynamic variables take the values of the URL variables in the URL, and you can use dynamic variables to output values within web pages.
Libraries 396 URL (CGI) Variables When there are no URL variables specified for a web request, the whole process runs in the background, and there must be no program interaction. If a URL variable is present (e.g. "?var0=5") web server checks if there is variable name that corresponds to the scheme "var" + number. The number must not exceed the maximum index of defined dynamic variables. If the scheme is met, the value "5" is assigned to the dynamic variable. Then the integer variable a gets the value 5.
397 C-Control Pro IDE Web Server Optimization The lwIP TCP / IP stack is optimized to work best with embedded devices that store websites in flash memory. The SD card allows to store much more websites than the flash memory of an embedded controller, but has the disadvantage that the web pages must be between loaded to RAM before they are sent over the Ethernet.
Libraries 398 5.27.3 WEB_GetFileHash Ethernet Functions Syntax word WEB_GetFileHash(byte request); Sub WEB_GetFileHash(request As Byte) As Word Description Returns the 16-bit CRC hash of the file name. The request parameter must be identical to the value that has been obtained from WEB_GetRequest(). Parameter request request parameter Return Parameter 16 Bit CRC hash of the file name (8.3) 5.27.
399 C-Control Pro IDE void WEB_SetDynVar(word indx, ptr var_addr[], byte len); byte type, byte flags, Sub WEB_SetDynVar(indx As Word, var_addr As Pointer, type As Byte, flags As Byte, len As Byte) Description Defines a dynamic variable on its index, address and variable type. The len parameter is important for string variables, other types ignore this parameter. You can specify multiple flags simultaneously by ORing values.
Libraries 400 5.27.6 WEB_StartServer Ethernet Functions Syntax void WEB_StartServer(word port, byte ramaddr[], word dynvar_cnt, word flags); Sub WEB_StartServer(port As Word, ByRef ramaddr As Byte, dynvar_cnt As Word, flags As Word) Description Starts the web server on TCP/IP port port. The parameter dynvar_cnt defines how many dynamic variables can be used. The user should provide a global variable as a buffer.
401 C-Control Pro IDE Description Stops the webserver.
Part 6
403 C-Control Pro IDE 6 FAQ 6.1 General 1. The spelling check does not function. Is the spelling check switched on in Options->Editor? The spelling check does only display spelling errors in the commentaries. The check of any other area would not make sense. 2. Where can be determined whether the new project is a BASIC or C project? There is no difference in project type. The source text files in a project determine which programming language is being used. Files with the extension *.
FAQ 404 There are many developing systems for the Atmel Mega CPU. Some of these Compilers are commercial, others a free. A good example of a free development system is the GNU C-Compiler. You can transfer programs, that you wrote with the GNU C-Compiler, to the Atmel Mega CPU with a AVR ISP programmer. But once you overwrote the installed bootloader, there is no way back, you cannot longer use the C-Control Pro software. 6.2 Mega 1.
405 C-Control Pro IDE 6. How much RAM do I have for my programs? There are 930 bytes left for own programs on the Mega32, on the Mega128 remain 2494 bytes. Interpreter and Debugger are using buffer for interrupt driven I/O, and 256 bytes for the data stack. Beside this resources, there are some internal tables, that are needed for interrupt handling and multitasking. Additionally some RAM Variables are used from library functions. 7.
FAQ 406 3. I need more ports for my hardware application. Many ports are used by other functions. Take a look at the Pin Assignment of the AVR32Bit. You can use all ports that have no special AVR32Bit Module functionality (not connected to I2C, SPI, MACB etc). Do not forget to remove the jumper that connects the port pins to the application board (e.g. for LED's or Button's). Otherwise the behavior can be undetermined. 4.
407 C-Control Pro IDE Index ---- 180, 201 -##define 167 #endif 167 #ifdef 167 #include 167 #pragma 169 -+++ 180, 201 -AAbsDelay 223 AC_Disable 227 AC_Enable 227 AC_InpHigher 228 AComp 225 acos 290 Actualize Variable 150 ADC Example 237 ADC_Disable 230, 233 ADC_Enable 233 ADC_GetValue 235 ADC_GetValues 235 ADC_Read 230 ADC_ReadInt 230 ADC_Set 231 ADC_SetInput 236 ADC_SetInt 232 ADC_Start 236 ADC_StartInt 232 Addition 179, 200 Analog-Comparator 225 And 179, 201 Arithmetic Operators 179, 200 Array 174,
Index Clock_SetTime 247 COM Interface 144 COM Port 161 Comments 171, 193 CompactC 170 Comparison Operators 180, 202 compile 130 compile projects 130 Compiler Presetting 161 Component Parts Plan Mega128 Appl. Board 58 Component Parts Plan Mega32 Appl. Board 49 Conditional Valuation 181 Connection Diagram AVR32 Appl. Board 93 Connection Diagram AVR32 Main Board 100 Connection Diagram AVR32 Module 80 Connection Diagram LCD1602 107 Connection Diagram Mega128 30 Connection Diagram Mega128 Appl.
409 C-Control Pro IDE exp 292 Expressions 171, 193 Ext 277 Ext_IntDisable 279 Ext_IntEnable 278 external RAM 51, 53 -Ffabs 293 FAQ 403 FAQ AVR32Bit 405 FAQ Mega 404 Fax 4 Firewall 160 Firmware 16, 65 float 173 floor 293 For 182, 204 ForceBootloader 224 formatted print 349 FPU 290 Frequency Generation 363 Frequency Measurement 364 Frequenzerzeugung 388 Functions 187, 208 -GGoto 183, 205 GPP 4 greater 180, 202 greater or equal 180, 202 -HHandling 2 Hardware 12, 144 Hardware Version 148 Help 164 History 5
Index Keyboard Layout 156 Keyboard Shortcuts 141 -LLCD Matrix 127 LCD_ClearLCD 284 LCD_CursorOff 285 LCD_CursorOn 285 LCD_CursorPos 286 LCD_Init 286 LCD_Locate 287 LCD_SubInit 283 LCD_TestBusy 283 LCD_WriteChar 288 LCD_WriteCTRRegister 284 LCD_WriteDataRegister 284 LCD_WriteFloat 288 LCD_WriteRegister 288 LCD_WriteText 289 LCD_WriteWord 289 LCD1602 Board 103 ldexp 293 left shift 179, 201 Liability 3 Library Management 134 ln 294 log 294 logical And 180 logical Not 180 logical Operators 180 logical Or 180 l
411 C-Control Pro IDE Port_ToggleBit 305 Port_Write 306 Port_WriteBit 306 Port-Ext-Board 108 pow 295 Precedence 211 predefined arrays 174, 195 Predefined Symbols 168 Preprocessor 167 previous error 130 Print Preview 140 Program 170, 192 Program version 164 Project 130 Project Name 130 project options 133 projectfiles 131 Projects 130 Proxy 160 Pulse Measurement 365 Pulse Width Modulation 364 Pulsweitenmodulation 389 PWM_Disable 389 PWM_Init 389 PWM_Update 390 -Rrand 297 RC5 311 RC5_Init 314 RC5_Read 315
Index SPI switch off 16 SPI_Disable 340, 343 SPI_Enable 341, 343 SPI_Read 341, 344 SPI_ReadBuf 342, 344 SPI_SetChan 345 SPI_Write 342, 345 SPI_WriteBuf 342, 345 sqrt 296 SRAM 51, 53 srand 298 Start Program 145 Static 174, 195 stop bits 161 Str_Comp 346 Str_Copy 347 Str_Fill 347 Str_Isalnum 348 Str_Isalpha 348 Str_Len 349 Str_Printf 349 Str_Printf Example 354 Str_ReadFloat 350 Str_ReadInt 350 Str_ReadNum 351 Str_Substr 351 Str_WriteFloat 352 Str_WriteInt 352 Str_WriteWord 353 Strings 173, 174, 194, 195, 346
413 C-Control Pro IDE Timer_T3GetPM 381 Timer_T3PM 382 Timer_T3PWA 382 Timer_T3PWB 383 Timer_T3PWM 383 Timer_T3PWMX 384 Timer_T3PWMY 384 Timer_T3Start 385 Timer_T3Stop 385 Timer_T3Time 386 Timer_TickCount 386, 394 Tool Settings 162 Tools 153 Transfer 145 Type Conversion 173, 194 While 186, 203 Window 163 Word 173, 194 -UUDP Programmierung 261 UNIT-BUS Exp.