Monday 6 July 2015

[MCU] Microcontroller Packaging

QFN : Quad Flat No Leads:

These connect IC's to PCB's without through-holes.
The figure shows with lead frame and wire bonding. Flat no-lead packages include an exposed thermal pad to improve heat transfer out of the IC (into the PCB).  Hand soldering is not possible with this package




QFP: Quad Flat Package

A surface mounted IC, pins extending for all the 4 sides.  Socketing such packages is rare and through-hole mounting is not possible.




LQFP: Low Profile Quad Flat Package (1.4mm)



TQFP: Thin Quad Flat Package (1.0 mm) 

Has shorter leads than the LQFP. To be used in a space constrained designs.
Helps in solving increased board density.

References

https://en.wikipedia.org/wiki/Quad_Flat_No-leads_package
https://en.wikipedia.org/wiki/Quad_Flat_Package


Friday 12 June 2015

[Exploring Freescale MCU Programming] #5 RTC (Real time clock) set and Time and alarm

#2 -  next one in my pipeline is Realtime Clock (RTC) initialize and get it working.

What is RTC?


real-time clock (RTC) is a computer clock (most often in the form of an integrated circuit) that keeps track of the current time. Although the term often refers to the devices in personal computers,servers and embedded systems, RTCs are present in almost any electronic device which needs to keep accurate time.

RTC in K20D Freescale Board


The Real Time Clock (RTC) module on the K20 has two modes of operation, system power‐up and system power‐ down. In system power‐up mode, the RTC may be powered by either the MCU regulator or the backup power supply, VBAT. During system power‐down, the RTC is only powered from the backup power supply, VBAT


I have used RTC with a FRDM-K20D50 Board to schedule an alarm at regular intervals.



The CPU Settings should enable the RTC Oscillator. Otherwise RTC will not work.




RTC Component added.



Setting Properties for the RTC Component



Now lets add the code to set the RTC time and get it back, the main.c


Code to set and get time

printf("--Test init--\n");
LDD_RTC_TTime ttime;
ttime.Day = 11;
ttime.Month = 06;
ttime.Year = 2015;
ttime.Hour = 17;
ttime.Minute = 45;
ttime.Second = 15;

RTC1_SetTime(NULL, &ttime);


int i;
for(i=1;i<=3000000;i++)
{

}

LDD_RTC_TTime ttime1;
RTC1_GetTime(NULL, &ttime1);

printf("%d-%d-%d %d:%d:%d\n", ttime1.Day, ttime1.Month, ttime1.Year, ttime1.Hour, ttime1.Minute, ttime1.Second);



Output

--Test init--
11-6-2015 17:45:16


- Printed the RTC time that is set

Lets try setting RTC alarm and triggering it

Enable the methods setAlarm and enable onAlarm Event and generate code



main.c

ttime1.Second += 30;

RTC1_SetAlarm(NULL, &ttime);

Event.c

void RTC1_OnAlarm(LDD_TUserData *UserDataPtr)
{
printf("---Alarm Triggered--\n");
LDD_RTC_TTime ttime1;
RTC1_GetTime(NULL, &ttime1);

printf("%d-%d-%d %d:%d:%d\n", ttime1.Day, ttime1.Month, ttime1.Year,
ttime1.Hour, ttime1.Minute, ttime1.Second);

}


Output after alarm


---Alarm Triggered--
11-6-2015 17:45:26


Project:


Wednesday 20 May 2015

[Codewarrior 10.6 Solution] printf(%f) Does not work

printf("-Value %f\n", floatValue) -   prints -Value %f as such, instead of the float value in the console.

Solution :  Change a project settings

Project   ->   Properties  ->  C/C++  Build  ->  Settings  ->  Tool Settings Tab ->  Librarian  -> 

Change print formats  to int_FP



Thursday 30 April 2015

[Freescale K20D50M MCU Programming] #4 External LED controlled by a GPIO Switch

#4 External LED  controlled by a GPIO Switch

We tried blinking of an LED. Now we will create a switch using one of the GPIO Pins.  The Reset Button in FRDM-K20D50 does not have an alternate function. Hence I wanted to try out a Input switch.

Take a look at the [Freescale K20D50M MCU Programming] #1 Helloworld on the Console using Processor Expert  for quickstart 

Lets get started.


First we need 2 things. 


  • Identify the PIN for the external LED and a ground pin
  • then another PIN to act as a Switch Input and a ground pin

I identified PTC0  and PTB2 respectively.






to see the schematic to identify the PINS.  There is a good youtube video which gives an example on K25Z board.


Next we will be adding the BITIO_LDD for the LDD configured to the PTC0 PIN.




Then a BITIO_LDD for the switch on PTB2



Setting up the BITIO_LDD isn't enough for the acting with in PTB2.  We need to initialize the GPIO for the PIN. We will add a init_GPIO component and configure it to PTB




Generate the Pex code, and then add then lets add the below logic to toggle the led based on whether a wire between PTB2 and the GRND is connected or not..


The Pin's are connected to cathode, so 0 means high and 1 means low.

Code in main.c 

  for(;;)
  {
  if(SW1_GetVal(NULL)==0)   // CONNECTED 
  {
  led_SetVal(led_DeviceData);
  }
  else
  {
  led_ClrVal(led_DeviceData);
  }
  WAIT1_Waitms(1000);
  }


Now build the code and lets test it. 

Here is how the pins are connected on the board




Now lets see what happens with ehe pins at PTB0 is connected, the red wires on the top side is connected.. and you see the LED glowing


