mirror of
https://github.com/aster94/logic-analyzer.git
synced 2026-05-01 23:53:02 +03:00
ordered files, added esp8266
This commit is contained in:
98
Microcontroller_Code/ESP8266/ESP8266.ino
Normal file
98
Microcontroller_Code/ESP8266/ESP8266.ino
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* ESP8266.ino
|
||||
*
|
||||
* Author : yoursunny
|
||||
* Led: LED_BUILTIN
|
||||
*/
|
||||
|
||||
#include <c_types.h>
|
||||
|
||||
#define baudrate 115200 // check if it is the same in processing
|
||||
// number of samples to collect
|
||||
static const int N_SAMPLES = 300;
|
||||
|
||||
|
||||
// what pins to use, between 0 and 15
|
||||
static const int PIN0 = 4;
|
||||
static const int PIN1 = 5;
|
||||
static const int PIN2 = 12;
|
||||
static const int PIN3 = 14;
|
||||
// unused pins should be tied to the ground
|
||||
|
||||
static_assert(PIN0 >= 0 && PIN0 < 16, "");
|
||||
static_assert(PIN1 >= 0 && PIN1 < 16, "");
|
||||
static_assert(PIN2 >= 0 && PIN2 < 16, "");
|
||||
static_assert(PIN3 >= 0 && PIN3 < 16, "");
|
||||
|
||||
static constexpr uint32_t MASK = (1 << PIN0) | (1 << PIN1) | (1 << PIN2) | (1 << PIN3);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(baudrate);
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
pinMode(PIN0, INPUT_PULLUP);
|
||||
pinMode(PIN1, INPUT_PULLUP);
|
||||
pinMode(PIN2, INPUT_PULLUP);
|
||||
pinMode(PIN3, INPUT_PULLUP);
|
||||
}
|
||||
|
||||
unsigned long times[N_SAMPLES]; // when did change happen
|
||||
uint32_t values[N_SAMPLES]; // GPI value at time
|
||||
|
||||
extern void ICACHE_RAM_ATTR collect() {
|
||||
times[0] = micros();
|
||||
values[0] = GPI & MASK;
|
||||
for (int i = 1; i < N_SAMPLES; ++i) {
|
||||
uint32_t value;
|
||||
do {
|
||||
value = GPI & MASK;
|
||||
} while (value == values[i - 1]);
|
||||
times[i] = micros();
|
||||
values[i] = value;
|
||||
}
|
||||
}
|
||||
|
||||
int compactValue(uint32_t value) {
|
||||
int res = 0;
|
||||
if ((value & (1 << PIN0)) != 0) {
|
||||
res |= (1 << 0);
|
||||
}
|
||||
if ((value & (1 << PIN1)) != 0) {
|
||||
res |= (1 << 1);
|
||||
}
|
||||
if ((value & (1 << PIN2)) != 0) {
|
||||
res |= (1 << 2);
|
||||
}
|
||||
if ((value & (1 << PIN3)) != 0) {
|
||||
res |= (1 << 3);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void report() {
|
||||
Serial.println("S");
|
||||
Serial.print(compactValue(values[0]));
|
||||
Serial.print(":");
|
||||
Serial.println(N_SAMPLES - 1);
|
||||
|
||||
for (int i = 1; i < N_SAMPLES; ++i) {
|
||||
Serial.print(compactValue(values[i] ^ values[i - 1]));
|
||||
Serial.print(":");
|
||||
Serial.println(times[i] - times[0]);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
while (Serial.read() != 'G') {
|
||||
delay(1);
|
||||
}
|
||||
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
ESP.wdtDisable();
|
||||
collect();
|
||||
ESP.wdtEnable(WDTO_8S);
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
report();
|
||||
}
|
||||
204
Microcontroller_Code/MEGA/MEGA.ino
Normal file
204
Microcontroller_Code/MEGA/MEGA.ino
Normal file
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
* MEGA.ino
|
||||
*
|
||||
* Created: 11/12/2016 19.35.51
|
||||
* Author : Vincenzo / sancho
|
||||
* Modificaciones agregadas para funcionar con ArduinoMega2560 por Enmanuel Sancho Quintanilla
|
||||
* La unidad minima en tiempo para este sistema es de 8 micro segundos lo que idealmente permitiria
|
||||
* observar clocks con periodos de 62 kHz sin embargo para poder apreciar las señales logicas con suficiente
|
||||
* resolucion se recomienda no superar los 30 kHz en el clock del sistema.
|
||||
*/
|
||||
|
||||
#define baudrate 115200 // check if it is the same in processing
|
||||
#define samples 200 // the number of samples you want to take
|
||||
|
||||
|
||||
#define pin_used
|
||||
#define timezerooffset 125 //microsegundos
|
||||
#define PULLUP true //Si queremos entradas con PULLUP lo dejamos activado(true), si queremos dejarlas al "aire" (false), en caso de desactivarlo deberemos aterrizar todos los pines que no utilizemos.
|
||||
#define F_CPU 16000000UL
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <util/delay.h>
|
||||
#define prescaler 0x02
|
||||
volatile uint16_t timer1_overflow_count;
|
||||
|
||||
uint8_t initial1, initial2, initial3, state1, state2, state3, old_state1, old_state2, old_state3;
|
||||
uint8_t pinChanged1[samples];
|
||||
uint8_t pinChanged2[samples];
|
||||
uint8_t pinChanged3[samples];
|
||||
uint32_t timer[samples];
|
||||
uint32_t timefix;
|
||||
uint16_t event = 0;
|
||||
uint8_t cambio = 0;
|
||||
void init_board()
|
||||
{
|
||||
|
||||
// PORTC = (0 << 0); DDRC |= (1 << 0); // led A0
|
||||
|
||||
DDRB = 0x00;
|
||||
DDRC = 0x00;
|
||||
DDRL = 0x00;
|
||||
|
||||
if (PULLUP)
|
||||
{
|
||||
PORTA = B11111111; // pull-up
|
||||
PORTC = B11111111; // Activamos el pull-up para que de no conectarse nada a puerto lea un uno siempre
|
||||
PORTL = B11111111;
|
||||
}
|
||||
else
|
||||
{
|
||||
PORTA = B00000000;
|
||||
PORTC = B00000000;
|
||||
PORTL = B00000000;
|
||||
}
|
||||
}
|
||||
|
||||
void init_timer()
|
||||
{
|
||||
//clear
|
||||
TCCR1A = 0b00000000;
|
||||
TCCR1B = 0b00000000;
|
||||
TIMSK1 = 0b00000000;
|
||||
|
||||
//settings
|
||||
TCCR1A |= (0 << COM1A1) | (0 << COM1A0) | (0 << COM1B1) | (0 << COM1B0); //normal port operation
|
||||
TCCR1A |= (0 << WGM11) | (0 << WGM10); //normal operation
|
||||
TCCR1B |= (0 << WGM13) | (0 << WGM12); //normal operation
|
||||
TCCR1B |= prescaler; //(0 << CS12) | (0 << CS11) | (1 << CS10); //clock prescaler
|
||||
sei(); //enable interrupts
|
||||
TIMSK1 |= (1 << TOIE1); // enable overflow interrupt
|
||||
}
|
||||
|
||||
ISR(TIMER1_OVF_vect)
|
||||
{
|
||||
timer1_overflow_count++;
|
||||
}
|
||||
|
||||
void reset_timer1()
|
||||
{
|
||||
TCNT1 = 0;
|
||||
timer1_overflow_count = 0;
|
||||
}
|
||||
|
||||
uint32_t myMicros()
|
||||
{
|
||||
cli();
|
||||
|
||||
if (TIFR1 & (1 << TOV1))
|
||||
{
|
||||
TIFR1 = (0 << TOV1);
|
||||
timer1_overflow_count++;
|
||||
}
|
||||
|
||||
uint32_t total_time = (65536 * timer1_overflow_count + TCNT1) / 2;
|
||||
sei();
|
||||
return total_time;
|
||||
}
|
||||
|
||||
void start()
|
||||
{
|
||||
_delay_ms(1000);
|
||||
// Serial.print("hi");
|
||||
reset_timer1();
|
||||
event = 0;
|
||||
|
||||
//PORTC = (1 << 0);
|
||||
initial1 = PINA;
|
||||
initial2 = PINL;
|
||||
initial3 = PINC;
|
||||
state1 = initial1;
|
||||
state2 = initial2;
|
||||
state3 = initial3;
|
||||
for (int i = 0; i < samples; i++)
|
||||
{
|
||||
pinChanged1[i] = 0;
|
||||
pinChanged2[i] = 0;
|
||||
pinChanged3[i] = 0;
|
||||
//Serial.print(pinChanged1[i]); Serial.print(','); Serial.print(pinChanged2[i]); Serial.print(','); Serial.println(pinChanged3[i]); //debug
|
||||
}
|
||||
}
|
||||
|
||||
void sendData()
|
||||
{
|
||||
//PORTC = (0 << 0); //turn off led
|
||||
//initial data
|
||||
Serial.println("S");
|
||||
Serial.print(initial1);
|
||||
Serial.print(',');
|
||||
Serial.print(initial2);
|
||||
Serial.print(',');
|
||||
Serial.print(initial3);
|
||||
Serial.print(":");
|
||||
Serial.println(samples);
|
||||
|
||||
timefix = -timer[0] + timezerooffset;
|
||||
|
||||
for (int i = 0; i < samples; i++)
|
||||
{
|
||||
timer[i] = timer[i] + timefix;
|
||||
}
|
||||
//data
|
||||
for (int i = 0; i < samples; i++)
|
||||
{
|
||||
Serial.print(pinChanged1[i]);
|
||||
Serial.print(',');
|
||||
Serial.print(pinChanged2[i]);
|
||||
Serial.print(',');
|
||||
Serial.print(pinChanged3[i]);
|
||||
Serial.print(":");
|
||||
Serial.println(timer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
Serial.begin(baudrate);
|
||||
init_board();
|
||||
init_timer();
|
||||
|
||||
start();
|
||||
|
||||
while (1)
|
||||
{
|
||||
cambio = 0;
|
||||
old_state1 = state1;
|
||||
old_state2 = state2;
|
||||
old_state3 = state3;
|
||||
state1 = PINA;
|
||||
state2 = PINL;
|
||||
state3 = PINC;
|
||||
//Serial.print(state1);Serial.print(" , ");Serial.print(state2);Serial.print(" , ");Serial.print(state3);Serial.print(" : ");Serial.println(event);
|
||||
|
||||
if (old_state1 != state1)
|
||||
{
|
||||
pinChanged1[event] = state1 ^ old_state1;
|
||||
cambio = 1;
|
||||
}
|
||||
if (old_state2 != state2)
|
||||
{
|
||||
pinChanged2[event] = state2 ^ old_state2;
|
||||
cambio = 1;
|
||||
}
|
||||
if (old_state3 != state3)
|
||||
{
|
||||
pinChanged3[event] = state3 ^ old_state3;
|
||||
cambio = 1;
|
||||
}
|
||||
|
||||
if (cambio == 1)
|
||||
{
|
||||
timer[event] = myMicros();
|
||||
event++;
|
||||
}
|
||||
if (event == samples)
|
||||
{
|
||||
sendData();
|
||||
while (Serial.read() != 'G')
|
||||
{
|
||||
;
|
||||
} //wait for the "go"
|
||||
start();
|
||||
}
|
||||
}
|
||||
}
|
||||
89
Microcontroller_Code/STM32F1/STM32F1.ino
Normal file
89
Microcontroller_Code/STM32F1/STM32F1.ino
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* STM32F1.ino
|
||||
*
|
||||
* Author : Vincenzo
|
||||
* this works using the unofficial STM32 core, more info: https://github.com/rogerclarkmelbourne/Arduino_STM32
|
||||
* Led: PB1
|
||||
*/
|
||||
|
||||
|
||||
#define baudrate 115200 // check if it is the same in processing
|
||||
#define samples 200 // the number of samples you want to take
|
||||
#define boardLed PB1
|
||||
|
||||
|
||||
|
||||
uint8_t initial, state, old_state;
|
||||
uint8_t pinChanged[samples];
|
||||
uint32_t timer[samples];
|
||||
uint16_t event = 0;
|
||||
|
||||
//uncomment it if you want to use the USART1 instead of DFU serial
|
||||
//#define Serial Serial1
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(baudrate);
|
||||
|
||||
pinMode (boardLed, OUTPUT);
|
||||
digitalWrite(boardLed, LOW);
|
||||
|
||||
pinMode(PB12, INPUT_PULLUP);
|
||||
pinMode(PB13, INPUT_PULLUP);
|
||||
pinMode(PB14, INPUT_PULLUP);
|
||||
pinMode(PB15, INPUT_PULLUP);
|
||||
|
||||
startLA();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void startLA() {
|
||||
//delay(1000);
|
||||
|
||||
event = 0;
|
||||
digitalWrite(boardLed, HIGH);
|
||||
|
||||
reset_timer();
|
||||
initial = GPIOB->regs->IDR >> 12;
|
||||
state = initial;
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
old_state = state;
|
||||
state = GPIOB->regs->IDR >> 12;
|
||||
|
||||
if (old_state != state) {
|
||||
timer[event] = micros();
|
||||
pinChanged[event] = state ^ old_state;
|
||||
event++;
|
||||
|
||||
if (event == samples) {
|
||||
sendData();
|
||||
while (Serial.read() != 'G') ; //wait for the "go"
|
||||
startLA();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sendData() {
|
||||
digitalWrite(boardLed, LOW);
|
||||
|
||||
//initial data
|
||||
Serial.println("S");
|
||||
Serial.print(initial); Serial.print(":");
|
||||
Serial.println(samples);
|
||||
|
||||
//data
|
||||
for (int i = 0; i < samples; i++) {
|
||||
Serial.print(pinChanged[i]); Serial.print(":");
|
||||
Serial.println(timer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void reset_timer() {
|
||||
systick_uptime_millis = -1;
|
||||
SYSTICK_BASE->CNT = 0;
|
||||
}
|
||||
126
Microcontroller_Code/UNO/UNO.ino
Normal file
126
Microcontroller_Code/UNO/UNO.ino
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* UNO.ino
|
||||
*
|
||||
* Created: 11/12/2016 19.35.51
|
||||
* Author : Vincenzo
|
||||
* Led on A0
|
||||
*/
|
||||
|
||||
#define baudrate 115200 // check if it is the same in processing
|
||||
#define samples 200 // the number of samples you want to take
|
||||
|
||||
#define F_CPU 16000000UL
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <util/delay.h>
|
||||
#define prescaler 0x02
|
||||
volatile uint16_t timer1_overflow_count;
|
||||
|
||||
uint8_t initial, state, old_state;
|
||||
uint8_t pinChanged[samples];
|
||||
uint32_t timer[samples];
|
||||
uint16_t event = 0;
|
||||
|
||||
void init_board() {
|
||||
|
||||
PORTC = (0 << 0); DDRC |= (1 << 0); // led A0
|
||||
DDRB |= 0x00; // pin 8-13 input
|
||||
PORTB |= 0x3F; // pull-up
|
||||
|
||||
}
|
||||
|
||||
void init_timer() {
|
||||
|
||||
//clear
|
||||
TCCR1A = 0b00000000;
|
||||
TCCR1B = 0b00000000;
|
||||
TIMSK1 = 0b00000000;
|
||||
|
||||
//settings
|
||||
TCCR1A |= (0 << COM1A1) | (0 << COM1A0) | (0 << COM1B1) | (0 << COM1B0); //normal port operation
|
||||
TCCR1A |= (0 << WGM11) | (0 << WGM10); //normal operation
|
||||
TCCR1B |= (0 << WGM13) | (0 << WGM12); //normal operation
|
||||
TCCR1B |= prescaler; //(0 << CS12) | (0 << CS11) | (1 << CS10); //clock prescaler
|
||||
|
||||
sei(); //enable interrupts
|
||||
TIMSK1 |= (1 << TOIE1); // enable overflow interrupt
|
||||
|
||||
}
|
||||
|
||||
ISR(TIMER1_OVF_vect) {
|
||||
timer1_overflow_count++;
|
||||
}
|
||||
|
||||
void reset_timer1 () {
|
||||
TCNT1 = 0;
|
||||
timer1_overflow_count = 0;
|
||||
}
|
||||
|
||||
uint32_t myMicros () {
|
||||
cli();
|
||||
|
||||
if (TIFR1 & (1 << TOV1)) {
|
||||
TIFR1 = (0 << TOV1);
|
||||
timer1_overflow_count++;
|
||||
}
|
||||
|
||||
uint32_t total_time = (65536 * timer1_overflow_count + TCNT1) / 2;
|
||||
sei();
|
||||
return total_time;
|
||||
}
|
||||
|
||||
void start() {
|
||||
_delay_ms(1000);
|
||||
|
||||
reset_timer1();
|
||||
event = 0;
|
||||
|
||||
PORTC = (1 << 0);
|
||||
initial = PINB;
|
||||
state = initial;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void sendData() {
|
||||
PORTC = (0 << 0); //turn off led
|
||||
|
||||
//initial data
|
||||
Serial.println("S");
|
||||
Serial.print(initial); Serial.print(":");
|
||||
Serial.println(samples);
|
||||
|
||||
//data
|
||||
for (int i = 0; i < samples; i++) {
|
||||
Serial.print(pinChanged[i]); Serial.print(":");
|
||||
Serial.println(timer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(void) {
|
||||
Serial.begin(baudrate);
|
||||
|
||||
init_board();
|
||||
init_timer();
|
||||
|
||||
start();
|
||||
|
||||
while (1) {
|
||||
|
||||
old_state = state;
|
||||
state = PINB;
|
||||
|
||||
if (old_state != state) {
|
||||
timer[event] = myMicros();
|
||||
pinChanged[event] = state ^ old_state;
|
||||
event++;
|
||||
|
||||
if (event == samples) {
|
||||
sendData();
|
||||
while (Serial.read() != 'G') ; //wait for the "go"
|
||||
start();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user