Skip to content

Instantly share code, notes, and snippets.

View s-estay's full-sized avatar
😎

Sebastian Estay s-estay

😎
  • Sweden
  • 21:25 (UTC +02:00)
View GitHub Profile
@s-estay
s-estay / code8.2.c
Last active September 7, 2016 22:39
msp430: turning on LED1 when S2 is pressed
// Source: Programmable Microcontrollers with Applications, p.115
// Turning on the red LED when the push button is pressed
// MSP430 LaunchPad Rev.1.5
#include <msp430g2553.h>
#define LED BIT0 // P1.0
#define BUTTON BIT3 // P1.3
void main(void){
@s-estay
s-estay / uA741.sub
Created September 7, 2016 22:49
LTspice: LM741 Op Amp model
* Model for uA741 Op Amp (from EVAL library in PSpice)
* connections: non-inverting input
* | inverting input
* | | positive power supply
* | | | negative power supply
* | | | | output
* | | | | |
*
.subckt uA741 1 2 3 4 5
*
@s-estay
s-estay / code8.4.c
Created September 7, 2016 23:31
msp430: toggling LED2 when S2 is pressed
// Source: Programmable Microcontrollers with Applications, p.117
// Toggling the green LED when the push button is pressed
// MSP430 LaunchPad Rev.1.5
#include <msp430g2553.h>
#define LED BIT6 //P1.6 LED2
#define BUTTON BIT3 //P1.3 S2
void delay_ms(int); // declare function delay_ms
@s-estay
s-estay / servo_test.c
Last active October 27, 2016 09:41
msp430: servo pwm test
// a PWM signal is created with the TimerA0 where CCR0 is the periode 20ms and CCR1 the duty cycle
// the PWM signal is output through pin P1.6 that correspond to TA0.1 (see MSP430G2553 uC datasheet)
// this code does not generate interruptions but uses the reset/set mode to generate the PWM signal when the timer counts up to CCR1
// in this case a duty cycle of 2ms (CCR1 = 2000 - 1) will rotate the axis clockwise (see sg90 datasheet)
// a duty cycle of 1.0ms (CCR1 = 1000 - 1) will rotate the axis anticlockwise
// a duty cycle of 1.5ms (CCR1 = 1500 - 1) will rotate the axis to the center position
// the servo used was a sg90 but I guess the code will work with any servo (refer to the servo's datasheet to confirm this)
#include <msp430g2553.h>
@s-estay
s-estay / crystal_test.c
Last active October 28, 2016 00:43
msp430: external crystal test
// test external crystal by observing ACLK frequency on ACLK pin
// ACLK correspond to pin P1.0 in MSP430G2553 (see MSP430G2553 datasheet)
// an external crystal connects to the XIN, XOUT pins
// XIN and XOUT correspond to pins P2.6 and P2.7 respectively in MSP430G2553 (see MSP430G2553 datasheet)
// P1SEL = BIT0 and P1DIR = BIT0 show ACLK in P1.0 (see MSP430G2553 datasheet, pin functions)
// this only works with small crystals in cylindrical package
// stand-alone uC test:
// DVCC to 3.3V
// DVSS to GND
@s-estay
s-estay / source_current.ino
Last active April 9, 2017 11:28
arduino basics: source current
// source current to a LED through digital pin 7
// connection: pin7 set to high - LED's anode .. LED's cathode - 1k resistor - GND
// LED's anode (+) long terminal
// LED's cathode (-) short terminal
// 1k resistor color code: brown black red
// code executed on Arduino Leonardo
void setup(){
pinMode(7, OUTPUT);
}
@s-estay
s-estay / sink_current.ino
Last active April 9, 2017 11:29
arduino basics: sink current
// sink current through a LED to digital pin 7
// connection: VCC - LED's anode .. LED's cathode - 1k resistor - pin7 set to low
// VCC is 5V
// LED's anode (+) long terminal
// LED's cathode (-) short terminal
// 1k resistor color code: brown black red
// code executed on Arduino Leonardo
void setup(){
pinMode(7, OUTPUT);
@s-estay
s-estay / blink_led.ino
Last active March 13, 2018 19:33
arduino basics: blink led
@s-estay
s-estay / switch_led.ino
Last active April 9, 2017 12:18
arduino basics: control LED using switch
// turn LED ON and OFF using switch
// we read the state of the switch through pin 7
// switch is connected between pin 7 and GND
// we use the microcontroller's internal 20k pullup resistor
// why do we use a pullup resistor? read here: https://learn.sparkfun.com/tutorials/pull-up-resistors
// you can choose between LED ON or LED OFF when switch is pressed
// pin 8 will source current to the LED
// refer to source_current.ino file to see how to connect the LED
// code executed on Arduino Leonardo
@s-estay
s-estay / pwm_led.ino
Last active April 9, 2017 18:23
arduino basics: PWM signal through LED
// PWM signal through pin 3
// 8 bits PWM: 0 (0% or GND) to 255 (100% or VCC)
// what's a PWM signal? read here: https://en.wikipedia.org/wiki/Pulse-width_modulation
// pin 3 will source current to the LED
// refer to source_current.ino file to see how to connect the LED
// code executed on Arduino Leonardo
void setup(){
pinMode(3, OUTPUT); // observe that only pins preceded by ~ in the board can output a PWM signal
}