Professional Documents
Culture Documents
Page 1
Agenda
Motor de Inferencia
Tcnicas de Diagnstico de un ECG
Medios de Comunicacin
Prototipo de un ECG
Page 2
Page 3
Modelando un PIC
Procesador
Oscilador
Memoria
PIC
GLCD
Temporizador
USB
ADC
Page 4
Modelando un PIC
Embedded Computer
Software
Output
Drive
Data
Conversion
Input
Variables
Signal
Conditioning
(User Interface)
(display, keypad etc.)
Output
Variables
Hardware
Page 5
Microcontrolador PIC
Como sabemos los micro
controladores de 8 bits de
Microchip se dividen en 3
gamas:
Page 6
Page 7
Page 8
Data
Memory
Data
Central
Processing
Unit (CPU)
Address
Input/
Output
Data
Program
Memory
Central
Processing
Unit (CPU)
Data
Memory
Address
Input/
Output
Data
Address
Program
Memory
Data
b) Enfoque de Harvard
Page 9
Arquitectura RISC-PIC
Power
Reset
Interrupt(s)
Program
Memory
Further
Peripheral
Data
Memory
Further
Peripheral
Microprocessor
Core
Internal Data &
Address Buses
Clock
Digital
I/0
Analog
I/0
Counters
& Timers
Page 10
Data from
Program
Memory,
carrying
instruction
word
Data
Memory
Address for
Data Memory
Data bus for
Data Memory
and
peripherals
Counter/Timer
Peripheral
Digital Input/
Output Ports
The CPU
Page 11
Condition
Code Flags
Page 12
The Interrupt
Service Routine
must start here
The program
must start here
Program Counter
points to locations
in program memory
Unimplemented memory
space, still addressable
by the 13-bit 16F84A
program address bus.
Page 13
Page 14
Control SFR(s)
Microcontroller
Core
Peripheral
"Outside
World"
Interrupt(s)
Microcontroller Interaction with its Peripherals, via Special Function Register (SFR) and Interrupt
microcontroller peripherals can be configured in software to operate in a number of different modes,
to do this certain control data must be sent to them to set them up in the desired way
once in use, there will be data flow between core and peripheral,
there may still be need for further control data,
these needs are commonly met by means of dedicated, memory - mapped registers, sometimes
called Special Function Registers,
this approach gives the microcontroller manufacturer great flexibility to extend a microcontroller
family SFRs for new peripherals can easily be located in gaps in the memory map.
Page 15
Page 16
Page 17
Oscilador Secundario
Oscilador Interno
Multiplica Frecuencia
de Oscilacin
Sin PLL
LP Low Power
Intended for low frequency crystal applications, and gives the lowest power consumption
possible. Will however operate at any frequency below around 200kHz.
RC - Resistor-Capacitor
Requires connection of an external resistor and capacitor. The lowest cost way of getting an
oscillator, but should not be used when any timing accuracy is required.
Page 19
18
10
RA1
Port A, Bit 1
RA0
Port A, Bit 0
OS C1/CLKIN Oscillator connections
OS C2/CLKOUT
VDD
Supply voltage
RB7
Port B, Bit 7
RB6
Port B, Bit 6
RB5
Port B, Bit 5
RB4
Port B, Bit 4
b) Resistor-Capacitor
Page 20
Page 21
Page 22
Page 23
Agenda
ADC
Motor de Inferencia
Tcnicas de Diagnstico de un ECG
Medios de Comunicacin
Prototipo de un ECG
Page 24
Page 25
Page 26
Page 27
Page 28
AVSS
VREF+
VR
Select
AVDD
VR+
VR-
Conversion
Control
VREFAN0
CH0
AN1
8/16 Level
Results
Buffer
Data
Format
Bus Interface
S/H
A/D
converter
AN15
Sample
Sequence
Page
Control
29
Entrada
Analgica
TAD
Clock A/D
Inicio del
Tiempo de
Adquisicin
Fin de
Conversin
Tiempo de
Adquisicin
Tiempo de
Conversin
Page 31
AD1CON3<ADCS7:ADCS0>
FCY = FOSC/2
AD Clock
Postscaler by
1 to 256
TCY to 256*TCY 0
TAD
RCAD 1
AD1CON3<ADRC>
Page 32
Page 33
Page 34
Page 35
AD1CON2<VCFG2:VCFG0>
VR Select
AVDD
AVSS
VREF+
VR+
VR-
VCFG2:VCFG0
VR+
VR-
000
AVDD
AVSS
001
VREF+
AVSS
010
AVDD
VREF-
011
VREF+
VREF-
1xx
AVDD
AVSS
VREF-
AD1CON2 Register
bit8
bit15
CSSL15=0
VCFG1 CSSL13=0
VCFG0
VCFG2 CSSL14=0
---
---
CSNA
---
bit7
BUFS
---
SMPI3
SMPI2
SMPI1
SMPI 0
BUFM
--bit0
Page
36
ALTS
Mux A
AD1CHS<CH0SA3:CH0SA0>
(1) AN1
VINH
VINL
(0) VRAD1CHS<CH0NA>
AN15
bit15
AD1CON2 Register
bit8
VCFG2
CSSL14=0
VCFG1 CSSL13=0
VCFG0
---
---
CSNA
bit7
---
--bit0
BUFS
---
SMPI3
SMPI2
SMPI1
SMPI 0
BUFM
bit15
AD1CSSL Register
bit0
CSSL15
CSSL14=0
CSSL14 CSSL13=0
CSSL13
CSSL2
CSSL1
CH0NB
---
---
---
CH0SB3
CH0SB2
CH0SB1
CH0SB0
bit0
bit7
CH0NA
CSSL0
bit8
bit15
AD1CHS Register
ALTS
---
---
---
CH0SA3
CH0SA2
CH0SA1
CH0SA0
PCFG1
bit0
Page
37
CSSL8=0
PCFG0
bit15
AN15
AN14
AN13
.
+B
-B
AN5
AN4
AN3
AN2
AN1
AN0
ADCBUF Buffer
ADCBUF0
AN0
AN2
INT
AN13
AN14
+
CH 0
-
+A
-A
AN1
VREF-
bit15
AD1CSSL Register
bit0
CSSL15
CSSL14=0
CSSL14 CSSL13=0
CSSL13
CSSL2
CSSL1
CSSL0
bit15
AD1CON2 Register
VCFG2
bit8
CSSL14=0
VCFG1 CSSL13=0
VCFG0
---
---
CSNA
--bit0
bit7
BUFS
---
---
SMPI3
SMPI2
SMPI1
SMPI 0
BUFM
ALTS
Page
38
Mux A
VINH
Mux B
S/H
VINL
AD1CON1<ASAM>
1
Seal de
Conversion
completa
0
AD1CON1<SAMP>
bit8
bit15
AD1CON2 Register
VCFG2
VCFG1
CSSL13=0
VCFG0
---
---
CSNA
---
BUFS
--bit0
bit7
---
SMPI3
SMPI2
SMPI1
SMPI 0
BUFM
ALTS
Page 39
AD1CON3<SAMC4:SAMC0> (7)
Timer4 Compare ends
(2)
Active Transition on INT0 pin (1)
Clearing AD1CON1<SAMP> (0)
AD1CON1
<SSRC2:SSRC0>
VINH
VINL
0 TAD to 31 TAD
Evitar 0 TAD
VR- VR+
S/
H
AD1CON1<ASAM>
VR-
VR+
A/D
converter
Conversion
complete Signal
AD1CON1<SAMP>
AD1CON1<DONE>
RESULT
ADC1BUF0
:
ADC1BUF15
Page 40
RESULT
FORMAT
ADC1BUF0
:
:
:
:
:
:
ADC1BUF15
AD1CON2<BUFM> = 0
ADC1BUF0
:
:
ADC1BUF7
0
AD1CON2<BUFS>
ADC1BUF8
:
:
ADC1BUF15
AD1CON2<BUFM> = 1
Page 41
Ejercicio N1:
Digitalizar la Seal Analgica ECG
Tareas a realizar:
Programar el PIC con MPLAB en C18.
Realizar la conversin digital de una seal
analgica en Proteus con PIC usando
Potencimetro.
Resultado esperado:
Digitalizacin de una seal analgica y su
visualizacin usando LCD.
Page 42
Configurar el ADC
Configurar los puertos de E/S
Leer el ADC y mostrarlos en LEDs
PIC24
VDD
POT R6
AN5
Vss
RA7-RA0
LEDs D10-D3
Page 43
Pasos a Realizar
STEP 2: AD1CON2
STEP 3: AD1CON3
Select Sample Time = 13TAD
Conversion Time is always 12TAD
Select AD Clock Source such that you get 16 samples in around 1 mSec (16
ksps)
Assume 1TCY =.25 uS (FCY = 4 MHz)
Page 44
Pasos a Realizar
STEP 5: AD1PCFG
Set AD1PCFG so that the only pin using analog functionality is AN5
STEP 6: AD1CSSL
Channel scanning is not enabled, so no input channels should be
selected for scanning
Page 45
Bit:8
--
ADC Module
enable bit
ADSIL
--
ADC Module
enable/disable
in IDLE mode
--
--
FORM1
FORM0
Result Format
00: Intiger (0000 00dd dddd dddd)
01: Signed Intiger (ssss sssd dddd dddd)
10: Fractional (dddd dddd dd00 0000)
11: Signed Fractional (sddd dddd dd00 0000)
Bit:7
SSRC2
Bit:0
SSRC1
SSRC0
--
--
ASAM
SAMP
DONE
Start Sampling,
If ASAM is 0
Conversion
Status bit
Page 46
Bit:8
VCFG2
VCFG2
VCFG0
--
--
CSCNA
--
--
VR-
000
AVDD
AVSS
001
VREF+
AVSS
010
AVDD
VREF-
011
VREF+
VREF-
1xx
AVDD
AVSS
VCFG2:VCFG0
AVDD
VREF+
VR
Select
VCFG2:VCFG0
AVSS
Bit:0
--
SMPI3
SMPI3:SMPI0
VR-
VREF-
Bit:7
BUFS
VR+
SMPI2
SMPI1
SMPI0
Interrupt Event
(Sample/convert sequence)
0000
each
0001
alternate
....
1110
Every 15th
1111
Every 16th
BUFM
ALTS
Sample alternatively
MUX-A & MUX-B
Buffer Mode Select bit
1: Buffer configured as two 8-words buffers
0: Buffer configured as one 16-words
buffers
Page 47
Bit:8
--
--
SAMC4
SAMC3
SAMC2
SAMC1
SAMC0
SAMC4:SAMC0
Sampling Time
00000
0 TAD
00001
1 TAD
....
11110
30 TAD
11111
31 TAD
1: ADRC is used
0: System clock is used
Bit:7
ADCS7
Bit:0
ADCS6
ADCS5
ADCS4
ADCS3
ADCS2
ADCS1
ADCS0
Conversion Clock
00000000
TCY ( FCY )
00000001
2*TCY ( FCY / 2 )
....
11111110
11111111
ADCS = (TAD/TCY) - 1
Page 48
Bit:8
CH0NB
--
--
--
CH0SB3
CH0SB2
CH0SB1
CH0SB0
CH0SB3:CH0SB0
0000
AN0
0001
AN1
....
1110
AN14
1111
AN15
Bit:7
Bit:0
CH0NA
--
--
--
CH0SA3
ANxx
AN0
+B
AN1
-B
VREF-
CH 0
AN15
+
A
-A
ANxx
AN0
CH0SA2
CH0SA1
CH0SA0
CH0SA3:CH0SA0
0000
AN0
0001
AN1
....
1110
AN14
1111
AN15
AN1
VREF-
CH0SA3:CH0SA0
CH0NA
Page 49
Bit:8
PCFG14
PCFG13
PCFG12
PCFG10
PCFG11
PCFG9
PCFG8
Bit:7
PCFG7
Bit:0
PCFG6
PCFG5
PCFG4
PCFG2
PCFG3
PCFG1
PCFG0
Bit:8
CSSL14
CSSL13
CSSL12
CSSL11
CSSL10
CSSL9
CSSL8
Bit:7
CSSL7
Bit:0
CSSL6
CSSL5
CSSL4
CSSL3
CSSL2
CSSL1
CSSL0
Page 50
Resultado Esperado
Page 51
Agenda
USB
Motor de Inferencia
Tcnicas de Diagnstico de un ECG
Medios de Comunicacin
Prototipo de un ECG
Page 52
Page 53
Interfaces USB
USB
Creado por Intel en el ao 1994, versin 1.0.
En el ao 1998 se lanza la versin 1.1 con una velocidad de
transferencia baja de 1.5 Mbps y a full capacidad de 12 Mbps.
En el ao 2000, se lanza la versin 2.0 de alta capacidad con 480 Mbps.
Page 54
Data Analysis,
Data Logging,
Firmware Updates,
Diagnostics,
Embedded Applications!
RS232
Paralelo
PS/2
3 velocidades:
Low- 1.5 Mbps, Full- 12 Mbps,
High- 480 Megabits/second
Page 55
4-wire
connection
Differential
Signaling
VBUS
VBUS
D+
D+
D-
D-
GND
GND
~ 5.0 V
~ 3.3 V
4.40 - 5.25 V
Guaranteed 100 mA
500 mA maximum through negotiation
Page 56
A Plug
USB Host
B Plug
FS, HS Peripheral
mini-B Plug
FS, HS Peripheral
Page 57
Guaranteed Latency
Guaranteed Data
Integrity
Interrupt
Bulk
Isochronous
USB Pipes
HOST PC
Page 59
Client
Software
Host
Buffers
Data Flows
Pipes
USB Device
Endpoints
Interface
Page 60
El Dispositivo Lgico
Device
(Manufacturer: Microchip Technology)
(Product: Mouse in a Circle Demo)
Configuration
Interface
IN (Endpoint x)
Analog/Digital I/O
OUT (Endpoint x)
IN (Endpoint 0)
OUT (Endpoint 0)
Trama USB
Slot
Trame = 1ms
Stereo Audio
BULK
Stereo Audio
BULK
Stereo Audio
BULK
Stereo Audio
BULK
Stereo Audio
BULK
Stereo Audio
BULK
Stereo Audio
BULK
Stereo Audio
BULK
Scanner
Stereo Audio
Interrupt,
Control,
Low
Speed
Rx Line
Tx Line
Rx Voice
Tx Voice
SOF
Stereo Audio
Low Speed
Low Speed
BULK
BULK
Page 62
Perifricos USB
UPS
Data
Logger
MIDI
Generic
Mouse
SD Card
Reader
Digitizer
Speaker
RS-232
Audio
Class
Mass Storage
Device Class (MSD)
Joystick
Keyboar
d
Human Interface Device
Class (HID)
Communication
Device Class (CDC)
WinUSB
LibUSB
MCHP
Custom Class
63
Page 63
(Vendor Class)
El Proceso de Enumeracin
Power
(self/bus)
POWERED
Bus
reset
ATTACHED
DEFAULT
Cable
Connected
Get Device
Descriptor
SUSPENDED
DETACHED
ADDRESS
Get
Descriptors
CONFIGURED
Page 64
Peripheral Device
VUSB 3.3 V
1.5 k5%
+5V
D+
Transceiver
DGND
USB
Connector
Page 65
Peripheral Device
VUSB 3.3 V
1.5 k5%
+5V
D+
Transceiver
DGND
USB
Connector
Page 66
Peripheral Device
VUSB 3.3 V
On-chip pull-up resistors
available!
+5V
D+
Transceiver
DGND
USB
Connector
Page 67
Control Transfers
Endpoint 0 IN
(Control Data)
Descriptors
Other Endpoints
Page 68
Descriptores
Device
String 0
String 1
String N
Configuration 1
To other Interfaces
if any
Interface 0
Endpoint
Endpoint
Interface 1
Endpoint
Endpoint
Ejemplo de Descriptores
Manu. String
Device
Configuration 1
Interface 0
Endpoint
Microchip
Prod. String
PICDEM USB
Other String
Go USB!
Unicode
Characters
Page 70
usb_descriptors.c
Descriptors
/* Device Descriptor */
ROM USB_DEVICE_DESCRIPTOR device_dsc=
{
0x12,
// Size of this descriptor in bytes
USB_DESCRIPTOR_DEVICE, // DEVICE descriptor type
0x0200,
// USB Spec Release Number
CDC_DEVICE,
// Class Code
0x00,
// Subclass code
0x00,
// Protocol code
EP0_BUFF_SIZE,
// Max packet size for EP0,
0x04D8,
// Microchip Vendor ID
0x000C,
// Product ID ID
Page 71
PIC Microcontroller
PC Computer
CDC
USB Cable
Design Considerations:
~80 KB/s max
Bulk Transfers
PC applications can access the device as though it
is connected to a serial COM port
Page 72
MCHPFSUSB Framework
- Polled Program Flow -
main()
Reset
InitializeSystem()
while(1)
Cooperative
Multitasking!!
USBDeviceTasks()
USB Stack
ProcessIO()
Your application
code
Function
Services
CDCTxService()
MSDTasks()
Re-arm OUT Endpoint
(HID & Generic)
Page 73
No blocking
functions.
Use state
machine.
MCHPFSUSB Framework
- Interrupt Program Flow -
Reset
main()
InitializeSystem()
USBDeviceAttach()
USB Interrupt
Context
You edit
UserInit()
while(1)
USBDeviceTasks()
ProcessIO()
Function
Services
Your application
code
CDCTxService()
MSDTasks()
Re-arm OUT Endpoint
(HID & Generic)
Page 74
Cdigo de Ejemplo
Main.c
#include
#include
#include
#include
Compiler.h
USB\usb.h
USB\usb_function_cdc.h
HardwareProfile.h
void UserInit(void){
}
void ProcessIO(void){
if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return;
CDCTxService();
}
static void InitializeSystem(void){
#if define
#endif
UserInit();
USBDeviceInit();
}
int main(void){
InitializeSystem();
USBDeviceAttach();
while(1){
ProcessIO();
}
}
Conditional compiling
(no need to change)
No need to change
USBDeviceTasks()
is executed in an ISR
(High Priority PIC18,
_USB1Interrupt()
PIC24 & PIC32)
Page 75
Agenda
GLCD
Motor de Inferencia
Tcnicas de Diagnstico de un ECG
Medios de Comunicacin
Prototipo de un ECG
Page 76
Page 77
R25
R3
10k
10k
V-
R23
LCD2
U8
AMPIRE128X64
4
8
4
8
20k
R14
R24
V-
U1
6
3
10k
2
6
3
7
1
7
1
10k
OP07
V+
SUMADOR
-Vout
RST
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
E
R/W
RS
V0
VCC
GND
CS2
CS1
OP07
V+
J2
10k
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
CONN-SIL5
RV4
2
AN 4-3-ECG
U2
4
3
2
1
C1
2
3
4
5
6
7
14
13
CONN-H4
22pF
X1
E
RW
DI
CS2
CS1
PGC
PGD
CRYSTAL
C2
22pF
A114
R26
R28
25K
25k
33
34
35
36
37
38
39
40
18
CS2
CS1
RST
E
RW
DI
1
2
3
4
5
U2(RC0/T1OSO/T1CKI)
RA0/AN0
RC0/T1OSO/T1CKI
RA1/AN1
RC1/T1OSI/CCP2/UOE
RA2/AN2/VREF-/CVREF
RC2/CCP1/P1A
RA3/AN3/VREF+
RC4/D-/VM
RA4/T0CKI/C1OUT/RCV
RC5/D+/VP
RA5/AN4/SS/LVDIN/C2OUT
RC6/TX/CK
RA6/OSC2/CLKO
RC7/RX/DT/SDO
OSC1/CLKI
RB0/AN12/INT0/FLT0/SDI/SDA
RB1/AN10/INT1/SCK/SCL
RB2/AN8/INT2/VMO
RB3/AN9/CCP2/VPO
RB4/AN11/KBI0/CSSPP
RB5/KBI1/PGM
RB6/KBI2/PGC
RB7/KBI3/PGD
RD0/SPP0
RD1/SPP1
RD2/SPP2
RD3/SPP3
RD4/SPP4
RD5/SPP5/P1B
RD6/SPP6/P1C
RD7/SPP7/P1D
RE0/AN5/CK1SPP
RE1/AN6/CK2SPP
RE2/AN7/OESPP
RE3/MCLR/VPP
VUSB
PIC18F4550
15
16
17
23
24
25
26
RST
USBCONN
10k
8
9
10
1
MCLR
ICSP 1-5
R1
MCLR
1uF
U10
VCC
D+
DGND
R4
19
20
21
22
27
28
29
30
D1
C3
J3
1
3
2
4
1N5817
10k
PGD
PGC
1
2
3
4
5
CONN-SIL5
OPAMP
25k
2
TR1
BR1
Page 78
VDD
R29
25k
R27
Page 79
Page 80
Page 81
Page 82
Page 83
Agenda:
Page 84