Showing posts with label microchip. Show all posts
Showing posts with label microchip. Show all posts

Sunday, 10 November 2024

TDR Pulse Generator (Microchip)

Introduction 
This post continues a previous blog that used a microcontroller driver design to generate a fast-rising edge for educational and bench-testing purposes. The microcontroller (PSoC) in the earlier blog was replaced with a microcontroller from Microchip (ATmega16U2). The board uses the Microchip part and is powered by USB.

Pulse Generator PCB
Pulse Generator PCB

Why Another Generator
While the previous design using a PSoC microcontroller was received well, the price of a PSoC microcontroller has become twice that of a competing device such as the Microchip ATmega16U2. Consequently, a design was produced to utilise the Microchip microcontroller.

Circuit Board Design
As featured in the previous design, a pulse train is initiated from a microcontroller (ATmega16U2).

ATmega 16U2 for Pulse Generation
ATmega 16U2 for Pulse Generation

The same output driver arrangement was reused on this design however the output driver was changed to a Nexperia 74AHC04 because of the 5 V supply rail (USB). A linear regulator was considered to maintain the supply rails at 3.3 V but was ultimately not included to keep the total cost as low as possible. Five outputs of the 74AHC04 driver are still connected in parallel to individual 249 R resistors. All five outputs are tied together thus providing a calculated 49.8 R at the output, CN2.

Buffered Output for Pulse Generator
Buffered Output for Pulse Generator


Software Design for Output Pulsing

A minimal software (code) project was prepared in Microchip Studio. This application generates a pulse by direct and continuous writes to the microcontroller port. The code to generate the pulses is shown below
.

int main(void)
{
DDRD = 0x08;
PORTD = 0x00;
for (;;)
{
PORTD |= _BV(PD3);
PORTD &= ~(_BV(PD3));
}
}


USB hardware connections were made to the ATmega to allow developers or users to enhance the code further. The ATmega software could be developed to support USB-controlled commands. Below are some links for software that may allow for HID solutions with the USB.

https://github.com/NicoHood/HoodLoader2

https://gitlab.com/arksine.code/HID/-/tree/2.0

A Note on Programming
The post includes details regarding the programming of the Microchip part because this design is intended for the educational system or illustrative purposes.

The 6-way programming connector on the pulse board interfaces with the ATmega. The connections are designed for SPI programming. See Table 3-6 in the Atmel ICE document for information concerning connections between the programmer and Microchip microcontrollers.

Pulser SPI Connector Pinouts
SPI Connector Pinouts

For programming of the microcontroller in this blog, the ‘Atmel squid’ connections were made to the pulse generator board as shown below.

SPI 'Squid' to Pulser Board
SPI 'Squid' to Pulser Board

PCB pad jumper J1 should be shorted with solder to power the external oscillator.

Powering External Oscillator J1
Powering External Oscillator J1

The settings displayed below are taken from the Microchip Studio's, Tools menu, and the Device Programming item. The settings can be adapted based on the functionality needed on the board. For example, the onboard 8 MHz oscillator could be replaced with a different frequency device or the board could be redesigned to suit a crystal.

Microchip Studio ISP Clock Settings
Microchip Studio ISP Clock Settings

Microchip Studio Oscillator Settings
Microchip Studio Oscillator Settings
 
Microchip Studio Fuse Settings
Microchip Studio Fuse Settings

Microchip Studio Fuse Settings Continued
Microchip Studio Fuse Settings Continued

Testing the Board
Since the output driver voltage rails were changed from 3.3 V to 5 V, the output rise time (10% - 90%) was predicted to be slower.

Prototype Pulser PCA
Prototype Pulser PCA

Drive Voltage from Pulse Tester (Microchip)
Drive Voltage from Pulse Tester (Microchip)
 
Period from Pulse Tester (Microchip)
Period from Pulse Tester (Microchip)

Signal measurements were again performed on a Keysight oscilloscope with a 20 GSa/s resolution. This board showed a rise time of 1.11 ns when measuring for a rise time of 10% to 90%.

Output Waveform Rise Time from Pulse Tester
Output Waveform Rise Time from Pulse Tester

Reflectometry Testing
Reflectometry tests were performed with a benchtop oscilloscope. The pulse was connected to the oscilloscope with a BNC Tee adaptor, and the other side of the BNC Tee was connected to a length of coaxial cable.

Pulse Tester as TDR Test Setup
Pulse Tester as TDR Test Setup

The initially launched and reflected pulses were captured as shown in the image below.

TDR Capture
TDR Capture

Engineering Files
The Atmel Studio project, schematic, Gerber and BOM files are available for download using the links below.

Pulse Generator Microchip Studio Project

Pulse Generator Schematic Rev2










Pulse Generator Bill of Materials Rev2























Wednesday, 15 February 2017

MCP23S17 IO Port Expander Header File / Register

Summary
For a recent project the 16bit IO Expander, MCP23S17, from Microchip was enlisted for low voltage input scanning. 

