Wednesday, August 31, 2022

7 segment display interface with LPC2148 : embedded C program with code


 








Circuit Diagram:



Source Code:

#include <LPC214x.H>                      

unsigned char dig[] = {0x88,0xeb,0x4c,0x49,0x2b,0x19,0x18,0xcb,0x8,0x9,0xa,0x38,0x9c,0x68,0x1c,0x1e};

void delay(unsigned int count)

{

  int j=0,i=0;

  for(j=0;j<count;j++)

  {

    for(i=0;i<120;i++);

  }

}

int main (void)

{

unsigned char count=0;

unsigned int i=0;

IO0DIR |= (1 << 11);        //Set Digit control lines as Outputs

IO0SET = (1 << 11);

IO0DIR |= 0x007F8000;

  while(1)

 {

                                count++;

                                if(count ==16) count = 0;

                                for (i=0; i < 100; i++)        //change to inc/dec speed of count

                                 {

                                  IO0CLR = 0x007F8000;

                                  IO0SET = (dig[count] << 15);

                                 delay(200);

                                }                             

  }

}

Tuesday, August 30, 2022

DAC interface with ARM7 LPC 2148 : Sine wave generation

 


PROGRAM LOGIC:

* Equation for generating sine wave is created.

* Program loop is created to send Sine wave value (0 to 360 radian ) to DAC

* DAC convert digital equivalent value of sine wave into analog signal

* CRO is connected in DAC output pin (P0.25) to display sine wave.



PROGRAM CODE

#include <lpc214x.h>

#include <stdio.h>

#include <math.h>

#define Rad 0.0174532925

int teta,DAC_In;

float sine_val;

int main()

{

PINSEL1 = 0X00080000;

while(1)

{

for(teta=0;teta<360;teta++)

{

sine_val = (1.65 * sin(teta*Rad));

DAC_In = ((sine_val * 1024 /3.3)+512);

DACR = (DAC_In<<6);

}

}

}


CIRCUIT DIAGRAM





Monday, August 29, 2022

ARM7 LPC 2148 Embedded C program to interface PC (UART)

 



Circuit Diagram




UART – Universal Asynchronous Receiver Transmitter (UART0 and UART1)

UART0 has lines TXD, RXD and Gnd lines for interfacing simple serial port.

UART1 has lines apart from the above, control lines for interfacing Modem also. Now, we are going to see only the registers available in UART0

UART0 is used to send the byte of data serially and receive the byte of the data serially.

At the time of receiving, it receives the bits seri ally and assembles as parallel 8 bit data and it places in the receiver buffer register U0RBR. It is the content of the top of the FIFO buffer registers. At the time of transmitting, the user is supposed to place the 8 bit data in Transmit Hold Register Namely U0THR.

In serial communication, the serial data is sent in the same rate at which the receiving system also receives. This is called baud rate (bits per second). For example, 9600 baud means 9600 bits per second. The internal clock is divided by 16 bit no. to arrive at the required baud rate.

The Most Significant 8 bits of the divider value are stored is called U0DLM. The Least Significant 8 bits of

the divider value are stored in the register called U0DLL. At the time of writing in these registers only, DLAB bit in the U0LCR register (Line Control Register) is to be made 1. Whenever, the U0THR register is empty, the next byte of data can be sent to send it out serially. Similarly, whenever, a byte of data is received, it is placed in U0RBR. As soon as it happen, interrupt may be raised to inform the user. But interrupts are to be enabled before the use. 

There is an interrupt enable register namely U0IER. By writing proper bits in the register, the above events will raise the interrupt. There is another register U0IIR, which is used to find what are all the interrupts pending. The register FIFO control register U0FCR is used to reset TX FIFO (Transmit First In First Out register set) and RX FIFO (Receive First In First Out) and to enable them.

The register U0LCR, line control register is used to write serial protocol parameters namely, the word length of the data, no. of stop bits, parity enable, parity select, Break control. The 7th bit in this register namely DLAB is used to enter the 16 bit divisor data. Line Status register U0LSR is the status register to know whether data has been received, data can be sent for transmission, to find out errors. There is another register U0TER which is used to enable the serial transmitter


