System for separating liquids and solids

AU2020373180B2Pending Publication Date: 2026-07-30SAVING SOLUTIONS SPA
View PDF 3 Cites 0 Cited by

Patent Information

Authority / Receiving Office
AU · AU
Patent Type
Applications
Current Assignee / Owner
SAVING SOLUTIONS SPA
Filing Date
2020-10-22
Publication Date
2026-07-30

AI Technical Summary

Technical Problem

Current methods for separating liquids with dissolved solids and suspending solids in fluids, particularly in industrial and wastewater treatment, require grounded electrodes and are inefficient in terms of energy consumption and space usage, and lack adaptability for diverse fluid conditions.

Method used

A resonance separation system utilizing conductive electrodes in a VLF frequency range within an insulated tank, powered by a microcontroller-driven system that performs electro-coagulation and electro-flocculation without grounded electrodes, allowing for efficient separation of liquids and solids in various fluid conditions using fewer resources.

Benefits of technology

The system effectively separates liquids and solids with reduced energy consumption (20-25% less than traditional methods), adapts to different fluid conditions, and operates without grounded electrodes, enhancing efficiency and adaptability in industrial and wastewater treatment applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 00000001_0000
    Figure 00000001_0000
  • Figure 00000232_0000
    Figure 00000232_0000
  • Figure 00000233_0000
    Figure 00000233_0000
Patent Text Reader

Abstract

The present invention relates to a system with electronic components, for the treatment of high-concentration fluids or solutions, or suspensions with solutes, such as wastewater treatment, the production of valuable elements that form part of a fluid, and sea water desalination, among other processes. The system comprises electrodes, a tank, a solid-state electronic device, an algorithm for managing the system and, optionally, a solid-removing device. The invention also relates to a method for treating fluids or solutions, which generally involves two steps, performed together or sequentially, wherein first dynamic electrocoagulation and subsequently dynamic electrofloculation are carried out to separate liquids and dissolved solids or liquids with solutes from a solution.
Need to check novelty before this filing date? Find Prior Art

Description

