34
Getting started with PhilRoboKit Anito Board January 19, 2013 Giancarlo Acelajado Software/Firmware Developer [email protected]

Getting Started with PhilRoboKit Anito

Embed Size (px)

DESCRIPTION

Philrobotic's first seminar for the year 2013. This is basically an introduction to Philrobokit Anito and its programming.

Citation preview

Page 1: Getting Started with PhilRoboKit Anito

Getting started with PhilRoboKit

Anito BoardJanuary 19, 2013

Giancarlo Acelajado

Software/Firmware Developer

[email protected]

Page 2: Getting Started with PhilRoboKit Anito

OBJECTIVES• Understand what PhilRoboKit Anito is.• Learn how to program PhilRoboKit Anito.

– configure a Pin– write output state– read input state– read analog input– using built-in components

• Blinking LED• Input Switch• Controlling Buzzer• Serial Communication (UART)

Page 3: Getting Started with PhilRoboKit Anito

• An open-source Microcontroller development kit powered by Microchip PIC16F877A**beta.

• 100% Filipino-made by PhilRobotics.• Arduino-inspired project.• Programming made-easy built-in functions• Multiplatform programming IDE.• Programmable using built-in bootloader(tinybldr)

or PICKit2 through ICSP.• Uses Microchip XC8 Compiler (with Redisitribution agreement)

Who is PhilRoboKit Anito?

Page 4: Getting Started with PhilRoboKit Anito

Specifications:

• up to 21 Digital I/Os (14 at default)

• 7 Analog-to-Digital Pins

• built-in 4 LEDs

• built-in 2 switches

• built-in buzzer

• 1 Servo Port, UART Port and Programming(ICSP) Port

• USB-to-TTL connection

Who is PhilRoboKit Anito?

Page 5: Getting Started with PhilRoboKit Anito

Who is PhilRoboKit Anito?

Page 6: Getting Started with PhilRoboKit Anito

Who is PhilRoboKit Anito?

Page 7: Getting Started with PhilRoboKit Anito

The PhilRoboKit IDE

Page 8: Getting Started with PhilRoboKit Anito

The PhilRoboKit IDE

Page 9: Getting Started with PhilRoboKit Anito

• Code Folding• AutoComplete• Line Numbers• Find/Replace Tool• PICKit2 Support with Bootloader Recovery• Import Hex file (Flash and Bootload Programming)

• Library Imports• Load Examples• Serial Monitor

The PhilRoboKit IDE

Page 10: Getting Started with PhilRoboKit Anito

My First PhilRoboKit ‘HelloWorld’ Program

Page 11: Getting Started with PhilRoboKit Anito

Getting Started:

//Hitech C

#include <htc.h>

void main(void)

{

TRISC &= ~0x01;

PORTC |= 0x01;

while(1)

{

rc0 = ~rc0

__delay_ms(500);

}

}

//PhilRoboKit

void init()

{

makeOutput(D0);

setPin(D0);

}

void program()

{

togglePin(D0);

delayMs(500);

}

Page 12: Getting Started with PhilRoboKit Anito

• Init() – where initializations are placed.

• Program() – main loop program.

Getting Started:

void init()

{

/* Statement here */

}

void program()

{

/* Statement here */

}

Page 13: Getting Started with PhilRoboKit Anito

Getting Started:

• Digital IO Pins:– D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11,

D12, D13

• Analog Input Pins:– AN0, AN1, AN2, AN3, AN4, AN5, AN6– Configurable to Digital IOs (D14 to D20)

Page 14: Getting Started with PhilRoboKit Anito

• makeInput(x) – configures a pin to Input

• getPinState(x) – get the state/logic of a pin whether it is HIGH(1) or LOW(0).

Basic IO Interface - Inputs

Page 15: Getting Started with PhilRoboKit Anito

• makeOutput(x) – configures a pin to Output

• setPin(x) – set Output Pin to HIGH(1)

• clrPin(x) – set Output Pin to LOW(1)

• togglePin(x) – Toggles Output Pin (invert its previous state)

Basic IO Interface

Page 16: Getting Started with PhilRoboKit Anito

• setADCPinsToDigital() – Sets your Analog Input Pins as Digital Input/Output.

Basic IO Interface

Page 17: Getting Started with PhilRoboKit Anito

Note:

Initial state of Digital Outputs are Low.

All pins are 5v Tolerant.

Basic IO Interface

Page 18: Getting Started with PhilRoboKit Anito

• Software Delay – waste instruction cycles. Used in a non-critical timing requirement.

• Hardware Delay – uses Timer peripheral. Used in time critical requirement.

Generating Delay

Page 19: Getting Started with PhilRoboKit Anito

Generating Delay - Software Delay

void init()

{

makeOutput(D0);

setPin(D0);

}

void program()

