Learn To Write Code For 8051, Arduino, AVR, dsPIC, PIC, STM32 ARM Microcontroller, etc.
Coding Embedded Controller With C/C++.
Printed Circuit Board (PCB) Project For Electronics Hobbyists.
Using a prototype board for micro-controller firmware testing could save time and safer. Putting an on-board device programmer with prototype board could be more satisfy for electronic hobbyists.
I have some PIC18 and PIC16 series of micro-controllers left from previous projects. I don't know what to do with them anymore. So I put them on single board to PIC program testing next time I need them without checking their pin diagram, and wiring them on bread board.
PCB Front View
PCB Back View
I designed a PCB with a
PICKit2 device programmer (with AVR ISP header)
+5VDC and +3.3VDC low drop out power supply
RS-232 to TTL logic converter
I2C DS1307 RTC and 24LC08 EEPROM
4-bit LCD (HD4478)
3-digit 056'common cathode multiplexing display
One passive buzzer with transistor driver (using CCP1 PWM output pin of PIC16F876A)
8-LED that connects to PORTC of PIC16F876A
A 4x4 keypad matrix that connects to PORTB of PIC16F876A
Three analog inputs (one LM35 and two potentiometers) that connect to RA0...RA1 of PIC16F876A.
A 28-pin IC socket for 28-pin PIC devices
A 20-pin IC socket for 20-pin PIC devices
A 18-pin IC socket for 18-pin PIC devices
A 14-pin IC socket for 14-pin PIC devices
And a 8-pin IC socket for 8-pin PIC devices
This board seem to be a large PCB with two copper layer near a size of an A4 paper that I'm not yet fabricate it. It need a PCB fabrication service.
Schematic
I use Protues VSM Release 8.16 SP3 to design draw its circuit diagram. Some components are not in its original libraries. So I find and download some devices symbol, footprints and 3D objects from snapeda website. I separate its schematic into A4 sheets.
Sheet #1
Sheet #2
Sheet #3
Sheet #4
Sheet #5
This board could fit,
28-pin PIC microcontrollers: PIC16F876A, PIC16F886, etc.
20-pin PIC microcontrollers: PIC16F1459(USB), PIC16F690, etc.
18-pin PIC microcontrollers: PIC16F1827, PIC16F84A, PIC16F818, etc.
14-pin PIC microcontrollers: PIC16F630, PIC16F676, etc.
8-pin PIC microcontrollers: PIC12F629, PIC12F675, PIC12F683, etc.
These are some mid-range PIC micro-controllers I have at my own workshop.
Printed Circuit Board (PCB)
This board size is 8.02x6.30 inches that could be a little bit expensive to order from any professional PCB fabrication service. But if we need to use it with classmate or friend the share cost is cheaper.
Top Copper non-mirror
Bottom Copper
Top Silk
I preview this PCB on an online Gerber viewer software.
I have been using PCBWay for many years now. PCBWay fabricate PCBs at low cost,
fast processing time for only 24 hours, and fast delivery time using
any carrier options. This double side 10cmx10cm can be fabricate at only
5USD for 5 to 10pcs by PCBWay. It's a standard PCB with silk screen and
solder mask.
Creating A Negative Voltage Regulator Using PIC16F818 PWM
An Overview Of Negative Voltage Creating
A negative voltage level is useful in some situations, a negative voltage reference for ADC module, a negative supply voltage for an op-amp.
A simulation program sample
It's easily built using two high speed diodes, two polarized capacitor with an oscillator. An oscillator could be created with NE555 timer, or using an op-amp with some extra passive components.
A block of negative voltage generator. At the high cycle of OSC1, it charges the capacitor C1, and bypass D1 diode to the ground creating a potential at both positive and negative pin of C1.
Another option to create a negative voltage is using a DC-DC converter, as a case of using MC34063A.
Using these two method as per above require an extra components placement on board. In any application where a microcontroller is needed, we can use a PWM signal created by the on-board microcontroller. Most 8-bit microcontroller, currently shipped with a PWM peripheral inside. If it isn't so, PWM signal could be created using software, by toggling an output pin with a specific period.
PIC16F818 PWM Programming And Interfacing With CCS PICC
PIC16F818 is an 8-bit microcontroller. It's a tiny 18-pin available in DIP package. PWM signal is created by CCP1 module inside this device.
With the ease of complexity of programming, CCS PICC could configure the PWM output using a few line of code. Unlike other compiler, that a calculation to find PWM frequency and duty cycle is needed.
In CCS PICC, I use the #use pwm(options) directive to configure the module, frequency and duty cycle. But it's required to set the direction of CCP1 pin to an output direction. It's done within a few lines C code.
In this program, I use CCP1 of PIC16F818 to create PWM signal at the frequency of 1 kHz, and 50% duty cycle. This signal fed into the negative voltage generator circuit, creating a negative output voltage around -5 V, the same magnitude to the input voltage.
Schematic Diagram, excludes the supply voltage circuit for the MCU. CCP1 creates a PWM output at RB2. The MCU clock is internal 8 MHz RC oscillator inside.
C source code is just a dozen of lines.
#include<16F818.h>
#fuses INTRC_IO,NOWDT
#use delay(clock=8M)
/*Use CCP1 Module with the frequency of
1 kHz and 50% duty cycle*/
#use pwm(CCP1,FREQUENCY=1000,DUTY=50)
void main(void){
output_B(0x00);
set_tris_b(0x00);
while(1){
}
}
A screen shot of the running program shown below.
A simulation screen shot. Output voltage probe connects to C2(-). Output voltage reaches around -5 V when C2 is fully charged.
TC72 is a temperature-to-digital converter with serial peripheral interface (SPI). It could read the temperature from -55 to +125 degree Celsius. The temperature data is 10-bit format in which the upper 8-bit is the signed decimal value. The remaining two lower bits is the fraction value. The fraction is 0.25 degree Celsius step.
A program screen shot reading the temperature of -16.25 degree Celsius.
The device comes with 8-pin SMD package.
Pins diagram of this device lists below.
The supply voltage is between 2.65 V to 5.5 V DC. All pins description are list below.
NC - No Connection
CE - Chip Enable (active high)
SCK - Serial Clock Input
GND - Ground
SDO - Serial Data Out
SDI - Serial Data In
NC - No Connection
VDD - Positive Supply
For data communication, there are two read and write operations- SPI single byte and SPI multiple byte. But here, I implement only the SPI single byte implementation.
Ax Denotes the address of register. Dx is the data written or reading from the corresponding address.
Reading and writing need one 8-bit address and one 8-bit data. There are four addresses registers- Control, LSB Temperature, MSB Temperature and Manufacturer ID Register. Control register is read/write while others are read-only.
Control register is for initialize the operation of this device. There are three modes- one-shot, continuous conversion and shut down. At power on reset or brown out reset, it is in shut down mode. Control register setting lists below.
One-shot = 0 and Shut-Down = 0 - Continuous temperature conversion
One-shot = 0 and Shut-Down = 1 - Shut Down
One-shot = 1 and Shut-Down = 0 - Continuous temperature conversion
One-shot = 1 and Shut-Down = 1 - One Shot
LSB temperature is the two-bit fraction number. It is 0.25 degree Celsius per bit, and 0.75 degree Celsius maximum value. We can ignore this fraction LSB temperature number with 0.75 degree Celsius error.
MSB temperature is the signed decimal temperature data. Manufacturer ID identifies this device.
Programming with CCS PICC
PIC16F818 comes with and SPI communication module. The program memory sizes up to 2 kB, sufficient for this programming example.
In this example, the SPI port commands to read the temperature from TC72 in continuous mode. An 16x2 character LCD display the result with full formatting.
The MCU clocks at 4 MHz, yielding a 1 micro second instruction speed. SPI clock is divided by 64 to make a steady serial data reading.
Schematic diagram
CCS PICC program lists below.
#include<16F818.h>
#use delay(clock=4M)
#fuses NOWDT,INTRC_IO
#define LCD_ENABLE_PIN PIN_A2
#define LCD_RS_PIN PIN_A0
#define LCD_RW_PIN PIN_A1
#define LCD_DATA4 PIN_A4
#define LCD_DATA5 PIN_A3
#define LCD_DATA6 PIN_A6
#define LCD_DATA7 PIN_A7
/*use a built-in LCD driver*/
#include<lcd.c>
void main(){
int sspL,sspH,fraction;
/*223 is custom code for degree*/
char c1=223,signing;
int fractionN[3]={75,50,25};
/*SPI master mode, clock low to high divided by 64*/