RESONANCE SEPARATING SYSTEM FOR LIQUIDS AND SOLIDS FIELD OF APPLICATION This system's field of application includes industrial applications for separating liquids and dissolved solids or liquids with solutes from a solution. Some applications of this technology include industrial water treatment, industrial liquid waste treatment, mining operations liquid treatment (such as electrolytes), agricultural water treatment, seawater treatment for the desalination process, tailings dam treatment for water recovery, settling pond treatment, brackish pond treatment, and brine treatment (such as the lithium carbonate purification process), among others. It should be mentioned that the only condition required of liquids in order to be treated by this technology is that they must have a minimum conductivity of 2 mS / m or more, which is the case in practically all of the above-mentioned cases. DESCRIPTION OF THE PRIOR ART Overall, the state of the art refers specifically to several patents that protect not a particular physical system but a set of devices and methods that enable a particular functionality. There are a number of documents that fall within the general field of liquid waste treatment, with decreases in typical pollution parameters such as BOD5, COD, TSS, fluoride ion removal, among others, through the use of coagulants or flocculants such as aluminum hydroxide or aluminum dioxide, and also through electromagnetic field generation created by a titanium cell coated with mixed oxides, as presented in document WO 2008062171. On the other hand, there is application CN203938560, which mentions a utility model referring to a domestic wastewater treatment system for a ship. The system consists of a wastewater storage tank, a grinding pump, a biochemical reaction device, an electrical flocculation treatment device, a membrane filter, a waste return slot, an incinerator, an electrocatalytic disinfection device, and a power supply control device. There is also Document US201566383, which shows an industrial and / or potable wastewater treatment process and plant through electrochemical methods and advanced oxidation processes, where the main treatment consists of electro- coagulation, electro-oxidation, and electro-flotation through the action of stainless steel, steel, and aluminum metal electrode sets, respectively, with parallel disinfection / oxidation by ozone, UV irradiation, and ultrasonic treatment, as well as recirculation in the electromagnetic field. In addition, there is document US6358398, which points to a method for separating pollutants from an aqueous source containing pollutants. The method uses a dissolved, highly oxidizing powder in the aqueous system, where the method can be enhanced by electro-coagulation. This involves the use of an electrical cell that is disposed of inside the tank containing the oxidizing material. Likewise, there is document RU2008112628, wherein the invention relates to devices for the electrochemical purification of water that can be used in the home for the post-treatment of tap water, as well as for the purification of natural water and the provision of physical and chemical, sanitary, and organoleptic properties for drinking water needs. The device aims at electrochemical water purification. Finally, there is document US6139717, which defines a process and device for treating water. The device has a grounding electrode and a pair of application electrodes connected to a DC voltage source through a register and first and second high frequency switches controlled by a high frequency switching circuit to convert the DC voltage from the DC voltage source to AC voltage to be fed to the application electrodes. The high frequency switching circuit of the command swich is connected to a first high frequency oscillation circuit connected to a control circuit which is controlled by a second high frequency oscillation circuit to provide a signal randomly changing in frequency as an output signal from the first high frequency oscillation circuit. The second high-frequency oscillation circuit also controls a flip-flop circuit connected to the first high-frequency oscillation circuit to add sharp, momentary frequency fluctuation portions into the random frequency change signal of the first oscillation circuit. In general, the entire state of the art is based on applied electro-coagulation and electro-flocculation processes for river and lake waters, where specific grounded electrodes with low structural life were tested. TECHNICAL PROBLEMS RESOLVED BY THIS INVENTION The technical problems that this system intends to solve are based on: Being able to separate liquids with dissolved solids with a minimum of conductivity using frequencies in the VLF band. Being able to separate solids suspended in a fluid using frequencies in the VLF band. Being able to perform electro-coagulation and dynamic electro-flocculation without requiring grounded electrodes to close the circuit and allow current circulation, nor their use as current returns to operate the system of this development. Being able to treat different types of fluids with a single system that adapts to different fluid conditions, so it can be used to treat industrial waters, for seawater desalination for industrial and human consumption, in tailings dam, settling ponds, brackish pond water recovery systems, for liquid recovery in electro-deposition processes, in brines for metal extraction and purification processes (lithium, potassium, sodium, among others), for the treatment of liquid industrial wastes, among others. A system that uses fewer man hours, less physical space, and less energy consumption, between 20% and 25%, than similar water filtration plants or processes, such as reverse osmosis plants. DEVELOPMENT OVERVIEW This development corresponds to a resonance separation system for liquids and solids comprising conductive electrodes (12) that produce electro-coagulation and electro-flocculation phenomena inside an electrically insulated tank where the fluid to be separated is placed. In addition, the system includes the connections of the conductive electrodes to a PCB (Printed Circuit Board), which in turn comprises microcontrollers, an electrical connection, and its operating algorithms, as well as AC / DC power supplies that provide the energy required for the control and separation process. On the other hand, the present development also comprises a method for operating the aforementioned system, where: Pre-evaluation of the liquid: the liquid to be separated is electrochemically evaluated beforehand, where a minimum conductivity of 2 mS / m of the liquid to be separated is required. On the other hand, to identify the type of electrodes to be used, the pH can be measured to determine the acidity of the liquid. For example, if the liquid contains acids, a change of electrodes to titanium electrodes coated with Tantalum, Ruthenium, or other conductive material is required. Resonance separation: With the above information, a suitable frequency program for the electrodes is selected and the conductive electrodes are immersed and activated in the very low frequency (VLF) range, generating a physical change that separates the liquid from the precipitate, leaving it in a condition of indissolubility through the phenomena of electro-flocculation and electro-coagulation (solubility phase change). The activation of the electrodes leads to the generation of 6 specific duty cycles designed for each of the frequencies used, with the system generating energy pulses of less than 2 milliseconds within one duty cycle. Resonance feedback: By measuring the temperature of the liquid and the current in the liquid, the duty cycle frequency parameters are adjusted. Electrode flushing: There is another stage involving frequency inversion in order to better maintain the electrodes used. (It is used at the end of the process and in intermediate stages of the process). Physical Separation: After the resonance separation stages, 3 phases are produced in the tank, flocculated solids on the surface, precipitated solids at the base of the tank, and "clean" liquid in the middle. The flocculated solids are separated by mechanical surface entrainment or overflow, the precipitated solids by decantation, and the liquid from the medium is recovered for reuse. It must be stated that this invention is not limited to the particular methodology, compounds, materials, manufacturing techniques, uses, and applications described herein, as these may vary. It should also be understood that the terminology employed herein is used for the sole purpose of describing a particular embodiment, and is not intended to limit the perspective and potential of this invention. It should be noted that in the use and method, here, in the statement of claims and throughout the text, the singular does not exclude the plural, unless the context clearly implies so. So, for example, the reference to a "use or method" is a reference to one or more uses or methods and includes equivalents known to those familiar with the subject matter (the art). Similarly, as a further example, the reference to "a step”, "a stage" or "a mode" is a reference to one or more steps, stages, or modes and may include implied and / or upcoming sub-steps, stages, or modes. All conjunctions used should be understood in the least restrictive and most inclusive sense possible. Thus, for example, the conjunction "or" should be understood in its orthodox logical sense, and not as an "or excluding”, unless the context or the text expressly requires or indicates it. The structures, materials, and / or elements described must be understood to also refer to those functionally equivalent in order to avoid endless, exhaustive enumerations. Expressions used to indicate approximations or conceptualizations should be understood as such, unless the context dictates a different interpretation. All technical and / or scientific names and terms used herein have the common meaning given to them by an ordinary person qualified in these matters, unless expressly indicated otherwise. Methods, techniques, elements, compounds, and compositions are described, although similar and / or equivalent methods, techniques, compounds, and compositions to those described may be used or preferred in practice and / or when testing this invention. All patents and other publications are incorporated as references, for the purpose of describing and / or reporting, for example, methodologies described in such publications, which may be useful in connection with this invention. These publications are included only for the information they contain prior to the filing date of this patent application. Nothing in this regard should be considered an admission or acceptance, rejection or exclusion, of the entitlement of the authors / inventors to be considered as such, or of such publications being backdated pursuant to previous ones, or for any other reason. In order to provide clarity to the present development, the following concepts will be defined: Conductive electrode: An electrode is an electrical conductor made of materials that allow current to flow through them, used to make contact with a non- metallic part of a circuit. On the other hand, the conductive level electrodes come into contact with a conductive liquid, where a small alternating current begins to flow. The present development uses conductive electrodes from the aluminum, titanium, stainless steel, ruthenium, tantalum, or other conductive material group, preferably aluminum or electrodes coated with, for example, a titanium core coated with tantalum. Electro-flocculation: Agglutination of colloidal substances present in a solution, thus facilitating their decantation and subsequent filtration resulting from the delivery of electrical energy to a solution. Electro-coagulation: Generation of electrical charges on particles or solids dissolved in a solution by delivering electrical energy to this solution in order to generate the conditions for these particles or solids to electrically group together. Duty Cycle: It is the ratio between the time the signal is in active state and the maintenance period of the same signal. Frequency: Frequency is a magnitude that measures the number of repetitions an event can have per unit of time. VLF: Very low frequencies whose wavelength is very large, in the range from 1 Hz to 250 Hz, and their corresponding even subharmonics. DSP : Digital signal processor. Electronic Microcontroller: A microcontroller is an integrated circuit that contains a central processing unit (CPU), memory units (RAM and ROM), input and output ports and peripherals, such as the PIC16F87X microchip® family PIC16F876X, PIC16F877X, PIC16F873X, PIC16F874X, or with similar capabilities, among others. DETAILED DESCRIPTION OF THE INVENTION The system comprises four interacting parts: the electrodes; the controller; the operating algorithm; a tank; and optionally a floc and precipitate extraction device. The abovementioned electrodes range in number from a single pair of electrodes to a number of electrodes meeting the ratio of 0.25 m2 of electrode per m? of tank capacity, preferably 2 conductive electrodes. Conductive electrodes are defined as electrical conductors used to make contact with a non-metallic part of an aqueous solution, which are made of metallic, ceramic composite, or polymeric conductive materials, preferably aluminum, and have a surface area in the range of 0.01 to 2 m2. The electrodes should be positioned at a height of between 5 cm to 25 cm from the base of the container, preferably 10 cm, and at a distance from the container walls of between 10 cm to 50 cm, preferably 40 cm. The electrodes are connected to a solid-state electronic device, which comprises: A. Control module with microcontroller and peripherals (1): This module comprises an integrated control element that is equipped with a microcontroller and peripheral elements (input and output ports, (8 bits or more) analog-to-digital converters, digital-to-analog converters, and internal oscillator outputs, among others). This module stores all the mathematical control programs and algorithms, the generation of the different oscillator frequencies, the different duty cycles and the system operating conditions. The way it works is by receiving power from the power supply (6) and the voltage adaptive programming module (2). The module is characterized by receiving frequency and duty cycle operation information from the voltage adaptive programming module (2) and generating the trigger control signals to be used by the power module (3). Battery-backed power supply module (6): This module has an energy transformation element, a rectifier, which is in charge of transforming the alternating current into direct current and also has a distribution system of the same current, which allows supplying the energy required by the control module (1), and all the rest of the modules. It includes a power backup system (9) to keep critical parameters under control at all times and permanently monitored, even in the event of a power supply voltage variation or total absence of power. Voltage adaptation and programming module (2): This module has two key functions. The first is to externally program the different operating modes without the need to access the PIC microcontroller. This function can be performed by accessing the integrated programming switches (mini Dips) included in this module. To this end, the equipment has an element that, when activated, generates a command response specially designed for this purpose. The second function incorporated in this module consists of adapting the voltages required by the microcontroller for its correct operation. Finally, it is the module in charge of supplying the trigger signals to the power module (3). Power module (3): This module has the specific function to directly feed the conductive electrodes (12). It consists of at least four independent channels (13) mounted on a terminal strip (5) whose signals are isolated from the integrated control element (1). This is done successfully, since the power module (3) has an optical isolation function through opto-couplers. Each channel has a set of high-power transistors that are activated by the signals generated by the integrated control element (1) and adapted by the programming and voltage adaptation module (2). The working algorithm, considering frequency inversion, operates under 6 basic processes that are integrated and related to each other, which are called mode 10, mode 20, mode 30, mode 40, mode 50, and mode 60. On the other hand, the system has the capacity to perform a frequency inversion in order to "flush" the electrodes and thus increase their useful life. The working algorithm, which is able to send the different working modes to the electrodes, achieves a phenomenon called molecular resonance on the suspended solids or dissolved solids of the liquid to be treated, causing these solids to modify their structure, thus achieving their separation. This phenomenon is also called dynamic electro-flocculation or dynamic electro-coagulation. Another phenomenon that occurs in resonance separation is the generation of bubbles by the electrodes, which helps the movement of electro-flocculated or electro-coagulated solids to the tank surface. The system further comprises one or more containers or treatment tanks, non- metallic, preferably plastic, epoxy resins, fiberglass, suitable to support a liquid volume from 0.1 cubic meters to 1 million cubic meters, to be processed in Bach form, without excluding continuous treatment. Containers can be cylindrical, rectangular, conical with decanters, irregular shapes to suit the terrain where they are placed, preferably cylindrical, among others. The tank also comprises inlets and outlets for the liquid to be treated, foam outlets, solids outlet, and optionally a surface floc removal device (16). The system can also optionally include devices to separate the flocs from the surface, among which we can mention paddle separators, rotary separators, overflow separators, although for this development we will preferably use paddle separators. In general, this development is based on the use of frequencies operating in the VLF (Very Low Frequency) band, between 1 Hz and 250 Hz, and their corresponding even subharmonics, where the effects related to the resonance phenomenon are mainly exploited. Thus, by being able to make the solids dissolved in a liquid "resonate", the structural threshold of its composition is exceeded, transforming crystalline structures into amorphous structures. Thus, as the structural bond is modified, it is separated from the liquid and precipitates, usually in a condition of indissolubility. All of the above is complemented by the variation of the specific duty cycles implemented in each of the frequencies used (see figures 5 / 9 and 6 / 9), which in turn are automatically fed back by process variables such as the current, producing modifications in the specific duty cycle, but preserving each specific frequency. The algorithm is also capable of generating new processes and duty cycles in real time, according to the current and temperature measured at the conductive electrodes. Thus, and considering the phase inversion of the frequencies used, the six different basic processes are generated as mentioned above. This same development also includes the system operation procedure, which covers the following stages: a) filling the container with the liquid to be separated up to a spill-proof safety edge; b) measuring pH, temperature, and conductivity of the liquid to be separated outside the system (without precluding that they can be measured internally as part of the data feedback). c) integrating the previously measured data into the algorithm and defining the duty cycle and modes to be applied through the microcontroller and the programming module (2) via its built-in analog and digital inputs; d) activating the solid-state electronic device, providing frequencies in the range of 1 Hz to 250 Hz, preferably in the six system operating modes, where the different modes are assigned according to: i) the measurements of the current flowing through the electrodes, ii) the voltage applied to the electrodes, and iii) the temperature of the liquid to be separated. (As seen in figures 5 / 9 and 6 / 9). The solid-state electronic device begins to sweep through the different modes, where infinitesimal current pulses are produced within each mode to break and reform the ionic and covalent bonds of the solids dissolved in the sample, thus generating larger flocs capable of being separated; e) formation of precipitated and / or electro-coagulated solids for extraction from the target liquid; f) formation of bubbles pushing the electro-flocculate to the surface of the tank; g) removal of the electro-flocculated solid to the surface of the tank, leaving the clean liquid; and h) phase inversion, only with modes 1, 2, and 3, on the electrodes in order to flush them, thus increasing their service life. To describe step d), as an example, if we take the value of 35 in the previous diagram of figure 5 / 9 as reference, we notice that there are 3 modes under this value, mode 10, mode 20, and mode 30. In the same way, if we consider the same value 35, we notice that there are 3 modes above that value, i.e. mode 40, mode 50, and mode 60. This configuration of modes is relevant because the mathematical algorithms can be associated and take a relative reference, differentiating the modes as "positive" or "negative" with respect to the referential value mentioned, e.g., of 35 in the mode diagram. Thus, if we consider that each mode can have an independent duty cycle, which directly influences the power module, and this in turn influences the electrodes and ultimately the electrodes acting directly on the liquid to be separated, we can have different "polarities" associated with different frequencies and different duty cycles. DESCRIPTION OF THE OPERATION OF THE DEVELOPED SYSTEM The liquid or solution to be treated enters the treatment tank (14), through the inlet area of the liquid to be treated (32). Once the liquid has reached the level of the conductive electrodes (12), the solid-state electronic device (15) begins to perform the first operating sequences with the preset modes (fig 5 / 9), taking the reference currents provided by the same conductive electrodes (12) through the programming status of the mini dips (24) and their connectors (30). The conductive electrodes (12) receive the energy provided by the power transistors (17) through their power output terminals (18), whose signals and voltage levels are adapted and activated by the driver command conductor transistors (20). This is done once the microcontroller (1) triggers the programming signal through its pushbutton (29) and the voltage regulators (26) are activated. Thus, the microcontroller (1) measures and analyzes the operating parameters such as the different modes and duty cycles, and starts the treatment process, following the control algorithms (which are described in the following paragraph). Once some time has elapsed (approximately 10 minutes) and the level of the liquid to be treated has reached its maximum level, the foam generated by the treatment itself (dynamic flocculation) is extracted from the treatment tank (14) through the foam outlet area (31). At the end of the desired treatment time, the treated liquid free of solids (dynamic coagulation and precipitation) is extracted from the tank's treated liquid outlet area (31). Likewise, the precipitated solids are extracted through the solids outlet area (34) specially provided for this purpose. As described above, the electrodes are separated by plastic pins and spacers (35) and adjusted by plastic nuts (36) made of non-conductive material. The working algorithm of this development is described below: CCS PCM C Compiler, Version 4.140, 2964 ROM used: 5263 words (64%) Largest free fragment is 2048 RAM used: 90 (24%) at main( level 149 (40%) worst case Stack: 7 worst case (6 in main + 1 for interrupts) * 0200: MOVLW 12 0201: MOVWF OA 0202: GOTO 277 0203: NOP 0204: MOVWF 7F 0205: SWAPF 03. W 0227: MOVF 20. W 0228: MOVWF OA 0229: SWAPF 21. W 022A: MOVWF 03 022B: SWAPF TF. F 022C: SWAPF TF. W 0220: RETFIE 022E: BCF 0A. 3 022F: BCF 0A. 4 0230: GOTO 239 SE Ts sere dene Bloods mai, Co . Hinclude <16F877.h> ceiiieiiaieaeooo [1171 / 77 Standard Header file for the PIG16F877 1 / 11111117111717 Co... ........ Hdevice PIC18F877 Co Hist Co... ....... #device adc=10 ceeiiiiiiioooo...... #fuses XT, NOWDT, BROWNOUT, PUT, NOLVP eee... Huse delay (clock=10000000) * 02BF: MOVLW AE 0200: MOVWF 04 0201: BCF 03.7 0202: MOVF 00. W 0203: BTFSC 03.2 0204: GOTO 2D3 0205: MOVLW 03 0206: MOVWF 78 0207: CLRF 77 0208: DECFSZ 77.F 0209: GOTO 2C8 02CA: DECFSZ 78,F 02CB: GOTO 207 02CC: MOVLW 3C 02C0D: MOVWF 77 02CE: DECFSZ 77.F 02CF: GOTO 2CE 0200: GOTO 2D1 0201: DECFSZ 00, F 0202: GOTO 205 0203: RETURN Co . #include <boot|oader. h> ou, HiT defined PCM #tdefine LOADER END Ox1FF #tdef ine LOADER SIZE Ox1BF iu uu telif defined( PCH #define FLASH_SIZE getenv (“FLASH_ERASE_SIZE™) HE BAAR Hs ED 5 #if ((0x500 % FLASH SIZE) == 0) / / 1F 0x500 is even flash boundary #tidefine LOADER END Ox4FF #tdef ine LOADER SIZE Ox3FF sw ove servis ones 0160 / / ELSE, goto next even boundary ttdefine LOADER END ((Ox500+FLASH_SIZE- (0x500%FLASH SIZE))-1) #tdef ine LOADER SIZE (LOADER _END-0x100) #endif Co #endif i ... ttifndef bootloader oo tif defined PCM TE #bui ld (reset=LOADER_END+1, interrupt=LOADER_END+5) Co... telif defined( PCH TE #bui ld (reset=LOADER_END+1, interrupt=LOADER_END+9) Co #endif vi uriiuiiui....... Borg 0, LOADER_END {} Co Hendif ieeiiiiieeieeeooo.. Hinclude “flex_led. ¢” eiiiiiiiiiiii...... include “system. h” Co ........ tifndef _SYSTEM H Ce ... tdefine _SYSTEM H so define Jeera ieee... / / Hdefine SWI PIN_BO Cu / / tdefine SW2 PIN.B1 civiiiiieiiieo.oo... [ / / #define LED1 PIN_B6 sa sas wears wea ff 50ef ine LEO2 PIN. DB? ee eas envencan ces J18%4 Keypad seiiririiseee....... / / Keypad connection ceiiiiiieiiiieoo.... Hdefine row0 PIN_BO ceiiiiiiiiiiiioo.... define row! PINB ciiiiiiiiiieneo..... Hdefine row2 PIN_B2 veiiiiiiiiiiioo..... Hdefine row3 PIN_B3 ciiiiiiiiiieno...... Hdefine colO PIN_B4 ciiiiiiiiiiiioio.... define coll PIN_BS viiiiiiiiiieioo..... Hdefine col2 PIN_B6 Cu ....... #define col3 PIN B7 Cou. / attdefine colO PIN_BO Co... ......... #Hdefine coll PIN Bil ou... tidefine col2 PIN. B2 eu... .... tidefine col3 PIN _B4 i .... #Hdefine row0 PIN B5 ou... define row! PIN_EO Ce .... tdefine row2 PIN_E1 i .... tidefine row3 PIN _E2 * / Ce / 16x2 LGD Ce . ....] / LCD connection: uu... ....... tHidefine LCD DB4 PIN.D5 Cu... ..... fidefine LCD DB5 PIN. D4 Cu... ..... fidefine LCD DB8 PIN. D3 uu... ....... tidefine LCD DB7 PIN. D2 ee ....... tidefine LCD E PIN D6 Cu... ..... Hidefine LCD. RS PIND7 uu ....... tHidefine LCD RW PIN.D7 vevieiiieieineeoo.. / / 1 you only want a 6-pin interface to your LCD, then teiiiiiiiiineai..o... / / connect the R / W pin on the LCD to ground, and comment iii... / / out the following line. C.J / tdefine USE_LCD RW eiiiiuuiiuuu....... / / External component define here / / ======zz=ooocommoooomoooooToSTT CECT SSCS SSIS SSSSSSSSSCSSSSSSSSSSSSSSSSSSSSSSSSSS Co #endif flex ded Ce uvuu uuu... .... [ / -=====occc=occooo=ooooomoooooos=ssooso=s sous won scar sven RUOFTHS Jed type-2 / / 0=5x7, 1=bx10, 2=2 lines i ... tidefine led line two 0x40 / / LCD RAM address for the 2nd line int8 const LCD INIT _STRING[4] = { 0x20 | (led type << 2), / / Func set: 4-bit, 2 lines, 5x8 dots Oxe, / / Display on 1; / / Clear display 6 / / Increment cursor 1: i meee eee void lcd send nibble(int8 nibble) { Ceiiiiiiiiieaoo... / / Note: Il converts an integer expression iu uuu uu / / to a boolean (1 or 0). output_bit (LCD_DB4, !! (nibble & 1)); 0204: BSF 03.5 0205: BTFSC 35.0 0206: GOTO 2DB 0207: BCF 03.5 02D8: BCF 08.5 0209: GOTO 20D 02DA: BSF 03.5 02DB: BCF 03.5 02DC: BSF 08.5 020D: BSF 03.5 02DE: BCF 08.5 [a _bit(LCD_DB5, !! (nibble & 2)) 02DF: BTFSC 35.1 02E0: GOTO 2ES 02E1: BCF 03.5 02E2: BCF 08.4 02E3: GOTO 2E7 02E4: BSF 03.5 02E5: BCF 03.5 02E6: BSF 08.4 02E7: BSF 03.5 02E8: BCF 08.4 [a _bit(LCD_DBB, !! (nibble & 4)) 02E9: BTFSC 35.2 02EA: GOTO 2EF 02EB: BCF 03.5 02EC: BCF 08.3 02ED: GOTO 2F1 02EE: BSF 03.5 O2EF: BCF 03.5 02F0: BSF 08.3 02F1: BSF 03.5 02F2: BCF 08.3 [a _bit(LCD_DB7, !!l (nibble & 8)) 02F3: BTFSC 35.3 02F4: GOTO 2F9 02F5: BCF 03.5 02F6: BCF 08.2 02F7: GOTO 2FB 02F8: BSF 03.5 02F9: BCF 03.5 02FA: BSF 08.2 02FB: BSF 03.5 02FC: BCF 08.2 delay cycles(1); 02FD: NOP output_high(LCD_E) ; 02FE: BCF 08.6 02FF: BCF 03.5 0300: BSF 08.6 delay us(2): 0301: GOTO 302 0302: GOTO 303 0303: NOP output_low(LCD_E); 0304: BSF 03.5 0305: BCF 08.6 0306: BCF 03.5 0307: BCF 08.6 0308: RETURN FS viviiiiiiiiiiaeo.... / / This sub-routine is only called by lcd_read_byte(). veviiiiiiiieeaoo. / / It's not a stand-alone routine. For example, the veiieiiieieineeoo... / / R / M signal is set high by lcd_read_byte() before Cu uu uuu / / this routine is called. uu... #ifdef USE LCD RW int8 led read nibble (void) { int8 retval: veiiiiiiiiioo....... / / Create bit variables so that we can easily set viiiiiiiiieeeooooo. / / individual bits in the retval variable. Cu... 1ibit retval 0 = retval.0 Ce ....... bit retval 1 = retval.1 uu... 1ibit retval 2 = retval.2 Ce ..... tibit retval 3 = retval.3 retval = 0: evrerirereieneee.. OUtput_high(LCD_E}; er rrieeinneee..... delay_cycles(1}; retval_0 = input (LCD_DB4); retval_1 = input (LCD_DB5) ; retval_2 = input (LCD_DBS) ; retval_3 = input (LCD_DB?); Ceieiiiiiiev...o.... oUtput_low(LCD_E); return(retval) ; Co #endif ss wn ea 4s es ofA em ei iiiviiuuvoi..... / / Read a byte from the LCD and return uu... #ifdef USE LCD RW int8 lcd_read_byte (void) { int8 low: int8 high; Ceiiiiiiiiiii..o..... output_high(LCD_RW): rernrerieneene.... delay _cycles(1}; ei iiiiiiienesn..... high = lcd_read_nibble(); low = lcd _read_nibble() ; return{ (high<<d) | low); Co #endif oi ds SE vn fe ee i iiiiiieue...... / / Send a byte to the LCD. void lod_send_byte(int8 address, int8 n) { Ceieiiiiiiei.o.o.... output_low(LCD_RS); 0309: BSF 03.5 030A: BCF 08.7 030B: BCF 03.5 030C: BCF 08.7 uu... #ifdef USE LCD RW veiiiiiiiiiiiio.o... while(bit_test (lcd_read_byte(},7)) Co Helse ieriieienieae... delay_us (60); 030D: MOVLW 31 030E: MOVWF 77 030F: DECFSZ 77.F 0310: GOTO 30F 0311: GOTO 312 Co Hendif if (address) 0312: BSF 03.5 0313: MOVF 32. F 0314: BTFSC 03.2 0315: GOTO 31B output_high (LCD_RS) ; 0316: BCF 08.7 0317: BCF 03.5 0318: BSF 08.7 So alse 0319: GOTO 31E 031A: BSF 03.5 Ty output_low(LCD_RS) : 031B: BCF 08.7 031C: BCF 03.5 031D: BCF 08.7 evireriiieeiee..... delay_cycles(1); 031E: NOP ceiiiiiiiiiiioo.... Hifdef USE_LCD_RW Ceiiiiiiiieiao..... output_low(LCD_RW) ; eiiiiieeieii...... delay_cycles(1); Co #endif Ceiiiiiiaiei.o..... output_low(LCD_E); 031F: BSF 03.5 0320: BCF 08.6 0321: BCF 03.5 0322: BCF 08.6 ceiiiiiiiiiiioooo... lod_send_nibble(n >> 4); 0323: BSF 03.5 0324: SWAPF 33. W 0325: MOVWF 34 0326: MOVLW OF 0327: ANDWF 34. F 0328: MOVF 34. W 0329: MOVWF 35 032A: BCF 03.5 032B: CALL 2p4 veiiiiiiiiiiioooo... lod_send_nibble(n & Oxf); 032C: BSF 03.5 032D: MOVF 33. W 032E: ANDLW OF 032F: MOVWF 34 0330: MOVWF 35 0331: BCF 03.5 0332: CALL 2p4 0333: RETURN J A void led init (void) { int8 i: viiiiiievieeean..... output_low(LCD_RS); 0334: BSF 03.5 0335: BCF 08.7 0336: BCF 03.5 0337: BCF 08.7 ceiiiiiiieeiooo... difdef USE_LCD_RW vevieiiieiioeo..... output_low(LCD_RW) ; Co #endif Ceiiiiiieieia...... oOUtput_low(LCD_E); 0338: BSF 03.5 0339: BCF 08.6 033A: BCF 03.5 033B: BCF 08.6 sina vin wna Lani G81AY MSLIBY: 033C: MOVLW OF 033D: BSF 03.5 033E: MOVWF 2E 033F: BCF 03.5 0340: CALL 2BF evn www ov enews TOFCED TT € 85 Te) 0341: CLRF 7B 0342: MOVF 7B. W 0343: SUBLW 02 0344: BTFSS 03.0 0345: GOTO 352 Ee BE ERR Ah led_send_nibble (0x03) ; 0346: MOVLW 03 0347: BSF 03.5 0348: MOVWF 35 0349: BCF 03.5 034A: CALL 2Dp4 delay _ms (5); 034B: MOVLW 05 034C: BSF 03.5 034D: MOVWF 2F 034E: BCF 03.5 034F: CALL 2BF 0350: INCF 7B,F 0351: GOTO 342 veiiiiiiiiiiiiooo... lod_send_nibble (0x02) ; 0352: MOVLW 02 0353: BSF 03.5 0354: MOVWF 35 0355: BCF 03.5 0356: CALL 2D4 Wn A WE ERS (i=0; i < sizeof (LCD_INIT_STRING) ; i++) 0357: CLRF 7B 0358: MOVF 7B. W 0359: SUBLW 03 035A: BTFSS 03.0 035B: GOTO 36C PE led_send_byte (0, LCD_INIT_STRING[il): 035C: MOVF 7B. W 035D: CALL 231 035E: MOVWF 7C 035F: BSF 03.5 0360: CLRF 132 0361: MOVF 7C.W 0362: MOVWF 33 0363: BCF 03.5 0364: CALL 309 / / 1f the R / W signal is not used, then / / the busy bit can't be polled. One of / / the init commands takes longer than / / the hard-coded delay of 60 us, so in / / that case, lets just do a 5 ms delay / / after all four of them. #ifndef USE_LCD RW delay _ms (5); 0365: MOVLW 05 0366: BSF 03.5 0367: MOVWF 2E 0368: BCF 03.5 0369: CALL 2BF endif 036A: INCF 7B,F 036B: GOTO 358 036C: BCF 0A. 3 036D: BSF 0A. 4 036E: GOTO 310 (RETURN) J A void led_gotoxy(int8 x, int8 y) { int8 address: ify 1=1) 036F: BSF 03.5 0370: DECFSZ 2F. W 0371: GOTO 373 0372: GOTO 376 ER a SERRA SE address = lcd_|ine_two; 0373: MOVLW 40 0374: MOVWF 30 else 0375: GOTO 377 address=0: 0376: CLRF 130 ............. address += x-1: 0377: MOVLW O01 0378: SUBWF 2E.W 0379: ADDWF 30,F ceiiiiiiiiiiiii.o... led_send_byte (0, 0x80 address); 037A: MOVF 30. W 037B: IORLW 80 037C: MOVWF 31 037D: CLRF 32 037E: MOVF 31. W 037F: MOVWF 33 0380: BCF 03.5 0381: CALL 309 0382: RETURN NY void led_putc (char c) { switch (c) 0383: BSF 03.5 0384: MOVF 2D. W 0385: XORLW 07 0386: BCF 03.5 0387: BTFSC 03.2 0388: GOTO 393 0389: XORLW OB 038A: BTFSC 03.2 038B: GOTO 139A 038C: XORLW 06 038D: BTFSC 03.2 038E: GOTO 3A6 038F: XORLW 02 0390: BTFSC 03.2 0391: GOTO 3AE 0392: GOTO 3BS case '¥a': / / Set cursor to upper left led_gotoxy (1,1); 0393: MOVLW O01 0394: BSF 03.5 0395: MOVWF 2E 0396: MOVWF 2F 0397: BCF 03.5 0398: CALL 36F break: 0399: GOTO 3BC case '¥f': / / Clear display, set cursor to 1 led_send_byte (0,1) ; 039A: BSF 03.5 039B: CLRF 32 039C: MOVLW O01 0390: MOVWF 33 039E: BCF 03.5 039F: CALL 309 delay _ms (2); 03A0: MOVLW 02 03A1: BSF 03.5 03A2: MOVWF 2E 03A3: BCF 03.5 03A4: CALL 2BF break: 03A5: GOTO 3BC case '¥n': / / Go to start of second line led_gotoxy (1,2); 03A6: MOVLW O01 03A7: BSF 03.5 03A8: MOVWF 2E 03A9: MOVLW 02 03AA: MOVWF 2F 03AB: BCF 03.5 03AC: CALL 36F break: 03AD: GOTO 3BC case '¥b': / / Move back one position led_send_byte (0, 0x10) ; 03AE: BSF 03.5 03AF: CLRF 132 03BO: MOVLW 10 03B1: MOVWF 33 03B2: BCF 03.5 03B3: CALL 309 break: 03B4: GOTO 3BC default: led_send_byte(1,¢); 03B5: MOVLW 01 03B6: BSF 03.5 03B7: MOVWF 32 03B8: MOVF 2D. W 03B9: MOVWF 33 03BA: BCF 03.5 03BB: CALL 309 break: 03BC: RETURN ws pn evan ws susan fret iiieliet Co ....... #ifdef USE LCD_RW eiiiiiiiiiiie...... char lod_getc(int8 x, int8 y) { char value: lcd_gotoxy (x,y): eviriiiineeeeeon... / / Wait until busy flag is low. ie... wWhile(bit_test(lcd_read byte), 7D); Ceiiiiiiiiiii..o..... output_high(LCD_RS): ceeiiiiiiiiii.o.o... value = lcd_read_byte(): Ceiiiiiiiieiao..... output_low(lcd_RS); return{value) ; Co Hendif Cu oo. Hinclude “math. h” i ., ttifndef MATH. H uu... tidefine MATH. H a Hifdef PI Co. . #undef PI Co Hendif Co... #Hdefine PI 3. 1415926535897932 Co ............. #define SORT? 1.4142135623730950 ceeiieiiiiiioo.. / / float const ps[4] = {5.9304945, 21.125224, 8.9403076, 0.29730279} ; cevienieaiei. / / float const gs[4] = {1.0000000, 15.035723, 17.764134, 2.4934718} ; coven JII710711171171117111777 Round Functions 117117711771171717711107171717 7 float32 CEIL_FLOOR(float32 x, unsigned int8 n) { float32 vy, res; unsigned int16 |; intl s: s=0: y= Xi if (x <0) s=1: y = -y; if (y <= 32768.0) res = (float32) (unsigned int16)y; else if (vy < 10000000. 0) = (unsigned int16) (y*0.000030517578125) ; y = 32768. 0x (y*0. 000030517578125 - (float32) 1): res = 32768. 0%(float32) |; res += (float32) (unsigned int16)y; else res = vy, y = y - (float32) (unsigned inti16)y; if (s) res = -res. if (y 1=0) if s==18&& n==0) res = 1.0: if s==08&&n="1 res += 1.0: if dx ==0) res = 0: return (res): veviiviieveina.oo... / / Overloaded Functions to take care for new Data types in PCD teiiiiiiiiineao.o... / / Overloaded function CEIL_FLOOR() for data type - Float48 ou, Bif defined PCD floatd8 CEIL_FLOOR (floatd8 x, unsigned int8 n) { floatd8 vy, res; unsigned int32 |; intl s: s=0: y =X, if (x <0) s=1: y = -y; if (y <= 32768.0) res = (float48) (unsigned int16)y; else if (vy < 549755813888. 0) = (unsigned int32) (y*0.000030517578125) ; y = 32768. 0x (y*0. 000030517578125 - (float48) |); res = 32768. 0% (float48) |; res += (float48) (unsigned int16)y; else res =y: y=00; ify 1= 0) y = y - (floatd8) (unsigned int16)y; if (s) res = -res. if (y 1=0) if (s==18& n==20) res -= 1.0: if s==08&&n==1) res += 1.0: if (x == 0) res = 0: return (res); iieeuiiuuui...... / / Overloaded function CEIL_FLOOR() for data type — float64 CEIL_FLOOR (float64 x, unsigned int8 n) { float64 vy, res; intéd |: intl s: s=0 y =X, if (x <0) s=1: y = -y; if (y <= 32768.0) res = (float64) (unsigned int16)y; else if (vy < 4503599627370496. 0) = (int64) (yx0.000030517578125) ; y = 32768. 0x (y*0. 000030517578125 - (float64) |); res = 32768. 0% (f loat64d) | ; res += (float64) (unsigned int16)y; else res = y, y =0.0; ify 1= 0) y = y - (float64) (unsigned int16)y; if (s) res = -res. if (y 1=0) if (s==18& n==20) res —= 1.0: if(s=088&n=1) res += 1.0: if (x == 0) res = 0: return (res); Co #endif JI1117017110071071011117171100001717170171717717017111771107110111711111117 ooo float floor (float x) LIIIII0100007700771710071071117777770117711777711017777111110111171111117 Cu uiuiiiiuuui...... / / Description : rounds down the number x. oo] Date : N / A float32 floor (float32 x) { return CEIL_FLOOR(x, 0); veiiiiiiiiiie.o..... / / Following 2 functions are overloaded functions of floor () PCD veiiiiiiiiiiooooo... / / Overloaded function floor 0 for data type - Float48 Co... if defined( PCD floatd8 floor (float48 x) { return CEIL_FLOOR(x, 0); ieeauieuu....... / / Overloaded function floor} for data type - Float64 float64 floor (float6d x) { return CEIL_FLOOR(x, 0); Co #endif LIIIII0100007700771710071071117777770117711777711017777111110111171111117 oo float ceil (float x) LIIIII0100007700771710071071117777770117711777711017777111110111171111117 Cu uieiiiiuuuu...... / / Description : rounds up the number x. oo] Date : N / A float32 ceil (float32 x) { return CEIL_FLOOR(x, 1); veiiiiiiiiiooo...... / / Following 2 functions are overloaded functions of ceil () for PCD veiiiiiiiiioooooo... / / Overloaded function ceil O for data type - Float48 Co... if defined( PCD floatd8 ceil (floatd8 x) { return CEIL_FLOOR(x, 1); Ce iiiiiiiauesn..... / / Overloaded function ceil (} for data type - Float64 float64 ceil (float6d x) { return CEIL_FLOOR(x, 1); Co Hendif JI1117017110071071011117171100001717170171717717017111771107110111711111117 oo float fabs(float x) JI110710070071700171000710071771717711171777177107771107110711711111117 veiiiiiiiiiee.o..... / / Description : Computes the absolute value of floating point number x uu uu ou / / Returns : returns the absolute value of x Cu uu uuu / / Date 1 N / A Co... ......... #Hdefine fabs abs JI110710070071700171000710071771717711171777177107771107110711711111117 ns wa ta meses = ZF Float fnodFioat xX) LIII1I17107777110771111071771117771770117710777771117717111111111111111117 veiiiiiiiieeea...... / / Description : Computes the floating point remainder of x / y veiiiiiiieiee.o..... / / Returns : returns the value of x= ixy, for some integer i such that, ify teiiiiiiiiiai.o.o... / / is non zero, the result has the same isgn of x na dmagnitude less than the viiiiiiiineeee...... / / magnitude of y. If y is zero then a domain error occurs. oo / / Date : N / A float fmod(float32 x, float32 y) { float3? i: if (y!1=0.0) i=(x / y < 0.0)? ceil (x / y): floor (x / y): return(x-(i*y)) ; else #ifdef ERRNO errno=EDOM: endif veiiiiiiiiiioooo.... / / 0Overloaded function for fmod 0 for PCD veviiiiiiiieiaoo.... / / Overloaded function fmod() for data type - Co... if defined( PCD floatd8 fmod(float48 x, floatd8 y) { floatd8 i: if (y!1=0.0) i=(x / y < 0.0)? ceil (x / y): floor (x / y); return(x-(i*y)) ; else #ifdef ERRNO errno=EDOM: ttendif Ce iiiiiiiauesi..... / / Overloaded function fmod() for data type — float64 fmod(float64 x, float6d y) { floatébd i: if (y!1=0.0) i=(x / y < 0.0)? ceil (x / y): floor (x / y); return(x-(i*y)) ; else #ifdef ERRNO errno=EDOM: ttendif Co Hendif i IIII1177171717111 1 Exponential and logarithmic functions 1 / 111111111111111117 JI110710070071700171000710071771717711171777177107771107110711711111117 iii Sl float exp(float x) JI110710070071700171000710071771717711171777177107771107110711711111117 Ce viiriiuiieii...... / / Description : returns the value (e"x) Cu uu uuu / / Date 1 N / A Co ......... #Hdefine LN2 0.6931471805599453 Co. . tdefine LN2_INV 1.4426950408889634073 civiieiiiiieaooo... float const pe[6] = {0.000207455774, 0.00127100575, 0. 00965065093, 0.0554965651, 0.240227138, 0.693147172} float32 exp (float32 x) { float32 vy, res, r; #if defined PCD int8 datal: #endif signed int8 n; intl s: #ifdef ERRNO if(x > 88.722838) errno=ERANGE : return(Q) ; endif n = (signed int16) (x*LN2_INV); s=0: y= Xi if (x <0) s=1: n=-n y = -y; res = 0.0: Co, tif defined( PCD Sas Fh SAT $A *( (unsigned int8 *) (&res)) = n + Ox7F: Co endif Cu oo... tif defined( _PCD_ / / Takes care of IEEE format datal = n+Ox7F: if(bit_ test (datal, 0)) bit_set (*(({unsigned int8 *) (&res)+2)), 7): rotate_right (&datal, 1); bit clear (datal. 7): Sas Fh SAT $A *(((unsigned int8 *) (&res)+3)) = datal; Co endif y = y#LN2_INV - (float32)n; r = pe[0]*y + pe[1]; r= rey + pel2]; r = rey + pe[3]; r = ry + pe[4]; r = rey + pe[5]; res = resx(1.0 + y*r); if (s) res = 1.0 / res. return(res) ; veiiiiiiiiiioooo.... / / 0Overloaded function for exp() for PCD Ciiiiiiiiiieeoooo. / / Overloaded function exp() for data type - Coo , Bif defined PCD floatd8 exp (floatd8 x) { floatd8 vy, res, r; int8 datal: signed int8 n; intl s: #ifdef ERRNO if(x > 88.722838) errno=ERANGE : return(Q) ; #endif n = (signed int16) (xxLN2_INV); s=0: y= Xi if (x <0) s=1: n=-n y = -y; res = 0.0: datal = n+Ox7F: if(bit_ test (datal, 0)) bit_set (x(((unsigned int8 *) (&res)+4)),7): rotate_right (&datal, 1); bit clear (datal. 7); *(((unsigned int8 *) (&res)+5)) = datal; y = y¥LN2_INV - (floatd48)n; r = pe[0]*y + pe[l]; r = rxy + pe[2]; r = rxy + pe[3]; r= rey + pel4]; r = rxy + pe[5]; res = resx(1.0 + y*xr); if (s) res = 1.0 / res; return(res) ieeaniieuu....... / / Overloaded function exp() for data type - Float64 ceviiiieiiiii... float64 const pe_64

[12] ={9.30741400474913e-011, - 4. 28655416283316e-011, 8 71486547014137e- 009, 9. 84458531538385e-008, 1. 32588296983536e— 006, 1. 52489283823016e-005, 0.000154037598423921, 0.00133335487036216, 0.00961812936407326. 0. 0555041086222122, 0. 240226506962827. 0. 693147180559823) ; float6d exp (float6d x) { float64 vy, res, r; unsigned intl16 datal, data2; unsigned int16 *p; signed int16 n; intl s: #tifdef ERRNO if(x > 709.7827128) errno=ERANGE : return (0); endif y = x*#LN2_INV; n= (signed int18)y; s=0: y= Xi if (x <0) s=1: n=-n y = -y, res = 0.0: tif )defined( PCD AAD VAD BRR SER *((unsigned int16 *) (&res)) =n + Ox7F; Ts. © Lid p= (({unsigned int16 *) (&res))+3); datal = *p; data? = *p; datal = n + Ox3FF: datal = datal <4: if(bit_test(data2 15)) bit set (datal, 15); data? = data? & Ox000F: datal “= data?: *(((unsigned int16 *) (&res)+3)) = datal; y = y¥LN2_INV - (floatéd)n; r = pe_64[0]*y + pe_64[1]; r = r*y + pe_64[2]; r= ry + pe_64[3]; r = r¥y + pe_64[4]; r = r*y + pe_64[5]; r = r*y + pe_64[6]; r = r*y + pe_64[7]; r = r*y + pe_64[8]; r= ry + pe_64[9]; r = r*y + pe_64

[10] ; r = r¥y + pe_64[111; res = resx(1.0 + y*r); if (s) res = 1.0 / res; return(res) Co. ........ HENDIF i [rekklkkleksekisol bik kiko kokok | float32 const pl [4] = {-1.080310025160955, 1.999999947089217) ; float32 const ql [4] = {0.091284365719509, -0.873491916557671}) ; JI110710070071700171000710071771717711171777177107771107110711711111117 iia Sl float log(float x) JI110710070071700171000710071771717711171777177107771107110711711111117 viiiiiiiiiiie.o..... / / Description : returns the the natural log of x uu uu uu / / Date : N / A float32 log(float32 x) { float32 vy, res, r, y2. #if defined(__PCD unsigned int8 datal, data; endif signed int8 n; #ifdef ERRNO if (x <0) errno=EDOM: if (x ==0) errno=ERANGE : return(Q) ; #endif on emo wns wesesonens vw 5 0 ” 0840: MOVF 2B, W 0841: MOVWF 2F 0842: MOVF 2A W 0843: MOVWF 2E 0844: MOVF 20. W 0845: MOVWF 2D 0846: MOVF 28, W 0847: MOVWF 2C BEER Sle SSRN SX 6 if (y=1.0 0848: MOVE 2F. W 0849: MOVWF 40 084A: MOVF 2EW 084B: MOVWF 3F 084C: MOVF 2D, W 084D: MOVWF 3E 084E: MOVF 2G. W 084F: MOVWF 3D 0850: CLRF 44 0851: CLRF 43 0852: CLRF 42 0853: MOVLW TF 0854: MOVWF 41 0855: BCF O0A.3 0856: BCF 03.5 0857: CALL 607 0858: BSF 0A. 3 0859: RBTFSC 03.2 085A: GOTO 21B Co Biff defined( PCD SR Eh ESE Lh 7 *( (unsigned int8 *) (&y)) = OxJE; 085B: BSF 03.5 085C: CLRF 3E 085D: MOVLW AC 085E: MOVWF 3D 085F: MOVF 3D. W 0860: MOVWF 04 0861: BCF 03.7 0862: BTFSC 3E.0 0863: BSF 03.7 0864: MOVLW TE 0865: MOVWF 00 Co #endif uo... #if defined( PCD _) / / Takes care of IEEE data2 = *(({unsigned int8 *) (&y))+3); *(((unsigned int8 *) (&y))+3) = Ox3F; datal = *(({unsigned int8 *) (&y))+2); bit clear (datal, 7): *(((unsigned int8 #*) (&y))+2) = datal; if(bit_test(data2 7)) T_T bit_set (*(((unsigned int8 Co #endif Ci ah ECR SW 9 y= (y-1.0 / (y +10; 0866: BSF 03.1 0867: MOVF 2F. W 0868: MOVWF 44 0869: MOVF 2EW 086A: MOVWF 43 086B: MOVF 2D. W 086C: MOVWF 42 086D: MOVF 2C. W 086E: MOVWF 41 086F: CLRF 48 0870: CLRF 47 0871: CLRF 46 0872: MOVLW TF 0873: MOVWF 45 0874: BCF 0A. 3 0875: BCF 03.5 0876: CALL 648 0877: BSF 0A. 3 0878: MOVF 77.W 0879: BSF 03.5 087A: MOVWF 13D 087B: MOVF 78. W 087C: MOVWF 3E 087D: MOVF 79. W 087E: MOVWF 3F 087F: MOVF 7A W 0880: MOVWF 40 0881: BCF 03.1 0882: MOVF 2F. W 0A 3 03.5 53B 0A. 3 TAW 03.5 %F 79.0 2E 78. W D0 A 20 FW 40 2EW 3F 20.0 3E 2060 3D FW 44 2E.W 43 20.0 42 20, W 41 0A 3 03.5 res = pl [0]*y2 + A 03.5 3D 78. W 3E 79.0 SF JAW 40 03.1 40 W 44 3FW 43 3EW 42 3D W 41 48 47 46 80 45 0A 3 03.5 648 0A. 3 JAW 03.5 23 79.0 32 78. W r = ql [0]*y2 + 40 03.1 40 W 44 3FW 43 3EW 42 33D W 41 2B 48 an 47 DF 46 TE 45 0A. 3 03.5 648 0A. 3 JAW 03 5 37 79.0 36 78. W 35 A 34 r=r + 37.W res = ykres / r; 09A3: MOVF 34. W 09A4: MOVWF 45 09A5: BCF 0A. 3 00A6: BCF 03.5 09A7: CALL 53B 09A8: BSF 0A. 3 09A9: MOVF 7A W 09AA: BSF 03.5 09AB: MOVWF 133 Q9AC: MOVF 79. W 09AD: MOVWF 32 Q9AE: MOVF 78. W 09AF: MOVWF 31 09BO: MOVF 77.W 09B1: MOVWF 30 tif )defined( PCD [a n = *((unsigned int8 x) (&x)) - OX7E: 09B2: CLRF 3E 09B3: MOVLW A8 09B4: MOVWF 3D 09B5: MOVF 3D. W 09B6: MOVWF 04 09B7: BCF 03.7 09B8: BTFSC 3E.0 09B9: BSF 03.7 09BA: MOVLW TE 09BB: SUBWF 00, W 09BC: MOVWF 3C Co #endif ou, Bf defined PCD datal = *(((unsigned int8 *) (&x)+3)); rotate left (&datal, 1); data2 = *(({unsigned int8 *) (&x)+2)); if(bit test (data? 7)) bit set (datal, 0); AAD VAD BRR SER n = datal - Ox7E; Ts. Lid if (n<0) 09BD: BTFSS 3C. 7 Q9BE: GOTO 1D4 Ee BE ERR Ah r = -(float32)-n; Q9BF: MOVF 3C.W 09C0: SUBLW 00 09C1: CLRF 3E 0902: MOVWF 13D 09C3: BTFSC 13D.7 09C4: DECF 3EF 09C5: BCF 0A. 3 09C6: BCF 03.5 09C7: CALL 78E 09C8: BSF 0A. 3 0909: MOVF 77.W 09CA: BSF 03.5 09CB: MOVWF 34 09CC: MOVF 78. W 09CD: XORLW 80 Q09CE: MOVWF 35 Q9CF: MOVF 79. W 09D0: MOVWF 36 09D1: MOVF 7A W 09D2: MOVWF 137 else 09D3: GOTO 1E6 HE BAAR Hs ED 5 r = (float32)n: 09D4: CLRF 3E res += r: QA15: MOVF 78. W Q0A16: MOVWF 31 QA17: MOVF T77.W Q0A18: MOVWF 30 else Q0A19: GOTO 220 OA1A: BCF 03.5 res = 0.0; OAIB: BSF 03.5 QA1C: CLRF 33 QAID: CLRF 132 OA1E: CLRF 31 OA1F: CLRF 30 return(res) 0A20: MOVF 30. W 0A21: MOVWF 77 0A22: MOVF 31. W 0A23: MOVWF 78 0A24: MOVF 32. W 0A25: MOVWF 79 0A26: MOVF 33. W 0A27: MOVWF 7A er iiiiiiiiuu...... [ / 0Overloaded function for log() for PCD ceiiiiiiiiiii.o.o... / / Overloaded function log() for data type — Floatd8 ooo , Bif defined PCD ieeaniieuu....... / / Overloaded function log() for data type - float64 float64 const pl_64[4] = {-0.145694052150681, 1.365485300000370, -3.120535668274329. 2. 000000000000000} float64 const gl_64[4] = {0.006047500465908, -0.208298281937234, 1.113943039156721. -1.893601167470470} floatd8 log (floatd8 x) { floatd8 vy, res, r, y2; unsigned int8 datal, data; signed int8 n; Co... ..... #ifdef ERRNO if (x <0) errno=EDOM: if(x ==0) errno=ERANGE : return (0); Co #endif y =X, if (vy 1=1.0) Co, tif defined( PCD Sas Fh SAT $A *( (unsigned int8 *) (&y)) = OXJE: Co endif data2 = *(((unsigned int8 x) (&y))+5); *(((unsigned int8 #*) (&y))+5) = Ox3F; datal = *(((unsigned int8 x) (&y))+4); bit clear (datal, 7); *(((unsigned int8 #*) (&y))+4) = datal; if(bit_test(data2 7)) bit_set (x(((unsigned int8 *) (&y))+4),7): y=(y-10 / (y+1.0; y2=y*y; res = pl_64[0]xy2 + pl_64[1]; res = resky2 + pl_64[2]; res = resxy2 + pl_64[3]; r = ql_64[0]*y2 + gl_64[1]; r= r¥y2 + ql_64[2]; r= r¥y2 + ql_64[3]; r=rky2 + 1.0; res = yxres / r; datal = *x(((unsigned int8 *) (8x)+5)): rotate left (&datal, 1); data2 = *(((unsigned int8 *) (8x)+4)): if(bit test (data? 7) bit set (datal, 0); n = datal - Ox7E: if (n<0) r = =(floatd48)-n; else r = (floatd48)n; res += rxLN?2: else res = 0.0: return(res) ; float64 log (float6d x) { float64 vy, res, r, y2; unsigned int16 datal, data2; unsigned int16 *p; signed int16 n; #ifdef ERRNO if (x <0) errno=EDOM: if (x ==0) errno=ERANGE : return(Q) ; #endif y =X, if (vy 1=1.0) #if ldefined(_ PCD *( (unsigned int8 *) (&y)) = Ox7E; #endif p= (((unsigned int16 *) (&y))}+3); datal = *p; data2 = *p; datal = Ox3FE: datal = datal <4: if(bit test (data? 15)) bit _set(datal, 15); data? = data? & 0x000F: datal “=data?: *p = datal; y= -1.0 / +1.0; y2=y*y; res = pl_64[0]*y2 + pl_64[1]; res = resxy2 + pl_64[2]; res = resxy2 + pl_64[3]; r = ql_64[0]%y2 + ql_64[1]; r= r*y2 + ql _64[2]; r= r¥y2 + ql_64[3]; r=rx2 + 1.0; res = ykres / r; p= (({(unsigned int16 x) (&x))+3): datal = *p; bit _clear (datal, 15); datal = datal >>4: n = datal - Ox3FE: if (n<0) r = =(float64) -n; else r = (floatéd)n; res += rxLN?2: else res = 0.0; return(res) Co Hendif Co... ..... Hdefine LN10 2.3025850929940456 Co. . tdefine LN10O_INV 0.4342944819032518276 JI110710070071700171000710071771717711171777177107771107110711711111117 iii] float loglO(float x) LIIIII0100007700771710071071117777770117711777711017777111110111171111117 vevieeiiiieio..o.... / / Description : returns the the log base 10 of x Co... .... / / Date : N / A float32 logl0(float32 x) { float32 r: r= log(x): r = r+LN10_INV; return(r): eeeeaiiuu....... / / 0verloaded functions for logl0() for PCD veviriiiiiiise.o.... / / Overloaded function logl10() for data type - Floatd8 ooo oo, Hf defined PCD floatd8 log10(floatd8 x) { floatd8 r: r= logx); r = rxLN10_INV; return(r); eeaaaauu...... / / Overloaded function log10() for data type - Float64 float64 logl0(float6d x) { floatébd r: r= log(x): r = r+LN10_INV; return(r): Co Hendif JI1117017110071071011117171100001717170171717717017111771107110111711111117 oo float modf (float x) JI110710070071700171000710071771717711171777177107771107110711711111117 ieiiiiiiiiiee.o..... / / Description :breaks the argument value int integral and fractional parts, veiiiiiiiiiii.o..... / / ach of which have the same sign as the argument. It stores the integral part i iiiiiienii..... / / as a float in the object pointed to by the iptr vevieiiievein..o.... / / Returns © returns the signed fractional part of value. oo / / Date : N / A float32 modf (float32 value, float32 *iptr) { *iptr=(value < 0.0)? ceil (value): floor (value); return{value - *iptr) veiiiiiiiiiioooo.... / / Overloaded functions for modf() for PCD veiiiiiiiiiiii...... / / Overloaded function modf() for data type — Float48 Cu... Bif defined PCD floatd8 modf (floatd8 value, floatd8 *iptr) { *iptr=(value < 0.0)? ceil (value): floor (value): return(value - *iptr) ; iieeiuieauu...... / / Overloaded function modf(}) for data type - Float64 float64 modf (float64 value, float64 *iptr) { *iptr=(value < 0.0)? ceil (value): floor (value): return(value - *iptr) ; Co Hendif JI1117017110071071011117171100001717170171717717017111771107110111711111117 Co ooo float pwr (float x, float y) JI110710070071700171000710071771717711171777177107771107110711711111117 Cu iuuiiiiiuiu ..... / / Description : returns the value (x'y) Cu uu uuu / / Date 1 N / A veiiiiiiiiiiooooo... / / Note 1 0 is returned when the function will generate an imaginary number float32 pwr (float32 x, float32 y) { if(0 > x && fmod(y, 1) == 0) | if (fmod(y, 2) == 0) { return (exp{log(-x) * y)); } else { return (exp (log(-x) * y)): } else if(O> x && fmod(y, 1) = 0) | return 0: } else { ifx 1201] 0>=y) | return (exp(log (x) * y)); ieeaiiiau....... / / 0verloaded functions for pwr for PCD viviiiviineena..o.... / / Overloaded function pwr) for data type - Float48 ooo tif defined PCD floatd8 pwr (float48 x, floatd8 y) { if > x & fmod(y, 1) == 0) | if(fmod(y, 2) == 0) { return (exp(log (=x) * y)); } else { return (—exp(log(=x) * y)). } else if(0> x & fmod(y, 1) 1=0) { return 0: } else { ifx 1201] 0>=y) | return (exp(log (x) * y)); Ce iiiiiiiuueun..... / / Overloaded function pwr) for data type - Float64 float64 pwr (float6d x, floatéd y) { if > x & fmod(y, 1) == 0) | if(fmod(y, 2) == 0) { return (exp(log (=x) * y)); } else { return (—exp(log(=x) * y)). } else if(O> x && fmod(y, 1) = 0) | return 0: } else { fx 1=0 1] 0>=y) | return (exp{log(x) * y)); Co Hendif I IS2222222217117 117 Power functions / / / / / 11117111111111 17 JI110710070071700171000710071771717711171777177107771107110711711111117 iii) float pow(float x, float y) LIIIII0100007700771710071071117777770117711777711017777111110111171111117 Cui. ....... / / Description : returns the value (x'y) Cu uu uuu / / Date 1 N / A veiiiiiiiiiiooooo... / / Note 1 0 is returned when the function will generate an imaginary number float32 pow (float32 x, float32 vy) { if(0 > x && fmod(y, 1) == 0) | if (fmod(y, 2) == 0) { return (exp{log(-x) * y)); } else { return (exp (log(-x) * y)): } else if(O> x && fmod(y, 1) = 0) | return 0: } else { ifx 1201] 0>=y) | return (exp(log (x) * y)); ieeuiiiau....... / / 0verloaded functions for pow() for PCD veiiiiiiiieisa.o.... / / Overloaded function for pow() data type - Float48 ooo oo, Hf defined PCD floatd8 pow (float48 x, floatd8 y) { if > x & fmod(y, 1) == 0) | if(fmod(y, 2) == 0) { return (exp(log (=x) * y)); } else { return (—exp(log(=x) * y)). } else if(0> x & fmod(y, 1) 1=0) { return 0: } else { ifx 1201] 0>=y) | return (exp(log (x) * y)); ieeaniieuu....... / / Overloaded function pow() for data type - Float64 float64 pow(float64 x, float6d y) { ifO > x & fmod(y, 1) == 0) { if (fmod(y, 2) == 0) { return (exp{log(-x) * y)); } else { return (—exp(log(=x) * y)). } else if(0> x & fmod(y, 1) 1=0) { return 0: } else { ifx 1201] 0>=y) | return (exp(log (x) * y)); Co Hendif JI1117017110071071011117171100001717170171717717017111771107110111711111117 iii J] float sart(float x) JI110710070071700171000710071771717711171777177107771107110711711111117 Ceiiiiiiiiioe.o..... / / Description : returns the square root of x uu uu uu / / Date : N / A float32 sqrt (float32 x) { float32 vy, res; #if defined(__PCD unsigned inti16 datal, data2; endif unsigned int8 *p; #ifdef ERRNO if(x <0) errno=EDOM: ttendif if ( x<=0.0) return(0.0) y=, #if ldefined(_ PCD p=Ry; (*xp)=(unsigned int8) ({((unsigned int16) (+p)) + #endif #if defined PCD p = (((unsigned int8 *) (&y))}+3); datal = *(({unsigned int8 *) (&y))+3); data2 = *(((unsigned int8 x) (&y))+2); rotate left (&datal, 1); if(bit_test(data2, 7)) bit _set(datal, 0); datal = ({(datal+127) >>1); bit clear (data? 7); if (bit test (datal, 0)) bit _set (data? 7); datal = datal >>1: *(((unsigned int8 x) (&y))+3) = datal; *(((unsigned int8 #*) (&y))+2) = data2; endif do | res=y, y+=(x / y) ; #if l!defined(_ PCD (xp) == ttendif #if defined(__PCD datal = *(((unsigned int8 *) (&))+3): data2 = *(((unsigned int8 *) (&))+2): rotate left (&datal, 1); if(bit_test(data2, 7)) bit _set(datal, 0); datal--: bit clear (data2, 7); if(bit test (datal 0)) bit _set(data2 7): datal = datal >>1: *(((unsigned int8 x) (&y))+3) = datal; *(((unsigned int8 #*) (&y))+2) = data2; #endif } while(res |= vy); return(res) ; ceiiiiiiiiiii.o..o... [ / / Overloaded functions for sart() for PGD veiiiiiiiiineao.o... / / Overloaded function sqrt () for data type - Float48 ou, Bif defined PCD floatd8 sqrt (floatd8 x) { floatd8 vy, res; unsigned intl16 datal, data2; unsigned int8 *p; #ifdef ERRNO if(x <0 errno=EDOM: ttendif if ( x<=0.0) return(0.0) y=, #if !defined( PCD p=8&y; (*p)=(unsigned int8) ((((unsigned int16) (xp)) + 127) #endif #if defined PCD p = (((unsigned int8 *) (&y))+5); datal = *(({unsigned int8 *) (&y))+5); data2 = *(({unsigned int8 x) (&y))+4); rotate left (&datal, 1); if(bit_test(data2, 7)) bit _set(datal, 0); datal = ((datal+127) >D>1); bit clear (data2, 7); if(bit_test(datal, 0)) bit _set(data2 7): datal = datal >>1: *(((unsigned int8 x) (&y))+5) = datal; *(((unsigned int8 #*) (&y))+4) = data2; #endif do { res=y,; y+=(x / y); #if l!defined(_ PCD (xp) == ttendif datal = *x(((unsigned int8 *) (&y))+5): data2 = *(((unsigned int8 *) (&y))+4): rotate left (&datal, 1); if(bit_test(data2, 7)) bit _set(datal, 0); datal--: bit clear (data? 7); if (bit test (datal, 0)) bit _set (data? 7); datal = datal >>1: *(((unsigned int8 *) (&))+5) = datal: *(((unsigned int8 #*) (&y))+4) = data2; } while(res |= vy); return(res) ; ieeeuuieuuu...... / / Overloaded function sqrt() for data float64 sqrt (floatéd x) { float6d4 y, res; unsigned int16 *p; unsigned int16 tempi, temp2; #ifdef ERRNO if(x <0) errno=EDOM: endif if( x<=0.0) return(0.0) ; y=, p= (((unsigned int16 *) (&y))}+3); templ = *p; temp2 = *p; bit _clear (templ, 15); templ = (tempi>>4) +1023; templ = temp! >> 1; templ = (tempi<<4) & OxFFFQ; if(bit_test (temp2 15)) bit_set (templ, 15) ; temp2 = temp2 & Ox000F; templ “= temp2; (*p) = tempi; do | res=y, y+=(x / y) ; templ = *p; temp2 = *p; bit_clear (tempi, 15) ; templ = (tempi>>4) ; templ—; templ = (tempi1<<4) & OxFFFQ; if(bit_test (temp2, 15)) bit_set (tempi, 15) ; temp2 = temp2 & 0x000F; templ “= temp2; (xp) = templ; } while(res |= vy); return(res) Co #endif even AIII11111717117111111711 Trig Functions 1 / 1171117117177117111117771117 i ... ttifdef PI DIV BY TWO INV uu. ...... #undef PI DIV BY TWO INV Co #endif ceeeeeieeiiiii.... Hdefine PI_DIV_BY_TWO_INV 0.63661977236758134 Ce ..... ttifdef PI DIV BY TWO Ce... ... Hundef PI DIV BY TWO Co #endif uu... .... Hdefine PI DIV. BY TWO 1.5707963267948966 Co #ifdef TWOBYPI Co... ..... #tundef TWOBYPI Co Hendif Co... ..... #Hdefine TWOBYPI 0.6366197723675813 JI110710070071700171000710071771717711171777177107771107110711711111117 a was Sa wes eans = ZF Float cosiflodt © LIIIII0100007700771710071071117777770117711777711017777111110111171111117 teiiiiiiiiiie.o..... / / Description : returns the cosine value of the angle x, which is in radian Co] Date : 9 / 20 / 2001 float32 cos (float32 x) { float32 vy, t, t2 =1.0; unsigned int8 quad, i: float3?2 frac: [ —— float32 p[5] = / / by the series definition for cosine iE WER Uk WR 5 -0. 49999999456337096, / / sum ( ( (=1)"n * x"2n Y / @n)! ) 0. 04166663896921267, -0.00138883894522527 0. 00002476138231734, -0. 00000026070414770 / 7-0. 00000000001147, / / 0. 00000000000005 Ty if (x <0) x=-x; / / absolute value of input quad = (unsigned int8) (x * PI_DIV_BY_TWO_INV): / / quadrant 3 STE Ve CVT ERRS TE frac = (x * PI_DIV_BY_TWO_INV) - quad: / / fractional part of input quad = quad % 4; / / quadrant (0 to 3) if (quad == 0 || quad == 2) = frac * PI DIV BY TWO; else if (quad == 1) = (1-frac) * Pl DIV _BY TWO; else / / should be 3 = (frac-1) * PI_DIV_BY_ TWO; y=1.0; =t1 = t for (i =0; i <4; i+) 12 =12 x t: y=vy+ pli] * 12; if (quad == 2 || quad == 1) y = -y, / / correct sign return (vy); i . ..... J / 0verloaded functions for cos(} for PCD veiiiiiiiiiiooooo... / / Overloaded function cos() for data type - Float48 Coo , Bif defined PCD floatd48 cos (floatd48 x) { floatd8 vy, t, t2 = 1.0; unsigned int8 quad, i; floatd8 frac: Ch SR SA SRR § float48 pl6] = / / by the series definition for cosine Si RIED Kh RHRRRE 4 -0.5, / / sum ( ( (=1)"n * x"2n Y / @n!) 0.04166666666667 -0.00138888888889, 0. 00002480158730, -0. 00000027557319, 0. 00000000208767, / / -0. 00000000001147, / / 0. 00000000000005 Ty if (x <0) x=-x; / / absolute value of input quad = (unsigned int8) (x * PI_DIV_BY TWO_INV); / / quadrant 3 STE Ve CVT ERRS TE frac = (x * PI_DIV_BY_TWO_INV) - quad: / / fractional part of input quad = quad % 4; / / quadrant (0 to 3) if (quad == 0 || quad == 2) = frac * PI DIV BY TWO; else if (quad == 1) = (1-frac) * PI DIV BY TWO; else / / should be 3 = (frac-1) * PI_DIV_BY_ TWO; y = 0.999999999781; =t1 = t for (i =0: i <5; i+) 12 =12 x t: y=vy + pli] *t2; if (quad == 2 || quad == 1) y = -y, / / correct sign return (vy); ieeaiiieau....... / / Overloaded function cos() for data type - Float64 float64 cos (float64 x) { float6d y, t, t2 =1.0; unsigned int8 quad, i; floatbd frac: TT float64 p_64[9] = { / / by the series definition for cosine iE WER Uk WR 5 -0. 49999999999998740, / / sum ( ( (=1)"n * x"2n Y / @n)! ) 0.04166666666656518. -0.00138888888851691, 0. 00002480158658490 -0. 00000027557239796. 0. 00000000208715031. -0. 00000000001126577. 0. 00000000000000427, 0. 00000000000000372} : if (x <0) x=-x; / / absolute value of input quad = (unsigned int8) (x * PI_DIV_BY_TWO_INV): / / quadrant + EER Sh CHET RE frac = (x * PI_DIV_BY TWO_INV) - quad: / / fractional part of input quad = quad % 4; / / quadrant (0 to 3) if (quad == 0 || quad == 2) = frac * PI DIV BY TWO; else if (quad == 1) = (1-frac) * Pl DIV _BY TWO; else / / should be 3 = (frac-1) * Pl DIV _BY_ TWO; y=1.0; =t1 = t for (i =0; i <8; i+) 12 =12 x t: y= y+ p_64[i] * t2; if (quad == 2 || quad == 1) y = -y, / / correct sign return (vy); Co Hendif JI1117017110071071011117171100001717170171717717017111771107110111711111117 i oo] float sin(float x) LIIIII0100007700771710071071117777770117711777711017777111110111171111117 vevieiiieeeioa.o.... / / Description : returns the sine value of the angle x, which is in radian Co] Date : 9 / 20 / 2001 float32 sin(float32 x) { return cos (x - PI DIV BY TWO): Cu .. / / 0ver loaded functions for sin() for PCD teiiiiiiiiiniao.o... / / Overloaded function sin() for data type — Floatd8 ooo Hf defined PCD floatd8 sin(float48 x) { return cos (x = PI DIV BY TWO): ieeaiiieau....... / / Overloaded function sin() for data type - Float48 float64 sin(float6d x) { return cos (x - PI DIV BY TWO): Co #endif JI110710070071700171000710071771717711171777177107771107110711711111117 a was Sa wes eans = ZF Float taniflode © LIIIII0100007700771710071071117777770117711777711017777111110111171111117 vevieiiieeeio..o.... / / Description : returns the tangent value of the angle x, which is in radian Cu uu uu / / Date 9 / 20 / 2001 float32 tan(float32 x) { float32 ¢, s; ¢ = cos(x): if (¢c ==0.0) return (1.0e+36) ; s = sin); return(s / c) ciiiiiiiiiiiiooo.. / / 0verloaded functions for tan() for PCD veiiiiiiiiiooooo.... / / Overloaded function tan() for data type - oo Hf defined PCD floatd8 tan(float48 x) { floatd8 ¢, s; ¢ = cosx): if (¢ == 0.0) return (1.0e+36) ; s = sin); return(s / c) vieeeaiiuau....... / / Overloaded function tan(}) for data type - float64 tan(float64 x) { float64 ¢, s; ¢ = cosx): if (¢ == 0.0) return (1.0e+36) ; s = sin); return(s / c) Co Hendif float32 const pas[3] = {0.49559947, -4.6145309, 5.6036290}; float32 const gas[3] = {1.0000000, -5.5484666, 5.6036290}; float32 ASIN COS (float32 x, unsigned int8 n) { float32 y, res, r, y2. intl s: #ifdef ERRNO fx <1 x>10 errno=EDOM: ttendif s=0: y =X, if (x <0) s=1: y = -y, if (y> 0.5) y = sqrt ((1.0 - y)*0.5) ; n+= 2: y2=yky | res = pas[0]*y2 + pas[1]; res = resxy2 + pas(2]; r = gas[0]*y2 + gas[1]; r = r*y2 + gas[2]; res = ykres / r; if n&2 J Ixl > 0.5 res = Pl DIV BY TWO — 2.0xres: if (s) res = -res. if n&1 / / take arccos res = Pl DIV BY TWO - res; return(res) ; veiiiiiiiiiooooo.... / / 0Overloaded functions for ASIN_COS() for PCD veiiiiiiiiieia.o.... / / Overloaded function ASIN_COS() for data type — Cu... Bif defined PCD floatd8 ASIN COS (floatd8 x, unsigned int8 n) { floatd8 vy, res, r, y2; intl s: #ifdef ERRNO fx <1] x>1 errno=EDOM: ttendif s=0: y= Xi if (x <0) s=1: y = -y; if (y> 0.5) y = sqrt ((1.0 = y)%0.5); n+= 2: y2=yky | res = pas[0]*y2 + pas[1]; res = resxy2 + pas(2]; r = gas[0]*y2 + gas[1]; r = r*y2 + gas[2]; res = ykres / r; if n&2) 7 / 7 |x| > 0.5 res = PI_DIV_BY_TWO - 2. Oxres: if (s) res = -res. if (n&1) / / take arccos res = Pl DIV BY TWO - res; return(res) ; veiiiiiiiiioooooo... / / Overloaded function ASIN_COS(O) for data type - Float64 Ce viiriiiiieiiio.... double pas_64[51={1.000000000000000, - 2.069938587724477, 1. 421444580548907, -0. 360690137621842, 0. 024929451660228} ; Ciiiiiiiiii....... double qas_84[5]={-2. 236605254391134, 1. 719212122946451, - 0.524122954476133, 0. 052808872045749, -0. 000662536036570} ; float64 ASIN_COS (float64 x, unsigned int8 n) { float64 y, res, r, y2. intl s: #tifdef ERRNO fx <1 x>10 errno=EDOM: #endif s=0 y =X, if (x <0) s=1: y = -y; if (y> 0.5) y = sqrt ((1.0 - y)#0.5); n+ 2; y2=yky | res = pas_64[4]*y2 + pas_64[3]: res = resky2 + pas_64[2]; res = resky2 + pas_64[1]; res = resky2 + pas_64[0]; r = qas_64[4]*y2 + qas_64[3]; r = rky2 + gas_64[2]. r = r¥y2 + gas_64[1]; r = rky2 + gas_64[0]; r=rky2 + 1.0; res = ykres / r; if n&2 J Ixl > 0.5 res = Pl DIV BY TWO — 2.0xres: if (s) res = -res. if n&1 / / take arccos res = Pl DIV BY TWO - res; return(res) ; Co Hendif JI110710070071700171000710071771717711171777177107771107110711711111117 nn wa ma meses = ZF Float asinioat xX) JI110710070071700171000710071771717711171777177107771107110711711111117 Ceiiiiiiiiiee.o..... / / Description : returns the arcsine value of the value x uu uu uu / / Date : N / A float32 asin(float32 x) { float32 r: r = ASIN COS(x. 0): return(r): veiiiiiiiiiioooo.... / / Overloaded functions for asin() for PCD veiiiiiiiiiiii...... / / Overloaded function asin() for data type — Float48 Cu... Bif defined PCD floatd8 asin(floatd8 x) { floatd8 r: r = ASIN COS(x, 0): return(r); i iiiiiiiauesi..... / / Overloaded function asin() for data type - Float64 float64 asin(float6d x) { floatéd r: r = ASIN COS(x, 0): return(r): Co Hendif JI110710070071700171000710071771717711171777177107771107110711711111117 ns wa ta meses = ZF Float jacosFioat xX) LIIIII0100007700771710071071117777770117711777711017777111110111171111117 vevieiiieiiio..o.... / / Description : returns the arccosine value of the value x. Co] Date : N / A float32 acos(float32 x) { float32 r: r = ASIN. COS(x, 1); return(r); . ..... J / 0verloaded functions for acos() for PCD veiiiiiiiiioooooo... / / Overloaded function acos() for data type - Float48 Co... if defined( PCD floatd48 acos(floatd8 x) { floatd8 r: r = ASIN COS(x. 1): return(r): iieeiuieauu...... / / Overloaded function acos(}) for data type - Float64 float64 acos(float6d x) { floatébd r: r = ASIN. COS(x, 1); return(r); Co Hendif ceviiiieiiieii... float32 const pat[4] = {0.17630401, 5.6710795, 22.376096, 19. 818457} ; ceviiiieiiieii... float32 const gat[4] = {1.0000000, 11.368190, 28.982246, 19. 818457} ; JI1117017110071071011117171100001717170171717717017111771107110111711111117 oo] float atan(float x) JI110710070071700171000710071771717711171777177107771107110711711111117 Ceiiiiiiiiiee.o..... / / Description : returns the arctangent value of the value x uu uu uu / / Date : N / A float32 atan(float32 x) { float32 vy, res, r; intl s, flag; s=0: flag = 0; y =X, if (x <0) s=1: y = -y; if (y> 1.0 y = 1.0 / y; flag = 1; res = pat[0]*yxy + pat[1]; res = resxyky + pat[2]; res = resxyky + pat[3]; r = qat[0]*yxy + qat[1]; r = rkyky + gat[2]; r = rxyky + gat[3]; res = ykres / r; if (flag) / / for |x| > res = Pl DIV BY TWO - res; if (s) res = -res. return(res) ; ciiiiiiiiiiiiooo.. / / 0verloaded functions for atan() for PCD veiiiiiiiiiooooo.... / / Overloaded function atan() for data type - Float48 oo Hf defined PCD floatd48 atan(floatd8 x) { floatd8 vy, res, r; intl s, flag; s=0 thag =z 0: y= Xi if (x <0) s=1: y = -y, if (y> 1.0 y = 1.0 / y; flag = 1; res = pat[0]*yxy + pat[1]; res = resxyky + pat[2]; res = resxyky + pat[3]; r = qat[0]#y+y + qat[1]; r = rxyky + gat[2]; r = rxyky + gat[3]; res = ykres / r; if (flag) res = PI_DIV_BY_TWO - res: if (s) res = -res. return(res) float6d pat_64[6]={0. 999999999999999, 2. 249923645595566, 1. 771541617806449, 0.579678874003185, 0. 072162702162882, 0. 002281100141660} ; float6d gat_64[6]={2. 583256978928510, 2. 432627277466967, 1. 016760379885393, 0. 182482977188688, 0. 011155377971690, 0. 000100013019160} ; ieeiiiui i... ... / / Overloaded function atan() for data type - float64 atan(float6d x) { float64 vy, v2, res, r; intl s, flag; s=0: flag = 0; y =X, if (x <0) s=1: y = -y; if (y> 1.0) y = 1.0 / y; flag = 1; y2 = yky, res = pat_64[5]*y2 + pat_64[4]; res = resky2 + pat_64[3]; res = resky2 + pat_64[2]; res = resky2 + pat_64[1]; res = resky2 + pat_64[0]; r = gat_64[5]*y2 + gat _64[4]; r = r¥y2 + gat_64[3]; r = rky2 + gat_64[2]; r = r¥y2 + gat_64[1]; r = rky2 + gat_64[0]; r=rky2 + 1.0; res = ykres / r; if (flag) / / for |x| > 1 res = Pl DIV BY TWO - res; if (s) res = -res. return(res) Co #endif JIII011100700710011100171107177777711007171717711771100111111111111711117 iii) float atan2(float y, float x) LIIII110707700717101077107701177177010017710777170117171111111111111111117 vevieiiieiiioe..o.... / / Description computes the principal value of arc tangent ¢ y / X, using the vevieiiiereinaooo... / / signs of both the arguments to determine the quadrant ¢ return value veiiiiiiiiee..o.... / / Returns : returns the arc tangent of y / x via as wines vas eww off Date 7 N / A float32 atan2(float32 vy, float32 x) { floatl3? z: intl sign; unsigned int8 quad; sign=0; quad=0; / / quadrant quad=((y<=0. 0)? ((x<=0.0)?3:4) : ((x£0.0)?2:1)); if (y<0.0) sign=1; y=-y. if (x<0.0) X==X. if (x==0.0) if (y==0.0) #tifdef ERRNO errno=EDOM: #endif return (-(P1_DIV BY _TWO)): else return (PI DIV _BY_ TWO): else z=y / X, switch (quad) case 1: return atan(z): break: case 2: SO return (atan(z)+Pl DIV BY / / 21.3122 return (Pl-atan(z)): break: case 3: return (atan(z)-Pl); return (-atan(z)): break: veiiiiiiiiiioooo.... / / 0Overloaded functions for atan2() for PCD veiiiiiiiiini.o.o... / / Overloaded function atan2() for data type - Floatd8 ou, Bif defined PCD floatd8 atan2 (floatd8 vy, floatd8 x) { floatd8 z: intl sign; unsigned int8 quad; sign=0; quad=0; / / quadrant quad=((y<=0. 0)? ((x<=0.0)?3:4) : ((x£0.0)?2:1)); if (y<0.0) sign=1; y=-y, if (x<0.0) X==X. if (x==0.0) if (y==0.0) #tifdef ERRNO errno=EDOM: ttendif else if(sign) return (-(P1_DIV BY _TWO)): else return (P1_DIV_BY_TWO); else z=y / X. switch (quad) case 1: return atan(z); break: case 2: SO return (atan(z)+Pl DIV BY / / 21.3122 return (Pl-atan(z)): return (atan(z)-Pl); break: case 4: return (-atan(z)): break: ieeauieuu....... / / Overloaded function atan2(}) for data type - Float64 float64 atan2(float64 y, float64 x) { floatébd z: intl sign; unsigned int8 quad; sign=0; quad=0; / / guadrant quad={(y<=0. 0)? ((x<=0. 0) 23:4) : ((x<0.0)?2:1)); if (y<0.0) sign=1; y=-y, if (x<0.0) X==X. if (x==0.0) if (y==0.0) #tifdef ERRNO errno=EDOM: ttendif else if(sign) return (-(P1_DIV_BY_TWO)): else return (P1_DIV_BY_TWO); else 2=y / X, switch (quad) case 1: return atan(z); SO return (atan(z)+Pl1 DIV BY TWO): / / 2L3122 return (Pl-atan(z)): break: case 3: return (atan(z)-PI): break: case 4: return (-atan(z)): break: Co Hendif a S11111111771117777) Hyperbolic functions / / / / / / / 1111111111]] / JI110710070071700171000710071771717711171777177107771107110711711111117 ns wa ta meses = ZF Float coshiFioat x) LIIIII0100007700771710071071117777770117711777711017777111110111171111117 veviiiiiiieee....... / / Description : Computes the hyperbolic cosine value of x veiiiiiiiiiee.o..... / / Returns : returns the hyperbolic cosine value of x Cu uu uuu / / Date : N / A float32 cosh(float32 x) { return ((exp (X)+exp (-x))*0. 5) ; ciiiiiiiiiiiiooo.. / / 0verloaded functions for cosh() for PCD veiiiiiiiiineao.o... / / Overloaded function cosh() for data type - Float48 ou, Bif defined PCD floatd8 cosh (floatd8 x) { return ((exp (X)+exp (-x))*0. 5) ; i iiiiiiiauesi..... / / Overloaded function cosh() for data type - Float64 float64 cosh(float6d x) { return ((exp (x)+exp(-x))*0.5); Co Hendif JI1117017110071071011117171100001717170171717717017111771107110111711111117 oo] float sinh(float x) JI110710070071700171000710071771717711171777177107771107110711711111117 vevieiiieieiie.o.... / / Description : Computes the hyperbolic sine value of x veiiiiiiiiiee.o..... / / Returns : returns the hyperbolic sine value of x Cu uu uuu / / Date : N / A float32 sinh(float32 x) { return ((exp (x) — exp(-x))*0.5); Ce uu... / / 0ver loaded functions for sinh() for PCD veiiiiiiiiiieao.o... / / Overloaded function sinh() for data type - Float48 Coo , Bif defined PCD floatd8 sinh(floatd8 x) { return ((exp (x) - exp(-x))*0.5); i iiiiiiiauesi..... / / Overloaded function sinh() for data type - Float48 float64 sinh(float6d x) { return ((exp (x) - exp(-x))*0.5); Co #endif JI110710070071700171000710071771717711171777177107771107110711711111117 nn wa ma meses = ZF Float taphFioat x) LIIIII0100007700771710071071117777770117711777711017777111110111171111117 vevieiiieiiiie.o.... / / Description : Computes the hyperbolic tangent value of x veviviiiieeee....... / / Returns : returns the hyperbolic tangent value of x Co ou 0] Date : N / A float32 tanh(float32 x) { return{sinh (x) / cosh(x)) ; Ce uu... / / 0ver loaded functions for tanh() for PCD i iiiiiiiauesi..... / / Overloaded function tanh() for data type - Float48 ou, Bf defined PCD floatd8 tanh(floatd8 x) { return(sinh (x) / cosh(x))}: iieeuiuauu...... / / Overloaded function tanh(}) for data type - Float64 float64 tanh(float64 x) { return{sinh (x) / cosh(x)) ; Co Hendif JI110710070071700171000710071771717711171777177107771107110711711111117 iii / ] float frexp(float x, signed int *exp) LIIIII0100007700771710071071117777770117711777711017777111110111171111117 vevieiiieeiioa.o.... / / Description : breaks a floating point number into a normalized fraction and an integral veviiiiiisneee.o.... / / power of 2. It stores the integer in the signed int object pointed to by exp. veeiiiiiiiioo....... / / Returns : returns the value x, such that x is a double with magnitude in the interval eevee [7 11 / 21) or zero, and value equals x times 2 raised to the power *exp. If value is zero, euiiiiiiieueei..... / / both parts of the result are zero. Cu uu uuu / / Date 1 N / A Co #Hdefine LOG2 .30102909566398119521 Cu... tidefine LOG2 INV 3.32192809488736234787 float32 frexp(float32 x, signed int8 *exp) float3?2 res: intl sign = 0; if(x == 0.0) *exp=0; return (0.0); if(x < 0.0) X==X. sign=1; if (x> 1.0) *exp=(ceil (1og10 (x) *LOG2_ res=x / (pow (2, *exp)); if (res == 1) *exp=xexp+l ; res=.5: else if(x < 0.5) *exp=-1, res=x*2: else if(sign) res=-res. return res. ceiiiiiiiiiiiao..o... [ / / Overloaded functions for frexp() for PCD veiiiiiiiieeea..o.... / / Overloaded function frexp() for data type - oo Hf defined PCD floatd8 frexp(floatd8 x, signed int8 *exp) { floatd8 res: intl sign = 0; if(x == 0.0) *exp=0; return (0.0): if(x < 0.0) X==X. sign=1; if (x> 1.0) *exp={(ceil (1og10(x)*LOG2_INV)) ; res=x / (pow (2, *exp)); if (res == 1) else if(x <0.5) *exp=-1. res=xx2: else *exp=0; res=x. if(sign) res=-res. return res: eeeanaiuuu....... / / Overloaded function frexp() for data type - float6d frexp(float6d x, signed int8 *exp) { float6d res: intl sign = 0; if(x == 0.0) *exp=0; return (0.0): if(x < 0.0) X==X. sign=1; if (x> 1.0) *exp=(ceil (1og10 (x) *LOG2_ res=x / (pow (2, *exp)). if (res == 1) *exp=xexp+l ; res=. 5: else if(x < 0.5) *exp=-1, res=x*2: else *exp=0; res=x. if(sign) res=-res. return res. Co Hendif JIIII1100000710117100710017017171771100177101117117111111111117111711111 iii) float Idexp(float x, signed int *exp) LIIII11000770077171100710711077777000107107777170110171111171111111111117 Ceviiiiiiiiee....... / / Description : multiplies a floating point number by an integral power of 2. vevieiiieieioa.o.... / / Returns © returns the value of x times 2 raised to the power exp. oo] Date : N / A float32 Idexp(float32 value, signed int8 exp) { return (value * pow(2, exp)); Cu... J / 0ver loaded functions for Idexp() for PCD eeaaiuuu...... / / Overloaded function Idexp() for data type - Float48 ou, Bf defined PCD floatd8 |dexp(floatd8 value, signed int8 exp) { return (value * pow (2, exp)): eeaaiuuu...... / / Overloaded function Idexp() for data type - Float64 float64 Idexp(float64 value, signed int8 exp) { return (value * pow(2, exp)); Co Hendif Co Hendif ieee... Binclude <string.h> Co ttifndef _STRING eu .... tidefine _STRING Co . #include <stddef.h> Co... ttifndef _STDDEF i ........ tidefine _STDDEF ceiiiiiiiiiiiooo... if sizeof (unsigned int8 *)==1 ieviiiiiiiieiai..... define ptrdiff_t unsigned int8 Helse ceviieiiiiieiei.... Hdefine ptrdiff_t unsigned int16 vn ss mean seen HERAVF ou uo, Bf defined PCB ieee... .... Hdefine size_t unsigned int8 Helse viiiiiiiiaio...... Hdefine size_t unsigned int16 Ts. © Lid eu. ...... tidefine wchar_t char Co... ... #Hdefine NULL O Co... tdefine offsetof(s, f) (offsetofbit(s, f) / 8) Co #endif eviinnirinnnrn..... include <ctype.h> Co ttifndef CTYPE au... .... tidefine CTYPE ceeiiiiiiiiiioo..... Hdefine islower (x) isamong (x, “abedefghi jk Imnoparstuvwxyz”) eiiiiiiiieeie...... Hdefine isupper (x) isamong (x, “ABCDEFGHIJKLMNOPQRSTUVWXYZ") i tdefine isalnum (x) isamong (x, “0123456789ABCDEFGH I JKLMNOPQRSTUVIXYZabedefeghi jk Imnopar stuvwxyz”) iii... define isalpha(x} isamong (x, “ABCDEFGHI JKLMNOPQRSTUVWXYZabcdefghi jk Imnoparstuvwxyz”™) iii... Hdefine isdigit(x) isamong (x, “0123456789") eerie... Hdefine isspace(x) ((X)='") eeiiiiiiiiiii..... Hdefine isxdigit (x) isamong (x, “0123456789ABCDEFabcdef”) i Hdefine isentrl 0 (OK) eee... define isprint(x) (0O>="") iene... Hdefine isgraph(x} ((x)>' ") ieee... Hdefine ispunct (x) (((O)>' ')&&!isalnum(x)) Co Hendif Ce «Copying functionsx / iieeeiieau....... / % standard template: void *memmove (void *s1, void *s2, size tn). Copies max of n characters safely (not following ending '¥0') from s2 in si; if s2 has less than n characters, appends 0 * / i ... char *memmove (void *s1, char *s2 size t n) { char *scl: char *sc?2: scl=s1: sc?2=82": if(sc2<scl && scl <sc2 +n) for (sc1+=n, sc2+=n.0<n;--n) *——8g0]=%——s0?2 else for (;0<n;——n) *SC| +4+=%§ 024+ return sl: iieanaiee........ / % Standard template: char *strcpy (char *s1, const char *s2) copies the string s2 including the null character to si. This is a compiler built in to handle the different address spaces * / eiiiiiiiiiii..... H#define stroopy strepy iieeeiieau....... / % standard template: char #*strncpy (char *s1, const char *s2, size_t n). Copies max of n characters (not following ending '¥0') from s2 in sl; if s2 has less than n characters, appends 0 * / i iiiiiiiuue....... char *strncpy(char *s1, char *s2, size_t n) { char *s: for (s=sl;: n>0& *s2 I= "¥0';: n—) *S++ = *§2++ for (: n> 0; n—) *S++ = '¥0' return(s1): CL [eels iskkk kiko okololkok Cu... .... / %concatenation functions* / Ceiiiiiaiaiai..o..... [ / % standard template: char *strcat (char *s1, const char *s2) i eiiiiiiiei....... appends s2 to six / i ..... char *xstrcat(char *s1, char *s2) { char *s: for (s = sl; *s |= "¥0'; ++s); while (xs2 = "¥0") *§ = *g2: ++§ ++82° *s = '¥0': return(sl); Ceiiiiiiiiiei..o..... [ / % standard template: char *strncat (char *s1, char *s2 size_t | ev uuiiiieue....... appends not more than n characters from s2 to si* / Cu... ..... char *strncat(char *s1, char *s2, size. t n) { char *s: for (s = sl; *s |= "¥0'; ++s); while (xs2 = "¥0' && 0<n) *§ = *g2: ++§ ++52° —_—n *s = '¥0': return(sl); i ekklkcaekekcioiskookokksioisiolokiollokkekailollokkokoRoRkolokok | Cu [comparison functions* / iieeauaeeu....... [x standard template: signed int mememp (void *s1, void *s2). BAER Ee VRE § Compares si & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 * / eviiniiiinuns...... signed int8 memcmp (void * si, char *s2, size_t n) { eu... .... char *sul, =*su2: for (sul=s1, su2=s2; 0<n; ++sul, ++su2, ——n) { if (ksul!=ksu2) return ((xsul<ksu2)?-1:+1): return 0: ri iiiiiieees...... / x standard template: int strcmp(const char *s1, const char *s2). Si GR WT LATER 7 Compares si & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 * / Cr iiiiiiiue....... signed int8 strcmp(char *s1, char *s2) { for (; *sl == *s2; sl++ §2++) if (ks == '"¥0') return); return{(xs1 < *s2) 2? -1: 1): Ceiiiiiiiiiii..o..... [% standard template: int strcoll (const char *s1, const char *s2) . BAER Ee VRE § Compares si & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 * / eiiiiiiienee...... signed int8 strcoll (char *s1, char *s2) { for (; *sl == %s2; s1++ §2++) if (ks == '"¥0') return (0) ; return{(xs1 < *s2) 2? -1: 1): et iiiiuiieees...... / % standard template: int strnemp (const char *s1, const char *s2, size_t n). Compares max of n characters (not following 0) from s1 to s2; returns same as stromp * / iieiuiiiuu....... signed int8 strncmp (char *s1, char *s2, size_t n) { for (; n> 0; sl++ s2++ n—) if (esl |= %s2) return( (xsl <*s2) 2? -1: 1): else if (xsl = '¥0') return); return(0); iieeeiieau....... / % standard template: int strxfrm(const char *s1, const char *s2, size t n). LE SS RR SR transforms maximum of n characters from s2 and places them into si* / Ce uu size_t strxfrm(char *s1, char *s2, size t n) { char *s: unsigned int8 ni; nil=n: for (s=sl; n> 0 &% *s2 |= "¥0': n—) *S++ = *§++ for (; n> 0; n=) *s++ = '¥0' return(nl); ee [eRkRoRRRIcR RRR ORR RIK ORR RRR RRR RRR RACK | Ce... ... / %Search functions* / iieaniieeu....... / % standard template: void *memchr (const char *s, int ¢). Finds first occurrence of ¢ in n characters of s * / eiiiiiirieuu....... char *memchr (void *s,unsigned int8 ¢, size_t n) { char uc: char *su: ue=¢. for (su=s:0<{n;++su, =-n) if (ksu==uc) return su. return NULL: Cu... ... / % standard template: char *strchr (const char *s, int ¢). Finds first occurrence of ¢ in s * / VC iiiiiiiiuue....... char *strchr(char *s, unsigned int8 ¢) { for (; *s |= ¢; s++) if (xs == "¥0') return); returns); iieeeiieau....... / % standard template: size_t strcspn(const char *s1, const char *s2). Computes length of max initial segment of si that consists entirely of characters NOT from s2x / Ceiiiiiiiiiai..o..... Unsigned int8 strespn(char *s1, char *s2) { char *scl, *sc2; for (scl = sl; *scl |= 0; scl++) for (sc? = s2: *sc2 != 0; sc2++) if (xscl == *sc2) return(scl - si); return(scl - st); et iiiiuiieees...... / % standard template: char #*strpbrk (const char *sl1, const char *s2). Locates first occurence of any character from s2 in si; returns sl if s2 is empty string * / uiiiiuiieiee...... Char *strpbrk (char *s1, char *s2) { char *scl, *sc2; for (scl = sl; *scl |= 0; scl++) for (sc2 = s2; *sc2 |= 0; sc2++) if (xscl == *sc2) return(scl) return{0); uu... ... / % standard template: char *strrchr (const char *s, int ¢). Finds last occurrence of ¢ ins * / ei iiiiiiiuuus...... char *strrchr (char *s, unsigned int8 ¢) { char #*p; for (p = 0; ; s++) if (ks == ¢) p=s; if (ks == '¥0') return(p) ; eee... [Xx computes length of max initial segment of si consisting entirely of characters from s2 * / Ceiiiiiiiiiie....... Unsigned int8 strspn(char *si, char *s2) { char *scl1, *sc2; for (scl = sl; *s¢1 I= 0; scl++) for (sc2 = s2. | SC2++) if (ksc2 == '¥0') return(scl - sl); else if (kscl == *sc2) break: return(scl - si); iieeeiieau....... / % standard template: char *strstr (const char *s1, const char *s2); Locates first occurence of character sequence s2 in returns 0 if s2 is empty string Uncomment #define FASTER_BUT_MORE_ROM at the top of file to use the faster algorithm * / Ce .... Char *xstrstr(char *s1, char *s2) { char #*s, *t; #ifdef FASTER BUT MORE ROM if (ks2 = '¥0') return(sl); #endif while (xsl) for(s = sl, t = 82; *t && (ks == *t); ++s, ++t); if (xt == "¥0") return si: ++s1: #ifdef FASTER BUT MORE ROM while (ksl |= '¥0' && *s1 |= *s2) ttendif return 0: iieeuaieeu....... / % standard template: char *strtok (char *s1, const char *s2). Finds next token in s1 delimited by a character from separator Ca ER SE SR EE § string s2 (which can be different from call to call). First call starts at beginning of sl searching for first character NOT contained in s2: returns 0 if none is found. Ve PR EY ARR If one is found, it is the start of first token (return value). dwn aE RRR SER Function then searches from there for a character contained in 82. Cove RR ET EE If none is found, current token extends to end of si, and subsequent searches for a token will return 0. If one is found, it is FR overwritten by '¥0', which terminates current token. Function saves ST EV TORIC PR pointer to following character from which next search will start. SO DE FT FA Each subsequent call, with 0 as first argument, starts searching from saved pointer * / Ce .... char *strtok(char *s1, char *s2) { char *beg, *end; static char *save: * 1203: BCF 03.5 12C4: CLRF 27 1205: CLRF 28 beg = (s1)? si: save; beg += strspn(beg, s2); if (xbeg == '"¥0') *save = | return(Q) ; end = strpbrk(beg, s2): if (xend |= "¥0') *end = '¥0' end++: save = end: return (beg) ; AsRkickiiclekskR ekki Rk Rk RRR Co. / HMiscellaneous functions* / ieeeuaieui....... / % standard template seiiiiiiiie......... Maps error number in errnum to an error message € eiiiiiiuiuu........ Returns: Pointer to string * / .... ttifdef _ERRNO ei iiiiiiiiues...... char * strerror (unsigned int8 errnum) { Cu... .... static char s

[13] : Co switch errnum { ease 0 stropy (s, “no errors”); return s: oo ease EDOM : stropy (s, “domain error”); return s: ............. case ERANGE: stropy (s, “range error”); return s: Co. ...... HENDIF ieeaauiiau....... [x standard template: size_t strlen(const char *s). Computes length of s1 (preceding terminating 0) * / Ce vriiiieiieev...... unsigned int8 strlen{char *s) { char *sc: for (sc = s; *s¢ |= 0; sc++); return(sc - s); Ceiiiiiiiiiai..o..... [% standard template: size_t stricmp(const char *s1, const « *s2) . Compares sl to s2 ignoring case (upper vs. lower) * / iieiuiiiuu....... signed int8 stricmp (char *s1, char *s2) { for (; *s1==+s2| | (isalpha(*s1)8&&isalpha (xs2) && (ks1==%xs2+32 | | *s2==%s1+32)) ; s1++ §2++) if (ks1 == '¥0') return (0) ; return((*s1 < *s2) 2 -1: 1); vieeanaieau....... / % standard template: char *strlwr (char *s). Replaces uppercase letters by lowercase; returns pointer to new string s * / Co ... char xstrlwr (char *s) { char *p; for (p= s; *p |= '¥0'; p++) if (kp >= "A && *p <='7') pi='a -'A; returns); Cu riiiiiiuee....... / %x standard template: char *strupr (char *s). Replaces lowercase letters by upercase; returns pointer to new string s * / riiiiiiiii........ Char *strupr (char *s) { char *p; for (p = s; *p |= '¥0'; p++) if kp >= "a && #p <='2") #p -= "a - "A; return(s); J rekklklleksekist bikie rokok | Co Hendif ceiieiiiiiieoo.... Huse rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS, stream = PC) Cu... ....... HUSE STANDARD I10(B) Co... .......... HUSE STANDARD I0(C) eeeeeeeieeeoooo.... / / Hrom 0x2100 = {30, 40, 43, 47, 10, 5, 6, 5, 4, 3, 2 1} / / 0x2100 is for 16F-series PICs aia... .... #Hpriority timeri1 / / , rda [Hristo kkk oki Rk kook I 5 4 DEFINITIONS / [ekki lloilo lololokokorkok Co ......... {DEFINE LCD_TYPE WIDTH 16 seeeeeieeii...... HDEFINE SALIDA_A PIN_BO / / Pin de Salida del PWM LOW FREQ seiiiiiiiiioo....... HDEFINE SALIDA_B PIN B1 / / Pin de Salida del PHM LOW FREQ veeiiiiieiiooo...... DEFINE salidaPWM PIN_C2 / / Pin de Salida del PWM Co... ....... UDEFINE TOROIDAL_ SAMPLES 258 Co ............ HDEFINE KS 1000 Cu. ........ UDEFINE Vref 5.0 / / 4.97 / / 5.04 / / 4.93 Cu ........... 1UDEFINE temp! 79 uieuuuauu........ HDEFINE temp2 90 eu. ......... DEFINE duty2 0 ieuuiuu........ HDEFINE fq 142 eu. ......... UDEFINE vDuty 4 Co ........ UDEFINE current max 200 Co ........ UDEFINE current limit 160 ieiiiiiiiiooo....... / *HDEFINE SIZE_COMMAND 3 / / Sets the Max command Length’ Ceeauuiu......... HDEFINE SIZE_MESSAGE 3 / / Message Length seeiiiiiiiooo....... HDEFINE SIZE_BUFFER SIZE_COMMAND + SIZE MESSAGE / / Serial Buffer Size * / Co .. #Hdefine toint(c) ((int) ((c)-'0")) [Hristo kkk oki Rk kook I 5 4 FUNCTIONS DECLARATIONS | / fisiiiioiskckiolbibobiboiokoobibioiiokioblbiolbibioooobioiooioiok wes fa meses = St TIMER void TIMER isrO: Cu. .... / AHINT_RDA void RDA _isr():* / void printf_ (int8 dutyCycle); float Thermister (float RawADC) ; void Set PWM _Freg(int16 frequency); float Set_PWM_Duty (float temp): float Set_DutyCrnt (float crnt); float Set_Duty Max(); int16 ReadAdc (int channel): float Calc Current (float v_med); viieeniiieui i... / xfloat Calculate_lavg (float toroidalavg); float Calculate_Ipeak (float toroidalmax): float Calculate_Irms (float toroidalmax, float toroidalavg): void HandleData(): void Clean() ;* / [Hristo kkk oki Rk kook I 5 4 VARIABLES & CONSTANTS DECLARATIONS / [ekki lloilo lololokokorkok ~~ BOOLEAN salida = TRUE: int16 adc value; float tempVolt; float temp; float duty_adc=50; float duty_crnt=50; float dutyl1=50; float psVoltage = 19.5; float Ipeak = 0; float lavg = 0; float Irms = 0; float Power = 0: int16 pwm_counter=0; / / ContadorPWM seiiiiiiiieeio...... int16 time_counter_ms=0; / / Contador1 cambio de frecuencia [mS] Ceeiiiiiiieee...o.... iNt8 time_counter_s=0; / / Contador? cambio de frecuencia [Ss] int16 time=0; / / Variable del PWM en 1 + ves aves ven dun snens THES high=0; / / tiempo en [high=duty_cycle*time / 100] int8 duty=0; int8 freg=0; BOOLEAN refresh = TRUE: a. ....... BOOLEAN lcd enable = TRUE: Cu... .... BOOLEAN slow start = TRUE: uu. ....... BOOLEAN slow change = FALSE: int8 slowstart = 0: Co eiiieeiii... / / _STRING dutyRS232 ="; int16 timer = 0: io oo] ints timer h, timer I: Ce iiieriiinnevi.... / / THz = 1 segundo = 1000mS eiiiiiiieiia.o.... / / 100 Hz = 0.01 segundos = 10mS viireiniveeinoo... / / La interrupciz se genera cada 1mS ee ou uu... / / float toroidal [TOROIDAL_ SAMPLES]; float toroidal aux; float toroidal max; / / maximo float toroidal sum; / / suma float toroidal _ave; / / promedio int16 sample_count; iiieriaiuu........ BOOLEAN sample = false; R232 i iiieriiues...... / %char Receive_String[SIZE_BUFFER]; Ciiiiiiiiiii...o.... int counter_read = 0: / / Serial Buffer Counter intl get_data=1:% / uuu... .... / / Handle Data eiiiiiiiiuui....... / / char Receive Message [SIZE_MESSAGE]; Cu uu... / / char Receive Command [SIZE_COMMAND] : int1 config _mode = 0; eee... ... / Hunsigned int8 peak_a = 30; eiiiiiiiiner....... unsigned int8 peak_b = 40; eiiiieiiiie........ unsigned int8 peak_c = 43; eiiiiiiiiner....... unsigned int8 peak_d = 47; eiiiiriiiie........ unsigned int8 peak_e = 10; eviiiiiiiueu....... unsigned int8 peak_f = 5; iiiiriiiie........ unsigned int8 avg_a = 6; eiiiiiiiiuer....... unsigned int8 avg b = 5; iiieriiiie........ unsigned int8 avg c = 4; eiiiiiiiiuer....... unsigned int8 avg d = 3; iiieriiiie........ unsigned int8 avg e = 2; Ce viuriiiiieeeeo.... unsigned int8 ave f = 1;% / | / fisiiiioiskckiolbibobiboiokoobibioiiokioblbiolbibioooobioiooioiok PTY INTERRUPTIONS [Hristo kkk oki Rk kook Ce Bint TIMER1 void TIMER isr (0 { pwm_counter++; * 0239: INCF 52. F 023A: BTFSC 03.2 023B: INCF 53 F time_counter_ms++; 023C: INCF 54. F 0230: BTFSC 03.2 023E: INCF 55,F sample = TRUE; 023F: BSF 2B. 5 slow _start=TRUE: 0240: BSF 2B. 3 / / sample_count++; S00 LOR WE BREESE 4 if (pwm_counter<=high) { 0241: MOVF 53 F 0242: BTFSS 03.2 0243: GOTO 254 0244: MOVF 52. W 0245: SUBWF 59. W 0246: BTFSS 03.0 0247: GOTO 254 if(salida) { 0248: BTFSS 2B. 0 0249: GOTO 24F Sh TEED SEE SAREE output_high(SALIDA_A) : 024A: BSF 03.5 024B: BCF 06.0 024C: BCF 03.5 024D: BSF 06.0 else{ 024E: GOTO 253 Ty output_high (SALIDA_B) ; 024F: BSF 03.5 0250: BCF 06.1 0251: BCF 03.5 0252: BSF 06.1 else{ 0253: GOTO 25F if(salida) { 0254: BTFSS 2B. 0 0255: GOTO 25B CUE Sue SEEN Sa 7 output_|ow (SALIDA_A) ; 0256: BSF 03.5 0257: BCF 06.0 0258: BCF 03.5 0259: BCF 06.0 else{ 025A: GOTO 25F Ty output_low (SALIDA_B) ; 025B: BSF 03.5 025C: BCF 06.1 025D: BCF 03.5 025E: BCF 06.1 BE —a if (pwm_counter>=time) { 025F: MOVF 58 W 0260: SUBWF 53. W 0261: BTFSS 03.0 0262: GOTO 26B 0263: BTFSS 03.2 0264: GOTO 269 0265: MOVF 57.W 0266: SUBWF 52. W 0267: BTFSS 03.0 0268: GOTO 26B Si GR WT LATER 7 pwm_counter=0; / / Reset pwm_counter 0269: CLRF 53 026A: CLRF 52 if (time_counter_ms==MS) { 026B: MOVF 54. W 026C: SUBLW E8 026D: BTFSS 03.2 026E: GOTO 27B 026F: MOVF 55 W 0270: SUBLW 03 0271: BTFSS 03.2 0272: GOTO 27B time_counter_s++; 0273: INCF 56,F refresh=TRUE: 0274: BSF 2B. 1 SIRE A FEET 7 § time_counter_ms=0; / / Reset milisegundos 0275: CLRF 55 0276: CLRF 54 if (time_counter_s=100) { 0277: MOVF 56. W 0278: SUBLW 64 0279: BTFSC 03.2 Cte SEES Sh EEE time_counter_s=0; / / Reset segundos 027A: CLRF 56 Set _Timer1 (64286) ; 027B: MOVLW FB 027C: MOVWF OF 0270: MOVLW 1E 027E: MOVWF OF [Hristo kkk oki Rk kook I 5 4 FUNCTIONS & MAIN | / kisiiiioiskiolbibobiioicoobibioiokiokioblbiolblbioliobioiooioiok 027F: BCF 0C. 0 0280: BCF 0A. 3 0281: BCF 0A. 4 0282: GOTO 21D void main( { * 1277: CLRF 04 1278: BCF 03.7 1279: MOVLW 1F 127A: ANDWF 03. F 127B: CLRF 29 127C: MOVLW 40 1270: BSF 03.5 127E: MOVWF 19 127F: MOVLW A6 1280: MOVWF 18 1281: MOVLW 90 1282: BCF 03.5 1283: MOVWF 18 1284: MOVLW FF se _adc_ports (ALL_ANALOG) ; 1207: BCF 1F.0 1208: BCF 1F.1 1209: BCF 1F.2 12CA: BCF 1F.3 setup_adc (ADC_CLOCK DIV 32); 120B: BCF 03.5 12CC: BCF 1F. 6 120D: BSF 1F.7 12CE: BSF 03.5 12CF: BSF 1F.7 1200: BCF 03.5 1201: BSF 1F.0 setup_psp (PSP_DISABLED) ; 12D2: BSF 03.5 12D3: BCF 09.4 setup_spi (FALSE) ; 1204: BCF 03.5 12D5: CLRF 14 / / setup_timer_O (RTCC_INTERNAL|RTCC DIV 1): EE setup_timer_1 (T1_INTERNAL | T1_DIV_BY_2); 12D6: MOVLW 95 12D7: MOVWF 10 Ca ER SE SR EE § setup_timer_2(T2_DIV_BY_16, (int8)fq, 10); .27hz pero PWM no ocupa POSTCALER 156 12D8: MOVLW 48 12D9: MOVWF 78 12DA: 10RLW 06 12DB: MOVWF 12 12DC: MOVLW 8E 120D: BSF 03.5 12DE: MOVWF 12 mr — set_pwm1_duty ((int8) (vDuty)); 12DF: MOVLW 04 12E0: BCF 03.5 12E1: MOVWF 15 Ss GHB SN CRE 4 / / setup_timer_2(T2_DIV_BY_16,79, 10): / / 61.27hz pero PWM no ocupa POSTCALER 156 Sid Lh Ria ae setup_ccpl (CCP_PWM) ; / / luego 612. 75Hz PWM 12E2: BCF 2A.2 12E3: MOVF 2A W 12E4: BSF 03.5 12E5: MOVWF 07 12E6: BCF 03.5 12E7: BCF 07.2 12E8: MOVLW OC 12E9: MOVWF 17 output_high (PIN_D1) ; 12EA: BSF 03.5 12EB: BCF 08.1 12EC: BCF 03.5 12ED: BSF 08.1 output_ low (PIN_DO) ; 12EE: BSF 03.5 12EF: BCF 08.0 12F0: BCF 03.5 12F1: BCF 08.0 output_high (PIN_B1) ; 12F2: BSF 03.5 12F3: BCF 06.1 12F4: BCF 03.5 12F5: BSF 06.1 output_high (PIN_B2) ; 12F6: BSF 03.5 12F7: BCF 06.2 12F8: BCF 03.5 12F9: BSF 06.2 output_low (PIN_B3) ; 12FA: BSF 03.5 12FB: BCF 06.3 12FC: BCF 03.5 12FD: BCF 06.3 HER Si EERE $i enable_interrupts (INT_TIMERT) ; / / Habilitamos Interrupcion 12FE: BSF 03.5 12FF: BSF 0C. 0 / / enable_interrupts (int _rda): enable_interrupts (GLOBAL) ; 1300: MOVLW CO 1301: BCF 03.5 1302: IORWF OB,F Set Timer1 (64286) ; 1303: MOVLW FB 1304: MOVWF OF 1305: MOVLW 1E 1306: MOVWF OF delay_ms (10); 1307: MOVLW OA 1308: BSF 03.5 1309: MOVWF 2F 130A: BCF 0A. 4 130B: BCF 03.5 130C: CALL 2BF 1300: BSF 0A. 4 led init 0: / / Initialise LCD.. 130E: BCF 0A. 4 130F: GOTO 334 1310: BSF 0A. 4 sus dn SARE SA led_putc (“¥fStarting ... 1311: MOVLW 83 1312: BSF 03.6 1313: MOVWF OD 1314: MOVLW 02 1315: MOVWF OF 1316: BCF 0A. 4 1317: BCF 03.6 1318: CALL 3BD 1319: BSF 0A. 4 delay_ms (500) ; 131A: MOVLW 02 131B: MOVWF 7B 131C: MOVLW FA 1310: BSF 03.5 131E: MOVWF 2E 131F: BCF 0A. 4 1320: BCF 03.5 1321: CALL 2BF 1322: BSF 0A. 4 1323: DECFSZ 7B,F 1324: GOTO 31C led_putc (“"¥f") ; 1325: MOVLW 8A 1326: BSF 03.6 1327: MOVWF OD 1328: MOVLW 02 1329: MOVWF OF 132A: BCF 0A. 4 132B: BCF 03.6 132C: CALL 3BD 132D: BSF 0A. 4 BOOLEAN firstln = TRUE: int8 cycleCount = 0; BOOLEAN prevSalida = salida; int8 rampCount = 0; int8 rampValue = 0; 132E: BSF 71.0 132F: CLRF 72 1330: BCF 71.1 1331: BTFSC 2B.0 1332: BSF 71.1 1333: CLRF 73 1334: CLRF 74 while (TRUE) | if (!config_mode) { 1335: BTFSC 2B. 6 1336: GOTO 6C6 1 SOFTWARE PWM / / set PWM frequency / / 0-20 sec ->16. 2Hz / / 20-50 sec -> 118. 6Hz / / 50-100 sec -> 236. 2Hz Ch TE EET SE if (time_counter_s==0) { 1337: MOVF 56. F 1338: RBTFSS 03.2 1339: GOTO 356 Ch TE EET SE if(prevSalida != salida) { 133A: CLRF 77 133B: BTFSC 2B.0 133C: BSF 77.1 133D: MOVF 71. W 133E: XORWF 77.W 133F: ANDLW 02 1340: BTFSC 03.2 1341: GOTO 347 Sid Lh Ria ae prevSalida = salida: 1342: BCF 71.1 1343: BTFSC 2B.0 1344: BSF 71.1 sl|owstart = 0: 1345: CLRF 5C A i EA ER slow_change = TRUE; 1346: BSF 2B. 4 firstln = TRUE: 1347: BSF 71.0 Set PWM_Freq (312); 1348: MOVLW O01 1349: MOVWF 7C 134A: MOVLW 38 134B: MOVWF 7B 134C: BCF 0A. 4 134D: CALL 42A 134E: BSF 0A. 4 freg=3; 134F: MOVLW 03 1350: MOVWF B5B if(lsalida) { 1351: BTFSC 2B.0 1352: GOTO 355 Ch TE EET SE else if(time_counter_s==49) { 1355: GOTO 3BD 1356: MOVF 56, W 1357: SUBLW 31 1358: BTFSS 03.2 1359: GOTO 367 Set PWM _Freq(78): 135A: CLRF 7C 135B: MOVLW 4E 135C: MOVWF 7B 135D: BCF OA. 4 135E: CALL 42A 135F: BSF 0A. 4 freg=1; 1360: MOVLW O01 1361: MOVWF B5B if(lsalida) { 1362: BTFSC 2B.0 1363: GOTO 366 freg=4; 1364: MOVLW 04 1365: MOVWF 5B TE else if (time_counter_s==69) { 1366: GOTO 3BD 1367: MOVF 56. W 1368: SUBLW 45 1369: BTFSS 03.2 136A: GOTO 378 Set PWM _Freq(156) 136B: CLRF 7C 136C: MOVLW 9C 136D: MOVWF 7B 136E: BCF 0A. 4 136F: CALL 42A 1370: BSF 0A. 4 freg=2; 1371: MOVLW 02 1372: MOVWF B5B if(lsalida) { 1373: BTFSC 2B.0 1374: GOTO 377 freg=h; 1375: MOVLW 05 1376: MOVWF 5B TE else if (time_counter_s==99) { 1377: GOTO 3BD 1378: MOVF 56. W 1379: SUBLW 63 137A: BTFSS 03.2 137B: GOTO 3BD if(firstin { 137C: BTFSS 71.0 1370: GOTO 3BD cycleCount++; 137E: INCF 72.F firstin = FALSE: 137F: BCF 71.0 if (cycleCount==2) { 1380: MOVF 72. W 1381: SUBLW 02 1382: BTFSS 03.2 1383: GOTO 3BD cycleCount = 0; 1384: CLRF 72 Sas Fh SAT $A Set_PWM_Freq (0): 1385: CLRF 7C 1386: CLRF 7B 1387: BCF 0A. 4 1388: CALL 42A 1380: BSF 0A. 4 / / slowstart = 0; Sas Fh SAT $A slow_change = TRUE: 138A: BSF 2B. 4 FR prevSalida = salida; 138B: BCF 71.1 138C: BTFSC 2B.0 138D: BSF 71.1 dwn aE RRR SER salida = !salida; 138E: MOVLW O01 138F: XORWF 2B. F TE output_high (PIN_BO) ; 1390: BSF 03.5 1391: BCF 06.0 1392: BCF 03.5 1393: BSF 06.0 WE PS EEE 0% output_high (PIN_B1) ; 1394: BSF 03.5 1395: BCF 06.1 1396: BCF 03.5 1397: BSF 06.1 delay _us (10) ; 1398: MOVLW 07 1399: MOVWF 77 139A: DECFSZ 77.F 139B: GOTO 139A 139C: GOTO 39D 139D: NOP if(salida) | 139E: BTFSS 2B. 0 139F: GOTO 3AF WE PS EEE 0% output_high (PIN_B2) ; 13A0: BSF 03.5 13A1: BCF 06.2 13A2: BCF 03.5 13A3: BSF 06.2 I — output_low (PIN_B3) ; 13A4: BSF 03.5 13A5: BCF 06.3 13A6: BCF 03.5 13A7: BCF 06.3 delay_us (10); 13A8: MOVLW 07 13A9: MOVWF 77 13AA: DECFSZ 77.F 13AB: GOTO 3AA 13AC: GOTO 3AD 13AD: NOP TE output_high (PIN_B3) ; 13AF: BSF 03.5 13B0: BCF 06.3 13B1: BCF 03.5 13B2: BSF 06.3 output_low (PIN_B2) ; 13B3: BSF 03.5 13B4: BCF 06.2 13B5: BCF 03.5 13B6: BCF 06.2 delay _us (10); 13B7: MOVLW 07 13B8: MOVWF 77 13B9: DECFSZ 77.F 13BA: GOTO 3B9 13BB: GOTO 3BC 13BC: NOP 1 END SOFTWARE PWM 1 ADC / / ciclo de trabajo temperatura termistor adc_value = ReadAdc (0) ; 13BD: CLRF 7B 13BE: BCF 0A. 4 13BF: CALL 43E 1300: BSF 0A. 4 13C1: MOVF 79. W 13C2: MOVWF 2D 1303: MOVF 78. W 13C4: MOVWF 2C SR Eh ESE Lh 7 / / tempVolt = (float) (adc_value * Vref) / 1023.0: / / voltage / / temp = Thermister (tempVolt) ; / / temperature temp = Thermister (adc_value) ; 1305: MOVF 2D. W 13C6: MOVWF 7C 13C7: MOVF 2C. W 13C8: MOVWF 7B 1309: BCF 0A. 4 13CA: CALL 4A7 13CB: BSF 0A. 4 13CC: MOVF 77.W 13CD: MOVWF 7B 13CE: MOVF 78. W 13CF: MOVWF 7C 13D0: MOVF 79. W 13D1: MOVWF 7D 13D2: MOVF 7A W 13D3: MOVWF 7E 13D4: BSF 03.5 13D5: MOVWF 23 13D6: MOVF 79. W 13D7: MOVWF 22 13D8: MOVF 78. W 13D9: MOVWF 21 13DA: MOVF 77.W 13DB: MOVWF 20 13DC: BCF 0A. 4 13DD: BSF 0A. 3 13DE: BCF 03.5 13DF: GOTO 000 13E0: BSF 0A. 4 13E1: BCF O0A.3 13E2: MOVF 7A W 13E3: MOVWF 35 13E4: MOVF 79. W 13E5: MOVWF 34 13E6: MOVF 78. W 13E7: MOVWF 33 13E8: MOVF 77.W 13E9: MOVWF 32 / / ciclo de trabajo miZEimo adc_value = ReadAdc (1) ; 13EA: MOVLW O01 13EB: MOVWF 7B 13EC: BCF 0A. 4 13ED: CALL 43E 13EE: BSF 0A. 4 13EF: MOVF 79. W 13F0: MOVWF 2D 13F1: MOVF 78. W 13F2: MOVWF 2C WE PS EEE 0% duty_adc = (float) (adc_value * 13F3: MOVF 2D. W 13F4: MOVWF 7C 13F5: MOVF 2C. W 13F6: MOVWF 7B 13F7: BCF 0A. 4 13F8: CALL 4A7 13F9: BSF 0A. 4 13FA: MOVF 7A W 03 5 40 79.0 SF 78. W 3E 77.0 3D 44 43 46 42 85 41 0A. 4 03.5 404 0A 4 A TB 78. W 7C 79.0 rh] TAW TE 03.5 44 79.0 43 78. W 42 A 141C: MOVWF 41 141D: CLRF 48 141E: MOVLW CO 141F: MOVWF 47 1420: MOVLW 7F 1421: MOVWF 46 1422: MOVLW 88 1423: MOVWF 45 1424: BCF OA. 4 1425: BCF 03.5 1426: CALL b53B 1427: BSF 0A. 4 1428: MOVF 7A W 1429: MOVWF 39 142A: MOVF 79. W 142B: MOVWF 38 142C: MOVF 78. W 1420: MOVWF 137 142E: MOVF 77.W 142F: MOVWF 36 / / voltaje de la fuente AR RE BRATS SE adc_value = ReadAdc (2) ; 1430: MOVLW 02 1431: MOVWF 7B 1432: BCF 0A. 4 1433: CALL 43E 1434: BSF 0A. 4 1435: MOVF 79. W 1436: MOVWF 2D 1437: MOVF 78. W 1438: MOVWF 2C Se SUE SE EH psVoltage = (float) (adc_value * * oficina) 1439: MOVF 143A: MOVWF 143B: MOVF 143C: MOVWF 143D: BCF 143E: CALL 143F: BSF 1440: MOVF 1441: BSF 1442: MOVWF 1443: MOVF 1444: MOVWF 1445: MOVF 1446: MOVWF 1447: MOVF 1448: MOVWF 1449: CLRF 144A: CLRF 144B: MOVLW 144C: MOVWF 144D: MOVLW 144E: MOVWF 144F: BCF 1450: BCF 1451: CALL 1452: BSF 1453: MOVF 1454: MOVWF 1455: MOVF 1456: MOVWF 1457: MOVF 1479: MOVF 78. W 147A: MOVWF 42 147B: MOVF 77.W 147C: MOVWF 41 147D: CLRF 48 147E: MOVLW CO 147F: MOVWF 47 1480: MOVLW TF 1481: MOVWF 46 1482: MOVLW 88 1483: MOVWF 45 1484: BCF 0A. 4 1485: BCF 03.5 1486: CALL b53B 1487: BSF 0A. 4 1488: MOVF 7A W 1489: MOVWF 45 148A: MOVF 79. W 148B: MOVWF 44 148C: MOVF 78. W 148D: MOVWF 43 148E: MOVF 77. W 148F: MOVWF 42 / / ciclo de trabajo corriente if (sample) { 1490: BTFSS 2B. 5 1491: GOTO 573 sample = FALSE; 1492: BCF 2B.5 / *set_adc_channel (3); delay_us (20) ; adc value = read_adc(): / / raw a adc_value = ReadAdc (3) ; 1493: MOVLW 03 1494: MOVWF 7B 1495: BCF 0A. 4 1496: CALL 43E 1497: BSF 0A. 4 1498: MOVF 79. W 1499: MOVWF 2D 149A: MOVF 78. W 149B: MOVWF 2C HE BAAR Hs ED 5 toroidal_aux = Calc_Current ((float) (adc_value * Vref) / 1023.0) ; 149C: MOVF 2D. W 149D: MOVWF 7C 149E: MOVF 2C. W 149F: MOVWF 7B 14A0: BCF 0A. 4 14A1: CALL 4A7 14A2: BSF 0A. 4 14A3: MOVF 7A W 14A4: BSF 03.5 14A5: MOVWF 40 14A6: MOVF 79. W 14A7: MOVWF 3F 14A8: MOVF 78. W 14A9: MOVWF 3E 14AA: MOVF 77.W 14AB: MOVWF 13D 14AC: CLRF 44 14AD: CLRF 43 14AE: MOVLW 20 14AF: MOVWF 42 14D1: MOVF 77.W 14D2: MOVWF 7B 14D3: MOVF 78. W 14D4: MOVWF 7C 14D5: MOVF 79. W 14D6: MOVWF 7D 14D7: MOVF 7A W 14D8: MOVWF 7E 14D9: BSF 03.5 14DA: MOVWF 23 14DB: MOVF 79. W 14DC: MOVWF 22 14DD: MOVF 78. W 14DE: MOVWF 21 14DF: MOVF 77.W 14E0: MOVWF 20 14E1: BCF 0A. 4 14E2: BCF 03.5 14E3: GOTO 7BS 14E4: BSF 0A. 4 14E5: MOVF 7A W 14E6: MOVWF 62 14E7: MOVF 79. W 14E8: MOVWF 61 14E9: MOVF 78. W 14EA: MOVWF 60 14EB: MOVF 77. W 14EC: MOVWF b5F / / toroidal aux = Calc Current (adc value) ; / / toroidal aux = 20.1; toroidal sum += toroidal aux; 03.1 6A W 03 5 44 03.5 69. W 03.5 43 03.5 68. W 03.5 42 03.5 67. W 03.5 41 03.5 62. W 03.5 48 03 5 61. W 03 5 47 03.5 60 W 03.5 46 03.5 5F W 03.5 45 0A. 4 150E: BCF 03.5 150F: CALL 648 1510: BSF 0A. 4 1511: MOVF 7A W 1512: MOVWF 6A 1513: MOVF 79. W 1514: MOVWF 69 1515: MOVF 78. W 1516: MOVWF 68 1517: MOVF 77.W 1518: MOVWF 67 / / promedio samp le_count++; 1519: INCF 6F,F 151A: BTFSC 03.2 151B: INCF 70,F / / peak AR RE BRATS SE if (toroidal_max<toroidal_ 1510: MOVF 66. W 151D: BSF 03.5 151E: MOVWF 40 151F: BCF 03.5 1520: MOVF 65 W 1521: BSF 03.5 1522: MOVWF 3F 1523: BCF 03.5 1524: MOVF 64. W 1525: BSF 03.5 1526: MOVWF 3E 1527: BCF 03.5 63. W 03.5 3D 03.5 62. W 03.5 44 03.5 61. W 03 5 43 03 5 60 W 03.5 42 03.5 BF. W 03.5 41 0A 4 03 5 607 0A. 4 03.0 549 toroidal =toroidal 62. W 66 61. W 65 60 W 64 BF. W / / muestras if (samp le_count>=TOROIDAL_SAMPLES) { 1549: MOVF 70. W 154A: SUBLW 00 154B: BTFSC 03.0 154C: GOTO 573 BA Si PEBTURRN $0 toroidal_avg = toroidal_sum / TOROIDAL_SAMPLES; 154D: MOVF 6A. W 154E: BSF 03.5 154F: MOVWF 44 1550: BCF 03.5 1551: MOVF 69. W 1552: BSF 03.5 1553: MOVWF 43 1554: BCF 03.5 1555: MOVF 68. W 1556: BSF 03.5 1557: MOVWF 42 1558: BCF 03.5 1559: MOVF 67. W 155A: BSF 03.5 155B: MOVWF 41 155C: CLRF 48 1550: CLRF 47 155E: CLRF 46 155F: MOVLW 87 1560: MOVWF 45 1561: BCF 0A. 4 1562: BCF 03.5 1563: CALL 53B 1564: BSF 0A. 4 1565: MOVF 7A W 1566: MOVWF 6E 1567: MOVF 79. W 1568: MOVWF 6D 1569: MOVF 78. W 156A: MOVWF 6C 156B: MOVF 77.W 156C: MOVWF 6B CH SER PTR samp le_count=0; 156D: CLRF 70 156E: CLRF 6F dwn aE RRR SER toroidal_sum=0; 156F: CLRF 6A 1570: CLRF 69 1571: CLRF 68 1572: CLRF 67 1 CURRENT CH SER PTR Ipeak = toroidal_max; 1573: MOVF 66. W 1574: MOVWF 49 1575: MOVF 65 W 1576: MOVWF 48 1577: MOVF 64. W 1578: MOVWF 47 1579: MOVF 63. W 157A: MOVWF 46 AAD VAD BRR SER lavg = toroidal _ave; 157B: MOVF GE. W = psVoltage * 159B: MOVF 4B. W 159C: BSF 03.5 159D: MOVWF 42 150E: BCF 03.5 159F: MOVF 4A W 15A0: BSF 03.5 15A1: MOVWF 41 15A2: BCF 0A. 4 15A3: BCF 03.5 15A4: CALL 4C4 15A5: BSF 0A. 4 15A6: MOVF 7A W 15A7: MOVWF 51 15A8: MOVF 79. W 15A9: MOVWF 50 15AA: MOVF 78. W 15AB: MOVWF 4F 15AC: MOVF 77.W 15AD: MOVWF 4E 1 END CURRENT MEASURE / / ciclo trabajo ADC Ja SE SRR SE duty_crnt = Set_DutyCrnt (Ipeak) ; 15AE: MOVF 49. W 15AF: MOVWF 7E 15B0: MOVF 48 W 15B1: MOVWF 7D 15B2: MOVF 47. W 15B3: MOVWF 7C 15B4: MOVF 46. W 15B5: MOVWF 7B 15B6: BCF 0A. 4 = Set_Duty_Max(): = Set_PWM_Duty (temp) ; 15D6: MOVF 32. W 15D7: MOVWF 7B 15D8: BCF 0A. 4 15D9: BSF 0A. 3 15DA: GOTO 3A6 15DB: BSF 0A. 4 15DC: BCF 0A. 3 15DD: MOVF 7A W 15DE: MOVWF 7E 15DF: MOVF 79. W 15E0: MOVWF 7D 15E1: MOVF 78. W 15E2: MOVWF 7C 15E3: MOVF 77.W 15E4: MOVWF 7B 15E5: BCF 0A. 4 15E6: BSF 0A. 3 15E7: GOTO 4AQ 15E8: BSF 0A. 4 15E9: BCF 0A. 3 15EA: MOVF 78. W 15EB: MOVWF BA 1 END ADC _ 1 SLOW START _ if (sl ow_change) { 15EC: RBTFSS 2B. 4 15ED: GOTO 5F1 rampValue = 10; 15EE: MOVLW OA 15EF: MOVWF 74 else{ / / slowstart 15F0: GOTO 5F3 rampValue = 20; 15F1: MOVLW 14 15F2: MOVWF 74 JE 2 ET SE if ((slow_start) && (slowstart<duty!)) { 15F3: BTFSS 2B. 3 15F4: GOTO 66B 15F5: CLRF 7C 15F6: MOVF 5C W 15F7: MOVWF 7B 15F8: BCF 0A. 4 15F9: CALL 4A7 15FA: BSF 0A. 4 15FB: MOVF 7A W 15FC: BSF 03.5 15FD: MOVWF 40 15FE: MOVF 79. W 15FF: MOVWF 3F 1600: MOVF 78. W 1601: MOVWF 3E 1602: MOVF 77. W 1603: MOVWF 3D 1604: BCF 03.5 1605: MOVF 41. W 1606: BSF 03.5 1607: MOVWF 44 1608: BCF 03.5 1609: MOVF 40. W 160A: BSF 03.5 160B: MOVWF 43 160C: BCF 03.5 160D: MOVF 3F. W 160E: BSF 03.5 160F: MOVWF 42 1610: BCF 03.5 1611: MOVF 3EW 1612: BSF 03.5 1613: MOVWF 41 1614: BCF 0A. 4 1615: BCF 03.5 1616: CALL 607 1617: BSF 0A. 4 1618: BTFSS 03.0 1619: GOTO 66B rampCount++; 161A: INCF 73,F dwn aE RRR SER slow_start = FALSE; 161B: BCF 2B. 3 if (slow_change) { 161C: BTFSS 2B. 4 161D: GOTO 620 AAD VAD BRR SER lcd_enable = TRUE; 161E: BSF 2B. 2 else 161F: GOTO 621 dwn aE RRR SER lcd_enable = FALSE; 1620: BCF 2B. 2 1621: MOVF 74.W 1622: SUBWF 73. W 1623: BTFSS 03.0 1624: GOTO 66A rampCount = 0; 1625: CLRF 73 WE PS EEE 0% if (slowstart<duty) { / / falla y temperatura partida 1626: MOVF BAW 1627: SUBWF 5C W 1628: BTFSC 03.0 1629: GOTO 64A YR Sh EA SR high=(int8) ((100-slowstart) time) / 100: 162A: MOVF 5C.W 162B: SUBLW 64 162C: MOVWF 7C 162D: CLRF 7E 162E: MOVF 7C. W 162F: MOVWF 7D 1630: MOVF 58 W 1631: BSF 03.5 1632: MOVWF 21 1633: BCF 03.5 1634: MOVF 57. W 1635: BSF 03.5 1636: MOVWF 20 1637: BCF 0A. 4 1638: BCF 03.5 1639: CALL 7E7 163A: BSF 0A. 4 163B: MOVF 79. W 163C: MOVWF 7E 163D: MOVF 78. W 163E: MOVWF 7D 163F: BSF 03.5 1640: CLRF 21 1641: MOVLW 64 1642: MOVWF 20 1643: BCF 0A. 4 1644: BCF 03.5 1645: CALL 403 1646: BSF 0A. 4 1647: MOVF 78. W 1648: MOVWF 59 1649: GOTO 669 FR SR WS SR = (int8) ((100-duty)*time) / 100; cycle vs temperature 164A: MOVF BAW 164B: SUBLW 64 164C: MOVWF 7C 164D: CLRF 7E 164E: MOVF 7C. W 164F: MOVWF 7D 1650: MOVF 58 W 1651: BSF 03.5 1652: MOVWF 21 16563: BCF 03.5 1654: MOVF 57. W 1655: BSF 03.5 1656: MOVWF 20 16567: BCF 0A. 4 1658: BCF 03.5 1659: CALL 7E7 165A: BSF 0A. 4 165B: MOVF 79. W 165C: MOVWF 7E 165D: MOVE 78, W 165E: MOVWF 7D 165F: BSF 03.5 1660: CLRF 21 1661: MOVLW 64 1662: MOWWF 20 1663: BCF 0A. 4 1664: BCF 03.5 1665: CALL 403 1666: BSF 0A. 4 1667: MOVF 78, W 1668: MOVWF 59 AAD VAD BRR SER slowstart+; 1669: INCF 5C F avs oh EER if (slowstart>= 166A: GOTO 6B1 1668: CLRF 7C 166C: MOVE 5C, W 166D: MOVWF 7B 166E: BCF 0A. 4 166F: CALL 4A7 1670: BSF 0A. 4 1671: MOVF 41. W 1672: BSF 03.5 1673: MOVWF 40 1674: BCF 03.5 1675: MOVF 40. W 1676: BSF 03.5 1677: MOVWF 3F 1678: BCF 03.5 1679: MOVF 3F. W 167A: BSF 03.5 167B: MOVWF 3E 167C: BCF 03.5 167D: MOVF 3EW 167E: BSF 03.5 167F: MOVWF 13D 1680: MOVF 7A W 1681: MOVWF 44 1682: MOVF 79. W 1683: MOVWF 43 1684: MOVF 78. W 1685: MOVWF 42 1686: MOVF 77. W 1687: MOVWF 41 1688: BCF 0A. 4 1689: BCF 03.5 168A: CALL 607 168B: BSF 0A. 4 168C: BTFSC 03.0 168D: GOTO 690 168E: BTFSS 03.2 168F: GOTO 6B1 [ —— = (int8) ((100-duty) *t ime) / 100; vs temperature 1690: MOVF BAW 1691: SUBLW 64 1692: MOVWF 7C 1693: CLRF 7E 1694: MOVF 7C. W 1695: MOVWF 7D 1696: MOVF 58, W 1697: BSF 03.5 1698: MOVWF 21 1699: BCF 03.5 169A: MOVF 57. W 1698: BSF 03.5 169C: MOWWF 20 169D: BCF 0A. 4 169E: BCF 03.5 169F: CALL 7E7 16A0: BSF 0A. 4 16A1: MOVE 79. W 16A2: MOWWF 7E 16A3: MOVF 78, W 16A4: MOVWF 7D 16A5: BSF 03.5 16A6: CLRF 21 16A7: MOVLW 64 16A8: MOVWF 20 16A9: BCF 0A. 4 16AA: BCF 03.5 16AB: CALL 403 16AC: BSF 0A. 4 16AD: MOVF 78, W 16AE: MOVWF 59 AAD VAD BRR SER lcd_enable = 16AF: BSF 2B. 2 gn slow_change = 16B0: BCF 2B. 4 1 END SLOW START _ 1 LCD & RS232 / / refresco rs232 if (refresh) { 16B1: BTFSS 2B. 1 16B2: GOTO 6C6 refresh=FALSE: 16B3: BCF 2B. 1 ——— if (slow_change || !lcd_enable) 16B4: BTFSC 2B. 4 16B5: GOTO 6BS 16B6: RBTFSC 2B. 2 16B7: GOTO 6BC printf_ (slowstart); 16B8: MOVF 5C W 16B9: MOVWF 7B 16BA: CALL OF1 else 16BB: GOTO 6BF printf_ (duty): 16BC: MOVF BAW 16BD: MOVWF 7B 16BE: CALL OF1 timer++: 16BF: INCF 5D,F 16C0: BTFSC 03.2 1601: INCF BEF AR RE BRATS SE toroidal_max=0; / / reset corriente 1602: CLRF 66 1603: CLRF 65 16C4: CLRF 64 1605: CLRF 63 1 END LCD & RS232 _ else / / config mode 16C6: GOTO 335 eiiiiiiiiiiieeo.... void printf_ (int8 dutyCycle) { 2 10F1: MOVF 5EW 10F2: MOVWF 7C 10F3: MOVF 5D. W 10F4: MOVWF 7D Ve PR EY ARR int8 timer_h=make8 (timer, 1); * 1607: SLEEP int8 timer_l=make8 (timer, 0): / / rs232 FR SR WS SR fprintf (PC, “%X;%X:%d:%2. 2; %3. 2f 5d: %2. timer_|, 10*freq, psVoltage, temp, dutyCycle, Ipeak, lavg): * 10F5: MOVLW OA 10F6: MOVWF 7E 10F7: MOVF 5B. W 10F8: BSF 03.5 2 78. W TE TC. W 2 37 21 0A 4 0A 3 03.5 ACA 0A 4 0A. 3 3B 0C. 4 12B 19 DW 03.5 2 37 21 0A. 4 0A. 3 03 5 4CA 0A. 4 0A. 3 3B 0C. 4 13A 19 JEW 03.5 2 18 21 0A. 4 0A 3 03.5 508 0A. 4 0A. 3 3B 0C. 4 149 19 89 04 45 W 03.5 23 03 5 44. W 03 5 22 03.5 43 W 03.5 21 03.5 42.0 03.5 2 02 03 5 21 03 5 46, W 03.5 2 02 24 0A 4 0A 3 03.5 5E1 0A 4 0A. 3 3B 0C. 4 1AF 19 89 04 4a. W 03.5 23 03 5 40, W 03 5 29 03 5 4B W 03 5 21 03 5 4A W 1101: BSF 03.5 1102: MOVWF 20 1103: MOVLW 02 11C4: MOVWF 24 11C5: BCF 0A. 4 1106: BSF 0A. 3 11C7: BCF 03.5 11C8: CALL 5E1 1109: BSF 0A. 4 11CA: BCF 0A. 3 11CB: MOVLW OA 11CC: BTFSS 0C. 4 11CD: GOTO 1CC 11CE: MOVWF 19 / / 1ed if (lcd_enable) { 11CF: BTFSS 2B. 2 11D0: GOTO 23D [ —— printf (lcd_putc, “¥f%d Temp:%3. 2f¥337C¥nModo: %d Ciclo:%d%%”, time_counter_s, temp, freq, dutyCycle): 11D1: MOVLW OC 11D2: BSF 03.5 11D3: MOVWF 2D 11D4: BCF 0A. 4 11D5: BCF 03.5 11D6: CALL 383 11D7: BSF 0A. 4 11D8: MOVF 56. W 11D9: MOVWF 7E 11DA: MOVLW 18 11DB: BSF 03.5 11DC: MOVWF 20 11DD: BCF 0A. 4 0A 3 03.5 6C0 0A 4 0A. 3 8E 03.6 oD 02 OF 06 TE 0A 4 0A. 3 03.6 798 0A. 4 0A 3 02 04 35. W 03.5 23 03 5 34 W 03 5 29 03 5 33 W 03 5 21 03 5 332.0 03 5 20 02 TE 03.5 000 09 03.6 oD 02 OF 08 TE 0A 4 0A. 3 03.6 728 0A 4 0A. 3 BBW TE 18 03 5 2 0A 4 0A 3 03.5 6C0 0A 4 0A 3 A3 03 6 oD 1220: MOVLW 02 1221: MOVWF OF 1222: MOVLW 07 1223: MOVWF 7E 1224: BCF OA. 4 1225: BSF 0A. 3 1226: BCF 03.6 1227: CALL 72B 1228: BSF 0A. 4 1229: BCF 0A. 3 122A: MOVF 7B. W 122B: MOVWF TE 122C: MOVLW 18 122D: BSF 03.5 122E: MOVWF 20 122F: BCF 0A. 4 1230: BSF 0A. 3 1231: BCF 03.5 1232: CALL 6C0 1233: BSF 0A. 4 1234: BCF 0A. 3 1235: MOVLW 25 1236: BSF 03.5 1237: MOVWF 2D 1238: BCF 0A. 4 1239: BCF 03.5 123A: CALL 383 123B: BSF 0A. 4 else 123C: GOTO 276 [ —— printf (led_putc, ” %d%%¥nS | ow %d”, slowstart, time_counter_s) ; AF 03.6 oD 02 OF 03.0 0c TE 0A 4 0A 3 03.6 75B 0A 4 0A. 3 BC, W TE 18 03.5 2 0A 4 0A 3 03.5 6C0 0A. 4 0A. 3 25 03.5 2D 0A 4 03 5 383 0A. 4 B7 125E: BSF 03.6 125F: MOVWF OD 1260: MOVLW 02 1261: MOVWF OF 1262: BCF 03.0 1263: MOVLW OC 1264: MOVWF 7E 1265: BCF 0A. 4 1266: BSF 0A. 3 1267: BCF 03.6 1268: CALL 75B 1269: BSF 0A. 4 126A: BCF O0A.3 126B: MOVF 56 W 126C: MOVWF 7E 126D: MOVLW 18 126E: BSF 03.5 126F: MOVWF 20 1270: BCF 0A. 4 1271: BSF 0A. 3 1272: BCF 03.5 1273: CALL 6C0 1274: BSF 0A. 4 1275: BCF 0A. 3 1276: RETURN eri iiiuiieees...... / / Steinhart-Hart Equation para termistor float Thermister (float voltADC) { / *float temp_1=70.0; float temp 2=35.0; float volti=0. 51: float volt2=1.27: float Temp; Temp=((temp_2-temp_1) / (volt2-volt1))* (vol tAdc-volt1)+temp_1; return Temp;* / HE BAAR Hs ED 5 return -38. 3xlog (( (float) (vol tADG * Vref) / 1023.0)) + 45.348: * 0800: BSF 03.5 0801: MOVF 23. W 0802: MOVWF 40 0803: MOVF 22. W 0804: MOVWF 3F 0805: MOVF 21. W 0806: MOVWF 3E 0807: MOVF 20. W 0808: MOVWF 13D 0809: CLRF 44 080A: CLRF 43 080B: MOVLW 20 080C: MOVWF 42 080D: MOVLW 81 080E: MOVWF 41 080F: BCF O0A.3 0810: BCF 03.5 0811: CALL 4C4 0812: BSF 0A. 3 0813: MOVF 77.W 0814: BSF 03.5 0815: MOVWF 24 0816: MOVF 78. W 0817: MOVWF 25 79.0 2 JAW 27 270 44 26 W 43 25 W 42 24 W 41 48 Ch 47 TF 46 88 45 0A 3 03 5 53R 0A 3 A 03.5 24 78. W 25 79.0 2 TAW 97 27.0 0A62: BCF 03.7 0AB3: BTFSC 29.0 0A64: BSF 03.7 Q0AB5: BCF 03.5 0A66: BCF 0A. 3 0A67: BSF 0A. 4 QA68: GOTO 3E0 (RETURN) Cu. J / frecuencia PWM void Set PWM _Freg(int16 frequency) [ —— disable_interrupts (INT_TIMER1) ; * 042A: BSF 03.5 042B: BCF 0C. 0 ee time=10000 / frequency: 042C: MOVLW 27 0420: MOVWF 7E 042E: MOVLW 10 042F: MOVWF 7D 0430: MOVF 7C.W 0431: MOVWF 21 0432: MOVF 7B. W 0433: MOVWF 20 0434: BCF 03.5 0435: CALL 403 0436: MOVF 79. W 0437: MOVWF 58 0438: MOVF 78. W 0439: MOVWF 57 Si GR WT LATER 7 enable_interrupts (INT_TIMER1) ; 043A: BSF 03.5 043B: BSF 0C. 0 043C: BCF 03.5 0430: RETURN iii... / / owm duty temperatura float Set_PWM_Duty (float temp) { float aux: Si GR WT LATER 7 disable_interrupts (INT_TIMERT) ; * OBA6: BSF 03.5 OBA7: BCF 0C. 0 / / duty cycle (%) vs temperature if (temp<=temp1) { OBA8: MOVF T7E.W 0BA9: MOVWF 40 OBAA: MOVF 7D. W OBAB: MOVWF 3F OBAC: MOVF 7C. W OBAD: MOVWF 3E OBAE: MOVF 7B. W OBAF: MOVWF 3D 0BBO: CLRF 44 OBB1: CLRF 43 0BB2: MOVLW 16 OBB3: MOVWF 42 0BB4: MOVLW 85 OBB5: MOVWF 41 0BB6: BCF 0A. 3 0BB7: BCF 03.5 0BB8: CALL 607 0BB9: BSF 0A.3 OBBA: BTFSC 03.0 0BBB: GOTO 3BE 0BBC: BTFSS 03.2 0BBD: GOTO 3CF PU Mi SAS SE aux=duty1: OBBE: MOVF 41. W OBBF: BSF 03.5 0BCO: MOVWF 23 0BCt: BCF 03.5 0BC2: MOVF 40. W 0BC3: BSF 03.5 0BC4: MOVWF 22 0BC5: BCF 03.5 0BC6: MOVF 3F. W 0BC7: BSF 03.5 0BC8: MOVWF 21 0BC9: BCF 03.5 OBCA: MOVF 3E.W 0BCB: BSF 03.5 OBCC: MOWWF 20 THES Eh TERRES BYE else if (temp>= 0BCD: GOTO 481 OBCE: BCF 03.5 OBCF: BSF 03.5 0BDO: CLRF 40 0BDT: CLRF 3F 0BD2: MOVLW 34 0BD3: MOVWF 3E 0BD4: MOVLW 85 OBD5: MOVWF 3D 0BD6: MOVF T7E.W OBD7: MOVWF 44 0BD8: MOVF 7D. W OBD9: MOVWF 43 OBDA: MOVF 7C. W OBDB: MOVWF 42 OBDC: MOVF 7B. W OBDD: MOVWF 41 OBDE: BCF 0A. 3 OBDF: BCF 03.5 OBEOQ: CALL 607 OBE1: BSF 0A. 3 OBE2: BTFSC 03.0 OBE3: GOTO 3E6 OBE4: BTFSS 03.2 OBES: GOTO 3ED aux=duty2; OBE6: BSF 03.5 0OBE7: CLRF 23 OBES: CLRF 22 OBES: CLRF 21 OBEA: CLRF 20 else OBEB: GOTO 481 OBEC: BCF 03.5 Si GR WT LATER 7 aux=((duty2-duty1) / (temp2-temp1) ) * (temp- + OBED: BSF 03.1 OBEE: BSF 03.5 OBEF: CLRF 44 OBFO: CLRF 43 OBF1: CLRF 42 0BF2: CLRF 41 03 5 41. W 03 5 48 03.5 40 W 03.5 47 03.5 3F.W 03.5 46 03.5 3EW 03.5 45 0A. 3 03.5 648 0A 3 A 03.5 24 78. W 925 79.0 2 JAW 27 44 26 W 43 25. W 25 79.0 2 TAW 27 03.1 270 44 26 W 43 25 W 42 24 W 41 03.5 41. W 03.5 48 03.5 40 W 03 5 47 03 5 3F.W 03.5 46 03.5 3EW 03.5 45 0A. 3 03 5 648 0C77: BSF O0A.3 0C78: MOVF 7A W 0079: BSF 03.5 OC7A: MOVWF 23 0C7B: MOVF 79. W 0C7C: MOVWF 22 0C7D: MOVF 78, W OCTE: MOVWF 21 OC7F: MOVE 77.W 0C80: MOVWF 20 0C81: MOVF 23. W 0082: MOVWF 40 0083: MOVF 22, W 0C84: MOVWF 3F 0C85: MOVF 21. W 0C86: MOVWF 3E 0C87: MOVF 20. W 0C88: MOVWF 3D 0089: CLRF 44 OCBA: CLRF 43 0C8B: CLRF 42 0C8C: CLRF 41 0C8D: BOF O0A.3 OC8E: BCF 03.5 OC8F: CALL 607 0090: BSF 0A.3 0091: BTFSC 03.0 0092: GOTO 495 0093: BTFSS 03.2 0094: GOTO 49B aux = 0: 0095: BSF 03.5 0096: CLRF 23 0097: CLRF 22 0098: CLRF 21 0099: CLRF 20 0C9A: BCF 03.5 SHE Su BEVECENE Es § enable_interrupts (INT_TIMERT) ; O0COB: BSF 03.5 009C: BSF 0C. 0 return aux: 0C9D: MOVF 20. W Q0CO9E: MOVWF 77 QCOF: MOVF 21. W OCAO: MOVWF 78 OCAT: MOVF 22. W 0CA2: MOVWF 79 OCA3: MOVF 23. W 0CA4: MOVWF 7A 0CA5: BCF 03.5 0CA6: BCF 0A. 3 0CA7: BSF 0A. 4 QCA8: GOTO 5DB (RETURN) float Set_DutyCrnt (float crnt) { float aux: / / duty cycle (%) vs temperature Vig SHER ER TERR 9 if{crnt < current_limit) { # JEW 03.5 40 DW SF TC. W 3E TB. W 3D 44 43 2 42 86 41 0A 3 03.5 607 0A. 3 03.0 28F aux = 39. W 03 5 23 03 5 38 W 03 5 29 03 5 37 W 03 5 21 OA89: BCF 03.5 QABA: MOVF 36. W OA8B: BSF 03.5 Q0A8C: MOVWF 20 ile REE SE TE + else 0A8D: GOTO 323 OABE: BCF 03.5 Ve PR EY ARR aux= _adc) / (current_max-currer _limit))*(crnt- current_limit)+duty_adc; OA8F: BSF 03.1 0A90: BSF 03.5 0A91: CLRF 44 0A92: CLRF 43 0A93: CLRF 42 0A94: CLRF 41 0A95: BCF 03.5 QA96: MOVF 39. W 0A97: BSF 03.5 0AQ8: MOVWF 48 0A99: BCF 03.5 QA9A: MOVF 38 W OA9B: BSF 03.5 0A9C: MOVWF 47 OAD: BCF 03.5 QA9E: MOVF 37.W OAQF: BSF 03.5 0AAO: MOVWF 46 O0AA1: BCF 03.5 0AA2: MOVF 36. W 0AA3: BSF 03.5 0AAd: MOVWF 45 0AAS: BCF O0A.3 03 5 648 0A 3 77.0 03.5 24 78. W 25 79.0 2 TAW 97 44 26 W 43 25 W 42 24 W 41 48 47 20 46 84 45 0A 3 03.5 53B 0A. 3 A 03.5 24 78. W 25 79.0 2 TAW 27 03.1 JEW 44 DW 43 TC. W 42 TB.W 41 48 47 2 46 86 45 0A 3 03.5 648 0A 3 03.5 27.0 40 26, W SF 25. W 3E 24.0 3D 0BO9: MOVWF 48 0BOA: BCF 03.5 0BOB: MOVF 38, W 0BOC: BSF 03.5 0BOD: MOVWF 47 OBOE: BCF 03.5 OBOF: MOVF 37. W 0B10: BSF 03.5 0B11: MOVWF 46 0B12: BCF 03.5 0B13: MOVF 36. W 0B14: BSF 03.5 0B15: MOVWF 45 0B16: BCF 0A.3 0B17: BCF 03.5 0B18: CALL 648 0B19: BSF 0A.3 OBTA: MOVF 7A W 0B1B: BSF 03.5 0BI1C: MOVWF 23 OBID: MOVF 79, W OBIE: MOVWF 22 OBIF: MOVF 78 W 0B20: MOWWF 21 0B21: MOVF 77.W 0B22: MOVWF 20 0B23: MOVF 23. W 0B24: MOVWF 40 0B25: MOVF 22, W 0B26: MOVWF 3F 0B27: MOVF 21, W 0B28: MOVWF 3E 0B29: MOVF 20, W 0B2A: MOVWF 3D 0B2B: CLRF 44 0B2C: CLRF 43 0B2D: CLRF 42 OB2E: CLRF 41 0B2F: BCF 0A.3 0B30: BCF 03.5 0B31: CALL 607 0B32: BSF 0A.3 0B33: BTFSC 03.0 0B34: GOTO 337 0B35: BTFSS 03.2 0B36: GOTO 33D 0B37: BSF 03.5 0B38: CLRF 23 0B39: CLRF 22 OB3A: CLRF 21 0B3B: CLRF 20 0B3C: BCF 03.5 0B3D: BSF 03.5 OB3E: MOVF 20, W 0B3F: MOVWF 77 0B40: MOVF 21, W 0B41: MOVWF 78 0B42: MOVF 22, W 0B43: MOVWF 79 0B44: MOVF 23. W 0B45: MOVWF 7A 0B46: BCF 03.5 0B47: BCF 0A. 3 0B48: BSF 0A. 4 0B49: GOTO 5B9 (RETURN) float Set_Duty Max () { float aux: / / duty cycle (%) vs temperature if (duty_crnt <= duty_adc) { OB4A: MOVF 3D W 0B4B: BSF 03.5 0B4C: MOVWF 40 0B4D: BCF 03.5 OB4E: MOVF 3C W OB4F: BSF 03.5 0B50: MOVWF 3F 0B51: BCF 03.5 0B52: MOVF 3B. W 0B53: BSF 03.5 0B54: MOVWF 3E 0B55: BCF 03.5 0B56: MOVF 3A W 0B57: BSF 03.5 0B58: MOVWF 3D 0B59: BCF 03.5 0B5A: MOVF 39. W OB5B: BSF 03.5 0B5C: MOVWF 44 0B5D: BCF 03.5 OBSE: MOVF 38 W 0B5F: BSF 03.5 0B60: MOVWF 43 0B61: BCF 03.5 0B62: MOVF 37. W 0B63: BSF 03.5 0B64: MOVWF 42 0B65: BCF 03.5 0B66: MOVF 36. W 0B67: BSF 03.5 0B68: MOVWF 41 0B69: BCF 0A.3 0B6A: BCF 03.5 0B6B: CALL 607 0B6C: BSF 0A.3 0B6D: BTFSC 03.0 OBE: GOTO 371 OB6F: BTFSS 03.2 0B70: GOTO 37A SR Eh ESE Lh 7 = duty_crnt; 0B71: MOVF 3D. W 0B72: MOVWF 7E 0B73: MOVF 3C.W 0B74: MOVWF 7D 0B75: MOVF 3B. W 0B76: MOVWF 7C 0B77: MOVF 3A W O0B78: MOVWF 7B 0B79: GOTO 382 BAER Ee VRE § = duty_adc, OB7A: MOVF 39. W OB7B: MOVWF 7E 0B7C: MOVF 38 W OB7D: MOVWF 7D OB7E: MOVF 37.W OB7F: MOVWF 7C 0BBO: MOVF 36, W OB81: MOVWF 7B FEE HT ETERS § if (aux<=0) { 0B82: MOVF 7E.W 0B83: BSF 03.5 0B84: MOVWF 40 0B85: MOVF 7D, W 0B86: MOWWF 3F 0B87: MOVF 7C.W 0B88: MOWWF 3E 0B89: MOVF 7B, W 0B8A: MOVWF 3D 0B8B: CLRF 44 0B8C: CLRF 43 0B8D: CLRF 42 OB8E: CLRF 41 0B8F: BCF 0A.3 0B90: BCF 03.5 0B91: CALL 607 0B92: BSF 0A.3 0B93: BTFSC 03.0 0B94: GOTO 397 0B95: BTFSS 03.2 0B96: GOTO 39B Wn A WE ERS aux = 0; 0B97: CLRF 7E 0B98: CLRF 7D 0B99: CLRF 7C 0OB9A: CLRF 7B return aux. 0BIB: MOVF 7B. W 0B9C: MOVWF 77 0BID: MOVF 7C. W OB9E: MOVWF 78 OBIF: MOVF 7D. W OBAO: MOVWF 79 OBA1: MOVF T7EW OBA2: MOVWF 7A OBA3: BCF 0A. 3 0OBA4: BSF 0A. 4 0BA5: GOTO 5C6 (RETURN) Ceiiiiiiiiiiii...... int16 ReadAdc (int channel) { 2 043E: CLRF 7D 043F: CLRF 7C 0440: BSF 03.5 0441: CLRF 21 0442: CLRF 20 int16 rawAde = 0: int16 temporary = 0; Ee BE ERR Ah set_adc_channel (channel) ; 0443: RLF 7B.W 0444: MOVWF 77 0445: RLF 77.F 0446: RLF 77.F 0447: MOVLW F8 0448: ANDWF 77.F 0449: BCF 03.5 044A: MOVF IF. W 044B: ANDLW C7 044C: I0RWF 77.W 044D: MOVWF 1F delay_us (20) ; 044E: MOVLW 10 044F: MOVWF 77 0450: DECFSZ 77.F 0451: GOTO 450 0452: NOP int counter=0; / / clear counter int16 lowest=0xFFFF: / / reset lowest PE TI ———— int16 highest=0; / / reset highest 0453: CLRF 7E 0454: MOVLW FF 0455: BSF 03.5 0456: MOVWF 23 0457: MOVWF 22 0458: CLRF 25 0459: CLRF 24 Si GR WT LATER 7 whi le (counter<10) / / Take 10 readings and average (16+highest+lowest) 045A: MOVF TE W 045B: SUBLW 09 045C: BTFSS 03.0 045D: GOTO 48D CUE Sue SEEN Sa 7 temporary=read_adc () ; / / take an ADC reading 045E: BCF 03.5 045F: BSF 1F.2 0460: BTFSC 1F.2 0461: GOTO 460 0462: MOVF 1EW 0463: MOVWF 7A 0464: BSF 03.5 0465: MOVF 1EW 0466: MOVWF 20 0467: MOVF 7A W 0468: MOVWF 21 Si GR WT LATER 7 if (temporary<|owest) / / check if smaller than lowest 0469: MOVF 21. W 046A: SUBWF 23. W 046B: BTFSS 03.0 046C: GOTO 477 046D: BTFSS 03.2 046E: GOTO 473 046F: MOVF 22. W 0470: SUBWF 20. W 0471: BTFSC 03.0 0472: GOTO 477 CAR SS SRNR SE lowest=temporary; / / save value if smal ler 0473: MOVF 21. W 0474: MOVWF 23 0475: MOVF 20. W 0476: MOVWF 22 Si GR WT LATER 7 if (temporary>highest) / / check if larger than highest 0477: MOVF 25. W 0478: SUBWF 21. W 0479: BTFSS 03.0 047A: GOTO 485 047B: BTFSS 03.2 047C: GOTO 481 047D: MOVF 20. W 047E: SUBWF 24. W 047F: BTFSC 03.0 0480: GOTO 485 3 SE TEER SA highest=temporary; / / save value if larger 0481: MOVF 21. W 0482: MOVWF 25 0483: MOVF 20. W 0484: MOVWF 24 TT rawAdc+=temporary; / / add the ADC values for averaging (Vout on LM35) 0485: MOVF 20. W 0486: ADDWF 7C,F 0487: MOVF 21. W 0488: BTFSC 03.0 0489: INCFSZ 21. W 048A: ADDWF 7D.F counter++: 048B: INCF 7E.F 048C: GOTO 456A Se SEE SE SEER rawAdc—=highest: / / remove highest value 048D: MOVF 24. W 048E: SUBWF 7C,F 048F: MOVF 25. W 0490: BTFSS 03.0 0491: INCFSZ 25. W 0492: SUBWF 7D,F rawAdc-=|owest ; / / remove lowest value 0493: MOVF 22. W 0494: SUBWF 7C F 0495: MOVF 23. W 0496: BTFSS 03.0 0497: INCFSZ 23. W 0498: SUBWF 7D, F rawAdc / =8; 0499: RRF 7D.F 049A: RRF 7C.F 049B: RRF 7D.F 049C: RRF 7C.F 049D: RRF 7D.F 049E: RRF 7C.F 049F: MOVLW 1F 04A0: ANDWF 7D. F return rawAde: 04A1: MOVF 7C.W 04A2: MOVWF 78 04A3: MOVF 7D. W 04A4: MOVWF 79 04A5: BCF 03.5 04A6: RETURN float Calc_Current (float v_med) { / *float v1 = 0.0086; / / 0.031; float v2 = 0.6305; / / 0.309; float al = 0.5: / / 0.13: / / 0.13; float a2 = 30.0: / / 30.9; / / 23.9: / / 28. float aux =((a2-al) / (v2-v1))*(v_med-v +¢ if (aux<=0) { aux = 0: return aux.* / [EE — return ((92.976xv_med) - 0.2819); * 07B5: MOVLW B6 07B6: BSF 03.5 07B7: MOVWF 40 07B8: MOVLW F3 07B9: MOVWF 3F 07BA: MOVLW 39 07BB: MOVWF 3E 07BC: MOVLW 85 07BD: MOVWF 3D Q7BE: MOVF 23. W 07BF: MOVWF 44 0700: MOVF 22. W 07C1: MOVWF 43 0702: MOVF 21. W 0703: MOVWF 42 0704: MOVF 20. W 07C5: MOVWF 41 07C6: BCF 03.5 07C7: CALL 4C4 0708: MOVF 77.W 0709: BSF 03.5 07CA: MOVWF 24 Q7CB: MOVF 78. W 07CC: MOVWF 25 Q7CD: MOVF 79. W Q7CE: MOVWF 26 Q7CF: MOVF 7A W 07D0: MOVWF 27 0ID1: BSF 03.1 0702: MOVF 27.W 07D3: MOVWF 44 07D4: MOVF 26. W 07D5: MOVWF 43 Q07D6: MOVF 25. W 07D7: MOVWF 42 07D8: MOVF 24. W 07D9: MOVWF 41 07DA: MOVLW 32 07DB: MOVWF 48 07DC: MOVLW 55 07DD: MOVWF 47 QO7DE: MOVLW 10 Q7DF: MOVWF 46 07E0: MOVLW 7D 07E1: MOVWF 45 07E2: BCF 03.5 07E3: CALL 648 07E4: BCF 0A. 3 07E5: BSF 0A. 4 Q7E6: GOTO 4E4 (RETURN) BRIEF DESCRIPTION OF THE FIGURES Figure 1 / 9 This figure describes the system described in this development, where the operating interactions of the different elements and devices that comprise the system can be seen in the following numbers. Two types of electrode distributions, and how they are separated when there are more than two according to the numbers, are also shown schematically: (12) Conductive electrodes (14) Treatment tank (or simply tank) (15) Solid-state electronic device (31) Foam outlet. An optional device to separate the flocs from the surface (16) may be associated with this outlet. (32) Inlet of the liquid to be treated (33) Treated liquid outlet (34) Solids outlet (35) Plastic bolt or spacer. (36) Plastic nut Figure 2 / 9 This figure shows a diagram of the solid-state electronic device, where the numbers represent: (1) Control module with microcontroller and peripherals 2) Voltage adaptation and programming module 3) Power module 4) Protections and output status indicators 5) Output channel terminal strip 6) Battery-backed power supply module 7) Power switch and input protection (220VAC) 8) 220VAC power terminal strip 9) 12VDC / 17AH batteries x2 10) Battery bank terminal and protection strip 11) Battery bank protection circuit breaker 13) Electrode output channels Figure 3 / 9 This figure shows a schematic diagram of the power module elements distribution, where the numerals represent: (17) Power transistors (18) Power output terminals (19) Power supply source (20) Command driver transistors (Driver) A (21) Driver Transistors (Driver) B 22) Optocoupler (23) Resistors Figure 4 / 9 This figure shows a distribution scheme of the functional programming module (2) and voltage adaptation elements, where the numerals represent: (24) Programming Mini Dips (25) Regulated direct current (DC) output (26) Voltage Regulators (27) Direct Current Power Supply (28) LED light indicator (29) Programming pushbutton (30) Connectors Figure 5 / 9 This figure presents a mode diagram applied on different samples for the separation of liquids from solids, where modes 10, 20, 30, represent the phase inversion of the frequencies used, with respect to a reference value of 35. The modes are dimensionless values, where each mode has a dynamic frequency associated with it. If one analyzes the diagram one can see that the mode sequence "10, 20, (phase reversal) 60, 40, 50, 60, 40, 50, (in phase) 30, 10 (phase reversal)" is repeated continuously throughout the diagram; this is because this sequence corresponds to one of the six basic operating processes of the system. Figure 6 / 9 This figure shows a zoom of figure 5 / 9, where one can specifically see the basic process given by the mode sequence "10, 20, 60, 40, 50, 50, 60, 40, 50, 30, 10". Where modes 10, 20, and 30 correspond to a phase reversal, as opposed to modes 40, 50, and 60, which occur in phase, where: F1is in phase and its corresponding phase inversion is F1 on superscript, F2 is in phase and its corresponding phase inversion is F2 on superscript, F3 is in phase and its corresponding phase inversion is F3 on superscript, mode 1 follows the following scale 10 pattern, mode 2 follows the following scale 20 pattern, mode 3 follows the following scale 30 pattern, mode 4 follows the following scale 40 pattern, mode 5 follows the following scale 50 pattern, mode 6 follows the following scale 60 pattern. Figure 7 / 9 This figure provides a graphical representation of the duty cycles on a sample, where the modes are related to their respective micro-impulses and samples per second. Figure 8 / 9 This figure zooms in on a section of the graph in Figure 7 / 9, where mode 60 is clearly visible. Figure 9 / 9 This figure presents the integration between the mode diagram and the associated duty cycle diagram, showing the ratio produced in a given duty cycle with regard to the mode used at that time. Note that there are different duty cycles for the same mode, which correspond to different substances present in the liquid to be treated. This means that there will be different duty cycles automatically fed back from the temperature and current measurements and their analysis using the control algorithm. IMPLEMENTATION EXAMPLE Example of liquid industrial waste (LIW) treatment 1 This test was conducted with dairy food industry effluents in 1 cubic meter tanks (EBC), with four aluminum electrodes located at the corners of the tank. Sampling for laboratory analysis was performed in the first third from the base of the tank along one of its lateral faces. Temperature was measured with an infrared thermometer, total dissolved solids (TDS) were measured with a sedimentation cone (laboratory), COD (chemical oxygen demand, also in the laboratory) and pH with a pH std. meter, and conductivity was delivered continuously by the developed system. The tests were performed by external laboratory Eurofins GCL under national sanitary regulations DS 90, DS 46, and DS 609 for liquid waste. Sampling was performed over time and the results were observed as shown in Table | below: Table | | Tank test analysis dairy effluent LIW 1000 L. 4 Electrodes Time Minutes Sample | COD | pH TDS | Conduct. Start Time Treatment 5090 10.7 1430 5280 10.36 | 0 | 2 | 5060 10.6 1560 4510 11.00 | 15 | 3 | 4800 104 1530 | 4430 1130 | 30 | 4 | 4390 10.1 1540 3810 12.45 | 105 | 5 | 4190 9.9 1540 3810 13.30 | 150 | 6 ] 4140 9.8 1610 3780 14.15 7 175 | 7 ] 3770 9.7 1620 3670 15.00 ] 220 The results of this experience clearly show that after 220 minutes of treatment, the chemical oxygen demand (COD) is reduced by approximately 26%, the pH remains relatively constant even though it is acidified by one point, and the total dissolved solids (TDS) increase by 13% because they are agglomerating or electro-coagulating in the treated liquid. On the other hand, conductivity decreases by approximately 31%, thus confirming the lower amount of dissolved substances that conduct electricity. Example of liquid industrial waste (LIW) treatment 2 This test was conducted using effluents from a fruit canning company in 1 cubic meter tanks (EBC), with four aluminum electrodes located at the corners of the tank. Sampling for laboratory analysis was performed in the first third from the base of the tank along one of its lateral faces. Temperature was measured with an infrared thermometer, total dissolved solids (TDS) were measured with a sedimentation cone (laboratory), COD (chemical oxygen demand, also in the laboratory) and pH with a pH std. meter, and conductivity was delivered continuously by the developed system. The tests were performed by external laboratory Eurofins GCL under national regulations DS 90, DS 46, and DS 609 for liquid waste. Sampling was performed over time and the results were observed as shown in Table i: Table || Tank test data analysis 1000 L. — cop 4940 Tank test data analysis 1000 L. Fruit LIW Time Minutes sample |= REDUC COD % sar ime [Treatment | 4940 0 11.05 0 | 2 | 3500 | 29% | 12.00 | 55 | 3 | 1210 | 76% | 1300 | ais | a | 1080 | 78% | 1400 | 27s |'s [sso -83% 15.00 |l2ss The results of this experience clearly show how after 235 minutes of treatment, the chemical oxygen demand (COD) is reduced by approximately 83%. Seawater treatment example These tests were conducted using wastewater effluent from a seawater reverse osmosis plant in one cubic meter tanks (EBC), with half a cubic meter of sample and one cubic meter of sample. In addition, four aluminum electrodes located at the corners of the tank were used. Sampling for laboratory analysis was performed in the first third from the base of the tank along one of its lateral faces. Temperature was measured with an infrared thermometer, total dissolved solids (TDS) were measured with a sedimentation cone (laboratory), COD (chemical oxygen demand, also in the laboratory), the different counterions measured (chloride, nitrate, nitrate / nitrite ratio, and sulfate) were measured in the external laboratory, and pH was measured with a pH std. meter; conductivity was continuously delivered by the developed system. The tests were performed by external laboratory Eurofins GCL under national regulations DS 90, DS 46, and DS 609 for liquid waste. Sampling was performed over time and the results were observed as shown in Table 1": Table III Osmosis plant wastewater analys's Test Date: 12 September 2017 Test 500 Lts. LDM Equipment Ver 2.0 Coce 334-2017-00052123 Rew Water Treated Water Difference Difference Chlorides 182 151 31 83.0% 0b Nitrates eer CEE Ls Nitrate / Nitrite Ratio “Tom ; -_ Tem 1 [ee Jee + Total Dissolved Solids 1255 4 | 0.03 Sulfate (505) Te — 3 | 140 rE Test Date: 28 September 2017 Test 1000 Lis. LOM Equipment Ver 2.0 Raw Water Treated Water Difference Difference Chlorides 746 577 © 169 77.3% Nitrates | 16s 4 53.7 ~~ Nitrate / Nitrite Ratio 27 163 aN 107 60.4% Total Dissolved Solids 3450 4 | or Sulfate (0,) 4 |= The results shown in the upper table of this experiment (half a cubic meter of sample) clearly show that water already treated by reverse osmosis (raw water), but which does not achieve satisfactory sanitary levels for counterions or water hardness, upon being exposed to the present development for 120 minutes is able to reduce chloride levels by 17%, nitrates by 10%, the nitrite / nitrate ratio by 11%, TDS by 11.2% and sulfate by 16.2%. The results of the lower table of this experiment (one cubic meter of sample) clearly show that water already treated by reverse osmosis (raw water), but which does not reach satisfactory sanitary levels for counterions or water hardness, upon exposure to the present development, is able to reduce chloride levels by 22.7%, nitrates by 39.8%, the nitrite / nitrate ratio by 39.6%, TDS by 18.3% and sulfate by 43.3%. The previously exposed minerals were measured using the 2007-MetAlt (19) IC method (Nitrate, Nitrate / Nitrite Ratio, Chloride and Sulfate) and the ME31-MetOf(8) method for Total Dissolved Solids. Electrolyte solution treatment example These tests were conducted using a low copper concentrate electrolytic solution obtained from one cubic meter tanks (EBC) in an electrowinning plant, with one cubic meter of sample. In addition, four tantalum-coated titanium electrodes located at the corners of the tank were used. Sampling for laboratory analysis was performed in the first third from the base of the tank along one of its lateral faces. Temperature was measured with an infrared thermometer, the different ions measured (antimony, bismuth, arsenic, selenium, copper, iron and Cl (HCI)) were measured in the external laboratory, pH was measured with a pH std. meter, and conductivity was delivered continuously by the developed system. The analyses were performed by external laboratory Eurofins GCL. Continuous treatment was performed for 10 minutes and the states and color modification produced were observed, the results of which are shown in Table IV below: Table IV Concantration (g / L) PINo. | Process Solutions Sb BI As Se Cu Fe Hel 11 Original Aclc CH, 30 / 11 / 18 34,91 1,76 7,50 0,03 1,15 0,22 252,61 3} Electrocoag. Acid pl, 30 / 11 / 18 13,98 2,00 4,25 0,02 1,01 0,30 197,59 DOM - PRODUCTION CATHODE CHEMICAL ANALYSIS (BATCH No 3) Laws (%) PINo. Electrowinning Sb Bi As Se Cu Fe 11 Solid Electrocoag. 30 / 11 / 18 | 30,40% 2,57% 21,49% | 0,02% 1,92% 0,06% The results of the upper table of this experiment clearly show that the low copper concentrate electrolyte reduces the ions and elements dissolved in the copper, when this technology is applied: Sb (-60%), Bi (+12), As (-43.3%), Cu (-12.2%), Se (- 33.3%), Fe (+36.4%) and HCI (-21.8%), when exposed to the present development for 10 minutes. The results of the lower table of this experiment clearly show how the electro- coagulated deposit by the system was enriched in the different elements that were separated from the electrolyte. With these results, this technology can be used to recover elements found in low concentrations in spent electrolytes (after the electrowinning process) or in percolated liquids from spent material piles to further optimize electrowinning. In summary, it is clear that the application of the system in the reject water from a reverse osmosis plant and in liquid industrial waste achieves a marked decrease in pollutant parameters.

Claims

CLAIMS 1. A system for separating liquids and solids with minimum conductivity, starting at 2mS / m, WHEREIN the system comprises a treatment tank (14) in which at least two conductive electrodes (12) are immersed at a ratio of the number of electrodes required so that the ratio of 0.25 m? of electrode surface area per m® of tank capacity is met, which are connected to the solid-state electronic device (15), to which an optional solids extraction device can also operate, where said solid-state electronic device (15) is connected to a power source and comprises an algorithm that controls the programming of the system and the conductive electrodes (12), where the solid-state electronic device (15) is capable of generating the electronic signals for the electrodes to emit VLF (very low frequency) band frequencies, between 1 Hz up to 250 Hz, and their corresponding even subharmonics.

2. A system for separating liquids and solids with a minimum conductivity, according to claim 1, WHEREIN the conductive electrodes (12) are made of conductive materials within the group of metallic, ceramic composite, or polymeric materials, preferably from the aluminum, titanium, stainless steel, ruthenium, tantalum, or other conductive material group, preferably of aluminum or also coated electrodes, such as with a titanium core coated with tantalum, where the electrodes are to be positioned inside the treatment tank (14) at a height from the base of the tank of between 5 cm to 25 cm, preferably 10 cm and at a distance from the container walls of between 10 cm to 50 cm, preferably 40 cm.

3. A system for separating liquids and solids with a minimum conductivity, according to claim 1, WHEREIN the treatment tank is one or more containers, non-metallic, preferably plastic, epoxy resins, fiberglass, suitable for holding a volume of liquid from 0.1 cubic meters to 1 million cubic meters, to be processed in Bach form, without excluding continuous treatment, where the containers may include cylindrical, rectangular, conical shapes with decanters, irregular shapes that suit the ground where they are placed, preferably cylindrical, where the tank also comprises inlets (32) and outlets (33) for the liquid to be treated and already treated, foam outlets (31), solids outlet (34) and optionally a surface floc extraction device (16).

4. A system for separating liquids and solids with minimal conductivity, according to claim 1, WHEREIN the solid-state electronic device comprises: a control module with microcontroller and peripherals (1), where the algorithm is stored and the different oscillator frequencies are generated for the different duty cycles of the system, where the operating frequency and duty cycle information is also received from the voltage adaptive programming module (2), and where the trigger control signals to be used by the power module (3) are also generated; a battery-backed power supply module (6) to supply energy to all the modules, where the current is also transformed from alternating current to direct current, and where a battery is also included to supply energy to all the modules; a programming and voltage adaptation module (2), where the different operation modes are programmed externally without the need to access the microcontroller (1) through the integrated programming switches (mini Dips) (24), and the voltages required by the microcontroller (1) for its correct operation are adapted, where it also supplies the trigger signals to the power module (3); a power module (3) fed directly to the conductive electrodes (12), where there are at least four independent channels (13) mounted on a terminal strip (5), where each channel has a set of high-power transistors which are activated by the signals generated by the integrated control element (1) and adapted through the programming and voltage adaptation module (2), where the signals of the power module (3) are isolated from the integrated control element (1), where this module has an optical isolation function through optocouplers (22); and an algorithm to control the different modules, where, considering the frequency inversion, it operates under 6 basic processes that are integrated and related to each other, which are called mode 10, mode 20, mode 30, mode 40, mode 50, and mode 60, where the algorithm also has the ability to perform a frequency inversion in order to "flush" the electrodes and thus increase their service life.

5. A system for separating liquids and solids with minimum conductivity, according to claim 1, WHEREIN the system operates with variable duty cycles, fed back by the current measured at the conductive electrodes (12).

6. A system for separating liquids and solids with minimal conductivity, according to claim 1, WHEREIN the system generates energy pulses of less than 2 milliseconds within a duty cycle. f. A system for separating liquids and solids with minimum conductivity, according to claim 1, WHEREIN the algorithm employed generates different processes and duty cycles in real time, according to the current and temperature measured in real time at the conductive electrodes (12).

8. A procedure for operating a system for separating liquids and solids with minimum conductivity, WHEREIN it comprises the following stages: a) filling the treatment tank with the liquid to be separated up to a spill-proof safety edge; b) measuring the pH, temperature, and conductivity of the liquid to be separated; c) integrating the previously measured data into the algorithm and defining the duty cycle and modes to be applied through the microcontroller (1) and the programming module (2) via its built-in analog and digital inputs; d) activating the solid-state electronic device that provides frequencies in the range of 1 Hz to 250 Hz, preferably in the six system operating modes, where the different modes are assigned according to: i) the measured current flowing through the electrodes; ii) the voltage applied to them; and iii) the temperature of the liquid to be separated, where the solid-state electronic device begins to sweep through the different modes, where infinitesimal current pulses are produced within each mode to break and reform the ionic and covalent bonds of the solids dissolved in the sample, thus generating larger flocs capable of being separated; e) formation of precipitated and / or coagulated solids for extraction from the target liquid; f) formation of bubbles pushing the electro-flocculate to the surface of the tank; 9) removal of the electro-flocculated solid to the surface of the tank, leaving the clean liquid; and h) phase inversion, only with modes 1, 2, and 3, on the electrodes in order to flush them, thus increasing their service life.

9. System operating procedure, according to claim 8, WHEREIN in stage d) it is optionally possible to use the value of 35 as a reference, where there are 3 modes under this value, mode 10, mode 20, and mode 30, and 3 modes above this value, i.e. mode 40, mode 50, and mode 60, where this configuration of modes associates the mathematical algorithms and they take a relative reference, differentiating the modes as "positive" or "negative" with respect to the mentioned reference value; thus, if one considers that each mode can have an independent duty cycle that directly influences the power module (3), and this in turn influences the conductive electrodes (12) and ultimately the electrodes acting directly on the liquid to be separated, different "polarities" associated with different frequencies and different duty cycles are generated.