Chapter 4. The reference point model: Tracking character roles in The New York Trilogy
4.3. Reader response: Tracking character roles
La prueba del tiempo de respuesta consistió en tres mediciones del tiempo con el osciloscopio desde que el microcontrolador recibe la primera trama de comunicación
128
para una configuración inicial o reconfiguración, hasta que finaliza la programación de la última FPAA. Estas mediciones se realizaron a través de un pin libre en el microcontrolador configurado como salida en donde su estado normal era nivel lógico alto y caía a nivel lógico cero cuando la programación de las FPAA estuviera en proceso.
La primera prueba fue la medición del tiempo de la configuración inicial realizada desde la GUI, ver Figura 5.17, en este caso todas las FPAA son programadas con los parámetros por defecto y el tiempo medido fue de 712,0 ms.
Figura 5.17. Tiempo de respuesta de la
configuración inicial.
Fuente: (AUTORES)
La segunda prueba fue la medición del tiempo de la reconfiguración de ganancias realizada desde la GUI, ver Figura 5.18, en este caso únicamente es programada la FPAA que contiene el CAM de ganancia a modificar y el tiempo medido fue de 9,4 ms.
129
Figura 5.18. Tiempo de respuesta de la
reconfiguración de ganancias.
Fuente: (AUTORES)
La tercera prueba fue la medición del tiempo de la reconfiguración de frecuencia central o factor de calidad realizada desde la GUI, ver Figura 5.19, en este caso únicamente es programada la FPAA que contiene el CAM del filtro pasa banda a modificar y el tiempo medido fue de 16,0 ms.
Figura 5.19. Tiempo de respuesta de la
reconfiguración de frecuencia central o factor de calidad.
130
El resultado de las tres mediciones del tiempo de respuesta se resume en la Tabla 5.8.
Tabla 5.8. Tiempos de respuestas de la configuración inicial y
reconfiguración del ecualizador paramétrico.
Tipo de configuración Parámetros a configurar. Tiempo de respuesta [ms]
Configuración inicial Todos los parámetros por
defecto del ecualizador. 712,0 Reconfiguración
Ganancia de cualquiera de las bandas y ganancia principal del ecualizador.
9,4
Reconfiguración
Frecuencia central o factor de calidad de cualquier banda del ecualizador
16,0
Fuente: (AUTORES)
De acuerdo a la Tabla 5.8, el mayor tiempo de respuesta fue cuando se realizó la configuración inicial y el menor tiempo fue cuando se realizó la reconfiguración de cualquiera de las ganancias del ecualizador. Estas variaciones son debido a la cantidad de información que se necesita para la configuración inicial o reconfiguración de un determinado CAM.
Cuando se realiza una reconfiguración en cualquiera de las FPAA, los datos se van almacenando en la memoria común (Shadow SRAM) mientras el ecualizador sigue funcionando normalmente y al finalizar se transfieren todos los datos de la memoria común a la memoria de configuración (Configuration SRAM) en un tiempo equivalente a un ciclo de reloj ACLK. Siendo ACLK igual a 16 MHz, el ciclo de reloj es el inverso de la frecuencia, resultando en 62,5 ns. Este tiempo muestra que la reconfiguración de las FPAA es muy rápida, llevando a cambios en el ecualizador de forma rápida sin afectar su funcionamiento actual.
131
RECOMENDACIONES
Para la alimentación del ecualizador paramétrico es recomendable utilizar
una fuente de voltaje de 9 V porque garantiza un menor consumo de potencia y el correcto funcionamiento de los componentes, aunque esta puede variar entre 9 V y 30 V, que sea capaz de entregar mínimo 500 mA.
La entrada de señal de audio del ecualizador paramétrico análogo
implementado está limitada por el parámetro de voltaje diferencial de entrada análogo del dpASP AN231E04 el cuál debe estar en un rango desde -2,75 V hasta +2,75 V. Si se excede este rango, uno o varios dpASP puede tener daños irreversibles.
El dpASP AN231E04 es un dispositivo sensible a descargas electroestáticas
desde los 1500 V, por tal motivo se recomienda tomar las precauciones necesarias para evitar la degradación en el desempeño o pérdida total de la funcionalidad.
Si se desean realizar mediciones con un osciloscopio, ubicando un
generador de señales en la entrada del ecualizador, se recomienda aislar la tierra de todos los instrumentos con supresores de polo y no deberán ponerse tierras o GND comunes entre la entrada y salida del ecualizador, dado que estas son diferenciales.
Para que al ecualizador se le puedan realizar reconfiguraciones, primero se
debe cargar la configuración inicial desde el botón “CONFIGURACIÓN INICIAL” de la GUI.
Si al querer realizar un reinicio, una configuración inicial o una
reconfiguración desde la GUI y el ecualizador no responde, se recomienda apagar el ecualizador desde el interruptor “ON/OFF” y posteriormente hacer un reinicio oprimiendo el pulsador “RESET”.
Los dpASP son dispositivos muy versátiles que pueden realizar diferentes
132
integración, filtrado y control análogo entre otras. Todas estas funciones se pueden llevar a cabo porque estos dispositivos utilizan la tecnología de capacitores conmutados.
133
CONCLUSIONES
Se diseñó e implementó un ecualizador paramétrico análogo de audio capaz
de ser controlado por una interfaz gráfica de usuario desde una computadora y con la capacidad de guardar y cargar archivos de texto plano con los parámetros de cada banda como la ganancia, frecuencia central y factor de calidad, permitiendo al usuario almacenar configuraciones y utilizarlas posteriormente de forma predeterminada ahorrando tiempo en la ecualización.
La respuesta en frecuencia por banda se caracterizó por mostrar la
comparación de cada uno de los parámetros principales entre el filtro ideal y el filtro real, destacándose por la exactitud de la frecuencia central en ambas partes ya que tuvo porcentajes de error menores al 0,1% y en su contra parte careció de precisión y fue muy regular el ancho de banda, pues hubo un 8% de error en la banda bajos.
La respuesta en frecuencia del ecualizador resultó satisfactorio, pues se
refleja la similitud de la curva entre ambas, aunque no se verificó mediante argumentos teóricos por el mismo comportamiento del sistema ya que en el funcionamiento de todas las bandas al mismo tiempo, estas se van afectando una a la otra por la cercanía de las mismas, por tanto su ancho de banda no coincide a los datos hallados teóricamente pero su frecuencia central se puede observar que no tiene ninguna modificación.
Los tiempos de respuestas de la configuración inicial (712,0 ms),
reconfiguración de ganancias (9,4 ms) y reconfiguración de la frecuencia central y factor de calidad (16,0 ms) del ecualizador son distintos por la cantidad de datos que contiene cada uno de los bloques de información enviados desde la GUI, pero el tiempo que toma el traspaso de la memoria común a la memoria de configuración dentro de las FPAA es de 62,5 ns,
134
permitiendo que los cambios en el funcionamiento del ecualizador análogo de audio sean rápidos e imperceptibles.
Debido a las dificultades que se tuvieron en el transcurso del proyecto con la
soldadura de los dispositivos AN231E04, al poseer un empaquetado QFN de 44 pines con tamaño de 7x7x0,9 mm, con una separación entre pines de 0,5 mm. Se optó por la fabricación de tarjetas electrónicas individuales y se utilizó estaño en pasta para realizar la soldadura en un horno de reflujo experimental.
El consumo de potencia es vital para un dispositivo electrónico por lo que se
le asegura al usuario qué rango debe manejar para garantizar su óptimo funcionamiento. Se debe tener un voltaje de entrada de 9 V a 30 V porque en este rango se certifica que se cumplen las características de cada uno de los elementos que componen el circuito de alimentación. Se concluye que hay más potencia con 30 V que con 9 V en cualquiera de sus estados (Encendido, programando y funcionando).
135
BIBLIOGRAFÍA
Akizukidenshi. (2016). Retrieved from http://akizukidenshi.com/catalog/g/gI-00267/
Anadigm. (2000). AN221E04 FPAA Anadigm. Retrieved from
http://www.anadigm.com/an221e04.asp Anadigm. (2001). AN10E40 Datasheet.
Anadigm. (2003a). AN221E04 Datasheet Dynamically Reconfigurable FPAA With Enhanced I / O. Retrieved from http://www.anadigm.com/_doc/DS030100- U006.pdf
Anadigm. (2003b). AN221E04 Field Programmable Analog Arrays - User Manual. Retrieved from http://www.anadigm.com/_doc/UM021200-U007.pdf
Anadigm. (2006). AN23x series AnadigmApex dpASP Family User Manual. Retrieved from http://www.anadigm.com/_doc/UM000231-U001.pdf
Anadigm. (2007). AN231E04 Datasheet Rev 1.2. Retrieved from
http://www.anadigm.com/_doc/DS231000-U001.pdf Anadigm. (2011). Switched Capacitor, 1–18.
Anadigm. (2015a). Anadigm QuadApex Development Board. Retrieved from http://www.anadigm.com/_doc/UM231004-K001.pdf
Anadigm. (2015b). SOFTWARE ANADIGM DESIGNER 2. Retrieved from http://www.anadigm.com/sup_downloadcenter.asp?tab=ad2
Aquino, E. A. (2015). Implementación de acciones básicas de control en FPAA. Retrieved from http://jupiter.utm.mx/~tesis_dig/12913.pdf
Arrow Electronics. (2016). Retrieved from https://www.arrow.com/
Caicedo Grueso, R., & Velasco Medina, J. (2005). DISEÑO DE CIRCUITOS ANÁLOGOS USANDO FPAAs. XI Workshop IBERCHIP. Retrieved from
136
http://www.iberchip.net/IX/Articles/PAP-073.pdf
Calvos electrónica. (2016). Retrieved from
http://www.calvoselectronica.com/multimetros-digitales/404-protek-506.html Cárdenas, D. G. A. (2011). Amplificación, pre amplificación y procesamiento de
señales de audio.
Components, C. E. (n.d.). Model CB3 & CB3LV Technical Data, (008), 1 – 4.
Retrieved from http://www.mouser.com/ds/2/96/008-0256-0-786323.pdf Digi-Key Electronics. (2016).
Eargle, J. (2006). Handbook Of Recording Engineering (Cuarta). Los Ángeles, USA.
Espectáculos Arranz. (2014). Retrieved from
http://web.espectaculosarranz.com/index.html
Grisolia, M. (2006). Propagación de errores, 1–3. Retrieved from
http://webdelprofesor.ula.ve/humanidades/marygri/documents/general/Errores. pdf
GW INSTEK. (2015a). Retrieved from http://www.gwinstek.com/en-
global/products/DC_Power_Supply/Multiple_Channel_DC_Power_Supplies/G PS-x303
GW INSTEK. (2015b). Retrieved from http://www.gwinstek.ca/products/68/instek- gds840s-250mhz-2channel-mono-lcd-display-dso
GW INSTEK. (2015c). Retrieved from http://www.gwinstek.com/en-
global/products/Signal_Sources/Analog_Function_Generators/GFG-8200A Hispasonic. (2013). Retrieved from http://www.hispasonic.com/noticias/nuevo-
ecualizador-eq3v-mellowmuse/7323
Izhaki, R. (2008). Mixing Audio, Concepts, Practices and Tools. Elsevier, Ltd.
137
https://www.silabs.com/Support Documents/TechnicalDocs/CP2102-9.pdf
Mexbusa S.A. (2016). Retrieved from
http://mexbusa.com/index.php/catalogo/accesorios-electronica- audio/conectores-jacks/jack-doble-rca.html
Microchip. (2013). PIC16F876A DATASHEET.
Miyara, F. (2004). Ecualizadores. Retrieved from
http://www.fceia.unr.edu.ar/acustica/audio/ecualizadores.pdf
Moya, J. P. A. (2011). Procesamiento Digital de Señales. Retrieved from http://www.ie.itcr.ac.cr/palvarado/PDS/pds.pdf
Pozo, J. D. C. (2007). Sistemas de Telefonía. Madrid, España.
SOUND & PIXEL. (2015). Retrieved from http://www.sound-pixel.com/blog/música- analógica-vs-digital-aclarando-diferencias
Sound On Sound. (2014). Retrieved from
http://www.soundonsound.com/sos/dec03/articles/edirolur80.htm
139
ANEXOS
ANEXO A. Código de programa principal abk_v432.c.
/****************************************************************************** * File Name : abk_v432.c *
* *
* Program : Anadigm Boot Kernel v4.3.2 * * Anadigm, Inc. * * Copyright © 2009. All Rights Reserved. * * *
* Author : Dave Lovell *
* * * Date : 5 Aug 2009 * * * * Target : AN231K04-DVLP3 Development Board with PIC16F876A * * * * Notes : See readme.txt for details of changes in this version. * * * * Checksum: 0xDED3 * * * ******************************************************************************/ #include <16F876A.h> #include "abk_v432.h"
// Configuration bitstreams stored in ROM (for chip detect routines) const unsigned char an_AN130_PrimaryConfigInfo[] =
{
0xD5,
0x00, //don't know JTAG bytes yet
0x00, //don't know JTAG bytes yet
0x00, //don't know JTAG bytes yet
0x00, //don't know JTAG bytes yet
0x02, 0xC1, 0xC0, 0x00, 0x12, 0x01, 0x00, 0x01, 0x00, 0x20, 0x04, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x51, 0xFF, 0x0F, 0xF1, 0x2A, 0x9F, 0x01, 0x01, 0xFF, 0x2A };
const unsigned char an_AN131_PrimaryConfigInfo[] = { 0xD5, 0xB7, 0x20, 0x02, 0x00, 0x04, 0xC1, 0xC0, 0x00, 0x12, 0x01, 0x00, 0x01, 0x00, 0x20, 0x04, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x51, 0xFF, 0x0F, 0xF1, 0x2A, 0x9F,
140 0x01, 0x01, 0xFF, 0x2A };
const unsigned char an_AN230_PrimaryConfigInfo[] = {
0xD5,
0x00, //don't know JTAG bytes yet
0x00, //don't know JTAG bytes yet
0x00, //don't know JTAG bytes yet
0x00, //don't know JTAG bytes yet
0x01, 0xC1, 0xC0, 0x00, 0x12, 0x01, 0x00, 0x01, 0x00, 0x20, 0x04, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x51, 0xFF, 0x0F, 0xF1, 0x2A, 0x9F, 0x01, 0x01, 0xFF, 0x2A };
const unsigned char an_AN231_PrimaryConfigInfo[] = { 0xD5, 0xB7, 0x20, 0x01, 0x00, 0x03, 0xC1, 0xC0, 0x00, 0x12, 0x01, 0x00, 0x01, 0x00, 0x20, 0x04, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x51, 0xFF, 0x0F, 0xF1, 0x2A, 0x9F, 0x01, 0x01, 0xFF, 0x2A }; /****************************************************************************** * * * Procedure Name : RS_232_GetData * * * * Purpose : This function retrieves information from the receive * * buffer, and returns it to the caller. * * * * Inputs : None * * * * Outputs : int8 - The first data available in the FIFO buffer. * * * ******************************************************************************/ int8 RS_232_GetData(void)
{
int8 Result;
while (BufferEmpty); // Wait until a character is available
Result = InputBuf[BufferTail]; // Retrieve the data from the buffer...
BufferTail++; // ...and update the buffer pointers.
if (BufferTail == BufferSize) BufferTail = 0; BufferFull = 0;
BufferEmpty = (BufferTail == BufferHead); return Result;
141 /******************************************************************************
* *
* Procedure Name : interrupt *
* *
* Purpose : This function provides the interrupt handler for the PIC * * microcontroller. It handles all serial transactions. *
* * * Inputs : None * * * * Outputs : None * * * ******************************************************************************/ #int_rda void interrupt(void) { if (kbhit()) { InputBuf[BufferHead] = getc(); BufferHead++; if (BufferHead == BufferSize) BufferHead = 0; BufferFull = (BufferHead == BufferTail); BufferEmpty = 0; } } /****************************************************************************** * *
* Procedure Name : interrupt_ext *
* *
* Purpose : This function wipes the config memory on an ext interrupt * * * * Inputs : None * * * * Outputs : None * * * ******************************************************************************/ #int_ext void interrupt_ext(void) { //int16 address; //for (address = CONFIG_SIZE_LOC ; address < 0x1FFF ; address++) // write_program_eeprom(address, 0x0000); write_program_eeprom(CONFIG_SIZE_LOC, 0x0000); } /****************************************************************************** * *
* Procedure Name : getHEXNumber *
* *
* Purpose : This function retrieves an ASCII hex value from the *
* serial port and converts it to binary. *
* *
* Inputs : None *
* *
* Outputs : int8 - The binary value that was read as ASCII *
* *
******************************************************************************/ int8 getHEXNumber(void) { int8 Result, Result2, input; // Retrieve the most-significant nibble input = RS_232_GetData(); if (input >= 'a') input = (input - ('a' - 'A')); if (input >= 'A') Result = ((input - 'A') + 10); else Result = input - '0'; Result <<= 4; // Retrieve the least-significant nibble input = RS_232_GetData(); if (input >= 'a') input = (input - ('a' - 'A')); if (input >= 'A') Result2 = ((input - 'A') + 10); else Result2 = (input - '0'); return (Result + Result2); } /****************************************************************************** * *
* Procedure Name : send_byte_to_chip *
* *
* Purpose : This function sends a byte of data to the FPAA. *
* *
* Inputs : int8 data - The data byte to send to the FPAA. *
* *
* Outputs : None *
* *
******************************************************************************/ void send_byte_to_chip(int8 data) { int8 dum; dum = spi_read(data); } /****************************************************************************** * *
* Procedure Name : send_byte_to_eprom *
* *
* Purpose : This function sends a byte of data to the EPROM *
142
* Inputs : int8 instr - The instruction to send to the EPROM *
* int16 addr - The address to send to the EPROM *
* int8 data - The data byte to send to the EPROM *
* *
* Outputs : None *
* *
******************************************************************************/ void send_byte_to_eprom(int8 type, int8 instr, int16 addr, int8 data) { int8 bit = 8; delay_us(2); eprom_CSb_low; delay_us(2); if (type < 5) //if type 0-3 then do instruction { while (bit) //do instruction whatever the type { if (instr & 0x80) eprom_SI_high; //if MSB=1 then set data pin high delay_us(2); eprom_SCK_high; //set DCLK pin high delay_us(2); eprom_SCK_low; //set DCLK pin low delay_us(2); eprom_SI_low; //set data pin low instr <<= 1; //left shift the data by 1 bit bit--; //dec the value of bit } } if ((type == 2) || (type == 3) || (type == 4)) //if type 2 or 3 or 4 then do address { bit = 16; while (bit) { if (addr & 0x8000) eprom_SI_high; //if MSB=1 then set data pin high delay_us(2); eprom_SCK_high; //set DCLK pin high delay_us(2); eprom_SCK_low; //set DCLK pin low delay_us(2); eprom_SI_low; //set data pin low addr <<= 1; //left shift the data by 1 bit bit--; //dec the value of bit } } if (type > 0) //if type 1, 2, 3 or 4 then do data { bit = 8; while (bit) { if (data & 0x80) eprom_SI_high; //if MSB=1 then set data pin high delay_us(2); eprom_SCK_high; //set DCLK pin high delay_us(2); eprom_SCK_low; //set DCLK pin low delay_us(2); eprom_SI_low; //set data pin low data <<= 1; //left shift the data by 1 bit bit--; //dec the value of bit } } delay_us(2); if ((type < 3) || (type == 6) || (type == 7)) eprom_CSb_high; //return CSb high if type 0, 1, 2, 6, 7 if ((type == 3) || (type == 6)) { output_high(CTS_to_PC); //deassert CTS delay_ms(10); //use delay if 3,6 output_low(CTS_to_PC); //assert CTS } } /****************************************************************************** * *
* Procedure Name : config_clocks *
* *
* Purpose : This function provides a way to run the configuration *
* clock to the FPAA 16 times. It is needed during software * * resets of the devices. *
* * * Inputs : None * * * * Outputs : None * * * ******************************************************************************/ void config_clocks(void) { send_byte_to_chip(0x00); send_byte_to_chip(0x00); } /****************************************************************************** * *
* Procedure Name : reset_chip *
* *
* Purpose : This function sends a soft reset command to the chip *
* chain. All devices in the chain should be reset if the *
* chipID parameter is 0xFF. Otherwise the specific chip *
* with that chip ID will be reset. *
* *
* Inputs : int8 chipID - The device to be reset. 0xFF will reset all * * devices. Any other value will reset only the* * device with a matching ID. *
143 * * * Outputs : None * * * ******************************************************************************/ void reset_chip(int8 chipID)
{
int8 loop; putc(XOFF); if (chipID == 0xFF) {
set_tris_b(port_b_inputs & drive_ERRb); //make PIC drive ERRb
output_low(ERRb); //& drive it low config_clocks(); //wait 16 clocks output_high(ERRb); //drive it high
set_tris_b(port_b_inputs & sense_ERRb); //& make PIC sense ERRb again
} else {
for (loop = 0; loop < 5; loop++)
send_byte_to_chip(0x00); //dummy bytes
send_byte_to_chip(0xD5); send_byte_to_chip(chipID);
send_byte_to_chip(0x27); //software reset
} config_clocks(); //send 32 clocks config_clocks(); putc(XON); } /****************************************************************************** * * * Procedure Name : configure_chip_from_input * * * * Purpose : This function provides a conduit for data coming from the * * serial port and sends it to the FPAA. * * * * Inputs : int8 PrimaryConfig - if == config_chip then starts with *
* reset, if == update_chip then no reset*
* * * Outputs : None * * * ******************************************************************************/ void configure_chip_from_input(int8 PrimaryConfig)
{
int16 num_bytes; // The number of bytes to be transferred
int8 data_read; // Data read from the serial port.
int16 boot_config_size = 5; int16 last_config_size; int8 boot_start_sequence = 0; int8 n; Status_flag = OK; if (PrimaryConfig) { reset_chip(0xFF); flash_start_addr = CONFIG_SIZE_LOC; last_config_size = 0; } else { last_config_size = read_program_eeprom(CONFIG_SIZE_LOC); flash_start_addr = CONFIG_SIZE_LOC + last_config_size; }
// Retrieve the number of bytes we will be moving. num_bytes = getHEXNumber();
num_bytes = (num_bytes << 8) + getHEXNumber();
// Move the data as long as we have data to send, and we haven't timed out while (num_bytes) { data_read = getHEXNumber(); if (Status_flag == OK) { send_byte_to_chip(data_read); if (!(input(ERRb))) Status_flag = CONFIG_ERROR; if (boot_start_sequence == 5) { boot_config_size++; if (input(STORE_FLASH)) { output_high(CTS_to_PC); //deassert CTS
write_program_eeprom(flash_start_addr + boot_config_size, data_read);
output_low(CTS_to_PC); //assert CTS } } for (n=5 ; n>0 ; n--) if (boot_start_sequence == n-1) if (data_read == an_AN231_PrimaryConfigInfo[n-1]) boot_start_sequence = n; else boot_start_sequence = 0; } num_bytes--; num_bytes--; }
144 if ((boot_start_sequence == 5) && input(STORE_FLASH))
{
output_high(CTS_to_PC); //deassert CTS
write_program_eeprom(CONFIG_SIZE_LOC, last_config_size + boot_config_size); /*
for (n=1 ; n<6 ; n++)
write_program_eeprom(flash_start_addr + n, an_AN231_PrimaryConfigInfo[n-1]); // doesn't work???? */ write_program_eeprom(flash_start_addr + 1, an_AN231_PrimaryConfigInfo[0]); write_program_eeprom(flash_start_addr + 2, an_AN231_PrimaryConfigInfo[1]); write_program_eeprom(flash_start_addr + 3, an_AN231_PrimaryConfigInfo[2]); write_program_eeprom(flash_start_addr + 4, an_AN231_PrimaryConfigInfo[3]); write_program_eeprom(flash_start_addr + 5, an_AN231_PrimaryConfigInfo[4]); output_low(CTS_to_PC); //assert CTS } //if (!input(ACTIVATE)) //Status_flag = CONFIG_ERROR; } /****************************************************************************** * *
* Procedure Name : write_eprom_from_flash *
* *
* Purpose : This function writes the config data stored in the PIC's * * flash to EPROM * * * * Inputs : None * * * * Outputs : None * * * ******************************************************************************/ void write_eprom_from_flash(void) { int8 data_array[32]; int16 address = 0x0000; int16 n, m, byt; int16 config_size; set_tris_a(port_a_inputs & drive_RA2); //set_tris_a(port_a_inputs & drive_RA4); //old board set_tris_c(port_c_inputs_eprom & drive_RC0_RC4); eprom_CSb_high; eprom_SCK_low; eprom_SI_low; delay_ms(20); config_size = read_program_eeprom(CONFIG_SIZE_LOC); if (config_size > 1024) config_size = 1024; send_byte_to_eprom(1, 0x01, 0x0000, 0x00); //unset block protect, WPEN=0 for ( n = 0 ; n < 32 ; n++) { address = 32 * n; for ( m = 0 ; m < 32 ; m++) { byt = address + m; if ((byt < config_size + 5) && (byt > 4)) data_array[m] = read_program_eeprom(CONFIG_SIZE_LOC + 1 + byt - 5); //subtract 5 because we added 5 dummy bytes at start else data_array[m] = 0x00; } send_byte_to_eprom(0, 0x06, 0x0000, 0x00); //send write enable instruction for ( m = 0 ; m < 32 ; m++) { if (m == 0) send_byte_to_eprom(4, 0x02, address, data_array[m]); //send first byte with write instr, keep CSb low, no delay else if (m == 31) send_byte_to_eprom(6, 0x00, 0x0000, data_array[m]); //send last byte & then make CSb high, use delay else send_byte_to_eprom(5, 0x00, 0x0000, data_array[m]); //send byte & then make CSb high, no delay } } delay_ms(20); eprom_CSb_high; set_tris_a(port_a_inputs); set_tris_c(port_c_inputs); } /****************************************************************************** * *
* Procedure Name : configure_chip_from_boot *
* *
* Purpose : This function configures the chip on boot up *
* * * Inputs : None * * * * Outputs : None * * * ******************************************************************************/ void configure_chip_from_boot(void) { int16 n, size; Status_flag = OK; if (!input(STORE_FLASH)) write_program_eeprom(CONFIG_SIZE_LOC, 0x0000); size = read_program_eeprom(CONFIG_SIZE_LOC);
145
if ((size > 0) && (read_program_eeprom(CONFIG_SIZE_LOC + 1) == an_AN231_PrimaryConfigInfo[0]) && (read_program_eeprom(CONFIG_SIZE_LOC + 2) == an_AN231_PrimaryConfigInfo[1]) && (read_program_eeprom(CONFIG_SIZE_LOC + 3) == an_AN231_PrimaryConfigInfo[2]) &&
(read_program_eeprom(CONFIG_SIZE_LOC + 4) == an_AN231_PrimaryConfigInfo[3]) && (read_program_eeprom(CONFIG_SIZE_LOC + 5) == an_AN231_PrimaryConfigInfo[4])) { reset_chip(0xFF); for (n = 0 ; n < 5 ; n++) send_byte_to_chip(0x00); for (n = 0 ; n < size ; n++) { send_byte_to_chip(read_program_eeprom(CONFIG_SIZE_LOC + 1 + n)); if (!(input(ERRb))) Status_flag = CONFIG_ERROR; } send_byte_to_chip(0x00); if (Status_flag == OK) output_high(CONFIG_OK); else output_high(CONFIG_ERR); } } /****************************************************************************** * *
* Procedure Name : readADC *
* *
* Purpose : This function reads one of the Analog-to-Digital *
* converter channels and returns the result. *
* *
* Inputs : int8 channel - The A/D channel to read. *
* *
* Outputs : int8 - The 8-bit result of the channel read. *
* *
******************************************************************************/ int8 readADC(int8 channel) { //if ((channel == 0) || (channel == 1) || (channel == 3)) - this doesn't work, always get 0 returned, don't know why //{ set_adc_channel(channel); delay_us(10); return (Read_ADC()); //} //else // return 0x00; } /****************************************************************************** * *
* Procedure Name : initialize *
* *
* Purpose : This function sets up the initial configuration of the PIC* * * * Inputs : None * * * * Outputs : None * * * ******************************************************************************/ void initialize(void) { enable_interrupts(GLOBAL); //enable global interrupts enable_interrupts(INT_RDA); //enable interrupt on RS232 receive data enable_interrupts(INT_EXT); //enable interrupt on ext int pin port_b_pullups(false); //disable port B pull-ups //set up connections between PIC & FPAA set_tris_a(port_a_inputs); set_tris_b(port_b_inputs); set_tris_c(port_c_inputs); output_high(CS2b); output_low(EXECUTE); output_low(SCLK); output_low(SI); output_high(CONFIG_OK); //turn on green LED output_high(CONFIG_ERR); //turn on red LED