PROGRAMLOGIC:

* Configure UART of ARM7 in 9600 baud rate.

* Program loop is created to send given string serially through transmitter pin of UART.

* Hyper terminal of PC is configured in 9600 baud rate in COM port 1

* Data transmitted through UART is received by receiver pin of COM port1 of PC.

* Received string is displayed in hyper terminal


PROGRAM CODE

#include <LPC214x.H>
#define PCLK 30000000 // PCLK for configuration baudrate
void UART0_Init(unsigned int baudrate);
void UART0_PutC(char c);
void UART0_PutS(char *p);
unsigned int getchar (void);
int main(void)
{
VPBDIV = 0x02; //Divide Pclk by two
UART0_Init(9600);
while(1)
{
UART0_PutS("\f*** TRENDY CODING ***\n\n\r");
}
}
unsigned int getchar (void) /* Read character from Serial Port */
{
while (!(U0LSR & 0x01));
return (U0RBR);
}
void UART0_Init(unsigned int baudrate)
{
unsigned short BAUD_REG;
BAUD_REG = PCLK/(16*baudrate); // Calculate for U0DL value
PINSEL0|= 0x00000005; // Enable rx,tx
U0LCR = 0x00000083; // 8 bit data,1 stop bit,no parity bit
U0DLL = BAUD_REG & 0xFF; // U0DL for low by te
U0DLM = (BAUD_REG>>8); // U0DL for high byte
U0LCR = 0x00000003; // DLAB =0
}
void UART0_PutC(char c)
{
while(!(U0LSR & 0x20)); // Wait until UART0 ready to send character
U0THR = c; // Send character
}
void UART0_PutS(char *p)
{
while(*p) // Point to character
{
UART0_PutC(*p++); // Send character then point to next character
}
}

Saturday, August 27, 2022

ARM LPC2148 embedded C programming : Timer implementation

ARM LPC2148 Timer programming



TIMERS (Timer0 and Timer1) & SFR Registers:

There are 2 nos. of 32 bit timers in this Microcontroller. Timer is basically a counter. For timer, internal clock is given as input. Internally, PCLK, Peripheral clock is given as the input pulses.

Timer0 registers

TC0 – Timer Counter Register (32 bit register). For every clock pulse, this register is incremented. Before the clock pulse is given to TCO, the clock pulses are given to the Prescale Counter namely

PC0 – 32 bit register. Along with PC0, there is another register namely Prescale Register PR0 – 32 bit register.

The PC0 gives one output pulse for each prescale register value. For example, if the PR0 has the value of decimal 10, then the PC0 gives one output pulse fo r every 10 input clock pulses. The Prescale  Counter output is given as the clock pulse to Timer Counter register TC0. In this way, 32 bit Prescale divider is included in the timer operation.

TCR0 – Timer Control Register. This register is used to reset the counter and disable/enable the Timer

Counter Register TC0.

T0MR0 – Match0 Register. It is a 32 bit register. The 32 bit content entered is compared with the content of  Timer/Counter Register TC0 continuously. When the match occurs, the following functions can be actuated.

1. If the interrupt enable bit is made 1, interrupt flag bit for MR0 is made 1 in T0IR register.

2. The Timer/Counter register can be made to reset.

3. The Timer/Counter register can be disabled.

4. In the corresponding pin MAT0.0 for MR0 , output can be generated.

The first 3 functions can be actuated by writing control bits in MCR register – Match Control Register.

Similar to T0MR0, there are T0MR1, T0MR2, T0MR3 match registers. They can be also used for comparing with the contents of Timer/Counter (TC) register. On match, the above functions for the corresponding match register can be actuated.

T0IR – It is an 8 bit interrupt register. For every match, corresponding bit in this interrupt register is set. On writing again the same bit in t he Interrupt Service Routine, the corresponding bit will be cleared. Similar to match registers, there are 4 capture registers namely T0CR0, T0CR1, T0CR2 and

T0CR3. The content of Timer/Counter (TC) register value is loaded into T0CR0, when an event on physical pin CAP0.0, one particular physical input.