{

togglePin(D0);

delayMs(500);

}

Page 20: Getting Started with PhilRoboKit Anito

Generating Delay - Hardware Delay

uint16_t ui16ToggleTimer; /* Create a Timer Variable */

void init()

{

makeOutput(D0); /* Configure D0 as Output */

setPin(D0); /* Initialize D0 as HIGH */

ui16ToggleTimer = getMs(); /* Initialize Timer */

}

void program()

{

if(getElapsedMs(ui16ToggleTimer) >= 500){

ui16ToggleTimer = getMs();

togglePin(D0);

}

}

Page 21: Getting Started with PhilRoboKit Anito

Using built-in Peripherals

Page 22: Getting Started with PhilRoboKit Anito

Using built-in Peripherals

• Composed of:• 4 LEDs• 2 Switches• 1 Buzzer• Analog-to-Digital Converter Port• USB-to-UART Connectivity

• Pre-initialized pin directions

Page 23: Getting Started with PhilRoboKit Anito

Using LEDs

void init()

{

}

void program()

{

setPin(LED1);

setPin(LED2);

clrPin(LED3);

clrPin(LED4);

}

Page 24: Getting Started with PhilRoboKit Anito

Using Switches

void init()

{

}

void program()

{

if(!getPinState(SW1)){

/* Do Something here */ }

if(getPinState(SW2)){

/* Do Something here */ }

}

• HIGH at initial state – with pull up resistor.

• “Active Low” – outputs LOW when pressed.

Page 25: Getting Started with PhilRoboKit Anito

Using Buzzer

void init()

{

}

void program()

{

setPin(BUZZER);

}

• LOW at initial state.• Turn on by setting it HIGH.

Page 26: Getting Started with PhilRoboKit Anito

• Stands for Analog-to-Digital Converter• Converts Analog Signals (voltage or current) into

Digital format (1’s and 0’s).• 7 ADC Channels (AN0-AN7)• 10bit ADC Resolution(210-1)• 5v Internal Voltage Reference

What is ADC?

ferenceVoltage

nsolutionADC

VoltagePin

ADCValue

Re

1)^2(Re

Page 27: Getting Started with PhilRoboKit Anito

What is ADC?

• setupADC() – setups the ADC Peripheral/module.• adcSetChannel() – select channel needed to be read.• adcStart() – start the ADC conversion (used in

conjunction with adcReadOnly).• adcReadOnly() – Reads the ADCValue (used in

conjunction with adcStart).• adcRead() – directly reads the pin, and wait for the

conversion to be finished, returns ADCValue.• adcReadOnChannel(x) – combination of adcSetChannel

and adcRead.• isADCConversionDone() – used to check/poll if the

conversion is already done.

Page 28: Getting Started with PhilRoboKit Anito

What is ADC?

uint16_t ui16ADCValue;

void init()

{

setupADC();

adcSetChannel(AN0);

}

void program()

{

ui16ADCValue = adcReadOnChannel(AN0);

}

Page 29: Getting Started with PhilRoboKit Anito

• Universal Asynchronous Receiver/ Transmitter• No clock signal required on data transmission• Simplest Serial Communication Interface• Used in conjunction with RS232, RS422 or

RS485

What is UART?

Page 30: Getting Started with PhilRoboKit Anito

• Start– Signal to begin the transmission. – High to Low transition

• Data Bits– May compose 5-9 bits.– Usually in 8bits.

• Parity (optional)– Parity bit is added to ensure that the number of “active” bits in a frame is even or odd, depending on your settings.

• Stop– Signal to end the transmission– Low to High transition

What is UART?

Page 31: Getting Started with PhilRoboKit Anito

• setupSerial(x) – setup the serial and its baudrate.• serialSendChar(x) – sends 1 byte/character• serialSendString(x) – sends a series of characters• serialSendBlock(x,y) – sends block characters with

defined size/count.• serialRead() – Read the received character from the

buffer.• isSerialDataAvailable() – checks if there’s a data

available in buffer• serialFlushData() – clears/reset the contents of the

Transmit and Receive Buffer.

What is UART?

Page 32: Getting Started with PhilRoboKit Anito

//PhilRoboKit

void init()

{

serialSetup(9600);

}

void program()

{

serialSendString(“Hello World!\r\n”);

}

What is UART?

Page 33: Getting Started with PhilRoboKit Anito

Questions?Questions?

Page 34: Getting Started with PhilRoboKit Anito

References

• Hardware Manual:

• Firmware Manual:

Online Reference in wiki and Document Generated by Doxygen

• Software Manual:

Online Reference in wiki and Document Generated by Doxygen

• PhilRobotics Forum:

http://philrobotics.com/forum/index.php/board,14.0.html

• PhilRobotics Bugzilla(Issue Tracker):

http://philrobotics.com/bugzilla