@@ -0,0 +1,74 | |||||
|
1 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> | |||
|
2 | <?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage"> | |||
|
3 | <storageModule moduleId="org.eclipse.cdt.core.settings"> | |||
|
4 | <cconfiguration id="de.innot.avreclipse.configuration.app.release.858010349"> | |||
|
5 | <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="de.innot.avreclipse.configuration.app.release.858010349" moduleId="org.eclipse.cdt.core.settings" name="Release"> | |||
|
6 | <externalSettings/> | |||
|
7 | <extensions> | |||
|
8 | <extension id="org.eclipse.cdt.core.MakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> | |||
|
9 | <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> | |||
|
10 | <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> | |||
|
11 | <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> | |||
|
12 | <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/> | |||
|
13 | </extensions> | |||
|
14 | </storageModule> | |||
|
15 | <storageModule moduleId="cdtBuildSystem" version="4.0.0"> | |||
|
16 | <configuration artifactName="${ProjName}" buildArtefactType="de.innot.avreclipse.buildArtefactType.app" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release,org.eclipse.cdt.build.core.buildArtefactType=de.innot.avreclipse.buildArtefactType.app" description="" id="de.innot.avreclipse.configuration.app.release.858010349" name="Release" parent="de.innot.avreclipse.configuration.app.release"> | |||
|
17 | <folderInfo id="de.innot.avreclipse.configuration.app.release.858010349." name="/" resourcePath=""> | |||
|
18 | <toolChain id="de.innot.avreclipse.toolchain.winavr.app.release.1201895281" name="AVR-GCC Toolchain" superClass="de.innot.avreclipse.toolchain.winavr.app.release"> | |||
|
19 | <option id="de.innot.avreclipse.toolchain.options.toolchain.objcopy.flash.app.release.1647185864" name="Generate HEX file for Flash memory" superClass="de.innot.avreclipse.toolchain.options.toolchain.objcopy.flash.app.release"/> | |||
|
20 | <option id="de.innot.avreclipse.toolchain.options.toolchain.objcopy.eeprom.app.release.1369579761" name="Generate HEX file for EEPROM" superClass="de.innot.avreclipse.toolchain.options.toolchain.objcopy.eeprom.app.release"/> | |||
|
21 | <option id="de.innot.avreclipse.toolchain.options.toolchain.objdump.app.release.83828298" name="Generate Extended Listing (Source + generated Assembler)" superClass="de.innot.avreclipse.toolchain.options.toolchain.objdump.app.release"/> | |||
|
22 | <option id="de.innot.avreclipse.toolchain.options.toolchain.size.app.release.684879297" name="Print Size" superClass="de.innot.avreclipse.toolchain.options.toolchain.size.app.release"/> | |||
|
23 | <option id="de.innot.avreclipse.toolchain.options.toolchain.avrdude.app.release.1667066990" name="AVRDude" superClass="de.innot.avreclipse.toolchain.options.toolchain.avrdude.app.release"/> | |||
|
24 | <targetPlatform id="de.innot.avreclipse.targetplatform.winavr.app.release.1768688297" name="AVR Cross-Target" superClass="de.innot.avreclipse.targetplatform.winavr.app.release"/> | |||
|
25 | <builder buildPath="${workspace_loc:/acquisitiond}/Release" id="de.innot.avreclipse.target.builder.winavr.app.release.780027386" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="AVR GNU Make Builder" superClass="de.innot.avreclipse.target.builder.winavr.app.release"/> | |||
|
26 | <tool id="de.innot.avreclipse.tool.assembler.winavr.app.release.2089771014" name="AVR Assembler" superClass="de.innot.avreclipse.tool.assembler.winavr.app.release"> | |||
|
27 | <option id="de.innot.avreclipse.assembler.option.debug.level.1133662769" name="Generate Debugging Info" superClass="de.innot.avreclipse.assembler.option.debug.level" value="de.innot.avreclipse.assembler.option.debug.level.none" valueType="enumerated"/> | |||
|
28 | <inputType id="de.innot.avreclipse.tool.assembler.input.1279294131" superClass="de.innot.avreclipse.tool.assembler.input"/> | |||
|
29 | </tool> | |||
|
30 | <tool id="de.innot.avreclipse.tool.compiler.winavr.app.release.271082271" name="AVR Compiler" superClass="de.innot.avreclipse.tool.compiler.winavr.app.release"> | |||
|
31 | <option id="de.innot.avreclipse.compiler.option.debug.level.565091964" name="Generate Debugging Info" superClass="de.innot.avreclipse.compiler.option.debug.level" value="de.innot.avreclipse.compiler.option.debug.level.none" valueType="enumerated"/> | |||
|
32 | <option id="de.innot.avreclipse.compiler.option.optimize.1018740717" name="Optimization Level" superClass="de.innot.avreclipse.compiler.option.optimize" value="de.innot.avreclipse.compiler.optimize.size" valueType="enumerated"/> | |||
|
33 | <inputType id="de.innot.avreclipse.compiler.winavr.input.1924568625" name="C Source Files" superClass="de.innot.avreclipse.compiler.winavr.input"/> | |||
|
34 | </tool> | |||
|
35 | <tool id="de.innot.avreclipse.tool.cppcompiler.app.release.847105960" name="AVR C++ Compiler" superClass="de.innot.avreclipse.tool.cppcompiler.app.release"> | |||
|
36 | <option id="de.innot.avreclipse.cppcompiler.option.debug.level.954847397" name="Generate Debugging Info" superClass="de.innot.avreclipse.cppcompiler.option.debug.level" value="de.innot.avreclipse.cppcompiler.option.debug.level.none" valueType="enumerated"/> | |||
|
37 | <option id="de.innot.avreclipse.cppcompiler.option.optimize.1175987034" name="Optimization Level" superClass="de.innot.avreclipse.cppcompiler.option.optimize" value="de.innot.avreclipse.cppcompiler.optimize.size" valueType="enumerated"/> | |||
|
38 | <inputType id="de.innot.avreclipse.cppcompiler.input.242019820" superClass="de.innot.avreclipse.cppcompiler.input"/> | |||
|
39 | </tool> | |||
|
40 | <tool id="de.innot.avreclipse.tool.linker.winavr.app.release.429279474" name="AVR C Linker" superClass="de.innot.avreclipse.tool.linker.winavr.app.release"/> | |||
|
41 | <tool id="de.innot.avreclipse.tool.cpplinker.app.release.971097438" name="AVR C++ Linker" superClass="de.innot.avreclipse.tool.cpplinker.app.release"> | |||
|
42 | <inputType id="de.innot.avreclipse.tool.cpplinker.input.337770889" name="OBJ Files" superClass="de.innot.avreclipse.tool.cpplinker.input"> | |||
|
43 | <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/> | |||
|
44 | <additionalInput kind="additionalinput" paths="$(LIBS)"/> | |||
|
45 | </inputType> | |||
|
46 | </tool> | |||
|
47 | <tool id="de.innot.avreclipse.tool.archiver.winavr.base.750925756" name="AVR Archiver" superClass="de.innot.avreclipse.tool.archiver.winavr.base"/> | |||
|
48 | <tool id="de.innot.avreclipse.tool.objdump.winavr.app.release.399623506" name="AVR Create Extended Listing" superClass="de.innot.avreclipse.tool.objdump.winavr.app.release"/> | |||
|
49 | <tool id="de.innot.avreclipse.tool.objcopy.flash.winavr.app.release.1920455843" name="AVR Create Flash image" superClass="de.innot.avreclipse.tool.objcopy.flash.winavr.app.release"/> | |||
|
50 | <tool id="de.innot.avreclipse.tool.objcopy.eeprom.winavr.app.release.991951467" name="AVR Create EEPROM image" superClass="de.innot.avreclipse.tool.objcopy.eeprom.winavr.app.release"/> | |||
|
51 | <tool id="de.innot.avreclipse.tool.size.winavr.app.release.864443464" name="Print Size" superClass="de.innot.avreclipse.tool.size.winavr.app.release"/> | |||
|
52 | <tool id="de.innot.avreclipse.tool.avrdude.app.release.533373240" name="AVRDude" superClass="de.innot.avreclipse.tool.avrdude.app.release"/> | |||
|
53 | </toolChain> | |||
|
54 | </folderInfo> | |||
|
55 | </configuration> | |||
|
56 | </storageModule> | |||
|
57 | <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/> | |||
|
58 | </cconfiguration> | |||
|
59 | </storageModule> | |||
|
60 | <storageModule moduleId="cdtBuildSystem" version="4.0.0"> | |||
|
61 | <project id="acquisitiond.de.innot.avreclipse.project.winavr.elf_2.1.0.1252544761" name="AVR Cross Target Application" projectType="de.innot.avreclipse.project.winavr.elf_2.1.0"/> | |||
|
62 | </storageModule> | |||
|
63 | <storageModule moduleId="scannerConfiguration"> | |||
|
64 | <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> | |||
|
65 | <scannerConfigBuildInfo instanceId="de.innot.avreclipse.configuration.app.release.858010349;de.innot.avreclipse.configuration.app.release.858010349.;de.innot.avreclipse.tool.cppcompiler.app.release.847105960;de.innot.avreclipse.cppcompiler.input.242019820"> | |||
|
66 | <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="de.innot.avreclipse.core.AVRGCCManagedMakePerProjectProfileCPP"/> | |||
|
67 | </scannerConfigBuildInfo> | |||
|
68 | <scannerConfigBuildInfo instanceId="de.innot.avreclipse.configuration.app.release.858010349;de.innot.avreclipse.configuration.app.release.858010349.;de.innot.avreclipse.tool.compiler.winavr.app.release.271082271;de.innot.avreclipse.compiler.winavr.input.1924568625"> | |||
|
69 | <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="de.innot.avreclipse.core.AVRGCCManagedMakePerProjectProfileC"/> | |||
|
70 | </scannerConfigBuildInfo> | |||
|
71 | </storageModule> | |||
|
72 | <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/> | |||
|
73 | <storageModule moduleId="refreshScope"/> | |||
|
74 | </cproject> |
@@ -0,0 +1,28 | |||||
|
1 | <?xml version="1.0" encoding="UTF-8"?> | |||
|
2 | <projectDescription> | |||
|
3 | <name>acquisitiond</name> | |||
|
4 | <comment></comment> | |||
|
5 | <projects> | |||
|
6 | </projects> | |||
|
7 | <buildSpec> | |||
|
8 | <buildCommand> | |||
|
9 | <name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name> | |||
|
10 | <triggers>clean,full,incremental,</triggers> | |||
|
11 | <arguments> | |||
|
12 | </arguments> | |||
|
13 | </buildCommand> | |||
|
14 | <buildCommand> | |||
|
15 | <name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name> | |||
|
16 | <triggers>full,incremental,</triggers> | |||
|
17 | <arguments> | |||
|
18 | </arguments> | |||
|
19 | </buildCommand> | |||
|
20 | </buildSpec> | |||
|
21 | <natures> | |||
|
22 | <nature>org.eclipse.cdt.core.cnature</nature> | |||
|
23 | <nature>org.eclipse.cdt.core.ccnature</nature> | |||
|
24 | <nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature> | |||
|
25 | <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature> | |||
|
26 | <nature>de.innot.avreclipse.core.avrnature</nature> | |||
|
27 | </natures> | |||
|
28 | </projectDescription> |
@@ -0,0 +1,8 | |||||
|
1 | avrtarget/ClockFrequency=1000000 | |||
|
2 | avrtarget/ExtRAMSize=0 | |||
|
3 | avrtarget/ExtendedRAM=false | |||
|
4 | avrtarget/MCUType=atxmega32d4 | |||
|
5 | avrtarget/UseEEPROM=false | |||
|
6 | avrtarget/UseExtendedRAMforHeap=true | |||
|
7 | avrtarget/perConfig=false | |||
|
8 | eclipse.preferences.version=1 |
@@ -0,0 +1,261 | |||||
|
1 | /* | |||
|
2 | * acquisitiond.c | |||
|
3 | * | |||
|
4 | * Created on: Mar 24, 2015 | |||
|
5 | * Author: shinobi | |||
|
6 | */ | |||
|
7 | ||||
|
8 | #include "acquisitiond.h" | |||
|
9 | #include "fpgaport.h" | |||
|
10 | ||||
|
11 | volatile uint8_t is_acquiring = 0; | |||
|
12 | volatile uint8_t send_flg = 0; | |||
|
13 | ||||
|
14 | // Comandos para el ADC | |||
|
15 | #define CMD_ACTV 0 | |||
|
16 | #define CMD_DACTV 1 | |||
|
17 | #define CMD_RATE 2 | |||
|
18 | #define CMD_RPARAM 3 | |||
|
19 | #define CMD_WPARAM 4 | |||
|
20 | #define CMD_START 5 | |||
|
21 | #define CMD_STOP 6 | |||
|
22 | #define CMD_INFO 7 | |||
|
23 | #define CMD_GAIN 8 | |||
|
24 | #define CMD_ID 9 | |||
|
25 | #define CMD_STATUS 10 | |||
|
26 | #define CMD_PPS 11 | |||
|
27 | ||||
|
28 | ||||
|
29 | /*! | |||
|
30 | * \fn acq_chn_activate | |||
|
31 | * \breif activa la comunicacion con el IC ADC | |||
|
32 | * \see acq_chn_deactivate | |||
|
33 | */ | |||
|
34 | void acq_chn_activate(){ | |||
|
35 | adcport_open(); | |||
|
36 | } | |||
|
37 | ||||
|
38 | ||||
|
39 | /*! | |||
|
40 | * \fn acq_chn_deactivate | |||
|
41 | * \breif desactiva la comunicacion con el IC ADC | |||
|
42 | * \see acq_chn_activate | |||
|
43 | */ | |||
|
44 | void acq_chn_deactivate(){ | |||
|
45 | adcport_close(); | |||
|
46 | } | |||
|
47 | ||||
|
48 | ||||
|
49 | /*! | |||
|
50 | * \fn acq_chn_datarate | |||
|
51 | * \breif Configura el datarate del ADC | |||
|
52 | * \param datarate El datarate deseado | |||
|
53 | */ | |||
|
54 | void acq_chn_datarate(uint16_t datarate){ | |||
|
55 | if(is_acquiring==1){ | |||
|
56 | acq_stop_acquisiton(); | |||
|
57 | } | |||
|
58 | acq_set_param_to_adc(CMD_RATE,datarate); | |||
|
59 | } | |||
|
60 | ||||
|
61 | ||||
|
62 | /*! | |||
|
63 | * \fn acq_send_information | |||
|
64 | * \breif Envia informacion relevante al Embebido (a traves de FPGA) | |||
|
65 | */ | |||
|
66 | void acq_send_information(){ | |||
|
67 | if(is_acquiring==1){ | |||
|
68 | acq_stop_acquisiton(); | |||
|
69 | } | |||
|
70 | acq_send_param(CMD_RATE); | |||
|
71 | acq_send_param(CMD_GAIN); | |||
|
72 | acq_send_param(CMD_ID); | |||
|
73 | acq_send_param(CMD_STATUS); | |||
|
74 | acq_send_param(CMD_PPS); | |||
|
75 | } | |||
|
76 | ||||
|
77 | ||||
|
78 | /*! | |||
|
79 | * \fn acq_chn_datarate | |||
|
80 | * \breif Envia parametros al embebido a traves del FPGA (este se debe encargar | |||
|
81 | * de hacer el puente al embebido) | |||
|
82 | * \param param El parametro que se quiere enviar al embebido | |||
|
83 | */ | |||
|
84 | void acq_send_param(uint8_t param){ | |||
|
85 | uint8_t data; | |||
|
86 | fpgaport_open(); | |||
|
87 | fpgaport_write(param); | |||
|
88 | switch(param){ | |||
|
89 | case CMD_RATE: | |||
|
90 | // TODO secuencia de comandos para obtener el datarate del ADC | |||
|
91 | break; | |||
|
92 | case CMD_GAIN: | |||
|
93 | data=adcport_get_param(GAIN0); | |||
|
94 | break; | |||
|
95 | case CMD_ID: | |||
|
96 | data=adcport_get_param(ID); | |||
|
97 | break; | |||
|
98 | case CMD_STATUS: | |||
|
99 | data=adcport_get_param(STATUS); | |||
|
100 | break; | |||
|
101 | case CMD_PPS: | |||
|
102 | break;// TODO | |||
|
103 | default: | |||
|
104 | // con esta opcion se puede leer los registros del ADC definidos en | |||
|
105 | // "adcpot.h" y enviarlos al embebido | |||
|
106 | data= adcport_get_param(param); | |||
|
107 | break; | |||
|
108 | } | |||
|
109 | ||||
|
110 | fpgaport_write(data); | |||
|
111 | fpgaport_close(); | |||
|
112 | } | |||
|
113 | ||||
|
114 | ||||
|
115 | /*! | |||
|
116 | * \fn acq_send_buff | |||
|
117 | * \breif Envia el contenido de un buffer de datos hacia el | |||
|
118 | * FPGA para que sean pre-procesados. | |||
|
119 | */ | |||
|
120 | /* | |||
|
121 | * Esta funcion debe ser ejecutada con la señal de una interrupcion externa | |||
|
122 | * manejada por software, que le indicara que hay un buffer lleno listo | |||
|
123 | * para pre-procesar (vea adcport.c ). | |||
|
124 | */ | |||
|
125 | void acq_send_buff(){ | |||
|
126 | uint8_t i=0; | |||
|
127 | uint32_t* pbuff = adcport_getbuff(); | |||
|
128 | fpgaport_open(); | |||
|
129 | while(!(i==BUFF_SIZE)){ | |||
|
130 | fpgaport_write(pbuff[i]); | |||
|
131 | i++; | |||
|
132 | } | |||
|
133 | fpgaport_close(); | |||
|
134 | } | |||
|
135 | ||||
|
136 | ||||
|
137 | /*! | |||
|
138 | * \fn acq_chn_set_datarate | |||
|
139 | * \breif configura edl datarate del ADC | |||
|
140 | * \param datarate | |||
|
141 | */ | |||
|
142 | void acq_chn_set_datarate(uint8_t datarate){ | |||
|
143 | // TODO secuencia de comandos para configurar el data rate | |||
|
144 | } | |||
|
145 | ||||
|
146 | ||||
|
147 | /*! | |||
|
148 | * \fn acq_process_cmd | |||
|
149 | * \breif Procesa todos los comandos enviados desde el FPGA. | |||
|
150 | * \param cmd Comando a procesar. | |||
|
151 | */ | |||
|
152 | /* | |||
|
153 | * Esta funcion debe ejecutarse al haber una interrupcion en el puerto que | |||
|
154 | * conecta al FPGA | |||
|
155 | */ | |||
|
156 | void acq_process_cmd(uint8_t cmd){ | |||
|
157 | static uint8_t param; | |||
|
158 | static uint8_t data; | |||
|
159 | cli();// desactiva interrupciones | |||
|
160 | fpgaport_open(); | |||
|
161 | switch(cmd){ | |||
|
162 | case CMD_ACTV: acq_chn_activate(); | |||
|
163 | break; | |||
|
164 | case CMD_DACTV:acq_chn_deactivate(); | |||
|
165 | break; | |||
|
166 | case CMD_RATE: | |||
|
167 | param=fpgaport_read(); | |||
|
168 | acq_chn_set_datarate(param); | |||
|
169 | break; | |||
|
170 | case CMD_RPARAM: | |||
|
171 | param=fpgaport_read(); | |||
|
172 | acq_send_param(param); | |||
|
173 | break; | |||
|
174 | case CMD_WPARAM: | |||
|
175 | cmd=fpgaport_read();//lee | |||
|
176 | data=fpgaport_read();//lee valor | |||
|
177 | acq_set_param_to_adc(cmd,data); | |||
|
178 | break; | |||
|
179 | case CMD_START: | |||
|
180 | acq_start_acquisition(); | |||
|
181 | break; | |||
|
182 | case CMD_STOP: | |||
|
183 | acq_stop_acquisition(); | |||
|
184 | break; | |||
|
185 | case CMD_INFO: | |||
|
186 | acq_send_information(); | |||
|
187 | break; | |||
|
188 | default: break; | |||
|
189 | } | |||
|
190 | fpgaport_close(); | |||
|
191 | sei();//acvtiva interrupciones | |||
|
192 | } | |||
|
193 | ||||
|
194 | ||||
|
195 | /*! | |||
|
196 | * \fn acq_set_param | |||
|
197 | * \breif Procesa todos los comandos enviados desde el FPGA. | |||
|
198 | * \param param Parametro a configurar. | |||
|
199 | * \param value Valor del parametro | |||
|
200 | */ | |||
|
201 | void acq_set_param(uint8_t param, uint8_t value){ | |||
|
202 | adcport_tranceiv(param); | |||
|
203 | adcport_tranceiv(value); | |||
|
204 | } | |||
|
205 | ||||
|
206 | ||||
|
207 | /*! | |||
|
208 | * \fn acq_start_acquisition | |||
|
209 | * \breif Inicia la adquisicion de datos, esta se hara a traves de interrupciones | |||
|
210 | * "software" (ver adcport.c) | |||
|
211 | */ | |||
|
212 | void acq_start_acquisition(){ | |||
|
213 | is_acquiring = 1; | |||
|
214 | adcport_start(); | |||
|
215 | } | |||
|
216 | ||||
|
217 | /*! | |||
|
218 | * \fn acq_stop_acquisition | |||
|
219 | * \breif Para la adquisicion de datos. Las interrupciones utilizadas para | |||
|
220 | * este fin son desactivadas. | |||
|
221 | */ | |||
|
222 | void acq_stop_acquisition(){ | |||
|
223 | is_acquiring=0; | |||
|
224 | adcport_stop(); | |||
|
225 | } | |||
|
226 | ||||
|
227 | ||||
|
228 | /* | |||
|
229 | * interrupcion en algun pin que no se este usdando. | |||
|
230 | * Interrupcion software. No puede ser PORTC_INT0_vect | |||
|
231 | * Se usara para le indiquen que ya hay un buffer lleno | |||
|
232 | * (ver adcport.c) | |||
|
233 | */ | |||
|
234 | ISR(PORTx_INTx_vect){ // FIXME | |||
|
235 | send_flg=1; | |||
|
236 | } | |||
|
237 | ||||
|
238 | ||||
|
239 | ||||
|
240 | /* | |||
|
241 | * interrupcion en algun pin que no se este usdando. | |||
|
242 | * Interrupcion software. No puede ser PORTC_INT0_vect | |||
|
243 | * Se usara para le indiquen que ya hay un buffer lleno | |||
|
244 | * (ver adcport.c) | |||
|
245 | */ | |||
|
246 | ISR(PORTx_INTx_vect){ // FIXME | |||
|
247 | send_flg=1; | |||
|
248 | } | |||
|
249 | ||||
|
250 | /*! | |||
|
251 | * \brief Espera que un buffer este lleno para enviarlo al fpga | |||
|
252 | */ | |||
|
253 | int main(){ | |||
|
254 | do{ | |||
|
255 | if(send_flg==1){ | |||
|
256 | send_flg=0; | |||
|
257 | acq_send_buff(); | |||
|
258 | } | |||
|
259 | }while(1); | |||
|
260 | return 0; | |||
|
261 | } |
@@ -0,0 +1,35 | |||||
|
1 | /* | |||
|
2 | * acquisitiond.h | |||
|
3 | * | |||
|
4 | * Created on: Mar 24, 2015 | |||
|
5 | * Author: shinobi | |||
|
6 | */ | |||
|
7 | ||||
|
8 | #ifndef ACQUISITIOND_H_ | |||
|
9 | #define ACQUISITIOND_H_ | |||
|
10 | ||||
|
11 | #include <avr/io.h> | |||
|
12 | #include <avr/interrupt.h> | |||
|
13 | #include "adcport.h" | |||
|
14 | ||||
|
15 | void acq_chn_activate(); | |||
|
16 | void acq_chn_deactivate(); | |||
|
17 | void acq_chn_datarate(uint16_t datarate); | |||
|
18 | ||||
|
19 | ||||
|
20 | void acq_send_information(); | |||
|
21 | void acq_send_param(uint8_t param); | |||
|
22 | void acq_send_buff(); | |||
|
23 | ||||
|
24 | ||||
|
25 | void acq_process_cmd(uint8_t cmd); | |||
|
26 | ||||
|
27 | void acq_set_param_to_adc(uint8_t cmd, uint8_t data); | |||
|
28 | ||||
|
29 | ||||
|
30 | void acq_start_acquisition(); | |||
|
31 | void acq_stop_acquisition(); | |||
|
32 | ||||
|
33 | ||||
|
34 | ||||
|
35 | #endif /* ACQUISITIOND_H_ */ |
@@ -0,0 +1,266 | |||||
|
1 | /* | |||
|
2 | * adcport.c | |||
|
3 | * | |||
|
4 | * Created on: Mar 25, 2015 | |||
|
5 | * Author: shinobi | |||
|
6 | */ | |||
|
7 | ||||
|
8 | #include "adcport.h" | |||
|
9 | #include <avr/io.h> | |||
|
10 | #include <avr/interrupt.h> | |||
|
11 | ||||
|
12 | ||||
|
13 | #define SPI_SS_bm PIN4_bm /*!< \brief Bit mask para el pin SS. */ | |||
|
14 | #define SPI_MOSI_bm PIN5_bm /*!< \brief Bit mask para el pin MOSI. */ | |||
|
15 | #define SPI_MISO_bm PIN6_bm /*!< \brief Bit mask para el pin MISO. */ | |||
|
16 | #define SPI_SCK_bm PIN7_bm /*!< \brief Bit mask para el pin SCK. */ | |||
|
17 | ||||
|
18 | ||||
|
19 | #define SS_OFF PORTC.OUTSET=PIN4_bm;/*!< \brief Deselecciona el ADC (puerto SPI) */ | |||
|
20 | #define SS_ON PORTC.OUTCLR=PIN4_bm;/*!< \brief Selecciona el ADC (puerto SPI) */ | |||
|
21 | ||||
|
22 | ||||
|
23 | /* | |||
|
24 | * Al iniciar la adquisicion se debe activar la interrupcion del pin RDY a | |||
|
25 | * traves del PINC6 del XMEGA. | |||
|
26 | * Luego al leer los datos digitalizados, se debe desactivar. Al terminar | |||
|
27 | * se reactiva para esperar la siguiente interrupcion. | |||
|
28 | * Esto se debe a que el DOUT y el RDY del ADC comparten el pin. Si se dejara | |||
|
29 | * activa la interrupcion al leer, se generarian interrupciones e los flancos | |||
|
30 | * de bajada generados por la transferencia de las muestras | |||
|
31 | */ | |||
|
32 | #define WAIT_DATA PORTC.INT0MASK=PIN6_bm/*!< \brief Activa interrupcion que indica dato nuevo */ | |||
|
33 | #define GET_DATA PORTC.INT0MASK=0/*!< \brief Desactiva iterrupcion que indica dato nuevo */ | |||
|
34 | ||||
|
35 | ||||
|
36 | volatile uint8_t buff_idx; | |||
|
37 | uint32_t * pfull_buff; | |||
|
38 | uint32_t * pread_buff; | |||
|
39 | volatile uint8_t buff_full_flg = 0; | |||
|
40 | ||||
|
41 | /*! | |||
|
42 | * \fn adcport_ready_interrupt_config | |||
|
43 | * \brief configura el pin de MISO (conectado a DOUT del ADC), para que dispare | |||
|
44 | * una interrupcion por flanco de bajada. | |||
|
45 | * una vez disparada la interrupcion, se puede leer el pin; sin embargo, debe | |||
|
46 | * desactivarse antes de leer la interrupcion por flanco (con GET_DATA). De lo | |||
|
47 | * contrario se disparara la interrupcion varias veces al leer los datos, ya | |||
|
48 | * que ese el pin RDY y DOUT es el mismo en el ADC. | |||
|
49 | */ | |||
|
50 | inline void adcport_ready_interrupt_config(){ | |||
|
51 | // pin6: MISO(xmega) --> DOUT/RDY(ADC) => pin6 entrada | |||
|
52 | PORTC.DIRCLR=PIN6_bm; | |||
|
53 | // El ADC llevara a "low" RDY cuando la conversion de un dato haya concluido | |||
|
54 | // Se debe leer el dato generado luego. Se espera una interrupcion de flanco | |||
|
55 | // de bajada para manejar esto | |||
|
56 | PORTC.PIN6CTRL=PORT_ISC_FALLING_gc; | |||
|
57 | // Se mapea la interrupcion externa INT0 de PORTC a PINC6 | |||
|
58 | PORTC.INT0MASK=PIN6_bm; | |||
|
59 | // Debido a que esta interrupcion va a manejar la adquisicion de datos, se | |||
|
60 | // le da maxima prioridad (nivel alto) | |||
|
61 | PORTC.INTCTRL=PORT_INT0LVL_HI_gc; | |||
|
62 | // Se habilita la atencion de interrupciones de nivel alto | |||
|
63 | PMIC.CTRL|= PMIC_HILVLEN_bm; | |||
|
64 | } | |||
|
65 | ||||
|
66 | ||||
|
67 | /*! | |||
|
68 | * \fn adcport_spi_config | |||
|
69 | * \brief configura el puerto SPI para que coincida con el requerimiento del ADC | |||
|
70 | * AD7178-2 | |||
|
71 | */ | |||
|
72 | inline void adcport_spi_config(){ | |||
|
73 | PORTC.DIRSET = SPI_MOSI_bm | SPI_SCK_bm | SPI_SS_bm; | |||
|
74 | // Preescaler: clkper/2 (con clk2x). Maestro. CPOL=1,CPHA=1 | |||
|
75 | // MSB primero | |||
|
76 | SPIC.CTRL = SPI_CLK2X_bm|SPI_ENABLE_bm|SPI_MASTER_bm| | |||
|
77 | SPI_MODE1_bm|SPI_MODE0_bm; | |||
|
78 | } | |||
|
79 | ||||
|
80 | ||||
|
81 | /*! | |||
|
82 | * \fn adcport_config | |||
|
83 | * \brief Configura el microcontrolador para darle servicio a la interrupcion | |||
|
84 | * del pin "RDY" del ADC, que reacciona con un flanco de bajada cuando se ha | |||
|
85 | * terminado de digitalar una muestra nueva. | |||
|
86 | * Tambien configura el puerto SPI que servira para comunicarse con el ADC. | |||
|
87 | * \see adcport_ready_interrupt_config | |||
|
88 | * \see adcport_spi_config | |||
|
89 | */ | |||
|
90 | inline void adcport_config(){ | |||
|
91 | adcport_ready_interrupt_config(); | |||
|
92 | adcport_spi_config(); | |||
|
93 | // TODO configurar ADC: datarate, ganancia, desactivar CRC, formato numerico | |||
|
94 | // de muestras debe ser "bipolar offset binary"(canales diferenciales). | |||
|
95 | } | |||
|
96 | ||||
|
97 | ||||
|
98 | /*! | |||
|
99 | * \fn adcport_open | |||
|
100 | * \brief Inicializa el buffer de entrada (para datos de 24bits del ADC) y | |||
|
101 | * activa la comunicacion a traves del pin "SS" del puerto SPI. | |||
|
102 | * \see adcport_close | |||
|
103 | */ | |||
|
104 | inline void adcport_open(){ | |||
|
105 | buff_idx=0; | |||
|
106 | // TODO configurar interrupcion externa PPS (pin 6) | |||
|
107 | // TODO configurar interrupcion externa LOCK (pin 21) | |||
|
108 | pfull_buff = malloc(sizeof(uint32_t)*BUFF_SIZE); | |||
|
109 | pread_buff = malloc(sizeof(uint32_t)*BUFF_SIZE); | |||
|
110 | adcport_config(); | |||
|
111 | SS_ON; | |||
|
112 | } | |||
|
113 | ||||
|
114 | ||||
|
115 | /*! | |||
|
116 | * \fn adcport_close | |||
|
117 | * \brief Desactiva la comunicacion con el ADC a traves del pin "SS" del puerto | |||
|
118 | * SPI. | |||
|
119 | * \see adcport_open | |||
|
120 | */ | |||
|
121 | inline void adcport_close(){ | |||
|
122 | SS_OFF; | |||
|
123 | free(pfull_buff); | |||
|
124 | free(pread_buff); | |||
|
125 | } | |||
|
126 | ||||
|
127 | ||||
|
128 | /*! | |||
|
129 | * \fn adcport_start | |||
|
130 | * \brief Inicia la digitalizacion de muestras del sensor. | |||
|
131 | * SPI. | |||
|
132 | * \see adcport_stop | |||
|
133 | * \see adcport_open | |||
|
134 | * \see adcport_close | |||
|
135 | */ | |||
|
136 | inline void adcport_start(){ | |||
|
137 | // necesario para darle servicio con interrupciones al flanco de bajada | |||
|
138 | // del pin "RDY" | |||
|
139 | WAIT_DATA; | |||
|
140 | // TODO enviar comandos al ADC para que inicie la adquisicion. | |||
|
141 | } | |||
|
142 | ||||
|
143 | ||||
|
144 | /*! | |||
|
145 | * \fn adcport_stop | |||
|
146 | * \brief Pausa la digitalizacion de muestras del sensor. | |||
|
147 | * SPI. | |||
|
148 | * \see adcport_start | |||
|
149 | * \see adcport_open | |||
|
150 | * \see adcport_close | |||
|
151 | */ | |||
|
152 | inline void adcport_stop(){ | |||
|
153 | // TODO enviar comandos al ADC para que deje de adquirir. | |||
|
154 | // necesario para cortar el servicio interrupcion del pin "RDY" | |||
|
155 | GET_DATA; | |||
|
156 | } | |||
|
157 | ||||
|
158 | ||||
|
159 | /*! | |||
|
160 | * \fn adcport_tranceiv | |||
|
161 | * \brief Realiza la transmision y recepcion simultanea de datos entre el ADC y | |||
|
162 | * el microcontrolador. | |||
|
163 | * Incluso en para leer un dato del ADC se debe transmitir, ya que solo la | |||
|
164 | * transmision genera clock en el pin "sclk" | |||
|
165 | * \param El dato a transmitir | |||
|
166 | * \return El dato leido del ADC | |||
|
167 | */ | |||
|
168 | inline uint8_t adcport_tranceiv(uint8_t data){ | |||
|
169 | // | |||
|
170 | SPIC.DATA = data; | |||
|
171 | ||||
|
172 | //Wait until transmission complete | |||
|
173 | while(!(SPIC.STATUS)&SPI_IF_bm); | |||
|
174 | ||||
|
175 | // Return received data | |||
|
176 | return SPIC.DATA; | |||
|
177 | } | |||
|
178 | ||||
|
179 | ||||
|
180 | /*! | |||
|
181 | * \fn adcport_start | |||
|
182 | * \brief Inicia la digitalizacion de muestras del sensor. | |||
|
183 | * SPI. | |||
|
184 | * \see adcport_open | |||
|
185 | */ | |||
|
186 | void adcport_read_sample(){ | |||
|
187 | uint32_t aux; | |||
|
188 | GET_DATA; // desactiva interrupciones de flaco de bajada | |||
|
189 | // Se le indica al adc que se va a leer el registro de data. | |||
|
190 | adcport_tranceiv(0x44); | |||
|
191 | // El byte mas significativo de la variable de 32bits es cero | |||
|
192 | // La codificacion de los numeros es "bipolar offset binary" y | |||
|
193 | // la transmision es MSB first | |||
|
194 | aux = adcport_tranceiv(0); | |||
|
195 | aux = (aux<<8)|adcport_tranceiv(0); | |||
|
196 | aux = (aux<<8)|adcport_tranceiv(0); | |||
|
197 | aux = (aux<<8)|adcport_tranceiv(0); | |||
|
198 | pread_buff[buff_idx]=aux; | |||
|
199 | ||||
|
200 | WAIT_DATA; // reactiva interrupciones de flanco de bajada | |||
|
201 | } | |||
|
202 | ||||
|
203 | ||||
|
204 | /*! | |||
|
205 | * \fn adcport_getbuff | |||
|
206 | * \brief Devuelve la direccion del buffer lleno | |||
|
207 | * \return Direccion del buffer lleno. 0 si no esta lleno aun | |||
|
208 | */ | |||
|
209 | inline uint32_t* adcport_getbuff(){ | |||
|
210 | if(buff_full_flg==1){ | |||
|
211 | buff_full_flg=0; | |||
|
212 | return pfull_buff; | |||
|
213 | } | |||
|
214 | return 0; | |||
|
215 | } | |||
|
216 | ||||
|
217 | ||||
|
218 | uint8_t adcport_get_param(uint8_t data){ | |||
|
219 | adcport_tranceiv(data); | |||
|
220 | return adcport_tranceiv(0); | |||
|
221 | } | |||
|
222 | ||||
|
223 | ||||
|
224 | /*! | |||
|
225 | * \brief interrupcion externa debe dispararse en flanco de bajada en PC6 (RDY del ADC). | |||
|
226 | * Cuando el ADC lleva este pin a "low", se debe leer el dato nuevo | |||
|
227 | */ | |||
|
228 | ISR(PORTC_INT0_vect){ | |||
|
229 | adcport_read_sample(); | |||
|
230 | buff_idx++; | |||
|
231 | if(buff_idx>=100){ | |||
|
232 | uint32_t* paux = pread_buff; | |||
|
233 | pread_buff = pfull_buff; | |||
|
234 | pfull_buff = paux; | |||
|
235 | buff_full_flg=1; | |||
|
236 | // TODO dar aviso al programa principal que el buffer esta lleno. | |||
|
237 | // Puede ser a traves de una interrupcion "externa" en un pin que no se | |||
|
238 | // use, para lo cual debe estar configurado como salida y para recibir | |||
|
239 | // interrupciones de IO. | |||
|
240 | // para hacer que funcione como una interrupcion software, solo escribir | |||
|
241 | // en ese pin un valor segun se configure la interrupcion | |||
|
242 | } | |||
|
243 | } | |||
|
244 | ||||
|
245 | ||||
|
246 | /* TODO | |||
|
247 | * interrupcion del LOCK del GNSS (pin numero 21 del xmega) | |||
|
248 | * servira para indicar que el GNSS esta sincronizado con satelites y la hora y | |||
|
249 | * PPS son correctos, a partir de ese momento se pueden contar los PPS y | |||
|
250 | * identificarlos en el header. | |||
|
251 | */ | |||
|
252 | ISR(PORTx_INTx_vect){ // FIXME | |||
|
253 | ||||
|
254 | } | |||
|
255 | ||||
|
256 | ||||
|
257 | /* TODO | |||
|
258 | * interrupcion del PPS del GNSS (pin numero 6 del xmega) | |||
|
259 | * servira para sincronizar la hora. Debe agregar un numero de serie entre 0 y 255 | |||
|
260 | * a la cabecera del buffer que indentifique al PPS; y el numero de muestra que se adquirio | |||
|
261 | * en el momento de la llegada de esta interrupcion. | |||
|
262 | */ | |||
|
263 | ISR(PORTx_INTx_vect){ // FIXME | |||
|
264 | ||||
|
265 | } | |||
|
266 |
@@ -0,0 +1,60 | |||||
|
1 | /* | |||
|
2 | * adcport.h | |||
|
3 | * | |||
|
4 | * Created on: Mar 25, 2015 | |||
|
5 | * Author: shinobi | |||
|
6 | */ | |||
|
7 | ||||
|
8 | #ifndef ADCPORT_H_ | |||
|
9 | #define ADCPORT_H_ | |||
|
10 | ||||
|
11 | #include <inttypes.h> | |||
|
12 | ||||
|
13 | #define BUFF_SIZE 100 | |||
|
14 | ||||
|
15 | /* Direcciones de registros del ADC */ | |||
|
16 | ||||
|
17 | #define COMMS 0x00 | |||
|
18 | #define STATUS 0x00 | |||
|
19 | #define ADCMODE 0x01 | |||
|
20 | #define IFMODE 0x02 | |||
|
21 | #define REGCHECK 0x03 | |||
|
22 | #define DATA 0X04 | |||
|
23 | #define GPIOCON 0x06 | |||
|
24 | #define ID 0x07 | |||
|
25 | ||||
|
26 | #define CHMAP0 0x10 | |||
|
27 | #define CHMAP1 0x11 | |||
|
28 | #define CHMAP2 0x12 | |||
|
29 | #define CHMAP3 0x13 | |||
|
30 | ||||
|
31 | #define SETUPCON0 0x20 | |||
|
32 | #define SETUPCON1 0x21 | |||
|
33 | #define SETUPCON2 0x22 | |||
|
34 | #define SETUPCON3 0x23 | |||
|
35 | ||||
|
36 | #define FILTCON0 0x28 | |||
|
37 | #define FILTCON1 0x29 | |||
|
38 | #define FILTCON2 0x2A | |||
|
39 | #define FILTCON3 0x2B | |||
|
40 | ||||
|
41 | #define OFFSET0 0x30 | |||
|
42 | #define OFFSET1 0x31 | |||
|
43 | #define OFFSET2 0x32 | |||
|
44 | #define OFFSET3 0x33 | |||
|
45 | ||||
|
46 | #define GAIN0 0x38 | |||
|
47 | #define GAIN1 0x39 | |||
|
48 | #define GAIN2 0x2A | |||
|
49 | #define GAIN3 0x2B | |||
|
50 | ||||
|
51 | ||||
|
52 | void adcport_open(); | |||
|
53 | void adcport_close(); | |||
|
54 | void adcport_start(); | |||
|
55 | void adcport_stop(); | |||
|
56 | uint32_t* adcport_getbuff(); | |||
|
57 | uint8_t adcport_tranceiv(uint8_t data); | |||
|
58 | uint8_t adcport_get_param(uint8_t data); | |||
|
59 | ||||
|
60 | #endif /* ADCPORT_H_ */ |
@@ -0,0 +1,57 | |||||
|
1 | /* | |||
|
2 | * fpgaport.c | |||
|
3 | * | |||
|
4 | * Created on: Mar 26, 2015 | |||
|
5 | * Author: shinobi | |||
|
6 | */ | |||
|
7 | ||||
|
8 | ||||
|
9 | /*! | |||
|
10 | * \fn fpgaport_open | |||
|
11 | * \brief actima la comunicacion con el FPGA | |||
|
12 | */ | |||
|
13 | inline void fpgaport_open(){ | |||
|
14 | // TODO configurar puerto pfga e interrupcion externa (pin 22) | |||
|
15 | // TODO configurar interrupcion externa PPS (pin 6) | |||
|
16 | // TODO configurar interrupcion externa LOCK (pin 21) | |||
|
17 | } | |||
|
18 | ||||
|
19 | ||||
|
20 | /*! | |||
|
21 | * \fn fpgaport_close | |||
|
22 | * \brief Desactiva la comunicacion con el FPGA | |||
|
23 | */ | |||
|
24 | inline void fpgaport_close(){ | |||
|
25 | // TODO configurar puerto pfga e interrupcion externa (pin 22) para | |||
|
26 | // clock | |||
|
27 | } | |||
|
28 | ||||
|
29 | ||||
|
30 | /*! | |||
|
31 | * \fn fpgaport_write | |||
|
32 | * \breif activa la comunicacion con el IC ADC | |||
|
33 | * \see acq_chn_deactivate | |||
|
34 | */ | |||
|
35 | inline void fpgaport_write(uint8_t data){ | |||
|
36 | // TODO | |||
|
37 | } | |||
|
38 | ||||
|
39 | ||||
|
40 | /*! | |||
|
41 | * \fn fpgaport_read | |||
|
42 | * \breif activa la comunicacion con el IC ADC | |||
|
43 | * \see acq_chn_deactivate | |||
|
44 | */ | |||
|
45 | inline uint8_t fpgaport_read(){ | |||
|
46 | // TODO | |||
|
47 | } | |||
|
48 | ||||
|
49 | ||||
|
50 | /* | |||
|
51 | * Interrupcion de dato entrante por el puerto FPGA. El pin debe ser alguno de los | |||
|
52 | * que estan conectatos al FPGA (el bus) | |||
|
53 | */ | |||
|
54 | ISR(PORTx_INTx_vect){ | |||
|
55 | // TODO debe idicar que se ejecute la funcion que procesa los comandos | |||
|
56 | // que bienen del FPGA | |||
|
57 | } |
@@ -0,0 +1,19 | |||||
|
1 | /* | |||
|
2 | * fpgaport.h | |||
|
3 | * | |||
|
4 | * Created on: Mar 26, 2015 | |||
|
5 | * Author: shinobi | |||
|
6 | */ | |||
|
7 | ||||
|
8 | #ifndef FPGAPORT_H_ | |||
|
9 | #define FPGAPORT_H_ | |||
|
10 | ||||
|
11 | #include <inttypes.h> | |||
|
12 | ||||
|
13 | void fpgaport_open(); | |||
|
14 | void fpgaport_close(); | |||
|
15 | void fpgaport_write(uint8_t data); | |||
|
16 | uint8_t fpgaport_read(); | |||
|
17 | ||||
|
18 | ||||
|
19 | #endif /* FPGAPORT_H_ */ |
@@ -0,0 +1,286 | |||||
|
1 | /* | |||
|
2 | * powerEngine.c | |||
|
3 | * | |||
|
4 | * Created on: Mar 23, 2015 | |||
|
5 | * Author: shinobi | |||
|
6 | */ | |||
|
7 | ||||
|
8 | #include "powerEngined.h" | |||
|
9 | #include "usi_i2c_slave.h" | |||
|
10 | #include <util/delay.h> | |||
|
11 | #include <avr/interrupt.h> | |||
|
12 | ||||
|
13 | #define DQ_HIGH DQ_PORT |= (1<<DQ_BIT) | |||
|
14 | #define DQ_LOW DQ_PORT &= ~(1<<DQ_BIT) | |||
|
15 | #define DQ_INPUT DQ_DDR &= ~(1<<DQ_BIT) | |||
|
16 | #define DQ_OUTPUT DQ_DDR |= (1<<DQ_BIT) | |||
|
17 | #define DQ_READ ((DQ_PIN&(1<<DQ_BIT))!=0)?0x01:0x00 | |||
|
18 | ||||
|
19 | #define US (1000000.0/ F_CPU ) | |||
|
20 | ||||
|
21 | ||||
|
22 | #define TM0_ON TCCR0B |=(0<<CS02)|(0<<CS01)|(1<<CS00) | |||
|
23 | #define TM0_OFF TCCR0B &= ~((1<<CS02)|(1<<CS01)|(1<<CS00)) | |||
|
24 | ||||
|
25 | #define TM1_ON TCCR1 |= (1<<CS13)|(1<<CS12)|(1<<CS11)|(1<<CS10) | |||
|
26 | #define TM1_OFF TCCR1 &= ~((1<<CS13)|(1<<CS12)|(1<<CS11)|(1<<CS10)) | |||
|
27 | ||||
|
28 | #define MAX_TM_CYCLES 15 | |||
|
29 | ||||
|
30 | volatile uint8_t presenced_flg = 0; | |||
|
31 | volatile uint8_t process_flg = 0; | |||
|
32 | volatile uint8_t tm_cycles = 0; | |||
|
33 | ||||
|
34 | ||||
|
35 | extern char* USI_Slave_register_buffer[]; | |||
|
36 | ||||
|
37 | /*! | |||
|
38 | * \fn write_0_signal | |||
|
39 | * \brief genera el simbolo que corresponde a '0' logico en el protocolo | |||
|
40 | * especificatdo en el datasheet del IC DS2438Z | |||
|
41 | * \see write_1_signal | |||
|
42 | * \see write_byte | |||
|
43 | */ | |||
|
44 | void write_0_signal(){ | |||
|
45 | DQ_LOW; | |||
|
46 | _delay_us(65); | |||
|
47 | DQ_HIGH; | |||
|
48 | _delay_us(1); | |||
|
49 | } | |||
|
50 | ||||
|
51 | /*! | |||
|
52 | * \fn write_1_signal | |||
|
53 | * \brief genera el simbolo que corresponde a '1' logico en el protocolo | |||
|
54 | * especificatdo en el datasheet del IC DS2438Z | |||
|
55 | * \see write_0_signal | |||
|
56 | * \see write_byte | |||
|
57 | */ | |||
|
58 | void write_1_signal(){ | |||
|
59 | DQ_LOW; | |||
|
60 | _delay_us(10); | |||
|
61 | DQ_HIGH; | |||
|
62 | _delay_us(56); | |||
|
63 | } | |||
|
64 | ||||
|
65 | ||||
|
66 | /*! | |||
|
67 | * \fn write_byte | |||
|
68 | * \brief Escribe un byte por el puerto DQ | |||
|
69 | * \param byte El byte a escribir | |||
|
70 | * \see write_0_signal | |||
|
71 | * \see write_1_signal | |||
|
72 | */ | |||
|
73 | void write_byte(uint8_t byte){ | |||
|
74 | uint8_t mask = 0x00; | |||
|
75 | ||||
|
76 | while(mask!=0){ | |||
|
77 | if((byte&mask)!=0){ | |||
|
78 | write_1_signal(); | |||
|
79 | }else{ | |||
|
80 | write_0_signal(); | |||
|
81 | } | |||
|
82 | mask = (uint8_t)(mask << 1); | |||
|
83 | } | |||
|
84 | } | |||
|
85 | ||||
|
86 | /*! | |||
|
87 | * \fn write_bytes | |||
|
88 | * \brief Escribe "len" bytes por el puerto DQ | |||
|
89 | * \param pbytes Puntero a inicio de buffer que contiene los bytes | |||
|
90 | * \param len >Numero de bytes a escribir | |||
|
91 | * \see write_byte | |||
|
92 | */ | |||
|
93 | void write_bytes(uint8_t* pbytes,uint8_t len){ | |||
|
94 | do{ | |||
|
95 | len-=1; | |||
|
96 | write_byte(pbytes[len]); | |||
|
97 | }while(len>0); | |||
|
98 | } | |||
|
99 | ||||
|
100 | ||||
|
101 | /*! | |||
|
102 | * \fn read_signal | |||
|
103 | * \brief Lee un bit del puerto DQ | |||
|
104 | * \return '1' o '0'. | |||
|
105 | * \see read_byte | |||
|
106 | */ | |||
|
107 | uint8_t read_signal(){ | |||
|
108 | uint8_t bit = 0; | |||
|
109 | ||||
|
110 | DQ_LOW; | |||
|
111 | _delay_us(2); | |||
|
112 | DQ_HIGH; | |||
|
113 | ||||
|
114 | DQ_INPUT; | |||
|
115 | _delay_us(8); | |||
|
116 | bit = DQ_READ; | |||
|
117 | _delay_us(55); | |||
|
118 | ||||
|
119 | DQ_OUTPUT; | |||
|
120 | DQ_HIGH; | |||
|
121 | _delay_us(1); | |||
|
122 | ||||
|
123 | return bit; | |||
|
124 | } | |||
|
125 | ||||
|
126 | ||||
|
127 | /*! | |||
|
128 | * \fn read_byte | |||
|
129 | * \brief Lee un byte de el puerto DQ | |||
|
130 | * \see read_signal | |||
|
131 | * \see read_bytes | |||
|
132 | */ | |||
|
133 | uint8_t read_byte(){ | |||
|
134 | uint8_t shift = 0x00; | |||
|
135 | uint8_t byte = 0x00; | |||
|
136 | uint8_t bit= 0; | |||
|
137 | while(shift< 8){ | |||
|
138 | bit = read_signal(); | |||
|
139 | byte |= (bit<<shift); | |||
|
140 | shift++; | |||
|
141 | } | |||
|
142 | return byte; | |||
|
143 | } | |||
|
144 | ||||
|
145 | ||||
|
146 | /*! | |||
|
147 | * \fn read_bytes | |||
|
148 | * \brief Lee "len" bytes de el puerto DQ | |||
|
149 | * \param pbytes puntero a buffer, contendra los bytes leidos. | |||
|
150 | * \param len Numero de bytes a leer. | |||
|
151 | * \see read_byte | |||
|
152 | */ | |||
|
153 | void read_bytes(uint8_t* pbytes, uint8_t len){ | |||
|
154 | do{ | |||
|
155 | len-=1; | |||
|
156 | pbytes[len] = read_byte(); | |||
|
157 | }while(len>0); | |||
|
158 | } | |||
|
159 | ||||
|
160 | ||||
|
161 | /*! | |||
|
162 | * \fn initialization | |||
|
163 | * \brief Inicia o reinicia al IC DS2438Z | |||
|
164 | */ | |||
|
165 | void initialization(){ | |||
|
166 | TCNT0 = 0x0000; | |||
|
167 | presenced_flg = 0; | |||
|
168 | DQ_LOW; | |||
|
169 | _delay_us(490); | |||
|
170 | TM0_ON; | |||
|
171 | DQ_HIGH; | |||
|
172 | while(presenced_flg != 1){} | |||
|
173 | } | |||
|
174 | ||||
|
175 | ||||
|
176 | /*! | |||
|
177 | * \fn memory_read | |||
|
178 | * \brief Realiza la lectura de toda la memoria del IC DS2438Z | |||
|
179 | */ | |||
|
180 | void memory_read(uint8_t* pbytes, uint8_t page_addr){ | |||
|
181 | uint8_t crc; | |||
|
182 | initialization(); | |||
|
183 | write_byte(SKIP_ROM); | |||
|
184 | write_byte(READ_SP); | |||
|
185 | write_byte(page_addr); | |||
|
186 | read_bytes(pbytes,8); | |||
|
187 | crc = read_byte(); | |||
|
188 | initialization(); | |||
|
189 | } | |||
|
190 | ||||
|
191 | /*! | |||
|
192 | * \fn convert | |||
|
193 | * \brief Inicia la conversion ADC de los parametros desados | |||
|
194 | * \param cmd CONVERT_T para iniciar la conversion de temperatura. CONVERT_V | |||
|
195 | * para iniciar la conversion de voltaje. | |||
|
196 | */ | |||
|
197 | void convert(uint8_t cmd){ | |||
|
198 | uint8_t bit = 0; | |||
|
199 | initialization(); | |||
|
200 | write_byte(SKIP_ROM); | |||
|
201 | write_byte(cmd); | |||
|
202 | do{ | |||
|
203 | bit = read_signal(); | |||
|
204 | }while(bit != 1); | |||
|
205 | initialization(); | |||
|
206 | } | |||
|
207 | ||||
|
208 | /*! | |||
|
209 | * \fn void send_data | |||
|
210 | * \brief Envia data al sistema enbebido por puerto twi | |||
|
211 | * \param pbytes Puntero a buffer de bytes a enviar. | |||
|
212 | * \param len Numero de bytes a enviar. Debe ser menor o igual a USI_SLAVE_REGISTER_COUNT. | |||
|
213 | */ | |||
|
214 | void send_data(uint8_t* pbytes, uint8_t len){ | |||
|
215 | int i; | |||
|
216 | for(i=0;i<USI_SLAVE_REGISTER_COUNT;i++){ | |||
|
217 | if(i<len){ | |||
|
218 | USI_Slave_register_buffer[i]=(char)(pbytes[i]); | |||
|
219 | }else{ | |||
|
220 | USI_Slave_register_buffer[i]='\0'; | |||
|
221 | } | |||
|
222 | } | |||
|
223 | ||||
|
224 | } | |||
|
225 | ||||
|
226 | ||||
|
227 | //usado para cronometrar la lectura del presence pulse | |||
|
228 | ISR(TIM0_COMPA_vect ){ | |||
|
229 | TM0_OFF; | |||
|
230 | } | |||
|
231 | ||||
|
232 | ||||
|
233 | //detecta el nivel bajo. usado para detectar el presence pulse | |||
|
234 | ISR(PCINT0_vect){ | |||
|
235 | uint16_t cnt; | |||
|
236 | if((PINB&(1<<PINB3))==0x00){ | |||
|
237 | if((cnt>=60*US)&&(cnt<=240*US)){ | |||
|
238 | presenced_flg=1; | |||
|
239 | } | |||
|
240 | } | |||
|
241 | } | |||
|
242 | ||||
|
243 | ||||
|
244 | ISR(TIM1_COMPB_vect){ | |||
|
245 | tm_cycles++; // cuenta de 60 segundos | |||
|
246 | if(tm_cycles>=MAX_TM_CYCLES){ | |||
|
247 | process_flg = 1; | |||
|
248 | tm_cycles=0; | |||
|
249 | } | |||
|
250 | } | |||
|
251 | ||||
|
252 | ||||
|
253 | int main(){ | |||
|
254 | uint8_t pbytes[8]; | |||
|
255 | // inicializa | |||
|
256 | USI_I2C_Init(I2C_SLAVE_ADDR); | |||
|
257 | cli(); | |||
|
258 | // interrupcion externa | |||
|
259 | GIMSK |= _BV(PCIE); // Turn on Pin Change interrupt | |||
|
260 | PCMSK |= _BV(PCINT3); // Which pins are affected by the interrupt | |||
|
261 | // timer0 CTC con OCRA como top. Debe interrumpir en 250us luego de | |||
|
262 | // TM0_ON | |||
|
263 | TCCR0A = (1<<COM0A1)|(1<<COM0A0)|(1<<WGM01)|(0<<WGM00); | |||
|
264 | TCCR0B = (0<<WGM02); | |||
|
265 | TM0_OFF; | |||
|
266 | OCR0A = (uint8_t)(250*US); | |||
|
267 | // timer1 CTC TOP : OCR1C ; pre-scaler 16384 | |||
|
268 | TCCR1 = (1<<COM1A1)|(1<<COM1A0); | |||
|
269 | TM1_OFF; | |||
|
270 | OCR1A = (uint8_t)(244*US);// x 15 ciclo x 16384 (pre-scaler) | |||
|
271 | //Activa interrupciones de timers | |||
|
272 | TIMSK |= (1<<OCIE1A)|(1<<OCIE0A); | |||
|
273 | ||||
|
274 | presenced_flg=0; | |||
|
275 | sei(); | |||
|
276 | do{ | |||
|
277 | process_flg = 0; | |||
|
278 | convert(CONV_T); | |||
|
279 | convert(CONV_V); | |||
|
280 | memory_read(pbytes,PAGE_0); | |||
|
281 | send_data(pbytes,8); | |||
|
282 | while(!(process_flg==1)){}; | |||
|
283 | }while(1==1); | |||
|
284 | ||||
|
285 | return 0; | |||
|
286 | } |
@@ -0,0 +1,349 | |||||
|
1 | /*-----------------------------------------------------*\ | |||
|
2 | | USI I2C Slave Driver | | |||
|
3 | | | | |||
|
4 | | This library provides a robust, interrupt-driven I2C | | |||
|
5 | | slave implementation built on the ATTiny Universal | | |||
|
6 | | Serial Interface (USI) hardware. Slave operation is | | |||
|
7 | | implemented as a register bank, where each 'register' | | |||
|
8 | | is a pointer to an 8-bit variable in the main code. | | |||
|
9 | | This was chosen to make I2C integration transparent | | |||
|
10 | | to the mainline code and making I2C reads simple. | | |||
|
11 | | This library also works well with the Linux I2C-Tools | | |||
|
12 | | utilities i2cdetect, i2cget, i2cset, and i2cdump. | | |||
|
13 | | | | |||
|
14 | | Adam Honse (GitHub: CalcProgrammer1) - 7/29/2012 | | |||
|
15 | | -calcprogrammer1@gmail.com | | |||
|
16 | \*-----------------------------------------------------*/ | |||
|
17 | ||||
|
18 | #include "usi_i2c_slave.h" | |||
|
19 | ||||
|
20 | char usi_i2c_slave_internal_address; | |||
|
21 | char usi_i2c_slave_address; | |||
|
22 | char usi_i2c_mode; | |||
|
23 | ||||
|
24 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |||
|
25 | ////USI Slave States/////////////////////////////////////////////////////////////////////////////// | |||
|
26 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |||
|
27 | ||||
|
28 | ||||
|
29 | ||||
|
30 | // The I2C register file is stored as an array of pointers, point these to whatever your I2C registers | |||
|
31 | // need to read/write in your code. This abstracts the buffer and makes it easier to write directly | |||
|
32 | // to values in your code. | |||
|
33 | char* USI_Slave_register_buffer[USI_SLAVE_REGISTER_COUNT]; | |||
|
34 | char USI_Slave_internal_address = 0; | |||
|
35 | char USI_Slave_internal_address_set = 0; | |||
|
36 | ||||
|
37 | enum | |||
|
38 | ||||
|
39 | { | |||
|
40 | ||||
|
41 | USI_SLAVE_CHECK_ADDRESS, | |||
|
42 | USI_SLAVE_SEND_DATA, | |||
|
43 | USI_SLAVE_SEND_DATA_ACK_WAIT, | |||
|
44 | USI_SLAVE_SEND_DATA_ACK_CHECK, | |||
|
45 | ||||
|
46 | USI_SLAVE_RECV_DATA_WAIT, | |||
|
47 | ||||
|
48 | USI_SLAVE_RECV_DATA_ACK_SEND | |||
|
49 | ||||
|
50 | } USI_I2C_Slave_State; | |||
|
51 | ||||
|
52 | ///////////////////////////////////////////////// | |||
|
53 | ////USI Register Setup Values//////////////////// | |||
|
54 | ///////////////////////////////////////////////// | |||
|
55 | ||||
|
56 | #define USI_SLAVE_COUNT_ACK_USISR 0b01110000 | (0x0E << USICNT0) //Counts one clock (ACK) | |||
|
57 | #define USI_SLAVE_COUNT_BYTE_USISR 0b01110000 | (0x00 << USICNT0) //Counts 8 clocks (BYTE) | |||
|
58 | #define USI_SLAVE_CLEAR_START_USISR 0b11110000 | (0x00 << USICNT0) //Clears START flag | |||
|
59 | #define USI_SLAVE_SET_START_COND_USISR 0b01110000 | (0x00 << USICNT0) | |||
|
60 | #define USI_SLAVE_SET_START_COND_USICR 0b10101000 | |||
|
61 | #define USI_SLAVE_STOP_DID_OCCUR_USICR 0b10111000 | |||
|
62 | #define USI_SLAVE_STOP_NOT_OCCUR_USICR 0b11101000 | |||
|
63 | ||||
|
64 | ///////////////////////////////////////////////// | |||
|
65 | ////USI Direction Macros///////////////////////// | |||
|
66 | ///////////////////////////////////////////////// | |||
|
67 | ||||
|
68 | #define USI_SET_SDA_OUTPUT() { DDR_USI |= (1 << PORT_USI_SDA); } | |||
|
69 | #define USI_SET_SDA_INPUT() { DDR_USI &= ~(1 << PORT_USI_SDA); } | |||
|
70 | ||||
|
71 | #define USI_SET_SCL_OUTPUT() { DDR_USI |= (1 << PORT_USI_SCL); } | |||
|
72 | #define USI_SET_SCL_INPUT() { DDR_USI &= ~(1 << PORT_USI_SCL); } | |||
|
73 | ||||
|
74 | #define USI_SET_BOTH_OUTPUT() { DDR_USI |= (1 << PORT_USI_SDA) | (1 << PORT_USI_SCL); } | |||
|
75 | #define USI_SET_BOTH_INPUT() { DDR_USI &= ~((1 << PORT_USI_SDA) | (1 << PORT_USI_SCL)); } | |||
|
76 | ||||
|
77 | //////////////////////////////////////////////////////////////////////////////////////////////////// | |||
|
78 | ||||
|
79 | void USI_I2C_Init(char address) | |||
|
80 | { | |||
|
81 | PORT_USI &= ~(1 << PORT_USI_SCL); | |||
|
82 | PORT_USI &= ~(1 << PORT_USI_SDA); | |||
|
83 | ||||
|
84 | usi_i2c_slave_address = address; | |||
|
85 | ||||
|
86 | USI_SET_BOTH_INPUT(); | |||
|
87 | ||||
|
88 | USICR = (1 << USISIE) | (0 << USIOIE) | (1 << USIWM1) | (0 << USIWM0) | (1 << USICS1) | (0 << USICS0) | (0 << USICLK) | (0 << USITC); | |||
|
89 | USISR = (1 << USISIF) | (1 << USIOIF) | (1 << USIPF) | (1 << USIDC); | |||
|
90 | } | |||
|
91 | ||||
|
92 | ///////////////////////////////////////////////////////////////////////////////// | |||
|
93 | // ISR USI_START_vect - USI Start Condition Detector Interrupt // | |||
|
94 | // // | |||
|
95 | // This interrupt occurs when the USI Start Condition Detector detects a // | |||
|
96 | // start condition. A start condition marks the beginning of an I2C // | |||
|
97 | // transmission and occurs when SDA has a high->low transition followed by an // | |||
|
98 | // SCL high->low transition. When a start condition occurs, the I2C slave // | |||
|
99 | // state is set to check address mode and the counter is set to wait 8 clocks // | |||
|
100 | // (enough for the address/rw byte to be transmitted) before overflowing and // | |||
|
101 | // triggering the first state table interrupt. If a stop condition occurs, // | |||
|
102 | // reset the start condition detector to detect the next start condition. // | |||
|
103 | ///////////////////////////////////////////////////////////////////////////////// | |||
|
104 | ||||
|
105 | ISR(USI_START_vect) | |||
|
106 | ||||
|
107 | { | |||
|
108 | ||||
|
109 | USI_I2C_Slave_State = USI_SLAVE_CHECK_ADDRESS; | |||
|
110 | ||||
|
111 | ||||
|
112 | USI_SET_SDA_INPUT(); | |||
|
113 | ||||
|
114 | ||||
|
115 | ||||
|
116 | // wait for SCL to go low to ensure the Start Condition has completed (the | |||
|
117 | ||||
|
118 | // start detector will hold SCL low ) - if a Stop Condition arises then leave | |||
|
119 | ||||
|
120 | // the interrupt to prevent waiting forever - don't use USISR to test for Stop | |||
|
121 | ||||
|
122 | // Condition as in Application Note AVR312 because the Stop Condition Flag is | |||
|
123 | ||||
|
124 | // going to be set from the last TWI sequence | |||
|
125 | ||||
|
126 | while((PIN_USI & (1 << PIN_USI_SCL)) && !((PIN_USI & (1 << PIN_USI_SDA)))); | |||
|
127 | ||||
|
128 | ||||
|
129 | ||||
|
130 | if(!(PIN_USI & (1 << PIN_USI_SDA))) | |||
|
131 | ||||
|
132 | { | |||
|
133 | ||||
|
134 | // a Stop Condition did not occur | |||
|
135 | ||||
|
136 | USICR = USI_SLAVE_STOP_NOT_OCCUR_USICR; | |||
|
137 | ||||
|
138 | } | |||
|
139 | ||||
|
140 | else | |||
|
141 | ||||
|
142 | { | |||
|
143 | // a Stop Condition did occur | |||
|
144 | ||||
|
145 | USICR = USI_SLAVE_STOP_DID_OCCUR_USICR; | |||
|
146 | ||||
|
147 | } | |||
|
148 | ||||
|
149 | ||||
|
150 | ||||
|
151 | USISR = USI_SLAVE_CLEAR_START_USISR; | |||
|
152 | ||||
|
153 | } | |||
|
154 | ||||
|
155 | ///////////////////////////////////////////////////////////////////////////////// | |||
|
156 | // ISR USI_OVERFLOW_vect - USI Overflow Interrupt // | |||
|
157 | // // | |||
|
158 | // This interrupt occurs when the USI counter overflows. By setting this // | |||
|
159 | // counter to 8, the USI can be commanded to wait one byte length before // | |||
|
160 | // causing another interrupt (and thus state change). To wait for an ACK, // | |||
|
161 | // set the counter to 1 (actually -1, or 0x0E) it will wait one clock. // | |||
|
162 | // This is used to set up a state table of I2C transmission states that fits // | |||
|
163 | // the I2C protocol for proper transmission. // | |||
|
164 | ///////////////////////////////////////////////////////////////////////////////// | |||
|
165 | ||||
|
166 | ISR(USI_OVERFLOW_vect) | |||
|
167 | ||||
|
168 | { | |||
|
169 | switch (USI_I2C_Slave_State) | |||
|
170 | ||||
|
171 | { | |||
|
172 | ///////////////////////////////////////////////////////////////////////// | |||
|
173 | // Case USI_SLAVE_CHECK_ADDRESS // | |||
|
174 | // // | |||
|
175 | // The first state after the start condition, this state checks the // | |||
|
176 | // received byte against the stored slave address as well as the // | |||
|
177 | // global transmission address of 0x00. If there is a match, the R/W // | |||
|
178 | // bit is checked to branch either to sending or receiving modes. // | |||
|
179 | // If the address was not for this device, the USI system is // | |||
|
180 | // re-initialized for start condition. // | |||
|
181 | ///////////////////////////////////////////////////////////////////////// | |||
|
182 | ||||
|
183 | case USI_SLAVE_CHECK_ADDRESS: | |||
|
184 | ||||
|
185 | ||||
|
186 | if((USIDR == 0) || ((USIDR >> 1) == usi_i2c_slave_address)) | |||
|
187 | ||||
|
188 | { | |||
|
189 | if (USIDR & 0x01) | |||
|
190 | ||||
|
191 | { | |||
|
192 | USI_I2C_Slave_State = USI_SLAVE_SEND_DATA; | |||
|
193 | ||||
|
194 | } | |||
|
195 | ||||
|
196 | else | |||
|
197 | ||||
|
198 | { | |||
|
199 | USI_Slave_internal_address_set = 0; | |||
|
200 | USI_I2C_Slave_State = USI_SLAVE_RECV_DATA_WAIT; | |||
|
201 | ||||
|
202 | } | |||
|
203 | ||||
|
204 | //Set USI to send ACK | |||
|
205 | ||||
|
206 | USIDR = 0; | |||
|
207 | ||||
|
208 | USI_SET_SDA_OUTPUT(); | |||
|
209 | ||||
|
210 | USISR = USI_SLAVE_COUNT_ACK_USISR; | |||
|
211 | } | |||
|
212 | ||||
|
213 | else | |||
|
214 | ||||
|
215 | { | |||
|
216 | //Set USI to Start Condition Mode | |||
|
217 | ||||
|
218 | USICR = USI_SLAVE_SET_START_COND_USICR; | |||
|
219 | ||||
|
220 | USISR = USI_SLAVE_SET_START_COND_USISR; | |||
|
221 | } | |||
|
222 | ||||
|
223 | break; | |||
|
224 | ||||
|
225 | ///////////////////////////////////////////////////////////////////////// | |||
|
226 | // Case USI_SLAVE_SEND_DATA_ACK_WAIT // | |||
|
227 | // // | |||
|
228 | // Wait 1 clock period for the master to ACK or NACK the sent data // | |||
|
229 | // If master NACK's, it means that master doesn't want any more data. // | |||
|
230 | ///////////////////////////////////////////////////////////////////////// | |||
|
231 | case USI_SLAVE_SEND_DATA_ACK_WAIT: | |||
|
232 | ||||
|
233 | //After sending, immediately shut off PORT = 1 to prevent driving | |||
|
234 | //the line high (I2C should *NEVER* drive high, and could damage | |||
|
235 | //connected devices if operating at different voltage levels) | |||
|
236 | PORT_USI &= ~(1 << PORT_USI_SDA); | |||
|
237 | ||||
|
238 | ||||
|
239 | USI_I2C_Slave_State = USI_SLAVE_SEND_DATA_ACK_CHECK; | |||
|
240 | USI_SET_SDA_INPUT(); | |||
|
241 | USISR = USI_SLAVE_COUNT_ACK_USISR; | |||
|
242 | break; | |||
|
243 | ||||
|
244 | ///////////////////////////////////////////////////////////////////////// | |||
|
245 | // Case USI_SLAVE_SEND_DATA_ACK_CHECK // | |||
|
246 | // // | |||
|
247 | // Check USIDR to see if master sent ACK or NACK. If NACK, set up // | |||
|
248 | // a reset to START conditions, if ACK, fall through into SEND_DATA // | |||
|
249 | // to continue sending data. // | |||
|
250 | ///////////////////////////////////////////////////////////////////////// | |||
|
251 | case USI_SLAVE_SEND_DATA_ACK_CHECK: | |||
|
252 | ||||
|
253 | if(USIDR) | |||
|
254 | { | |||
|
255 | //The master sent a NACK, indicating that it will not accept | |||
|
256 | //more data. Reset into START condition state | |||
|
257 | USICR = USI_SLAVE_SET_START_COND_USICR; | |||
|
258 | USISR = USI_SLAVE_SET_START_COND_USISR; | |||
|
259 | return; | |||
|
260 | } | |||
|
261 | //else: fall through into SEND_DATA | |||
|
262 | ||||
|
263 | ///////////////////////////////////////////////////////////////////////// | |||
|
264 | // Case USI_SLAVE_SEND_DATA // | |||
|
265 | // // | |||
|
266 | // Set USIDR to the data to be sent, then set up SDA registers to // | |||
|
267 | // enable data transmission in the next 8 clocks. Set to wait 8 // | |||
|
268 | // clocks and proceed to wait for ACK. // | |||
|
269 | ///////////////////////////////////////////////////////////////////////// | |||
|
270 | case USI_SLAVE_SEND_DATA: | |||
|
271 | ||||
|
272 | if(USI_Slave_internal_address <= USI_SLAVE_REGISTER_COUNT) | |||
|
273 | { | |||
|
274 | USIDR = *(USI_Slave_register_buffer[USI_Slave_internal_address]); | |||
|
275 | } | |||
|
276 | else | |||
|
277 | { | |||
|
278 | USIDR = 0x00; | |||
|
279 | } | |||
|
280 | USI_Slave_internal_address++; | |||
|
281 | ||||
|
282 | ||||
|
283 | USI_I2C_Slave_State = USI_SLAVE_SEND_DATA_ACK_WAIT; | |||
|
284 | ||||
|
285 | ||||
|
286 | //To send data, DDR for SDA must be 1 (Output) and PORT for SDA | |||
|
287 | //must also be 1 (line drives low on USIDR MSB = 0 or PORT = 0) | |||
|
288 | ||||
|
289 | USI_SET_SDA_OUTPUT(); | |||
|
290 | PORT_USI |= (1 << PORT_USI_SDA); | |||
|
291 | ||||
|
292 | USISR = USI_SLAVE_COUNT_BYTE_USISR; | |||
|
293 | ||||
|
294 | break; | |||
|
295 | ||||
|
296 | ||||
|
297 | ///////////////////////////////////////////////////////////////////////// | |||
|
298 | // Case USI_SLAVE_RECV_DATA_WAIT // | |||
|
299 | // // | |||
|
300 | // Prepares to wait 8 clocks to receive a data byte from the master. // | |||
|
301 | ///////////////////////////////////////////////////////////////////////// | |||
|
302 | ||||
|
303 | case USI_SLAVE_RECV_DATA_WAIT: | |||
|
304 | ||||
|
305 | USI_I2C_Slave_State = USI_SLAVE_RECV_DATA_ACK_SEND; | |||
|
306 | ||||
|
307 | USI_SET_SDA_INPUT(); | |||
|
308 | ||||
|
309 | USISR = USI_SLAVE_COUNT_BYTE_USISR; | |||
|
310 | ||||
|
311 | break; | |||
|
312 | ||||
|
313 | ||||
|
314 | ///////////////////////////////////////////////////////////////////////// | |||
|
315 | // Case USI_SLAVE_RECV_DATA_ACK_SEND // | |||
|
316 | // // | |||
|
317 | // After waiting for the master to finish transmission, this reads // | |||
|
318 | // USIDR into either the i2c buffer or internal address, then sends // | |||
|
319 | // an acknowledgement to the master. // | |||
|
320 | ///////////////////////////////////////////////////////////////////////// | |||
|
321 | ||||
|
322 | case USI_SLAVE_RECV_DATA_ACK_SEND: | |||
|
323 | ||||
|
324 | ||||
|
325 | ||||
|
326 | USI_I2C_Slave_State = USI_SLAVE_RECV_DATA_WAIT; | |||
|
327 | ||||
|
328 | ||||
|
329 | if(USI_Slave_internal_address_set == 0) | |||
|
330 | { | |||
|
331 | USI_Slave_internal_address = USIDR; | |||
|
332 | USI_Slave_internal_address_set = 1; | |||
|
333 | } | |||
|
334 | else if(USI_Slave_internal_address <= USI_SLAVE_REGISTER_COUNT) | |||
|
335 | { | |||
|
336 | *(USI_Slave_register_buffer[USI_Slave_internal_address]) = USIDR; | |||
|
337 | } | |||
|
338 | ||||
|
339 | USIDR = 0; | |||
|
340 | ||||
|
341 | USI_SET_SDA_OUTPUT(); | |||
|
342 | ||||
|
343 | USISR = USI_SLAVE_COUNT_ACK_USISR; | |||
|
344 | ||||
|
345 | break; | |||
|
346 | ||||
|
347 | } | |||
|
348 | ||||
|
349 | } |
@@ -0,0 +1,39 | |||||
|
1 | /*-----------------------------------------------------*\ | |||
|
2 | | USI I2C Slave Driver | | |||
|
3 | | | | |||
|
4 | | This library provides a robust, interrupt-driven I2C | | |||
|
5 | | slave implementation built on the ATTiny Universal | | |||
|
6 | | Serial Interface (USI) hardware. Slave operation is | | |||
|
7 | | implemented as a register bank, where each 'register' | | |||
|
8 | | is a pointer to an 8-bit variable in the main code. | | |||
|
9 | | This was chosen to make I2C integration transparent | | |||
|
10 | | to the mainline code and making I2C reads simple. | | |||
|
11 | | This library also works well with the Linux I2C-Tools | | |||
|
12 | | utilities i2cdetect, i2cget, i2cset, and i2cdump. | | |||
|
13 | | | | |||
|
14 | | Adam Honse (GitHub: CalcProgrammer1) - 7/29/2012 | | |||
|
15 | | -calcprogrammer1@gmail.com | | |||
|
16 | \*-----------------------------------------------------*/ | |||
|
17 | #ifndef USI_I2C_SLAVE_H | |||
|
18 | #define USI_I2C_SLAVE_H | |||
|
19 | ||||
|
20 | #include <avr/io.h> | |||
|
21 | #include <avr/interrupt.h> | |||
|
22 | ||||
|
23 | #ifdef __AVR_ATtiny85__ | |||
|
24 | #define DDR_USI DDRB | |||
|
25 | #define PORT_USI PORTB | |||
|
26 | #define PIN_USI PINB | |||
|
27 | #define PORT_USI_SDA PB0 | |||
|
28 | #define PORT_USI_SCL PB2 | |||
|
29 | #define PIN_USI_SDA PINB0 | |||
|
30 | #define PIN_USI_SCL PINB2 | |||
|
31 | #endif | |||
|
32 | ||||
|
33 | #define USI_SLAVE_REGISTER_COUNT 8 | |||
|
34 | ||||
|
35 | //USI I2C Initialize | |||
|
36 | // address - If slave, this parameter is the slave address | |||
|
37 | void USI_I2C_Init(char address); | |||
|
38 | ||||
|
39 | #endif |
@@ -0,0 +1,17 | |||||
|
1 | <?xml version="1.0" encoding="UTF-8"?> | |||
|
2 | <projectDescription> | |||
|
3 | <name>int_cic_simul</name> | |||
|
4 | <comment></comment> | |||
|
5 | <projects> | |||
|
6 | </projects> | |||
|
7 | <buildSpec> | |||
|
8 | <buildCommand> | |||
|
9 | <name>org.python.pydev.PyDevBuilder</name> | |||
|
10 | <arguments> | |||
|
11 | </arguments> | |||
|
12 | </buildCommand> | |||
|
13 | </buildSpec> | |||
|
14 | <natures> | |||
|
15 | <nature>org.python.pydev.pythonNature</nature> | |||
|
16 | </natures> | |||
|
17 | </projectDescription> |
@@ -0,0 +1,8 | |||||
|
1 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> | |||
|
2 | <?eclipse-pydev version="1.0"?><pydev_project> | |||
|
3 | <pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH"> | |||
|
4 | <path>/${PROJECT_DIR_NAME}</path> | |||
|
5 | </pydev_pathproperty> | |||
|
6 | <pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property> | |||
|
7 | <pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property> | |||
|
8 | </pydev_project> |
1 | NO CONTENT: new file 10644 |
|
NO CONTENT: new file 10644 |
1 | NO CONTENT: new file 10644 |
|
NO CONTENT: new file 10644 |
1 | NO CONTENT: new file 10644 |
|
NO CONTENT: new file 10644 |
1 | NO CONTENT: new file 10644 |
|
NO CONTENT: new file 10644 |
1 | NO CONTENT: new file 10644 |
|
NO CONTENT: new file 10644 |
1 | NO CONTENT: new file 10644 |
|
NO CONTENT: new file 10644 |
1 | NO CONTENT: new file 10644 |
|
NO CONTENT: new file 10644 |
@@ -0,0 +1,131 | |||||
|
1 | ''' | |||
|
2 | Created on Jan 6, 2015 | |||
|
3 | ||||
|
4 | @author: aras | |||
|
5 | ''' | |||
|
6 | from primitives.wire import wire | |||
|
7 | from cic.integrator import integrator | |||
|
8 | from cic.comb import comb | |||
|
9 | from primitives.attenuator import atten | |||
|
10 | ||||
|
11 | ||||
|
12 | class cic_decimator(object): | |||
|
13 | ''' | |||
|
14 | classdocs | |||
|
15 | ''' | |||
|
16 | ||||
|
17 | def __init__(self, clk,wire_in, wire_out, k=1, r=1, m=1): | |||
|
18 | ''' | |||
|
19 | Constructor | |||
|
20 | ''' | |||
|
21 | self.__clk__ = clk; | |||
|
22 | self.__dec__ = r; | |||
|
23 | self.__stages__ = k; | |||
|
24 | self.__dly__ = m; | |||
|
25 | ||||
|
26 | self.__wire_int_in__ = wire_in; | |||
|
27 | self.__wire_1__ = None; | |||
|
28 | self.__wire_int_out__ = wire_out; | |||
|
29 | ||||
|
30 | self.wires=[]; | |||
|
31 | ||||
|
32 | self.wires.append(wire_in); | |||
|
33 | self.__generate_integrator__(); | |||
|
34 | self.__generate_comb__(); | |||
|
35 | self.wires.append(wire_out); | |||
|
36 | ||||
|
37 | self.__aux=0; | |||
|
38 | ||||
|
39 | ||||
|
40 | ||||
|
41 | def __generate_integrator__(self): | |||
|
42 | wire_in = self.__wire_int_in__; | |||
|
43 | clk = self.__clk__; | |||
|
44 | for i in range(self.__stages__): | |||
|
45 | wire_out1 = wire(); | |||
|
46 | wire_out2 = wire(); | |||
|
47 | integrator(clk,wire_in,wire_out1); | |||
|
48 | atten( wire_out1, wire_out2 , atte=float(self.__dec__)); | |||
|
49 | wire_in = wire_out2; | |||
|
50 | self.__wire_1__ = wire_out2; | |||
|
51 | ||||
|
52 | ||||
|
53 | ||||
|
54 | ||||
|
55 | def __generate_comb__(self): | |||
|
56 | wire_in = self.__wire_1__; | |||
|
57 | clk = self.__clk__; | |||
|
58 | for i in range(self.__stages__-1): | |||
|
59 | wire_out = wire(); | |||
|
60 | self.wires.append(wire_out); | |||
|
61 | comb(clk,wire_in,wire_out,deep=self.__dec__*self.__dly__); | |||
|
62 | wire_in = wire_out; | |||
|
63 | comb(clk,wire_in,self.__wire_int_out__,deep=self.__dec__*self.__dly__); | |||
|
64 | ||||
|
65 | ||||
|
66 | if __name__=="__main__": | |||
|
67 | from primitives.clock import clock | |||
|
68 | from primitives.pin import pin | |||
|
69 | from primitives.pout import pout | |||
|
70 | ||||
|
71 | import matplotlib.pyplot as plt | |||
|
72 | import numpy as np | |||
|
73 | ||||
|
74 | # parametros de decimacion | |||
|
75 | dec = 64; # decimacion | |||
|
76 | stgs = 3; # numero de pares integrador-comba | |||
|
77 | dtsz = 2**16; # cantidad de muestras de data original | |||
|
78 | dtszd= dtsz/dec # cantidad de muestras de data decimada | |||
|
79 | Fs = 1.0;#1000.0; # frecuencia de muestreo de data original | |||
|
80 | Fsd = Fs/dec; # frecuencia de muestreo de data decimada | |||
|
81 | Ts = 1.0/Fs; # tiempo de muestreo de data original | |||
|
82 | Tsd = 1.0/Fsd; # tiempo de muestreo de data decimada | |||
|
83 | Tt = Ts*dtsz; # tiempo total | |||
|
84 | Fst = Fs/dtsz; | |||
|
85 | ||||
|
86 | # data original (impulso) | |||
|
87 | sig = [0 for i in range(dtsz)]; | |||
|
88 | sig[0] = 1; | |||
|
89 | ||||
|
90 | ||||
|
91 | tsig = [Ts*i for i in range(dtsz)]; | |||
|
92 | freq = [Fst*i-Fs/2 for i in range(dtsz)]; | |||
|
93 | ||||
|
94 | ||||
|
95 | # descripcion del circuito | |||
|
96 | clk = clock(); # clock maestro | |||
|
97 | ||||
|
98 | sig0 = wire(); | |||
|
99 | sig1 = wire(); | |||
|
100 | cic = cic_decimator(clk,sig0,sig1,k=stgs,r=dec,m=1); | |||
|
101 | ||||
|
102 | p_int = pin(clk,sig0); | |||
|
103 | p_int.set_data(sig); | |||
|
104 | ||||
|
105 | p3 = pout(clk,sig0); | |||
|
106 | p4 = pout(clk,sig1); | |||
|
107 | ||||
|
108 | for x in range(dtsz): | |||
|
109 | clk.tick(); | |||
|
110 | ||||
|
111 | ||||
|
112 | out = np.array(p4.get_data()); | |||
|
113 | ||||
|
114 | ||||
|
115 | fft_out = np.fft.fft(out); | |||
|
116 | fft_out = np.fft.fftshift(fft_out); | |||
|
117 | fft_gain = np.abs(fft_out*np.conj(fft_out))+0.000000001; | |||
|
118 | fft_db = 10.0*np.log10(fft_gain); | |||
|
119 | ||||
|
120 | ||||
|
121 | fig = plt.figure() | |||
|
122 | amp_f = fig.add_subplot(2,1,1) | |||
|
123 | amp_f.plot(freq,fft_db, color='blue'); | |||
|
124 | amp_f.grid(); | |||
|
125 | amp_t = fig.add_subplot(2,1,2) | |||
|
126 | amp_t.plot(tsig,out, color='blue'); | |||
|
127 | amp_t.plot(tsig,p3.get_data(), color='red'); | |||
|
128 | amp_t.grid(); | |||
|
129 | plt.show(); | |||
|
130 | ||||
|
131 | No newline at end of file |
@@ -0,0 +1,61 | |||||
|
1 | ''' | |||
|
2 | Created on Jan 7, 2015 | |||
|
3 | ||||
|
4 | @author: aras | |||
|
5 | ''' | |||
|
6 | ||||
|
7 | from primitives.delay import delay | |||
|
8 | from primitives.adder import adder,NEG | |||
|
9 | from primitives.wire import wire | |||
|
10 | ||||
|
11 | ||||
|
12 | class comb(object): | |||
|
13 | ''' | |||
|
14 | classdocs | |||
|
15 | ''' | |||
|
16 | ||||
|
17 | ||||
|
18 | def __init__(self, clk , wire_in, wire_out, deep=1): | |||
|
19 | ''' | |||
|
20 | Constructor | |||
|
21 | ''' | |||
|
22 | self.__wire_in = wire_in; | |||
|
23 | self.__wire_out = wire_out; | |||
|
24 | self.__wire_1 = wire(); | |||
|
25 | ||||
|
26 | self.__adder = adder(); | |||
|
27 | self.__z1 = delay(clk,self.__wire_in,self.__wire_1, deep=deep); | |||
|
28 | self.__clk = clk; | |||
|
29 | ||||
|
30 | self.__adder.connect_to_in(self.__wire_in); | |||
|
31 | self.__adder.connect_to_in(self.__wire_1 , NEG); | |||
|
32 | self.__adder.connect_to_out(self.__wire_out); | |||
|
33 | ||||
|
34 | ||||
|
35 | ||||
|
36 | ||||
|
37 | if __name__=="__main__": | |||
|
38 | from primitives.clock import clock | |||
|
39 | from primitives.pin import pin | |||
|
40 | from primitives.pout import pout | |||
|
41 | ||||
|
42 | ||||
|
43 | segnal = [i for i in range(30)]; | |||
|
44 | segnal[0]=0.0; | |||
|
45 | clk = clock(); | |||
|
46 | sig0 = wire(); | |||
|
47 | sig1 = wire(); | |||
|
48 | ||||
|
49 | comb1 = comb(clk,sig0,sig1,deep=2); | |||
|
50 | ||||
|
51 | p_int = pin(clk,sig0); | |||
|
52 | p_int.set_data(segnal); | |||
|
53 | pi = pout(clk,sig0); | |||
|
54 | po = pout(clk,sig1); | |||
|
55 | ||||
|
56 | for sig in segnal: | |||
|
57 | clk.tick(); | |||
|
58 | comb1.print_() | |||
|
59 | ||||
|
60 | print pi.get_data() | |||
|
61 | print po.get_data() No newline at end of file |
@@ -0,0 +1,113 | |||||
|
1 | ''' | |||
|
2 | Created on Feb 10, 2015 | |||
|
3 | ||||
|
4 | @author: shinobi | |||
|
5 | ''' | |||
|
6 | ||||
|
7 | from primitives.wire import wire | |||
|
8 | from primitives.delay import delay | |||
|
9 | from primitives.gain import gain | |||
|
10 | from primitives.adder import adder | |||
|
11 | ||||
|
12 | class Hc(object): | |||
|
13 | def __init__(self,clk,M,Kc,wire_in, wire_out): | |||
|
14 | ||||
|
15 | self.__A = -2**-4; | |||
|
16 | self.__B = -(2**4+2); | |||
|
17 | self.__Kc = Kc; | |||
|
18 | self.__M = M; | |||
|
19 | self.__wire_in = wire_in; | |||
|
20 | self.__wire_out = wire_out; | |||
|
21 | self.__clk = clk; | |||
|
22 | ||||
|
23 | ||||
|
24 | for i in range(Kc-1): | |||
|
25 | wire_out = wire(); | |||
|
26 | self.__generate_single_module(wire_in, wire_out); | |||
|
27 | wire_in = wire_out; | |||
|
28 | self.__generate_single_module(wire_in, self.__wire_out); | |||
|
29 | ||||
|
30 | ||||
|
31 | def __generate_single_module(self,wire_in,wire_out): | |||
|
32 | clk = self.__clk; | |||
|
33 | M = self.__M; | |||
|
34 | A = self.__A; B = self.__B; | |||
|
35 | w1 = wire(); | |||
|
36 | w2 = wire(); | |||
|
37 | w3 = wire(); | |||
|
38 | w4 = wire(); | |||
|
39 | delay(clk, wire_in, w1, deep=M); | |||
|
40 | delay(clk, w1, w2, deep=M); | |||
|
41 | gain(w1, w3, gain=B); | |||
|
42 | ad = adder(); | |||
|
43 | ad.connect_to_in(wire_in); | |||
|
44 | ad.connect_to_in(w3); | |||
|
45 | ad.connect_to_in(w2); | |||
|
46 | ad.connect_to_out(w4); | |||
|
47 | gain(w4, wire_out, gain=A); | |||
|
48 | ||||
|
49 | if __name__=="__main__": | |||
|
50 | from primitives.clock import clock | |||
|
51 | from primitives.pin import pin | |||
|
52 | from primitives.pout import pout | |||
|
53 | import numpy as np | |||
|
54 | ||||
|
55 | import matplotlib.pyplot as plt | |||
|
56 | ||||
|
57 | # parametros de decimacion | |||
|
58 | M1 = 2 | |||
|
59 | M2 = 5; | |||
|
60 | M = M1*M2; | |||
|
61 | Kc = 4; | |||
|
62 | ||||
|
63 | dtsz = 2**16; # cantidad de muestras de data original | |||
|
64 | Fs = 1000.0; # frecuencia de muestreo de data original | |||
|
65 | Ts = 1.0/Fs; # tiempo de muestreo de data original | |||
|
66 | Tt = Ts*dtsz; # tiempo total | |||
|
67 | Fst = Fs/dtsz; | |||
|
68 | ||||
|
69 | # data original (impulso) | |||
|
70 | sig = [0 for i in range(dtsz)]; | |||
|
71 | sig[0] = 1; | |||
|
72 | ||||
|
73 | tsig = [Ts*i for i in range(dtsz)]; | |||
|
74 | freq = [Fst*i-Fs/2 for i in range(dtsz)]; | |||
|
75 | ||||
|
76 | # descripcion del circuito | |||
|
77 | clk = clock(); # clock maestro | |||
|
78 | ||||
|
79 | sig0 = wire(); | |||
|
80 | sig1 = wire(); | |||
|
81 | ||||
|
82 | h = Hc(clk,M,Kc,sig0, sig1); | |||
|
83 | ||||
|
84 | p_int = pin(clk,sig0); | |||
|
85 | p_int.set_data(sig); | |||
|
86 | ||||
|
87 | p3 = pout(clk,sig0); | |||
|
88 | p4 = pout(clk,sig1); | |||
|
89 | ||||
|
90 | for x in range(dtsz): | |||
|
91 | clk.tick(); | |||
|
92 | ||||
|
93 | ||||
|
94 | out = np.array(p4.get_data()); | |||
|
95 | ||||
|
96 | ||||
|
97 | fft_out = np.fft.fft(out); | |||
|
98 | fft_out = np.fft.fftshift(fft_out); | |||
|
99 | fft_gain = np.abs(fft_out*np.conj(fft_out))+0.000000001; | |||
|
100 | fft_db = 10.0*np.log10(fft_gain); | |||
|
101 | ||||
|
102 | ||||
|
103 | fig = plt.figure() | |||
|
104 | amp_f = fig.add_subplot(2,1,1) | |||
|
105 | amp_f.plot(freq,fft_db, color='blue'); | |||
|
106 | amp_f.grid(); | |||
|
107 | amp_t = fig.add_subplot(2,1,2) | |||
|
108 | amp_t.plot(tsig,out, color='blue'); | |||
|
109 | amp_t.plot(tsig,p3.get_data(), color='red'); | |||
|
110 | amp_t.grid(); | |||
|
111 | plt.show(); | |||
|
112 | ||||
|
113 |
@@ -0,0 +1,126 | |||||
|
1 | ''' | |||
|
2 | Created on Jan 7, 2015 | |||
|
3 | ||||
|
4 | @author: aras | |||
|
5 | ''' | |||
|
6 | from primitives.adder import adder | |||
|
7 | from primitives.delay import delay | |||
|
8 | from primitives.wire import wire | |||
|
9 | from primitives.gain import gain | |||
|
10 | ||||
|
11 | ||||
|
12 | ||||
|
13 | class fir_decimator(object): | |||
|
14 | ''' | |||
|
15 | classdocs | |||
|
16 | ''' | |||
|
17 | ||||
|
18 | ||||
|
19 | def __init__(self, clk,wire_in, wire_out, dec = 1 ): | |||
|
20 | ''' | |||
|
21 | Constructor | |||
|
22 | ''' | |||
|
23 | self.__clk = clk; | |||
|
24 | ||||
|
25 | self.__win = wire_in; | |||
|
26 | self.__wout = wire_out; | |||
|
27 | self.__w1 = wire(); | |||
|
28 | self.__w2 = wire(); | |||
|
29 | self.__w3 = wire(); | |||
|
30 | self.__w4 = wire(); | |||
|
31 | self.__w5 = wire(); | |||
|
32 | self.__w6 = wire(); | |||
|
33 | ||||
|
34 | ||||
|
35 | self.__z1 = delay(clk,deep=3); | |||
|
36 | self.__z2 = delay(clk,deep=dec); | |||
|
37 | self.__z3 = delay(clk,deep=dec); | |||
|
38 | self.__g1 = gain(gain=1); | |||
|
39 | self.__g2 = gain(gain=-1.3) | |||
|
40 | self.__g3 = gain(gain=-1.7) | |||
|
41 | self.__adder = adder(); | |||
|
42 | ||||
|
43 | self.__z1.connect_to_in(self.__win); | |||
|
44 | self.__z1.connect_to_out(self.__w2); | |||
|
45 | self.__g1.connect_to_in(self.__w2); | |||
|
46 | self.__g1.connect_to_out(self.__w3); | |||
|
47 | ||||
|
48 | self.__z2.connect_to_in(self.__win); | |||
|
49 | self.__z2.connect_to_out(self.__w1); | |||
|
50 | self.__g2.connect_to_in(self.__w1); | |||
|
51 | self.__g2.connect_to_out(self.__w6); | |||
|
52 | ||||
|
53 | self.__z3.connect_to_in(self.__w3); | |||
|
54 | self.__z3.connect_to_out(self.__w4); | |||
|
55 | self.__g3.connect_to_in(self.__w4); | |||
|
56 | self.__g3.connect_to_out(self.__w5); | |||
|
57 | ||||
|
58 | ||||
|
59 | self.__adder.connect_to_in(self.__w5); | |||
|
60 | self.__adder.connect_to_in(self.__w6); | |||
|
61 | self.__adder.connect_to_out(self.__wout); | |||
|
62 | ||||
|
63 | def print_(self): | |||
|
64 | print "in",self.__win.read(); | |||
|
65 | print "1", self.__w1.read(); | |||
|
66 | print "2",self.__w2.read(); | |||
|
67 | print "3", self.__w3.read(); | |||
|
68 | print "out",self.__wout.read(); | |||
|
69 | ||||
|
70 | ||||
|
71 | if __name__=="__main__": | |||
|
72 | from primitives.clock import clock | |||
|
73 | from primitives.pin import pin | |||
|
74 | from primitives.pout import pout | |||
|
75 | ||||
|
76 | import matplotlib.pyplot as plt | |||
|
77 | import numpy as np | |||
|
78 | ||||
|
79 | # parametros de decimacion | |||
|
80 | dec = 20; # decimacion | |||
|
81 | dtsz = 2**16; # cantidad de muestras de data original | |||
|
82 | Fs = 1.0#300.0/dec; # frecuencia de muestreo de data original | |||
|
83 | Ts = 1.0/Fs; # tiempo de muestreo de data original | |||
|
84 | Tt = Ts*dtsz; # tiempo total | |||
|
85 | Fst = 2*Fs/dtsz; | |||
|
86 | ||||
|
87 | sig = [0.0 for i in range(dtsz)]; | |||
|
88 | sig[1] = 1.0 | |||
|
89 | tsig = [Ts*i for i in range(dtsz)]; | |||
|
90 | freq = [Fst*i - Fs for i in range(dtsz)]; | |||
|
91 | ||||
|
92 | # descripcion del circuito | |||
|
93 | clk = clock(); # clock maestro | |||
|
94 | ||||
|
95 | sig0 = wire(); | |||
|
96 | sig1 = wire(); | |||
|
97 | fir = fir_decimator(clk, sig0, sig1, dec=dec); | |||
|
98 | ||||
|
99 | p_int = pin(clk,sig0); | |||
|
100 | p_int.set_data(sig); | |||
|
101 | ||||
|
102 | p3 = pout(clk,sig0); | |||
|
103 | p4 = pout(clk,sig1); | |||
|
104 | ||||
|
105 | ||||
|
106 | for x in range(dtsz): | |||
|
107 | clk.tick(); | |||
|
108 | ||||
|
109 | out = np.array(p4.get_data()); | |||
|
110 | ||||
|
111 | ||||
|
112 | fft_out = np.fft.fft(out); | |||
|
113 | fft_out = np.fft.fftshift(fft_out); | |||
|
114 | fft_gain = np.abs(fft_out*np.conj(fft_out))+0.000000001; | |||
|
115 | fft_db = 10.0*np.log10(fft_gain); | |||
|
116 | ||||
|
117 | fig = plt.figure() | |||
|
118 | amp_f = fig.add_subplot(2,1,1) | |||
|
119 | amp_f.plot(freq,fft_db, color='blue'); | |||
|
120 | amp_f.grid(); | |||
|
121 | amp_t = fig.add_subplot(2,1,2) | |||
|
122 | amp_t.plot(tsig,out, color='blue'); | |||
|
123 | amp_t.plot(tsig,p3.get_data(), color='red'); | |||
|
124 | amp_t.grid(); | |||
|
125 | plt.show(); | |||
|
126 | No newline at end of file |
@@ -0,0 +1,61 | |||||
|
1 | ''' | |||
|
2 | Created on Jan 7, 2015 | |||
|
3 | ||||
|
4 | @author: aras | |||
|
5 | ''' | |||
|
6 | ||||
|
7 | from primitives.delay import delay | |||
|
8 | from primitives.adder import adder | |||
|
9 | from primitives.wire import wire | |||
|
10 | ||||
|
11 | ||||
|
12 | class integrator(object): | |||
|
13 | ''' | |||
|
14 | classdocs | |||
|
15 | ''' | |||
|
16 | ||||
|
17 | ||||
|
18 | def __init__(self, clk , wire_in, wire_out, deep=1): | |||
|
19 | ''' | |||
|
20 | Constructor | |||
|
21 | ''' | |||
|
22 | self.__wire_in = wire_in; | |||
|
23 | self.__wire_out = wire_out; | |||
|
24 | self.__wire_1 = wire(); | |||
|
25 | ||||
|
26 | ||||
|
27 | self.__adder = adder(); | |||
|
28 | self.__z1 = delay(clk,self.__wire_out,self.__wire_1, deep=deep); | |||
|
29 | self.__clk = clk; | |||
|
30 | ||||
|
31 | ||||
|
32 | self.__adder.connect_to_in(self.__wire_in); | |||
|
33 | self.__adder.connect_to_in(self.__wire_1); | |||
|
34 | self.__adder.connect_to_out(self.__wire_out); | |||
|
35 | ||||
|
36 | ||||
|
37 | ||||
|
38 | if __name__=="__main__": | |||
|
39 | from primitives.clock import clock | |||
|
40 | from primitives.pin import pin | |||
|
41 | from primitives.pout import pout | |||
|
42 | ||||
|
43 | segnal = [ 1 for i in range(1,11)]; | |||
|
44 | segnal += [ -1 for i in range(1,11)]; | |||
|
45 | segnal += [ 0 for i in range(1,11)]; | |||
|
46 | ||||
|
47 | clk = clock(); | |||
|
48 | sig0 = wire(); | |||
|
49 | sig1 = wire(); | |||
|
50 | inte1 = integrator(clk,sig0,sig1); | |||
|
51 | ||||
|
52 | p_int = pin(clk,sig0); | |||
|
53 | p_int.set_data(segnal); | |||
|
54 | pi = pout(clk,sig0); | |||
|
55 | po = pout(clk,sig1); | |||
|
56 | ||||
|
57 | for sig in segnal: | |||
|
58 | clk.tick(); | |||
|
59 | ||||
|
60 | print pi.get_data() | |||
|
61 | print po.get_data() No newline at end of file |
@@ -0,0 +1,244 | |||||
|
1 | ''' | |||
|
2 | Created on Feb 10, 2015 | |||
|
3 | ||||
|
4 | @author: shinobi | |||
|
5 | ''' | |||
|
6 | ||||
|
7 | from primitives.wire import wire | |||
|
8 | from cic.comb import comb | |||
|
9 | from cic.integrator import integrator | |||
|
10 | from cic.rotated_zero_filter import Hr | |||
|
11 | from cic.droop_correction_filter import Hc | |||
|
12 | from numpy import math | |||
|
13 | from primitives.attenuator import atten | |||
|
14 | from primitives.clock import clock | |||
|
15 | from primitives.pin import pin | |||
|
16 | from primitives.pout import pout | |||
|
17 | ||||
|
18 | ||||
|
19 | import numpy as np | |||
|
20 | import matplotlib.pyplot as plt | |||
|
21 | ||||
|
22 | class Hx(object): | |||
|
23 | def __init__(self, clk,wire_in, wire_out,M=1, k=1, cm=1, im=1): | |||
|
24 | ''' | |||
|
25 | Constructor | |||
|
26 | ''' | |||
|
27 | self.__clk = clk; | |||
|
28 | self.__stages = k; | |||
|
29 | self.__cdly = cm; | |||
|
30 | self.__idly = im; | |||
|
31 | self.__M = M; | |||
|
32 | ||||
|
33 | self.__wire_int_in = wire_in; | |||
|
34 | self.__wire_1 = None; | |||
|
35 | self.__wire_int_out = wire_out; | |||
|
36 | ||||
|
37 | ||||
|
38 | self.__generate_integrator(); | |||
|
39 | self.__generate_comb(); | |||
|
40 | ||||
|
41 | self.__aux=0; | |||
|
42 | ||||
|
43 | def __generate_integrator(self): | |||
|
44 | wire_in = self.__wire_int_in; | |||
|
45 | clk = self.__clk; | |||
|
46 | for i in range(self.__stages): | |||
|
47 | wire_out1 = wire(); | |||
|
48 | wire_out2 = wire(); | |||
|
49 | atten(wire_in, wire_out1, atte=float(self.__M)); | |||
|
50 | integrator(clk,wire_out1,wire_out2,deep=self.__idly); | |||
|
51 | wire_in = wire_out2; | |||
|
52 | self.__wire_1 = wire_out2; | |||
|
53 | ||||
|
54 | ||||
|
55 | def __generate_comb(self): | |||
|
56 | wire_in = self.__wire_1; | |||
|
57 | clk = self.__clk; | |||
|
58 | for i in range(self.__stages-1): | |||
|
59 | wire_out = wire(); | |||
|
60 | comb(clk,wire_in,wire_out,deep=self.__cdly); | |||
|
61 | wire_in = wire_out; | |||
|
62 | comb(clk,wire_in,self.__wire_int_out,deep=self.__cdly); | |||
|
63 | ||||
|
64 | ||||
|
65 | ||||
|
66 | ||||
|
67 | class cic_designer(object): | |||
|
68 | ||||
|
69 | def __init__(self,M,K,b0, clk,wire_in, wire_out): | |||
|
70 | self.__M1 = 1; | |||
|
71 | self.__M2 = 1; | |||
|
72 | self.__M = M; | |||
|
73 | self.__K1 = K; | |||
|
74 | self.__K2 = K; | |||
|
75 | self.__Kc = K+1; | |||
|
76 | self.__calc_dowsmpls(); | |||
|
77 | self.__clk = clk; | |||
|
78 | self.__win = wire_in; | |||
|
79 | self.__wout= wire_out; | |||
|
80 | ||||
|
81 | self.w1 = wire(); | |||
|
82 | self.w2 = wire(); | |||
|
83 | self.w3 = wire(); | |||
|
84 | # H1 | |||
|
85 | Hx(clk,wire_in, self.w1, k=self.__K1, M=self.__M1, cm=self.__M1, im=1); | |||
|
86 | # H2 | |||
|
87 | Hx(clk,self.w1,self.w2, k=self.__K2, M=self.__M2, cm=self.__M, im=self.__M1); | |||
|
88 | # Hr | |||
|
89 | Hr(clk,self.__M1,self.__M2,b0, self.w2, self.w3); | |||
|
90 | # Hc | |||
|
91 | Hc(clk,M,self.__Kc, self.w3, wire_out); | |||
|
92 | ||||
|
93 | ||||
|
94 | ||||
|
95 | def simulate(self,sig): | |||
|
96 | # descripcion del circuito | |||
|
97 | clk = self.__clk; | |||
|
98 | p_int = pin(clk,self.__win); | |||
|
99 | p_int.set_data(sig); | |||
|
100 | self.dtsz = len(sig); | |||
|
101 | ||||
|
102 | self.pin = pout(clk,self.__win); | |||
|
103 | self.p1 = pout(clk,self.w1); | |||
|
104 | self.p2 = pout(clk,self.w2); | |||
|
105 | self.p3 = pout(clk,self.w3); | |||
|
106 | self.pout = pout(clk,self.__wout); | |||
|
107 | ||||
|
108 | for x in range(self.dtsz): | |||
|
109 | clk.tick(); | |||
|
110 | ||||
|
111 | ||||
|
112 | def plot_frequency_response(self,Fs): | |||
|
113 | # parametros de decimacion | |||
|
114 | ||||
|
115 | dtsz = self.dtsz; | |||
|
116 | Fst = Fs/dtsz; | |||
|
117 | Ts = 1.0/Fs; | |||
|
118 | tsig = [Ts*i for i in range(dtsz)]; | |||
|
119 | # freq = [Fst*i-Fs/2 for i in range(dtsz)]; | |||
|
120 | ||||
|
121 | t_in = np.array(self.pin.get_data()); | |||
|
122 | # t_s1 = np.array(self.p1.get_data()); | |||
|
123 | # t_s2 = np.array(self.p2.get_data()); | |||
|
124 | # t_s3 = np.array(self.p3.get_data()); | |||
|
125 | # t_out = np.array(self.pout.get_data()); | |||
|
126 | ||||
|
127 | # f_in = self.__calc_fft(t_in); | |||
|
128 | # f_s1 = self.__calc_fft(t_s1); | |||
|
129 | # f_s2 = self.__calc_fft(t_s2); | |||
|
130 | # f_s3 = self.__calc_fft(t_s3); | |||
|
131 | # f_out = self.__calc_fft(t_out); | |||
|
132 | ||||
|
133 | # plt.figure(); | |||
|
134 | # plt.title("Seismic Signal"); | |||
|
135 | # plt.plot(freq,f_in); | |||
|
136 | # plt.grid(); | |||
|
137 | ||||
|
138 | plt.figure(); | |||
|
139 | # plt.subplot(231); | |||
|
140 | # plt.title("Comparacion"); | |||
|
141 | # i0 = len(freq)/2; | |||
|
142 | # plt.plot(freq[i0:7*i0/5],f_s1[i0:7*i0/5],'r--',freq[i0:7*i0/5],f_s2[i0:7*i0/5],'g--', | |||
|
143 | # freq[i0:7*i0/5],f_s3[i0:7*i0/5],'b--',freq[i0:7*i0/5],f_out[i0:7*i0/5],'r'); | |||
|
144 | # plt.ylim(-300, 25); | |||
|
145 | # plt.grid(); | |||
|
146 | ||||
|
147 | # plt.subplot(232); | |||
|
148 | # plt.title("H1"); | |||
|
149 | # plt.plot(freq,f_s1); | |||
|
150 | # plt.grid(); | |||
|
151 | # | |||
|
152 | # plt.subplot(233); | |||
|
153 | # plt.title("H1 + H2 (CIC)"); | |||
|
154 | # plt.plot(freq,f_s2); | |||
|
155 | # plt.grid(); | |||
|
156 | # | |||
|
157 | # plt.subplot(234); | |||
|
158 | # plt.title("H1 + H2 + Hr (CIC + Rotacion de Zero)"); | |||
|
159 | # plt.plot(freq,f_s3); | |||
|
160 | # plt.grid(); | |||
|
161 | # | |||
|
162 | # plt.subplot(235); | |||
|
163 | # plt.title("CIC + Rotacion de Zero + Compensador"); | |||
|
164 | # plt.plot(freq,f_out); | |||
|
165 | # plt.grid(); | |||
|
166 | # | |||
|
167 | # plt.subplot(236); | |||
|
168 | plt.title("Respuesta al Impulso del Filtro"); | |||
|
169 | #i1 = len(tsig)/8; | |||
|
170 | plt.plot(tsig,t_out,'blue'); | |||
|
171 | plt.plot(tsig,t_in,'red'); | |||
|
172 | plt.grid(); | |||
|
173 | plt.show(); | |||
|
174 | ||||
|
175 | ||||
|
176 | ||||
|
177 | ||||
|
178 | def __calc_fft(self,sig): | |||
|
179 | fft_out = np.fft.fft(sig); | |||
|
180 | fft_out = np.fft.fftshift(fft_out); | |||
|
181 | fft_gain = np.abs(fft_out*np.conj(fft_out)); | |||
|
182 | fft_db = 10.0*np.log10(fft_gain); | |||
|
183 | return fft_db; | |||
|
184 | ||||
|
185 | ||||
|
186 | ||||
|
187 | def __calc_dowsmpls(self): | |||
|
188 | sqrm_ = int(math.floor(math.sqrt(self.__M))); | |||
|
189 | if self.__M <= 64: | |||
|
190 | # if M <= 64 , M2 >= M1; whenever possible M1 = M2 | |||
|
191 | rang = range(1,sqrm_+1); | |||
|
192 | rang.reverse(); | |||
|
193 | for m1_ in rang: | |||
|
194 | if ((self.__M % m1_) == 0) and (m1_ <> 1): | |||
|
195 | self.__M2 = int(self.__M/m1_); | |||
|
196 | self.__M1 = int(m1_); | |||
|
197 | print self.__M, self.__M1,self.__M2 | |||
|
198 | return; | |||
|
199 | else: | |||
|
200 | # if M > 64 , M2 < M1 | |||
|
201 | rang = range(1,sqrm_); | |||
|
202 | rang.reverse(); | |||
|
203 | for m2_ in rang: | |||
|
204 | if ((self.__M % m2_) == 0) and (m2_ <> 1): | |||
|
205 | self.__M1 = int(self.__M/m2_); | |||
|
206 | self.__M2 = int(m2_); | |||
|
207 | print self.__M, self.__M1,self.__M2 | |||
|
208 | return; | |||
|
209 | ||||
|
210 | print "Elegir otro valor para M", self.__M, self.__M1,self.__M2; | |||
|
211 | self.__M1 = -1; | |||
|
212 | self.__M2 = -1; | |||
|
213 | ||||
|
214 | ||||
|
215 | ||||
|
216 | def test_downsamples(self): | |||
|
217 | for i in range(1,101): | |||
|
218 | self.__M=i; | |||
|
219 | self.__calc_dowsmpls(); | |||
|
220 | ||||
|
221 | ||||
|
222 | ||||
|
223 | if __name__=="__main__": | |||
|
224 | M = 2; | |||
|
225 | K = 3; | |||
|
226 | ro= 100; | |||
|
227 | ||||
|
228 | dtsz = 2**16; # cantidad de muestras de data original | |||
|
229 | Fs = 1.0; # frecuencia de muestreo de data original | |||
|
230 | ||||
|
231 | # data original (impulso) | |||
|
232 | #sig = np.random.normal(0,1,dtsz); | |||
|
233 | sig = [0 for i in range(dtsz)]; | |||
|
234 | sig[0] =1; | |||
|
235 | ||||
|
236 | win = wire(); | |||
|
237 | wout = wire(); | |||
|
238 | clk = clock(); | |||
|
239 | cic = cic_designer(M,K,ro, clk,win, wout); | |||
|
240 | ||||
|
241 | cic.simulate(sig); | |||
|
242 | cic.plot_frequency_response(Fs); | |||
|
243 | ||||
|
244 | No newline at end of file |
@@ -0,0 +1,136 | |||||
|
1 | ''' | |||
|
2 | Created on Feb 10, 2015 | |||
|
3 | ||||
|
4 | @author: shinobi | |||
|
5 | ''' | |||
|
6 | ||||
|
7 | from primitives.wire import wire | |||
|
8 | from primitives.gain import gain | |||
|
9 | from primitives.delay import delay | |||
|
10 | from primitives.adder import adder | |||
|
11 | import numpy as np | |||
|
12 | from primitives.attenuator import atten | |||
|
13 | ||||
|
14 | class Hr(object): | |||
|
15 | def __init__(self,clk,M1,M2,ro,wire_in, wire_out): | |||
|
16 | self.__clk = clk; | |||
|
17 | self.__M1 = M1; | |||
|
18 | self.__M2 = M2; | |||
|
19 | self.__ro = ro; # oversampling factor | |||
|
20 | self.__C = []; | |||
|
21 | self.__calc_zero_rotated_coefs(); | |||
|
22 | self.__wiew_in = wire_in; | |||
|
23 | self.__wire_out = wire_out; | |||
|
24 | self.__generate_filter(); | |||
|
25 | self.__atte = 1; | |||
|
26 | ||||
|
27 | ||||
|
28 | def __generate_filter(self): | |||
|
29 | wire_1 = self.__wiew_in; | |||
|
30 | clk = self.__clk; | |||
|
31 | M = self.__M1*self.__M2; | |||
|
32 | M2 = self.__M2; | |||
|
33 | M1 = self.__M1; | |||
|
34 | C = self.__C; | |||
|
35 | wadd = []; | |||
|
36 | ||||
|
37 | for i in range(self.__M2-1): | |||
|
38 | w2 = wire(); | |||
|
39 | w3 = wire(); | |||
|
40 | w4 = wire(); | |||
|
41 | w5 = wire(); | |||
|
42 | wadd.append(w5); | |||
|
43 | wout = wire(); | |||
|
44 | delay(clk, wire_1, w2,deep=M); | |||
|
45 | gain(wire_1, w3, C[i]); | |||
|
46 | gain(w2, w4, C[M2-2-i]); | |||
|
47 | ad = adder(); | |||
|
48 | ad.connect_to_in(w3);ad.connect_to_in(w4); | |||
|
49 | ad.connect_to_out(w5); | |||
|
50 | delay(clk, wire_1, wout,deep=M1); | |||
|
51 | wire_1 = wout; | |||
|
52 | ||||
|
53 | w5 = wire(); | |||
|
54 | w6 = wire(); | |||
|
55 | wadd.append(w5); | |||
|
56 | gain(wire_1,w5 , C[i]); | |||
|
57 | ||||
|
58 | ad = adder(); | |||
|
59 | for w in wadd: | |||
|
60 | ad.connect_to_in(w); | |||
|
61 | ad.connect_to_out(w6); | |||
|
62 | self.__atte = atten(w6,self.__wire_out, atte=M2**2); | |||
|
63 | ||||
|
64 | ||||
|
65 | def __calc_zero_rotated_coefs(self): | |||
|
66 | betha = np.pi*self.__M1/(2.0*self.__ro); | |||
|
67 | c = [1.0 , 2*np.cos(betha)]; | |||
|
68 | for i in range(2, self.__M2): | |||
|
69 | c.append(2*np.cos(betha)*c[i-1]-c[i-2]); | |||
|
70 | for i in range(self.__M2): | |||
|
71 | self.__C.append(np.round(c[i]/2**-5)*2**-5); | |||
|
72 | ||||
|
73 | if __name__=="__main__": | |||
|
74 | from primitives.clock import clock | |||
|
75 | from primitives.pin import pin | |||
|
76 | from primitives.pout import pout | |||
|
77 | ||||
|
78 | import matplotlib.pyplot as plt | |||
|
79 | ||||
|
80 | # parametros de decimacion | |||
|
81 | M1 = 6 | |||
|
82 | M2 = 10; | |||
|
83 | ro = 70;#18.85; | |||
|
84 | ||||
|
85 | dtsz = 2**16; # cantidad de muestras de data original | |||
|
86 | Fs = 1000.0; # frecuencia de muestreo de data original | |||
|
87 | Ts = 1.0/Fs; # tiempo de muestreo de data original | |||
|
88 | Tt = Ts*dtsz; # tiempo total | |||
|
89 | Fst = Fs/dtsz; | |||
|
90 | ||||
|
91 | # data original (impulso) | |||
|
92 | sig = [0 for i in range(dtsz)]; | |||
|
93 | sig[0] = 1; | |||
|
94 | ||||
|
95 | tsig = [Ts*i for i in range(dtsz)]; | |||
|
96 | freq = [Fst*i-Fs/2 for i in range(dtsz)]; | |||
|
97 | ||||
|
98 | # descripcion del circuito | |||
|
99 | clk = clock(); # clock maestro | |||
|
100 | ||||
|
101 | sig0 = wire(); | |||
|
102 | sig1 = wire(); | |||
|
103 | ||||
|
104 | h = Hr(clk,M1,M2,ro,sig0, sig1); | |||
|
105 | ||||
|
106 | p_int = pin(clk,sig0); | |||
|
107 | p_int.set_data(sig); | |||
|
108 | ||||
|
109 | p3 = pout(clk,sig0); | |||
|
110 | p4 = pout(clk,sig1); | |||
|
111 | ||||
|
112 | for x in range(dtsz): | |||
|
113 | clk.tick(); | |||
|
114 | #cic.print_() | |||
|
115 | ||||
|
116 | ||||
|
117 | out = np.array(p4.get_data()); | |||
|
118 | ||||
|
119 | ||||
|
120 | fft_out = np.fft.fft(out); | |||
|
121 | fft_out = np.fft.fftshift(fft_out); | |||
|
122 | fft_gain = np.abs(fft_out*np.conj(fft_out))+0.000000001; | |||
|
123 | fft_db = 10.0*np.log10(fft_gain); | |||
|
124 | ||||
|
125 | ||||
|
126 | fig = plt.figure() | |||
|
127 | amp_f = fig.add_subplot(2,1,1) | |||
|
128 | amp_f.plot(freq,fft_db, color='blue'); | |||
|
129 | amp_f.grid(); | |||
|
130 | amp_t = fig.add_subplot(2,1,2) | |||
|
131 | amp_t.plot(tsig,out, color='blue'); | |||
|
132 | amp_t.plot(tsig,p3.get_data(), color='red'); | |||
|
133 | amp_t.grid(); | |||
|
134 | plt.show(); | |||
|
135 | ||||
|
136 |
1 | NO CONTENT: new file 10644 |
|
NO CONTENT: new file 10644 |
@@ -0,0 +1,85 | |||||
|
1 | ''' | |||
|
2 | Created on Jan 6, 2015 | |||
|
3 | ||||
|
4 | @author: aras | |||
|
5 | ''' | |||
|
6 | ||||
|
7 | from decimal import * | |||
|
8 | ||||
|
9 | POS = 1; | |||
|
10 | NEG = -1; | |||
|
11 | ||||
|
12 | class adder(object): | |||
|
13 | ''' | |||
|
14 | classdocs | |||
|
15 | ''' | |||
|
16 | ||||
|
17 | def __init__(self): | |||
|
18 | ''' | |||
|
19 | Constructor | |||
|
20 | ''' | |||
|
21 | self.__wires_in__ = []; | |||
|
22 | self.__wire_out__ = None; | |||
|
23 | ||||
|
24 | self.__wires_in_signs__ = []; | |||
|
25 | ||||
|
26 | ||||
|
27 | def __update__(self): | |||
|
28 | acum = 0; | |||
|
29 | inputs = zip(self.__wires_in__,self.__wires_in_signs__); | |||
|
30 | for adding,sign in inputs: | |||
|
31 | acum += adding.read()*sign; | |||
|
32 | if type(self.__wire_out__)<> type(None): | |||
|
33 | self.__wire_out__.drive(acum); | |||
|
34 | ||||
|
35 | ||||
|
36 | ||||
|
37 | def connect_to_in(self,wire_in,sign=POS): | |||
|
38 | self.__wires_in__.append(wire_in); | |||
|
39 | self.__wires_in_signs__.append(sign); | |||
|
40 | wire_in.async_element(self); | |||
|
41 | self.__update__(); | |||
|
42 | ||||
|
43 | def connect_to_out(self,wire_out): | |||
|
44 | self.__wire_out__ = wire_out; | |||
|
45 | self.__wire_out__.drive(0); | |||
|
46 | self.__update__(); | |||
|
47 | ||||
|
48 | if __name__=="__main__": | |||
|
49 | from primitives.clock import clock | |||
|
50 | from primitives.pin import pin | |||
|
51 | from primitives.wire import wire | |||
|
52 | ||||
|
53 | clk = clock(); | |||
|
54 | ||||
|
55 | s = adder(); | |||
|
56 | sig1 = wire(); | |||
|
57 | sig2 = wire(); | |||
|
58 | sig3 = wire(); | |||
|
59 | sig4 = wire(); | |||
|
60 | ||||
|
61 | s.connect_to_in(sig1); | |||
|
62 | s.connect_to_in(sig2); | |||
|
63 | #s.connect_to_in(sig3,NEG); | |||
|
64 | s.connect_to_out(sig4); | |||
|
65 | ||||
|
66 | segnal1 = [ Decimal(1) *i for i in range(100)]; | |||
|
67 | segnal2 = [ Decimal(2) for i in range(100)]; | |||
|
68 | #segnal3 = [3 for i in range(100)]; | |||
|
69 | ||||
|
70 | p1 = pin(clk,sig1); | |||
|
71 | p1.set_data(segnal1); | |||
|
72 | ||||
|
73 | p2 = pin(clk,sig2); | |||
|
74 | p2.set_data(segnal2); | |||
|
75 | ||||
|
76 | #p3 = pin(clk,sig3); | |||
|
77 | #p3.set_data(segnal3); | |||
|
78 | ||||
|
79 | ||||
|
80 | for i in segnal1: | |||
|
81 | clk.tick(); | |||
|
82 | print sig1.read(),sig2.read()#,sig3.read(); | |||
|
83 | print sig4.read(); | |||
|
84 | print "-------" | |||
|
85 | No newline at end of file |
@@ -0,0 +1,45 | |||||
|
1 | ''' | |||
|
2 | Created on Jan 8, 2015 | |||
|
3 | ||||
|
4 | @author: aras | |||
|
5 | ''' | |||
|
6 | from primitives.wire import wire | |||
|
7 | import numpy as np | |||
|
8 | from decimal import * | |||
|
9 | ||||
|
10 | class atten(object): | |||
|
11 | ''' | |||
|
12 | classdocs | |||
|
13 | ''' | |||
|
14 | ||||
|
15 | ||||
|
16 | def __init__(self, wire_in,wire_out, atte = Decimal(1)): | |||
|
17 | ''' | |||
|
18 | Constructor | |||
|
19 | ''' | |||
|
20 | ||||
|
21 | self.__wire_in = wire_in; | |||
|
22 | self.__wire_out = wire_out; | |||
|
23 | ||||
|
24 | wire_in.async_element(self); | |||
|
25 | self.__atte = Decimal(atte); | |||
|
26 | self.__wire_out.drive(Decimal(0)); | |||
|
27 | self.__update__() | |||
|
28 | ||||
|
29 | ||||
|
30 | def __update__(self): | |||
|
31 | if type(self.__wire_out)<> type(None): | |||
|
32 | self.__wire_out.drive(self.__wire_in.read()/self.__atte); | |||
|
33 | ||||
|
34 | ||||
|
35 | if __name__=="__main__": | |||
|
36 | sig1 = wire(Decimal(2)); | |||
|
37 | sig2 = wire(); | |||
|
38 | g = atten(sig1,sig2,atte=Decimal(10)); | |||
|
39 | ||||
|
40 | ||||
|
41 | print sig2.read(); | |||
|
42 | ||||
|
43 | sig1.drive(Decimal(2500)); | |||
|
44 | ||||
|
45 | print sig2.read(); No newline at end of file |
@@ -0,0 +1,110 | |||||
|
1 | ''' | |||
|
2 | Created on Jan 7, 2015 | |||
|
3 | ||||
|
4 | @author: aras | |||
|
5 | ''' | |||
|
6 | ||||
|
7 | class clock(object): | |||
|
8 | ''' | |||
|
9 | classdocs | |||
|
10 | ''' | |||
|
11 | ||||
|
12 | def __init__(self,steps=1,name=""): | |||
|
13 | ''' | |||
|
14 | Constructor | |||
|
15 | ''' | |||
|
16 | self.__elems__ = []; | |||
|
17 | self.__clks__ = []; | |||
|
18 | self.__steps__ = steps; | |||
|
19 | self.__cnt__ = steps; | |||
|
20 | self.__name = name; | |||
|
21 | self.__first_tick__=True; | |||
|
22 | ||||
|
23 | def connect_element(self,elem): | |||
|
24 | if type(elem) <> type(self): | |||
|
25 | self.__elems__.append(elem); | |||
|
26 | ||||
|
27 | def get_subclock(self,div): | |||
|
28 | clk = clock(steps=div); | |||
|
29 | self.__clks__.append(clk); | |||
|
30 | return clk; | |||
|
31 | ||||
|
32 | def __initialization__(self): | |||
|
33 | for elem in self.__elems__: | |||
|
34 | elem.__initialization__(); | |||
|
35 | for elem in self.__clks__: | |||
|
36 | elem.__initialization__(); | |||
|
37 | ||||
|
38 | def tick(self): | |||
|
39 | if self.__first_tick__: | |||
|
40 | self.__first_tick__= False; | |||
|
41 | self.__initialization__(); | |||
|
42 | self.__next_sample__(); | |||
|
43 | self.__edge__(); | |||
|
44 | self.__stabilize__(); | |||
|
45 | self.__propagate__(); | |||
|
46 | self.__read_sample__(); | |||
|
47 | ||||
|
48 | #print "--------------------" | |||
|
49 | ||||
|
50 | def __next_sample__(self): | |||
|
51 | self.__cnt__ += 1; | |||
|
52 | if self.__cnt__ >= self.__steps__: | |||
|
53 | ||||
|
54 | for elem in self.__elems__: | |||
|
55 | elem.__next_sample__(); | |||
|
56 | for elem in self.__clks__: | |||
|
57 | elem.__next_sample__(); | |||
|
58 | #print "next sample",self.__name; | |||
|
59 | ||||
|
60 | def __edge__(self): | |||
|
61 | if self.__cnt__ >= self.__steps__: | |||
|
62 | for elem in self.__elems__: | |||
|
63 | elem.__edge__(); | |||
|
64 | for elem in self.__clks__: | |||
|
65 | elem.__edge__(); | |||
|
66 | #print "edge",self.__name,self.__cnt__,self.__steps__; | |||
|
67 | ||||
|
68 | def __stabilize__(self): | |||
|
69 | if self.__cnt__ >= self.__steps__: | |||
|
70 | for elem in self.__elems__: | |||
|
71 | elem.__stabilize__(); | |||
|
72 | for elem in self.__clks__: | |||
|
73 | elem.__stabilize__(); | |||
|
74 | #print "stabilize",self.__name;; | |||
|
75 | ||||
|
76 | ||||
|
77 | def __propagate__(self): | |||
|
78 | if self.__cnt__ >= self.__steps__: | |||
|
79 | for elem in self.__elems__: | |||
|
80 | elem.__propagate__(); | |||
|
81 | for elem in self.__clks__: | |||
|
82 | elem.__propagate__(); | |||
|
83 | #print "propagate",self.__name; | |||
|
84 | ||||
|
85 | ||||
|
86 | def __read_sample__(self): | |||
|
87 | if self.__cnt__ >= self.__steps__: | |||
|
88 | self.__cnt__ = 0; | |||
|
89 | for elem in self.__elems__: | |||
|
90 | elem.__read_sample__(); | |||
|
91 | for elem in self.__clks__: | |||
|
92 | elem.__read_sample__(); | |||
|
93 | #print "read sample",self.__name; | |||
|
94 | ||||
|
95 | ||||
|
96 | def get_cnt(self): | |||
|
97 | return self.__cnt__; | |||
|
98 | ||||
|
99 | ||||
|
100 | if __name__=="__main__": | |||
|
101 | clk1 = clock(name="master"); | |||
|
102 | clk2 = clk1.get_subclock(4); | |||
|
103 | clk1.tick() | |||
|
104 | clk1.tick() | |||
|
105 | clk1.tick() | |||
|
106 | clk1.tick() | |||
|
107 | clk1.tick() | |||
|
108 | clk1.tick() | |||
|
109 | clk1.tick() | |||
|
110 | clk1.tick() No newline at end of file |
@@ -0,0 +1,74 | |||||
|
1 | ''' | |||
|
2 | Created on Jan 6, 2015 | |||
|
3 | ||||
|
4 | @author: aras | |||
|
5 | ''' | |||
|
6 | from decimal import * | |||
|
7 | ||||
|
8 | class delay(object): | |||
|
9 | ''' | |||
|
10 | classdocs | |||
|
11 | ''' | |||
|
12 | ||||
|
13 | def __init__(self,clk,wire_in, wire_out, deep=1): | |||
|
14 | ''' | |||
|
15 | Constructor | |||
|
16 | ''' | |||
|
17 | self.__wire_in = wire_in; | |||
|
18 | self.__wire_out = wire_out; | |||
|
19 | self.__stt = [Decimal(0) for i in range(deep)]; | |||
|
20 | self.__clk = clk; | |||
|
21 | self.__clk.connect_element(self); | |||
|
22 | ||||
|
23 | ||||
|
24 | ||||
|
25 | def __initialization__(self): | |||
|
26 | self.__wire_out.drive(Decimal(0)); | |||
|
27 | ||||
|
28 | ||||
|
29 | def __next_sample__(self): | |||
|
30 | pass; | |||
|
31 | ||||
|
32 | ||||
|
33 | def __edge__(self): | |||
|
34 | pass; | |||
|
35 | ||||
|
36 | ||||
|
37 | def __stabilize__(self): | |||
|
38 | self.__wire_out.drive(self.__stt.pop(0)); | |||
|
39 | ||||
|
40 | ||||
|
41 | def __propagate__(self): | |||
|
42 | self.__stt.append(self.__wire_in.read()); | |||
|
43 | ||||
|
44 | ||||
|
45 | def __read_sample__(self): | |||
|
46 | pass; | |||
|
47 | ||||
|
48 | ||||
|
49 | ||||
|
50 | ||||
|
51 | if __name__=="__main__": | |||
|
52 | from primitives.wire import wire | |||
|
53 | from primitives.clock import clock | |||
|
54 | from primitives.pin import pin | |||
|
55 | ||||
|
56 | signal = [Decimal(i) for i in range(1,31)]; | |||
|
57 | #signal[0]=1; | |||
|
58 | ||||
|
59 | clk = clock(); | |||
|
60 | sig0 = wire(); | |||
|
61 | sig1 = wire(); | |||
|
62 | z1 = delay(clk,sig0,sig1,deep=1); | |||
|
63 | ||||
|
64 | ||||
|
65 | p_int = pin(clk,wire_out=sig0); | |||
|
66 | p_int.set_data(signal); | |||
|
67 | ||||
|
68 | ||||
|
69 | ||||
|
70 | for i in signal: | |||
|
71 | clk.tick(); | |||
|
72 | print sig0.read(), sig1.read(); | |||
|
73 | print "-----------------" | |||
|
74 | No newline at end of file |
@@ -0,0 +1,104 | |||||
|
1 | ''' | |||
|
2 | Created on Jan 7, 2015 | |||
|
3 | ||||
|
4 | @author: aras | |||
|
5 | ''' | |||
|
6 | from primitives.wire import wire | |||
|
7 | from primitives.clock import clock | |||
|
8 | ||||
|
9 | class downsampler(object): | |||
|
10 | ''' | |||
|
11 | classdocs | |||
|
12 | ''' | |||
|
13 | ||||
|
14 | ||||
|
15 | def __init__(self, clk, dec): | |||
|
16 | ''' | |||
|
17 | Constructor | |||
|
18 | ''' | |||
|
19 | self.__wire_in__ = None; | |||
|
20 | self.__stt__ = 0; | |||
|
21 | if dec <= 0 : dec = 1; | |||
|
22 | self.__dwn_clk__ = clk.get_subclock(dec); | |||
|
23 | self.__wire_out__ = None; | |||
|
24 | self.__clk__ = clk; | |||
|
25 | self.__dwn_clk__.connect_element(self); | |||
|
26 | ||||
|
27 | self.__high_level__ = False; | |||
|
28 | ||||
|
29 | ||||
|
30 | def get_down_clock(self): | |||
|
31 | return self.__dwn_clk__; | |||
|
32 | ||||
|
33 | def __update__(self): | |||
|
34 | pass; | |||
|
35 | ||||
|
36 | ||||
|
37 | ||||
|
38 | def __initialization__(self): | |||
|
39 | self.__wire_out__.drive(0); | |||
|
40 | ||||
|
41 | ||||
|
42 | def __next_sample__(self): | |||
|
43 | pass; | |||
|
44 | ||||
|
45 | ||||
|
46 | def __edge__(self): | |||
|
47 | pass; | |||
|
48 | # self.__high_level__ = True; | |||
|
49 | # self.__wire_out__.drive(self.__wire_in__.read()); | |||
|
50 | ||||
|
51 | ||||
|
52 | def __stabilize__(self): | |||
|
53 | self.__wire_out__.drive(self.__wire_in__.read()); | |||
|
54 | ||||
|
55 | ||||
|
56 | def __propagate__(self): | |||
|
57 | pass; | |||
|
58 | ||||
|
59 | ||||
|
60 | def __read_sample__(self): | |||
|
61 | self.__high_level__ = False; | |||
|
62 | ||||
|
63 | def connect_to_in(self,wire_in): | |||
|
64 | self.__wire_in__ = wire_in; | |||
|
65 | #wire_in.async_element(self); | |||
|
66 | ||||
|
67 | ||||
|
68 | def connect_to_out(self,wire_out): | |||
|
69 | self.__wire_out__ = wire_out; | |||
|
70 | ||||
|
71 | ||||
|
72 | if __name__=="__main__": | |||
|
73 | from primitives.pin import pin | |||
|
74 | from primitives.pout import pout | |||
|
75 | segnal = [i for i in range(1,101)]; | |||
|
76 | dec = 5; | |||
|
77 | ||||
|
78 | clk = clock(); | |||
|
79 | d1 = downsampler(clk,dec); | |||
|
80 | dclk = d1.get_down_clock() | |||
|
81 | ||||
|
82 | ||||
|
83 | sig0 = wire(); | |||
|
84 | sig1 = wire(); | |||
|
85 | ||||
|
86 | d1.connect_to_in(sig0); | |||
|
87 | d1.connect_to_out(sig1); | |||
|
88 | ||||
|
89 | ||||
|
90 | p_int = pin(clk,sig0); | |||
|
91 | p_int.set_data(segnal); | |||
|
92 | ||||
|
93 | p4 = pout(clk,sig0); | |||
|
94 | p5 = pout(dclk,sig1); | |||
|
95 | ||||
|
96 | ||||
|
97 | print sig0.read(),sig1.read(); | |||
|
98 | for sig in segnal[1:103]: | |||
|
99 | clk.tick(); | |||
|
100 | print sig0.read(),sig1.read(); | |||
|
101 | ||||
|
102 | print segnal; | |||
|
103 | print p4.get_data(); | |||
|
104 | print p5.get_data(); No newline at end of file |
@@ -0,0 +1,45 | |||||
|
1 | ''' | |||
|
2 | Created on Jan 8, 2015 | |||
|
3 | ||||
|
4 | @author: aras | |||
|
5 | ''' | |||
|
6 | from primitives.wire import wire | |||
|
7 | import numpy as np | |||
|
8 | from decimal import * | |||
|
9 | ||||
|
10 | class gain(object): | |||
|
11 | ''' | |||
|
12 | classdocs | |||
|
13 | ''' | |||
|
14 | ||||
|
15 | ||||
|
16 | def __init__(self, wire_in,wire_out, gain = Decimal(1)): | |||
|
17 | ''' | |||
|
18 | Constructor | |||
|
19 | ''' | |||
|
20 | ||||
|
21 | self.__wire_in = wire_in; | |||
|
22 | self.__wire_out = wire_out; | |||
|
23 | ||||
|
24 | wire_in.async_element(self); | |||
|
25 | self.__gain = Decimal(gain); | |||
|
26 | self.__wire_out.drive(Decimal(0)); | |||
|
27 | self.__update__() | |||
|
28 | ||||
|
29 | ||||
|
30 | def __update__(self): | |||
|
31 | if type(self.__wire_out)<> type(None): | |||
|
32 | self.__wire_out.drive(self.__wire_in.read()*self.__gain); | |||
|
33 | ||||
|
34 | ||||
|
35 | if __name__=="__main__": | |||
|
36 | sig1 = wire(Decimal(2)); | |||
|
37 | sig2 = wire(); | |||
|
38 | g = gain(sig1,sig2,gain=Decimal(100)); | |||
|
39 | ||||
|
40 | ||||
|
41 | print sig2.read(); | |||
|
42 | ||||
|
43 | sig1.drive(Decimal(25)); | |||
|
44 | ||||
|
45 | print sig2.read(); No newline at end of file |
@@ -0,0 +1,67 | |||||
|
1 | ''' | |||
|
2 | Created on Jan 8, 2015 | |||
|
3 | ||||
|
4 | @author: aras | |||
|
5 | ''' | |||
|
6 | ||||
|
7 | from primitives.wire import wire | |||
|
8 | from decimal import * | |||
|
9 | ||||
|
10 | class pin(object): | |||
|
11 | ''' | |||
|
12 | classdocs | |||
|
13 | ''' | |||
|
14 | ||||
|
15 | ||||
|
16 | def __init__(self,clk,wire_out=wire()): | |||
|
17 | ''' | |||
|
18 | Constructor | |||
|
19 | ''' | |||
|
20 | ||||
|
21 | self.__clk__ = clk; | |||
|
22 | self.__clk__.connect_element(self); | |||
|
23 | self.__wire_out__ = None; | |||
|
24 | ||||
|
25 | self.__data__ = []; | |||
|
26 | self.__size__ = 0; | |||
|
27 | self.__tick_idx__ = 0; | |||
|
28 | ||||
|
29 | self.__wire_out__ = wire_out; | |||
|
30 | ||||
|
31 | def __initialization__(self): | |||
|
32 | self.__wire_out__.drive(0); | |||
|
33 | ||||
|
34 | ||||
|
35 | def __next_sample__(self): | |||
|
36 | self.__wire_out__.drive(Decimal(self.__data__[self.__tick_idx__])); | |||
|
37 | self.__tick_idx__ += 1; | |||
|
38 | if self.__tick_idx__ < self.__size__: | |||
|
39 | pass | |||
|
40 | else: | |||
|
41 | self.__wire_out__.drive(0); | |||
|
42 | #self.__tick_idx__ = 0; | |||
|
43 | ||||
|
44 | def __edge__(self): | |||
|
45 | pass; | |||
|
46 | ||||
|
47 | def __stabilize__(self): | |||
|
48 | pass; | |||
|
49 | ||||
|
50 | ||||
|
51 | def __propagate__(self): | |||
|
52 | pass; | |||
|
53 | ||||
|
54 | ||||
|
55 | def __read_sample__(self): | |||
|
56 | pass; | |||
|
57 | ||||
|
58 | ||||
|
59 | def set_data(self,data=[]): | |||
|
60 | self.__data__ = data; | |||
|
61 | self.__size__ = len(data); | |||
|
62 | self.__index__ = 0; | |||
|
63 | self.__wire_out__.drive(Decimal(data[self.__index__])); | |||
|
64 | ||||
|
65 | ||||
|
66 | ||||
|
67 | No newline at end of file |
@@ -0,0 +1,72 | |||||
|
1 | ''' | |||
|
2 | Created on Jan 12, 2015 | |||
|
3 | ||||
|
4 | @author: aras | |||
|
5 | ''' | |||
|
6 | ||||
|
7 | from primitives.wire import wire | |||
|
8 | ||||
|
9 | class pout(object): | |||
|
10 | ''' | |||
|
11 | classdocs | |||
|
12 | ''' | |||
|
13 | ||||
|
14 | ||||
|
15 | def __init__(self, clk, wire_in=wire()): | |||
|
16 | ''' | |||
|
17 | Constructor | |||
|
18 | ''' | |||
|
19 | self.__wire_in__ = wire_in; | |||
|
20 | self.__data__ = []; | |||
|
21 | ||||
|
22 | self.__clk__ = clk; | |||
|
23 | clk.connect_element(self); | |||
|
24 | ||||
|
25 | def __initialization__(self): | |||
|
26 | pass; | |||
|
27 | ||||
|
28 | ||||
|
29 | def __next_sample__(self): | |||
|
30 | pass; | |||
|
31 | ||||
|
32 | ||||
|
33 | def __edge__(self): | |||
|
34 | pass; | |||
|
35 | ||||
|
36 | def __stabilize__(self): | |||
|
37 | pass; | |||
|
38 | ||||
|
39 | ||||
|
40 | def __propagate__(self): | |||
|
41 | pass; | |||
|
42 | ||||
|
43 | ||||
|
44 | def __read_sample__(self): | |||
|
45 | self.__data__.append(float(self.__wire_in__.read())); | |||
|
46 | ||||
|
47 | ||||
|
48 | def get_data(self): | |||
|
49 | data = self.__data__; | |||
|
50 | self.__data__ = []; | |||
|
51 | return data; | |||
|
52 | ||||
|
53 | if __name__=="__main__": | |||
|
54 | from primitives.clock import clock | |||
|
55 | from primitives.pin import pin | |||
|
56 | ||||
|
57 | segnal = [float(i) for i in range(1,31)]; | |||
|
58 | clk = clock(); | |||
|
59 | sig0 = wire(); | |||
|
60 | ||||
|
61 | p_int = pin(clk,wire_out=sig0); | |||
|
62 | p_int.set_data(segnal); | |||
|
63 | ||||
|
64 | p_out = pout(clk,wire_in=sig0); | |||
|
65 | ||||
|
66 | print sig0.read(); | |||
|
67 | ||||
|
68 | for sig in segnal: | |||
|
69 | clk.tick(); | |||
|
70 | print sig0.read(); | |||
|
71 | ||||
|
72 | print p_out.get_data() No newline at end of file |
@@ -0,0 +1,60 | |||||
|
1 | ''' | |||
|
2 | Created on Jan 6, 2015 | |||
|
3 | ||||
|
4 | @author: aras | |||
|
5 | ''' | |||
|
6 | from decimal import * | |||
|
7 | ||||
|
8 | class wire(object): | |||
|
9 | ''' | |||
|
10 | classdocs | |||
|
11 | ''' | |||
|
12 | wire_cnt = 0; | |||
|
13 | all_wires = {}; | |||
|
14 | ||||
|
15 | @staticmethod | |||
|
16 | def get_wires(): | |||
|
17 | return wire.all_wires; | |||
|
18 | ||||
|
19 | def __init__(self,initval=Decimal(0)): | |||
|
20 | ''' | |||
|
21 | Constructor | |||
|
22 | ''' | |||
|
23 | wire.wire_cnt += 1; | |||
|
24 | ||||
|
25 | self.__wire_stt__ = initval; | |||
|
26 | self.__asyncs__ = []; | |||
|
27 | ||||
|
28 | self.__wire_name__ = "__wire_"+str(wire.wire_cnt)+"__"; | |||
|
29 | wire.all_wires[self.__wire_name__] = self; | |||
|
30 | ||||
|
31 | ||||
|
32 | ||||
|
33 | def get_name(self): | |||
|
34 | return self.__wire_name__; | |||
|
35 | ||||
|
36 | def drive(self, val): | |||
|
37 | self.__set_val__(val); | |||
|
38 | self.__update__(); | |||
|
39 | ||||
|
40 | def __set_val__(self,val): | |||
|
41 | self.__wire_stt__ = val; | |||
|
42 | ||||
|
43 | def __update__(self): | |||
|
44 | for elem in self.__asyncs__: | |||
|
45 | elem.__update__(); | |||
|
46 | ||||
|
47 | def read(self): | |||
|
48 | return self.__wire_stt__; | |||
|
49 | ||||
|
50 | def async_element(self,elem): | |||
|
51 | self.__asyncs__.append(elem); | |||
|
52 | ||||
|
53 | if __name__=="__main__": | |||
|
54 | wi1 = wire(); print wire.wire_cnt | |||
|
55 | wi2 = wire(); print wire.wire_cnt | |||
|
56 | wi3 = wire(); print wire.wire_cnt | |||
|
57 | wi4 = wire(); print wire.wire_cnt | |||
|
58 | wi5 = wire(); print wire.wire_cnt | |||
|
59 | print wire.get_wires() | |||
|
60 | No newline at end of file |
@@ -0,0 +1,49 | |||||
|
1 | ''' | |||
|
2 | Created on Feb 16, 2015 | |||
|
3 | ||||
|
4 | @author: shinobi | |||
|
5 | ''' | |||
|
6 | import obspy | |||
|
7 | from cic.mless_cic import cic_designer | |||
|
8 | from primitives.wire import wire | |||
|
9 | from primitives.clock import clock | |||
|
10 | from copy import copy | |||
|
11 | import numpy | |||
|
12 | from decimal import * | |||
|
13 | ||||
|
14 | if __name__ == '__main__': | |||
|
15 | trace = obspy.read("./ENEFEB15/015930/PE.STPO..BHZ.MSEED"); | |||
|
16 | #print trace[0].stats; | |||
|
17 | data = trace[0].data; | |||
|
18 | dat = copy(data); | |||
|
19 | dat.sort(); | |||
|
20 | dc = dat[len(dat)/2]; | |||
|
21 | #print dc | |||
|
22 | data = numpy.array(data,Decimal); | |||
|
23 | data = data -dc; | |||
|
24 | trace[0].data = data; | |||
|
25 | #trace.plot() | |||
|
26 | #print data | |||
|
27 | ||||
|
28 | M = 10; | |||
|
29 | K = 5; | |||
|
30 | ro= 8*2; | |||
|
31 | ||||
|
32 | dtsz = len(data); # cantidad de muestras de data original | |||
|
33 | print dtsz; | |||
|
34 | Fs = 100.0; # frecuencia de muestreo de data original | |||
|
35 | ||||
|
36 | sig = numpy.array([0 for i in range(dtsz)]); | |||
|
37 | sig[0]=Decimal(1); | |||
|
38 | ||||
|
39 | win = wire(); | |||
|
40 | wout = wire(); | |||
|
41 | clk = clock(); | |||
|
42 | ||||
|
43 | cic = cic_designer(M,K,ro, clk,win, wout); | |||
|
44 | cic.test_downsamples(); | |||
|
45 | exit(); | |||
|
46 | cic.simulate(data); | |||
|
47 | cic.plot_frequency_response(Fs); | |||
|
48 | ||||
|
49 | No newline at end of file |
@@ -5,15 +5,15 | |||||
5 | <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="de.innot.avreclipse.configuration.app.debug.2000262611" moduleId="org.eclipse.cdt.core.settings" name="Debug"> |
|
5 | <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="de.innot.avreclipse.configuration.app.debug.2000262611" moduleId="org.eclipse.cdt.core.settings" name="Debug"> | |
6 | <externalSettings/> |
|
6 | <externalSettings/> | |
7 | <extensions> |
|
7 | <extensions> | |
8 | <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/> |
|
|||
9 | <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> |
|
8 | <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> | |
10 | <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> |
|
9 | <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> | |
11 | <extension id="org.eclipse.cdt.core.MakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> |
|
10 | <extension id="org.eclipse.cdt.core.MakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> | |
12 | <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> |
|
11 | <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> | |
|
12 | <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/> | |||
13 | </extensions> |
|
13 | </extensions> | |
14 | </storageModule> |
|
14 | </storageModule> | |
15 | <storageModule moduleId="cdtBuildSystem" version="4.0.0"> |
|
15 | <storageModule moduleId="cdtBuildSystem" version="4.0.0"> | |
16 |
<configuration artifactName="${ProjName}" buildArtefactType="de.innot.avreclipse.buildArtefactType.app" buildProperties="org.eclipse.cdt.build.core.build |
|
16 | <configuration artifactName="${ProjName}" buildArtefactType="de.innot.avreclipse.buildArtefactType.app" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug,org.eclipse.cdt.build.core.buildArtefactType=de.innot.avreclipse.buildArtefactType.app" description="" id="de.innot.avreclipse.configuration.app.debug.2000262611" name="Debug" parent="de.innot.avreclipse.configuration.app.debug"> | |
17 | <folderInfo id="de.innot.avreclipse.configuration.app.debug.2000262611." name="/" resourcePath=""> |
|
17 | <folderInfo id="de.innot.avreclipse.configuration.app.debug.2000262611." name="/" resourcePath=""> | |
18 | <toolChain id="de.innot.avreclipse.toolchain.winavr.app.debug.822649946" name="AVR-GCC Toolchain" superClass="de.innot.avreclipse.toolchain.winavr.app.debug"> |
|
18 | <toolChain id="de.innot.avreclipse.toolchain.winavr.app.debug.822649946" name="AVR-GCC Toolchain" superClass="de.innot.avreclipse.toolchain.winavr.app.debug"> | |
19 | <option id="de.innot.avreclipse.toolchain.options.toolchain.objcopy.flash.app.debug.2015112688" name="Generate HEX file for Flash memory" superClass="de.innot.avreclipse.toolchain.options.toolchain.objcopy.flash.app.debug"/> |
|
19 | <option id="de.innot.avreclipse.toolchain.options.toolchain.objcopy.flash.app.debug.2015112688" name="Generate HEX file for Flash memory" superClass="de.innot.avreclipse.toolchain.options.toolchain.objcopy.flash.app.debug"/> | |
@@ -30,11 +30,17 | |||||
30 | <tool id="de.innot.avreclipse.tool.compiler.winavr.app.debug.2139820795" name="AVR Compiler" superClass="de.innot.avreclipse.tool.compiler.winavr.app.debug"> |
|
30 | <tool id="de.innot.avreclipse.tool.compiler.winavr.app.debug.2139820795" name="AVR Compiler" superClass="de.innot.avreclipse.tool.compiler.winavr.app.debug"> | |
31 | <option id="de.innot.avreclipse.compiler.option.debug.level.570414624" name="Generate Debugging Info" superClass="de.innot.avreclipse.compiler.option.debug.level"/> |
|
31 | <option id="de.innot.avreclipse.compiler.option.debug.level.570414624" name="Generate Debugging Info" superClass="de.innot.avreclipse.compiler.option.debug.level"/> | |
32 | <option id="de.innot.avreclipse.compiler.option.optimize.1336415215" name="Optimization Level" superClass="de.innot.avreclipse.compiler.option.optimize"/> |
|
32 | <option id="de.innot.avreclipse.compiler.option.optimize.1336415215" name="Optimization Level" superClass="de.innot.avreclipse.compiler.option.optimize"/> | |
|
33 | <option id="de.innot.avreclipse.compiler.option.incpath.1723721463" name="Include Paths (-I)" superClass="de.innot.avreclipse.compiler.option.incpath" valueType="includePath"> | |||
|
34 | <listOptionValue builtIn="false" value=""${workspace_loc:/powerEngined/TinyWireS}""/> | |||
|
35 | </option> | |||
33 | <inputType id="de.innot.avreclipse.compiler.winavr.input.722044572" name="C Source Files" superClass="de.innot.avreclipse.compiler.winavr.input"/> |
|
36 | <inputType id="de.innot.avreclipse.compiler.winavr.input.722044572" name="C Source Files" superClass="de.innot.avreclipse.compiler.winavr.input"/> | |
34 | </tool> |
|
37 | </tool> | |
35 | <tool id="de.innot.avreclipse.tool.cppcompiler.app.debug.1857231833" name="AVR C++ Compiler" superClass="de.innot.avreclipse.tool.cppcompiler.app.debug"> |
|
38 | <tool id="de.innot.avreclipse.tool.cppcompiler.app.debug.1857231833" name="AVR C++ Compiler" superClass="de.innot.avreclipse.tool.cppcompiler.app.debug"> | |
36 | <option id="de.innot.avreclipse.cppcompiler.option.debug.level.784182061" name="Generate Debugging Info" superClass="de.innot.avreclipse.cppcompiler.option.debug.level"/> |
|
39 | <option id="de.innot.avreclipse.cppcompiler.option.debug.level.784182061" name="Generate Debugging Info" superClass="de.innot.avreclipse.cppcompiler.option.debug.level"/> | |
37 | <option id="de.innot.avreclipse.cppcompiler.option.optimize.1325093322" name="Optimization Level" superClass="de.innot.avreclipse.cppcompiler.option.optimize"/> |
|
40 | <option id="de.innot.avreclipse.cppcompiler.option.optimize.1325093322" name="Optimization Level" superClass="de.innot.avreclipse.cppcompiler.option.optimize"/> | |
|
41 | <option id="de.innot.avreclipse.cppcompiler.option.incpath.1305859042" name="Include Paths (-I)" superClass="de.innot.avreclipse.cppcompiler.option.incpath" valueType="includePath"> | |||
|
42 | <listOptionValue builtIn="false" value=""${workspace_loc:/powerEngined/TinyWireS}""/> | |||
|
43 | </option> | |||
38 | <inputType id="de.innot.avreclipse.cppcompiler.input.811241046" superClass="de.innot.avreclipse.cppcompiler.input"/> |
|
44 | <inputType id="de.innot.avreclipse.cppcompiler.input.811241046" superClass="de.innot.avreclipse.cppcompiler.input"/> | |
39 | </tool> |
|
45 | </tool> | |
40 | <tool id="de.innot.avreclipse.tool.linker.winavr.app.debug.124544837" name="AVR C Linker" superClass="de.innot.avreclipse.tool.linker.winavr.app.debug"/> |
|
46 | <tool id="de.innot.avreclipse.tool.linker.winavr.app.debug.124544837" name="AVR C Linker" superClass="de.innot.avreclipse.tool.linker.winavr.app.debug"/> | |
@@ -60,15 +66,15 | |||||
60 | <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="de.innot.avreclipse.configuration.app.release.1919827046" moduleId="org.eclipse.cdt.core.settings" name="Release"> |
|
66 | <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="de.innot.avreclipse.configuration.app.release.1919827046" moduleId="org.eclipse.cdt.core.settings" name="Release"> | |
61 | <externalSettings/> |
|
67 | <externalSettings/> | |
62 | <extensions> |
|
68 | <extensions> | |
63 | <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/> |
|
|||
64 | <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> |
|
69 | <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> | |
65 | <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> |
|
70 | <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> | |
66 | <extension id="org.eclipse.cdt.core.MakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> |
|
71 | <extension id="org.eclipse.cdt.core.MakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> | |
67 | <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> |
|
72 | <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> | |
|
73 | <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/> | |||
68 | </extensions> |
|
74 | </extensions> | |
69 | </storageModule> |
|
75 | </storageModule> | |
70 | <storageModule moduleId="cdtBuildSystem" version="4.0.0"> |
|
76 | <storageModule moduleId="cdtBuildSystem" version="4.0.0"> | |
71 |
<configuration artifactName="${ProjName}" buildArtefactType="de.innot.avreclipse.buildArtefactType.app" buildProperties="org.eclipse.cdt.build.core.build |
|
77 | <configuration artifactName="${ProjName}" buildArtefactType="de.innot.avreclipse.buildArtefactType.app" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release,org.eclipse.cdt.build.core.buildArtefactType=de.innot.avreclipse.buildArtefactType.app" description="" id="de.innot.avreclipse.configuration.app.release.1919827046" name="Release" parent="de.innot.avreclipse.configuration.app.release"> | |
72 | <folderInfo id="de.innot.avreclipse.configuration.app.release.1919827046." name="/" resourcePath=""> |
|
78 | <folderInfo id="de.innot.avreclipse.configuration.app.release.1919827046." name="/" resourcePath=""> | |
73 | <toolChain id="de.innot.avreclipse.toolchain.winavr.app.release.534015259" name="AVR-GCC Toolchain" superClass="de.innot.avreclipse.toolchain.winavr.app.release"> |
|
79 | <toolChain id="de.innot.avreclipse.toolchain.winavr.app.release.534015259" name="AVR-GCC Toolchain" superClass="de.innot.avreclipse.toolchain.winavr.app.release"> | |
74 | <option id="de.innot.avreclipse.toolchain.options.toolchain.objcopy.flash.app.release.1132179635" name="Generate HEX file for Flash memory" superClass="de.innot.avreclipse.toolchain.options.toolchain.objcopy.flash.app.release"/> |
|
80 | <option id="de.innot.avreclipse.toolchain.options.toolchain.objcopy.flash.app.release.1132179635" name="Generate HEX file for Flash memory" superClass="de.innot.avreclipse.toolchain.options.toolchain.objcopy.flash.app.release"/> | |
@@ -85,11 +91,17 | |||||
85 | <tool id="de.innot.avreclipse.tool.compiler.winavr.app.release.1325848445" name="AVR Compiler" superClass="de.innot.avreclipse.tool.compiler.winavr.app.release"> |
|
91 | <tool id="de.innot.avreclipse.tool.compiler.winavr.app.release.1325848445" name="AVR Compiler" superClass="de.innot.avreclipse.tool.compiler.winavr.app.release"> | |
86 | <option id="de.innot.avreclipse.compiler.option.debug.level.182518345" name="Generate Debugging Info" superClass="de.innot.avreclipse.compiler.option.debug.level" value="de.innot.avreclipse.compiler.option.debug.level.none" valueType="enumerated"/> |
|
92 | <option id="de.innot.avreclipse.compiler.option.debug.level.182518345" name="Generate Debugging Info" superClass="de.innot.avreclipse.compiler.option.debug.level" value="de.innot.avreclipse.compiler.option.debug.level.none" valueType="enumerated"/> | |
87 | <option id="de.innot.avreclipse.compiler.option.optimize.1347150146" name="Optimization Level" superClass="de.innot.avreclipse.compiler.option.optimize" value="de.innot.avreclipse.compiler.optimize.size" valueType="enumerated"/> |
|
93 | <option id="de.innot.avreclipse.compiler.option.optimize.1347150146" name="Optimization Level" superClass="de.innot.avreclipse.compiler.option.optimize" value="de.innot.avreclipse.compiler.optimize.size" valueType="enumerated"/> | |
|
94 | <option id="de.innot.avreclipse.compiler.option.incpath.1288368775" name="Include Paths (-I)" superClass="de.innot.avreclipse.compiler.option.incpath" valueType="includePath"> | |||
|
95 | <listOptionValue builtIn="false" value=""${workspace_loc:/powerEngined/TinyWireS}""/> | |||
|
96 | </option> | |||
88 | <inputType id="de.innot.avreclipse.compiler.winavr.input.541241653" name="C Source Files" superClass="de.innot.avreclipse.compiler.winavr.input"/> |
|
97 | <inputType id="de.innot.avreclipse.compiler.winavr.input.541241653" name="C Source Files" superClass="de.innot.avreclipse.compiler.winavr.input"/> | |
89 | </tool> |
|
98 | </tool> | |
90 | <tool id="de.innot.avreclipse.tool.cppcompiler.app.release.680417450" name="AVR C++ Compiler" superClass="de.innot.avreclipse.tool.cppcompiler.app.release"> |
|
99 | <tool id="de.innot.avreclipse.tool.cppcompiler.app.release.680417450" name="AVR C++ Compiler" superClass="de.innot.avreclipse.tool.cppcompiler.app.release"> | |
91 | <option id="de.innot.avreclipse.cppcompiler.option.debug.level.2026274981" name="Generate Debugging Info" superClass="de.innot.avreclipse.cppcompiler.option.debug.level" value="de.innot.avreclipse.cppcompiler.option.debug.level.none" valueType="enumerated"/> |
|
100 | <option id="de.innot.avreclipse.cppcompiler.option.debug.level.2026274981" name="Generate Debugging Info" superClass="de.innot.avreclipse.cppcompiler.option.debug.level" value="de.innot.avreclipse.cppcompiler.option.debug.level.none" valueType="enumerated"/> | |
92 | <option id="de.innot.avreclipse.cppcompiler.option.optimize.1138792397" name="Optimization Level" superClass="de.innot.avreclipse.cppcompiler.option.optimize" value="de.innot.avreclipse.cppcompiler.optimize.size" valueType="enumerated"/> |
|
101 | <option id="de.innot.avreclipse.cppcompiler.option.optimize.1138792397" name="Optimization Level" superClass="de.innot.avreclipse.cppcompiler.option.optimize" value="de.innot.avreclipse.cppcompiler.optimize.size" valueType="enumerated"/> | |
|
102 | <option id="de.innot.avreclipse.cppcompiler.option.incpath.264571846" name="Include Paths (-I)" superClass="de.innot.avreclipse.cppcompiler.option.incpath" valueType="includePath"> | |||
|
103 | <listOptionValue builtIn="false" value=""${workspace_loc:/powerEngined/TinyWireS}""/> | |||
|
104 | </option> | |||
93 | <inputType id="de.innot.avreclipse.cppcompiler.input.950434664" superClass="de.innot.avreclipse.cppcompiler.input"/> |
|
105 | <inputType id="de.innot.avreclipse.cppcompiler.input.950434664" superClass="de.innot.avreclipse.cppcompiler.input"/> | |
94 | </tool> |
|
106 | </tool> | |
95 | <tool id="de.innot.avreclipse.tool.linker.winavr.app.release.344510769" name="AVR C Linker" superClass="de.innot.avreclipse.tool.linker.winavr.app.release"/> |
|
107 | <tool id="de.innot.avreclipse.tool.linker.winavr.app.release.344510769" name="AVR C Linker" superClass="de.innot.avreclipse.tool.linker.winavr.app.release"/> | |
@@ -115,14 +127,28 | |||||
115 | <storageModule moduleId="cdtBuildSystem" version="4.0.0"> |
|
127 | <storageModule moduleId="cdtBuildSystem" version="4.0.0"> | |
116 | <project id="powerEngine.de.innot.avreclipse.project.winavr.elf_2.1.0.750782110" name="AVR Cross Target Application" projectType="de.innot.avreclipse.project.winavr.elf_2.1.0"/> |
|
128 | <project id="powerEngine.de.innot.avreclipse.project.winavr.elf_2.1.0.750782110" name="AVR Cross Target Application" projectType="de.innot.avreclipse.project.winavr.elf_2.1.0"/> | |
117 | </storageModule> |
|
129 | </storageModule> | |
|
130 | <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/> | |||
|
131 | <storageModule moduleId="refreshScope" versionNumber="2"> | |||
|
132 | <configuration configurationName="Release"> | |||
|
133 | <resource resourceType="PROJECT" workspacePath="/powerEngined"/> | |||
|
134 | </configuration> | |||
|
135 | <configuration configurationName="Debug"> | |||
|
136 | <resource resourceType="PROJECT" workspacePath="/powerEngined"/> | |||
|
137 | </configuration> | |||
|
138 | </storageModule> | |||
118 | <storageModule moduleId="scannerConfiguration"> |
|
139 | <storageModule moduleId="scannerConfiguration"> | |
119 | <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> |
|
140 | <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> | |
120 | <scannerConfigBuildInfo instanceId="de.innot.avreclipse.configuration.app.release.1919827046;de.innot.avreclipse.configuration.app.release.1919827046.;de.innot.avreclipse.tool.compiler.winavr.app.release.1325848445;de.innot.avreclipse.compiler.winavr.input.541241653"> |
|
141 | <scannerConfigBuildInfo instanceId="de.innot.avreclipse.configuration.app.debug.2000262611;de.innot.avreclipse.configuration.app.debug.2000262611.;de.innot.avreclipse.tool.cppcompiler.app.debug.1857231833;de.innot.avreclipse.cppcompiler.input.811241046"> | |
121 | <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="de.innot.avreclipse.core.AVRGCCManagedMakePerProjectProfileC"/> |
|
142 | <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="de.innot.avreclipse.core.AVRGCCManagedMakePerProjectProfileCPP"/> | |
122 | </scannerConfigBuildInfo> |
|
143 | </scannerConfigBuildInfo> | |
123 | <scannerConfigBuildInfo instanceId="de.innot.avreclipse.configuration.app.release.1919827046;de.innot.avreclipse.configuration.app.release.1919827046.;de.innot.avreclipse.tool.cppcompiler.app.release.680417450;de.innot.avreclipse.cppcompiler.input.950434664"> |
|
144 | <scannerConfigBuildInfo instanceId="de.innot.avreclipse.configuration.app.release.1919827046;de.innot.avreclipse.configuration.app.release.1919827046.;de.innot.avreclipse.tool.cppcompiler.app.release.680417450;de.innot.avreclipse.cppcompiler.input.950434664"> | |
124 | <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="de.innot.avreclipse.core.AVRGCCManagedMakePerProjectProfileCPP"/> |
|
145 | <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="de.innot.avreclipse.core.AVRGCCManagedMakePerProjectProfileCPP"/> | |
125 | </scannerConfigBuildInfo> |
|
146 | </scannerConfigBuildInfo> | |
|
147 | <scannerConfigBuildInfo instanceId="de.innot.avreclipse.configuration.app.release.1919827046;de.innot.avreclipse.configuration.app.release.1919827046.;de.innot.avreclipse.tool.compiler.winavr.app.release.1325848445;de.innot.avreclipse.compiler.winavr.input.541241653"> | |||
|
148 | <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="de.innot.avreclipse.core.AVRGCCManagedMakePerProjectProfileC"/> | |||
|
149 | </scannerConfigBuildInfo> | |||
|
150 | <scannerConfigBuildInfo instanceId="de.innot.avreclipse.configuration.app.debug.2000262611;de.innot.avreclipse.configuration.app.debug.2000262611.;de.innot.avreclipse.tool.compiler.winavr.app.debug.2139820795;de.innot.avreclipse.compiler.winavr.input.722044572"> | |||
|
151 | <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="de.innot.avreclipse.core.AVRGCCManagedMakePerProjectProfileC"/> | |||
|
152 | </scannerConfigBuildInfo> | |||
126 | </storageModule> |
|
153 | </storageModule> | |
127 | <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/> |
|
|||
128 | </cproject> |
|
154 | </cproject> |
@@ -7,23 +7,57 | |||||
7 |
|
7 | |||
8 | #ifndef POWERENGINED_POWERENGINED_H_ |
|
8 | #ifndef POWERENGINED_POWERENGINED_H_ | |
9 | #define POWERENGINED_POWERENGINED_H_ |
|
9 | #define POWERENGINED_POWERENGINED_H_ | |
10 |
#include < |
|
10 | #include <avr/io.h> | |
11 |
|
11 | |||
12 | /* primitivas 1-wire transaction ds2438 . toda data/comandos es leida y escrita |
|
12 | /* primitivas 1-wire transaction ds2438 . toda data/comandos es leida y escrita | |
13 | * primero el bit menos significativo */ |
|
13 | * primero el bit menos significativo */ | |
14 |
|
14 | |||
15 |
|
15 | |||
16 |
|
16 | |||
|
17 | /* Hardware definitions */ | |||
|
18 | #define I2C_SLAVE_ADDR 0x26 | |||
17 |
|
19 | |||
18 | inline void write_0_signal();//pull-low, wait 15us, remain low 45us (min), release (high),wait 1us |
|
20 | #define DQ_BIT PB3 | |
19 | inline void write_1_signal();//pull-low, wait 10us, release (high) 50us (min), remain high,wait 1us |
|
21 | #define DQ_PORT PORTB | |
20 | inline void write_byte(uint8_t byte); |
|
22 | #define DQ_PIN PINB | |
|
23 | #define DQ_DDR DDRB | |||
|
24 | ||||
|
25 | /* DS2438Z definitions */ | |||
|
26 | #define READ_ROM 0X33 | |||
|
27 | #define MATCH_ROM 0x55 | |||
|
28 | #define SEARCH_ROM 0xF0 | |||
|
29 | #define SKIP_ROM 0xCC | |||
|
30 | #define WRITE_SP 0x4E | |||
|
31 | #define READ_SP 0xBE | |||
|
32 | #define COPY_SP 0x48 | |||
|
33 | #define CONV_T 0x44 | |||
|
34 | #define CONV_V 0xB4 | |||
|
35 | #define RCALL_MEM 0xB8 | |||
|
36 | ||||
|
37 | ||||
|
38 | /* DS2438Z Memory Pages (ver datasheet) */ | |||
|
39 | #define PAGE_0 0x00 | |||
|
40 | #define PAGE_1 0x01 | |||
|
41 | #define PAGE_2 0x02 | |||
|
42 | #define PAGE_3 0x03 | |||
|
43 | #define PAGE_4 0x04 | |||
|
44 | #define PAGE_5 0x05 | |||
|
45 | #define PAGE_6 0x06 | |||
|
46 | #define PAGE_7 0x07 | |||
|
47 | ||||
|
48 | ||||
|
49 | ||||
|
50 | ||||
|
51 | /* Funciones de escritura */ | |||
|
52 | void write_0_signal();//pull-low, wait 15us, remain low 45us (min), release (high),wait 1us | |||
|
53 | void write_1_signal();//pull-low, wait 10us, release (high) 50us (min), remain high,wait 1us | |||
|
54 | void write_byte(uint8_t byte); | |||
21 | void write_bytes(uint8_t* pbytes,uint8_t len); |
|
55 | void write_bytes(uint8_t* pbytes,uint8_t len); | |
22 |
|
56 | |||
23 |
|
57 | /* Funciones de lectura */ | ||
24 |
|
|
58 | uint8_t read_signal();//pull-low, wait 1us, release, pin I , wait 9us, read line, | |
25 | //wait 50us(min), pin O, wait 1us |
|
59 | //wait 50us(min), pin O, wait 1us | |
26 |
|
|
60 | uint8_t read_byte(); | |
27 | void read_bytes(uint8_t* pbytes, uint8_t len); |
|
61 | void read_bytes(uint8_t* pbytes, uint8_t len); | |
28 |
|
62 | |||
29 |
|
63 | |||
@@ -36,18 +70,15 | |||||
36 |
|
70 | |||
37 | void initialization(); |
|
71 | void initialization(); | |
38 |
|
72 | |||
|
73 | void memory_read(uint8_t* pbytes, uint8_t page_addr); | |||
|
74 | ||||
39 |
|
75 | |||
40 | // 5 CONVERT_T (0x44) inicia conversion A/D de temperatura |
|
76 | // 5 CONVERT_T (0x44) inicia conversion A/D de temperatura | |
41 | // 6 CONVERT_V (0xB4) inicia conversion A/D de voltaje |
|
77 | // 6 CONVERT_V (0xB4) inicia conversion A/D de voltaje | |
42 | void convert(uint8_t cmd); |
|
78 | void convert(uint8_t cmd); | |
43 |
|
79 | |||
44 | void memory_read(uint8_t* pbyte, uint8_t page_addr); |
|
|||
45 |
|
80 | |||
46 | void ISR_int0(); //usado para cronometrar la lectura del presence pulse |
|
81 | void send_data(uint8_t* pbytes, uint8_t len); | |
47 | void ISR_low_level();//detecta el nivel bajo. usado para detectar el presence pulse |
|
|||
48 |
|
||||
49 | void ISR_twi();// usado para enviar datos |
|
|||
50 | void ISR_int1();//usado para cronometrar la lectura de datos |
|
|||
51 |
|
82 | |||
52 |
|
83 | |||
53 | #endif /* POWERENGINED_POWERENGINED_H_ */ |
|
84 | #endif /* POWERENGINED_POWERENGINED_H_ */ |
@@ -9,7 +9,7 | |||||
9 |
|
9 | |||
10 | channel::channel(): |
|
10 | channel::channel(): | |
11 | chn_id(0),chn_name{"\0"},chn_gain(0), |
|
11 | chn_id(0),chn_name{"\0"},chn_gain(0), | |
12 |
chn_ |
|
12 | chn_datarate(0),chn_status(0) | |
13 | { |
|
13 | { | |
14 | // TODO Auto-generated constructor stub |
|
14 | // TODO Auto-generated constructor stub | |
15 |
|
15 | |||
@@ -31,7 +31,7 | |||||
31 | return 1; |
|
31 | return 1; | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 |
uint32_t channel::chn_get_ |
|
34 | uint32_t channel::chn_get_datarate(void){ | |
35 | return 1; |
|
35 | return 1; | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
@@ -51,10 +51,6 | |||||
51 | return true; |
|
51 | return true; | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 |
bool channel::chn_set_ |
|
54 | bool channel::chn_set_datarate(uint32_t){ | |
55 | return true; |
|
55 | return true; | |
56 | } |
|
56 | } | |
57 |
|
||||
58 | bool channel::chn_set_status(uint8_t){ |
|
|||
59 | return true; |
|
|||
60 | } |
|
@@ -8,7 +8,7 | |||||
8 | #include "processEnginectrl.h" |
|
8 | #include "processEnginectrl.h" | |
9 |
|
9 | |||
10 | processEngine_ctrl::processEngine_ctrl(): |
|
10 | processEngine_ctrl::processEngine_ctrl(): | |
11 | pdtpkg(nullptr),pe_chns(nullptr){ |
|
11 | pdtpkg(nullptr),pe_chns(nullptr),conf_dir(nullptr){ | |
12 | // TODO Auto-generated constructor stub |
|
12 | // TODO Auto-generated constructor stub | |
13 |
|
13 | |||
14 | } |
|
14 | } | |
@@ -17,46 +17,27 | |||||
17 | // TODO Auto-generated destructor stub |
|
17 | // TODO Auto-generated destructor stub | |
18 | } |
|
18 | } | |
19 |
|
19 | |||
20 | bool processEngine_ctrl::peCtrl_initialization(void*){ |
|
20 | ||
|
21 | void processEngine_ctrl::peCtrl_set_config_directory(const char* confdir){ | |||
|
22 | } | |||
|
23 | ||||
|
24 | bool processEngine_ctrl::peCtrl_initialization(){ | |||
21 | return true; |
|
25 | return true; | |
22 | } |
|
26 | } | |
23 |
|
27 | |||
24 |
bool processEngine_ctrl::peCtrl_ |
|
28 | bool processEngine_ctrl::peCtrl_start_acquisition(){ | |
25 | return true; |
|
29 | return true; | |
26 | } |
|
30 | } | |
27 |
|
31 | |||
28 |
bool processEngine_ctrl::peCtrl_ |
|
32 | bool processEngine_ctrl::peCtrl_stop_acquisition(){ | |
29 | return true; |
|
33 | return true; | |
30 | } |
|
34 | } | |
31 |
|
35 | |||
32 |
bool processEngine_ctrl::peCtrl_ |
|
36 | bool processEngine_ctrl::peCtrl_get_data_buffer(void* buff){ | |
33 | return true; |
|
37 | return true; | |
34 | } |
|
38 | } | |
35 |
|
39 | |||
36 |
bool processEngine_ctrl::peCtrl_chn_ |
|
40 | bool processEngine_ctrl::peCtrl_chn_initialization(uint8_t chn){ | |
37 | return true; |
|
41 | return true; | |
38 | } |
|
42 | } | |
39 |
|
43 | |||
40 | bool processEngine_ctrl::peCtrl_chn_get_information(void*){ |
|
|||
41 | return true; |
|
|||
42 | } |
|
|||
43 |
|
||||
44 | bool processEngine_ctrl::peCtrl_chn_set_param(void*){ |
|
|||
45 | return true; |
|
|||
46 | } |
|
|||
47 |
|
||||
48 | bool processEngine_ctrl::peCtrl_chn_get_param(void*){ |
|
|||
49 | return true; |
|
|||
50 | } |
|
|||
51 |
|
||||
52 | bool processEngine_ctrl::peCtrl_start_acquisition(void*){ |
|
|||
53 | return true; |
|
|||
54 | } |
|
|||
55 |
|
||||
56 | bool processEngine_ctrl::peCtrl_stop_acquisition(void*){ |
|
|||
57 | return true; |
|
|||
58 | } |
|
|||
59 |
|
||||
60 | bool processEngine_ctrl::peCtrl_get_new_data(void*){ |
|
|||
61 | return true; |
|
|||
62 | } |
|
General Comments 0
You need to be logged in to leave comments.
Login now