T0CCR is a 32 bit register which controls which edges of the capture inputs are used to load the Capture registers and whether or not an interrupt is generated when a capture takes place. In order to use the timer as counter, T0CTCR register is used. It is used to change to counter mode and to determine in which pin, physical count input pulses is given.


PROGRAMLOGIC:

* Configure 8 pins of port1 from P1.16 to P1.23as output pins by writing value ‘1’ to these pins

* Connect 8 LEDS in output pins.

*Timer 0 of ARM7 is configure to produce delay of 0.5 Second

* Program loop is created to toggle LEDs connected in PORT1 for every 0.5 sec.


Program code

#include <LPC214x.h>

#define DELAY_MS 1000 //0.5 Second(s) Delay

#define PRESCALE 60000 //60000 PCLK clock cycles to increment TC by 1

void Timer0_Init(void);

void Timer0_Run(void);

int main(void)

{

VPBDIV = 0x01; //PCLK=60Mhz

IO1DIR = 0x00FF0000; //P1.16 to P1.23 are output

Timer0_Init(); //Initialize Timer0

while(1)

{

Timer0_Run();

}

}

void Timer0_Init(void)

{

/*Assuming that PLL0 has been setup with CCLK = 60Mhz and PCLK also = 60Mhz.*/

T0CTCR = 0x0;

T0PR = PRESCALE-1; //(Value in Decimal!) - Increment T0TC at every 60000 clock cycles

//Count begins from zero hence subtracting 1

//60000 clock cycles @60Mhz = 1 mS

T0MR0 = DELAY_MS-1; //(Value in Decimal!) Zero Indexed Count - hence subtracting 1

T0MCR = 3; //Set bit0 & bit1 to High which is to : Interrupt & Reset TC on MR0

T0TCR = 0x02; //Reset Timer

T0TCR = 0x01; //Enable timer

}

void Timer0_Run(void)

{

unsigned char regVal;

if(T0IR) //Polling the Interrupt Flag

{

regVal = T0IR;  //R ead current IR value

IO1PIN ^= 0x00FF0000; // Toggle LED pins in Port 1

T0IR = regVal; // Write back to IR to clear Interrupt Flag

}

}




Circuit Diagram







Friday, August 26, 2022

Getting started with KEIL and Proteus : Switches and LED interface with ARM LPC218 using Embedded C programming.

 




PROGRAM LOGIC:

* Select 8 pins of port1 from P1.24 to P1.31 as input pins by sending value ‘0’ to these pins

* Connect 8 switches in the input pins.

* Configure 8 pins of port1 from P1.16 to P1.23as output pins by writing value ‘1 ’ to these pins

*Connect 8 LEDS in output pins.

*Read status of the switches. If switch 1 is on , make LED1 ON else OFF

*Repeat the above step for all switches and do corresponding changes in LED.


GENERAL PURPOSE I/O

LPC2148 processor has two I/O po rts, port0 and port1

Port 0 – P0.31 – P0.0 – 32 I/O lines

Port 1 – P1.31 – P1.16 – 16 I/O lines

Each pin out of the Microcontroller has several functions, maximum of 4 functions. In order to use the physical pin out for a specific function, the pin is to b e configured for that function. In order to Configure, it needs 2 bits (to carry out any one of 4 functions). For this purpose, there is a register called PINSEL register.PINSEL0, 32 bit register is used to configure Pin outs for P0.0 to P0.15 (16 pins), since each pin needs 2 bits.

PINSEL1 register is used to configure Pin outs for P0.16 to P0.31

PINSEL2 register is used to configure Pin outs for P1 Port, P1.16 to P1.31

After, configuring the pin as I/O line, next it is to be designated as input pin or ou tput pin. It is done by another register namely IODIR.

IODIR0, 32 bit register is used to designate each I/O line in Port 0. Against the particular bit, if 1 is written, then that bit in the Port 0 is designated as Output pin. If 0 is written in the particular bit position, then that I/O pin will act as input pin.

Similarly, IODIR1, the bits 16 to 31 is used to designate the Port1 pins either as output or as input If the pin is configured as output pin, in order to write 1 level in that pin, IOSET register is used. In order to write 0 level in that pin, IOCLR register is used. It is to be noted that using single register IOSET register, it is not possible to clear the bit.