Searching online, at the time of writing this blog, there were no projects using this part with sample code. 

Below is the header file that may be of use.


MCP23S17 Microchip IO Expander QFN Package
Microchip IO Expander QFN Package


Downloads


mcp23s17.h

Code


/******************************
* mcp23s17.h
******************************/

#ifndef mcp23s17_h
#define mcp23s17_h

typedef unsigned char   uint8;
    
#define MCP_READ   0x41     /* Read */
#define MCP_WRITE   0x40     /* Write */
#define Mode_8Bit     1         /* Addressing 8/16bit */
#define Mode_16bit    0

#ifdef Mode_16Bit
    /******************************
    * Control register for BANK=0
    ******************************/
    #define IODIRA        0x00      /* Data Direction Register for PORTA */
    #define IODIRB        0x01      /* Data Direction Register for PORTB */ 
    #define IPOLA         0x02      /* Input Polarity Register for PORTA */ 
    #define IPOLB         0x03      /* Input Polarity Register for PORTB */ 
    #define GPINTENA      0x04      /* Interrupt-on-change enable Register for PORTA */ 
    #define GPINTENB      0x05      /* Interrupt-on-change enable Register for PORTB */ 
    #define DEFVALA       0x06      /* Default Value Register for PORTA */    
    #define DEFVALB       0x07      /* Default Value Register for PORTB */      
    #define INTCONA       0x08      /* Interrupt-on-change control Register for PORTA */  
    #define INTCONB       0x09      /* Interrupt-on-change control Register for PORTB */      
    #define IOCON         0x0A      /* Configuration register for device */                      
    #define GPPUA         0x0C      /* 100kOhm pullup resistor register for PORTA (sets pin to input when set) */    
    #define GPPUB         0x0D      /* 100kOhm pullup resistor register for PORTB (sets pin to input when set) */      
    #define INTFA         0x0E      /* Interrupt flag Register for PORTA */        
    #define INTFB         0x0F      /* Interrupt flag Register for PORTB */    
    #define INTCAPA       0x10      /* Interrupt captured value Register for PORTA */  
    #define INTCAPB       0x11      /* Interrupt captured value Register for PORTB */    
    #define GPIOA         0x12      /* General purpose I/O Register for PORTA */  
    #define GPIOB         0x13      /* General purpose I/O Register for PORTB */ 
    #define OLATA         0x14      /* Output latch Register for PORTA */ 
    #define OLATB         0x15      /* Output latch Register for PORTB */
#endif

#ifdef Mode_8Bit
    /******************************
    * Control register for BANK=1
    ******************************/
    #define IODIRA        0x00      /* Data Direction Register for PORTA */
    #define IPOLA         0x01      /* Input Polarity Register for PORTA */  
    #define GPINTENA      0x02      /* Interrupt-on-change enable Register for PORTA */     
    #define DEFVALA       0x03      /* Default Value Register for PORTA */    
    #define INTCONA       0x04      /* Interrupt-on-change control Register for PORTA */     
    #define IOCONA        0x05      /* Configuration register for device */          
    #define GPPUA         0x06      /* 100kOhm pullup resistor register for PORTA (sets pin to input when set) */     
    #define INTFA         0x07      /* Interrupt flag Register for PORTA */
    #define INTCAPA       0x08      /* Interrupt captured value Register for PORTA */
    #define GPIOA         0x09      /* General purpose I/O Register for PORTA */  
    #define OLATA         0x0A      /* Output latch Register for PORTA */ 
    #define IODIRB        0x10      /* Data Direction Register for PORTB */ 
    #define IPOLB         0x11      /* Input Polarity Register for PORTB */ 
    #define GPINTENB      0x12      /* Interrupt-on-change enable Register for PORTB */
    #define DEFVALB       0x13      /* Default Value Register for PORTB */      
    #define INTCONB       0x14      /* Interrupt-on-change control Register for PORTB */
    #define IOCONB        0x15      /* Configuration register for device */  
    #define GPPUB         0x16      /* 100kOhm pullup resistor register for PORTB (sets pin to input when set) */        
    #define INTFB         0x17      /* Interrupt flag Register for PORTB */    
    #define INTCAPB       0x18      /* Interrupt captured value Register for PORTB */    
    #define GPIOB         0x19      /* General purpose I/O Register for PORTB */ 
    #define OLATB         0x1A      /* Output latch Register for PORTB */
#endif
    
/* Config bits - IOCON */
#define BANK  0x80
#define MIRROR  0x40
#define SEQOP  0x20
#define DISSLW  0x10
#define HAEN  0x08
#define ODR      0x04
#define INTPOL  0x02

/******************************
* Prototypes
******************************/
void MCP23S17_init();
void MCP23S17_write(uint8 address, uint8 value);
uint8 MCP23S17_read(uint8 address);
uint8 MCP23S17_verify(uint8 address, uint8 verify_data);
    
#endif
/* END */



Change Summary

Version 1.00 (10 February 2017)

  • Created register mapping for MCP23S17, 8 and 16 bit modes