Now lets see what happens when one of the wire on top is pulled out..

Do you see only 1 wire on top is connected, and the LED is off.

This is an example of how you use a GPIO pin as a switch to control through software.



Wednesday 22 April 2015

[Freescale K20D50M MCU Programming] #3 Blinky GPIO - External LED

#3  Blinky External LED 


In [Freescale K20D50M MCU Programming]  #2 Blinky Red LED  onboard, We tried blinky with onboard LED. Lets try out blinking the external LED connected to a GPIO pin.. We are going to use Codewarrior and processorexpert with FRDM-K20D50M board

Take a look at the [Freescale K20D50M MCU Programming] #1 Helloworld on the Console using Processor Expert  for quickstart  

Lets get started.

First we need to see the schematic to identify the GPIO pin for our external LED.  There is a good youtube video which gives an example on K25Z board.






and the pin connectivity as below





Now Lets create a new project as mentioned in [Freescale K20D50M MCU Programming]  #2 Blinky Red LED  onboard we add a BITIO_LDD Component







And setting the properties to PTD0




I have added a WAIT custom component from processor expert to show a delay


And add this code in main.c

  gpio_led_NegVal(NULL);
  WAIT1_Waitms(1000);

  gpio_led_NegVal(NULL);

And you see the external LED Blinking.





Wednesday 15 April 2015

[Freescale K20D50M MCU Programming] #2 Blinky Red LED onboard

#2  Blinky Red LED onboard


Lets try out blinking the RED onboard LED. We are going to use Codewarrior and processorexpert with FRDM-K20D50M board

Take a look at the [Freescale K20D50M MCU Programming] #1 Helloworld on the Console using Processor Expert  for quickstart 

Lets get started.


First we need to see the schematic to identify the onboard LED.  There is a good youtube video which gives an example on K25Z board.




LED  Schematic :





Red LED connected to D6.
Green LED connected to D3
Blue LED connected to D9



Identify the Ports and Pins for the LED's :



Red, look for D6





Green, Look for D3



Blue, Look for D9








The FRDM-K20D50 CPU uses the Blue LED. So, this has to be disabled to get this on-board LED to work.




Then Lets add BITIO_LDD component, 1 for each LED to control them.

Now lets setup the Bit_IO pins for the 3 LED's.  LED Cathode is connected to the microcontroller pin. i.e., Low Level (0) turns it on, and (1) turns it off.   By default we need to set all the 3 LED's to (1) to turn it off.


WE add 3 BitIO_LDD Components, for RED, Green and Blue. 




Green LED -> Switch off by Default. Cathode connected. So 1 is Off


Blue LED -> Switch off by Default. Cathode connected. So 1 is Off. But this pin is used by CPU, so enable PIN Sharing.




Red LED -> Switch ON by Default. Cathode connected. So 0 is On.



Now build and Run the Main.c  you will see the RED LED glowing by the code is flashed.







Now lets make a blinky. :-)


We need to enable the NegVal() method of the BitIO_LDD






And add this code in the main.c or processorexpert.c

int main(void)
/*lint -restore Enable MISRA rule (6.3) checking. */
{
  /* Write your local variable definition here */

  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/

  for(;;)
  {
 int i =0;
 for(i=0;i<=1000000;i++)
 {
 }
 RED_LED_NegVal(NULL);  // Blink the RED Led
  }
  

Here is the blinky.



CodeWarrior, PEX Project :   Download  onboard_blinky.zip

Saturday 4 April 2015

[Freescale K20D50M MCU Programming] #1 Helloworld on the Console using Processor Expert.

Just starting exploring the world of MCU programming.  I was referred a freescale board K20D50M




Being a hardcore java/j2ee developer, Looking at this was little scary.   Followed the steps in QuickStart package in a OpenSDA Mode.  Now comes the time to write some code. I was told that Processor Expert in Codewarrior can do wonders. You do not need to be a hardcore Embedded developer who knows Bits/Registers/MUXing. ;-)

As a beginner. Codewarrior is the best place to start with. Code, test the device from one place. Later you can jump into the Processor Expert Driver suite to write code, while to test you need to use IAR workbench for Kinetics or a Kinetics Design Studio.


Tools you need 

1. FRDM-K20D50M board
2. Codewarrior or other similar tools
3. Realterm - Terminal viewer tool


Assuming, you got your openSDA configuration done on the bootloader mode.  
Lets get into action. 


Create a Bareboard Project -



Name the project


Select the device - K20D50 - MK20DX128:





Select Connections :




Build and Debug Selection:



RAD :



FINISH


CodeWarrior Perspective :


This is what you will see in your codewarrior. You can read more about the perspectivies, look for videos in Youtube if you are not  used to the eclipse environment.




Now comes the real usecase to print Helloworld  by writing code, run it on the freescale board, and see it on the terminal.

Add the ConsoleIO component to the project:



Component (Advanced) Properties:




Serial_LDD  Changes :

You need to change the Serial to UART0.  Lets check the schematic pdf for their pins




Now lets fix the errors in the properties by setting the in and out appropriately, and the baud rate error will be gone.


Locate the main.c:




Add your Printf :




Lets build :




Run it : 




If device/board is not connected to your USB.



Connect, Refresh and Retry:



Console Output: 



Realterm Configuration:



Realterm Output Configuration:




Realterm Output when you run the program. Press the reset button, you will see the program restarting.


You can add the printf in a for loop.
there you go! The 1st MCU Hello world is done.