IOSET0, 32 bit register is used to write 1 in any one of the output pin of Port0

IOCLR0, 32 bit register is used to write 0 in any one of the output pin of Port0

IOSET1, 32 bit register is used to write 1 in any one of the output pin of Port1

IOCLR1, 32 bit register is used to write 1 in any one of the output pin of Port1

If the pin is configured as input pin, in order to read the data from that pin, IOPIN register is used.

IOPIN0, 32 bit register is used to read the data from any one of the I/O pins of Port0.

IOPIN1, 32 bit register is used to read the data from any one of the I/O pins of Port1.


Program code

#include<lpc214x.h>

#define LED0 (1<<16)

#define LED1 (1<<17)

#define LED2 (1<<18)

#define LED3 (1<<19)

#define LED4 (1<<20)

#define LED5 (1<<21)

#define LED6 (1<<22)

#define LED7 (1<<23)

unsigned int SW_RD;

int main()

{

IODIR1 |= 0x00FF0000; // GPIO pins 16 to 23 configured as output

IODIR1 &= ~(0xFF000000); //All the other remaining GPIO pins configured as input

while(1)

{

SW_RD = ((IOPIN1 & 0xFF000000)>>24 & 0xFF);

if(SW_RD&0x01) IOSET1 = LED0; else IOCLR1 = LED0;

if(SW_RD&0x02) IOSET1 = LED1; else IOCLR1 = LED1;

if(SW_RD&0x04) IOSET1 = LED2; else IOCLR1 = LED2;

if(SW_RD&0x08) IOSET1 = LED3; else IOCLR1 = LED3;

if(SW_RD&0x10) IOSET1 = LED4; else IOCLR1 = LED4;

if(SW_RD&0x20) IOSET1 = LED5; else IOCLR1 = LED5;

if(SW_RD&0x40) IOSET1 = LED6; else IOCLR1 = LED6;

if(SW_RD&0x80) IOSET1 = LED7; else IOCLR1 = LED7;

}

}


Circuit Diagram





Thursday, August 11, 2022

ai projects

Augmented reality

Virtual object Fox is created through augmented reality concept. Python programming is used in this project. Fox  will come as virtual object when reference image is shown in front of camera.  





Human pose estimation using mediapipe and opencv python programming


Human pose such as hand, leg , foot and head movements are estimated in 3D. Each actions are estimated in real time through mediapipe ai concept using opencv python programming.  



 Car parking slot identification using OpenCv and python programming. 




Green color rectangular box indicates free slot. Red color rectangular box shows that car parking slot is already occupied. If any vehicle is moving away from any slot, then automatically green color indication will be shown. Python coding is used in this project. Python package used is openCV.  



 Artificial intelligence project: Volume Control without keyboard


Volume level of music played in PC will be controlled by Angle created between thumb and index finger. More angle created will increase volume level. Reduced angle will decrease volume level. Hand detection by Mediapipe concept is used in this project. This project is build by python coding. Package used  is opencv and Mediapipe.  



 Artificial intelligence project : Hand detection and finger count 


Hand is identified by Mediapipe and openCV through python programming. Number of fingers opened will be taken as count value. It will be displayed in output frame. It is a real time projects. Count value will be accurate as per the input given through finger opening / closing.  


Artificial intelligence project : Social distance analysis. 


People are identified by object classifier of python programming. Red color rectangular box shows that people are coming close to one another. Orange color indicates people are little bit away but not in safe zone. Green color indicates people away from one another and they are in safe zone. Python coding is used in this project.  


Eye movement tracking using opencv python


Eye movement is tracked continuously using opencv python programming. Left and right direction movement are tracked and it's status are updated in display in the output frame. Blinking of eye are monitored and counted for each eye blink. Visual display is there in output frame to show no of time eyes are blinked.  




GPS sensor interface with ESP8266 using Blynk IoT cloud

   Circuit diagram: Source Code: #include <TinyGPS++.h> #include <SoftwareSerial.h> #define BLYNK_PRINT Serial #include <ESP8...