Skip to content

Commit 1ddd232

Browse files
committed
Merge branch 'Hrishi'
2 parents 3620625 + 14c662f commit 1ddd232

File tree

100 files changed

+108546
-310
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+108546
-310
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,4 @@ eye-Blink_Conditioning.xcodeproj/project.xcworkspace/contents.xcworkspacedata
121121
eye-Blink_Conditioning.xcodeproj/project.pbxproj
122122
*.o
123123

124+
CAD/KiCAD/AnimalBehaviour.kicad_pcb-bak

Arduino/Shocker.h

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* Description: Shock protocol.
3+
* Author : Upinder Bhalla. See attached file on issue #44.
4+
* Maintainer: Dilawar Singh (), dilawars@ncbs.res.in
5+
* Organization: NCBS Bangalore
6+
*
7+
*/
8+
9+
#ifndef SHOCKER_H
10+
#define SHOCKER_H
11+
12+
#include "TimerOne/TimerOne.h"
13+
14+
void enableReadingShockPad();
15+
void disableReadingShockPad();
16+
17+
int NUM_SAMPLES = 100;
18+
volatile size_t idx = 0;
19+
20+
// Do analog sampling only 1 in 10 times, for a freq of of 100 Hz.
21+
int SAMPLING_DIVIDER = 10;
22+
int STIM_INTERVAL = 150;
23+
int NUM_LOOP_RESET = 50;
24+
25+
// Minimum reading for foot touch to allow stimulus to go ahead.
26+
int TOUCH_THRESHOLD = 50;
27+
int numLoops = 0;
28+
volatile int shock_pin_readout = 0;
29+
30+
31+
// To save the adc status.
32+
byte adc_;
33+
34+
// Enable disable STIM isolator.
35+
void enableInputToStimIsolator()
36+
{
37+
digitalWrite(SHOCK_STIM_ISOLATER_PIN, HIGH);
38+
}
39+
40+
void disableInputToStimIsolator()
41+
{
42+
digitalWrite(SHOCK_STIM_ISOLATER_PIN, LOW);
43+
}
44+
45+
// Voltage across shock pad should be 5v.
46+
void disableReadingShockPad()
47+
{
48+
// First switch off each pin.
49+
digitalWrite( SHOCK_RELAY_PIN_CHAN_12, HIGH );
50+
digitalWrite( SHOCK_RELAY_PIN_CHAN_34, LOW );
51+
shock_pin_readout = 0;
52+
}
53+
54+
void enableReadingShockPad()
55+
{
56+
// The order is very important here. Don't switch them ON at the same time.
57+
// First switch OFF the high voltage input and wait for some time. then
58+
// switch ON the low voltage input
59+
digitalWrite( SHOCK_RELAY_PIN_CHAN_34, HIGH );
60+
digitalWrite( SHOCK_RELAY_PIN_CHAN_12, LOW );
61+
}
62+
63+
/* --------------------------------------------------------------------------*/
64+
/**
65+
* @Synopsis Shock monitor is being a called every 100us (0.1ms or 10k). Use
66+
* this to generate a tone on SHOCK_PWM_PIN.
67+
*/
68+
/* ----------------------------------------------------------------------------*/
69+
void shockMonitor()
70+
{
71+
// Generate 5K tone.
72+
if( HIGH == digitalRead( SHOCK_PWM_PIN ))
73+
digitalWrite(SHOCK_PWM_PIN, LOW);
74+
else
75+
digitalWrite(SHOCK_PWM_PIN, HIGH);
76+
77+
idx++;
78+
79+
// Read very 10 ms.
80+
if( idx == 10)
81+
{
82+
noInterrupts();
83+
shock_pin_readout = analogRead( SHOCK_PAD_READOUT_PIN );
84+
interrupts(); // enable interrupts again. We are done reading values.
85+
idx = 0;
86+
}
87+
}
88+
89+
90+
/* --------------------------------------------------------------------------*/
91+
/**
92+
* @Synopsis ISR.
93+
*
94+
* THIS TIMER IS 8 bit.
95+
*
96+
* NOTE: Timer1 controlls pin 5. This PIN acts as a fast switch: switching
97+
* between stimulus delivery (when available) and reading value from
98+
* SHOCK pad. When reading values from SHOCK_VALUE, a 5V
99+
*
100+
* TIMER0 is used by millis(), delays() etc. Better I do not touch it.
101+
* TIMER2 is used by tone(). You can't use it here.
102+
*
103+
* TIMER1 is used which is 16 bits.
104+
*/
105+
/* ----------------------------------------------------------------------------*/
106+
107+
void configureShockingTimer()
108+
{
109+
Serial.println("[INFO] Configuring ShockingTimer --- ");
110+
// Timer1.initialize(microseconds);
111+
// Begin using the timer. This function must be called first. "microseconds"
112+
// is the period of time the timer takes.
113+
Timer1.initialize(100);
114+
Timer1.attachInterrupt( shockMonitor );
115+
}
116+
117+
118+
#endif /* end of include guard: SHOCKER_H */

Arduino/TimerOne/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#TimerOne Library#
2+
3+
Paul Stoffregen's modified TimerOne. This version provides 2 main benefits:
4+
5+
1: Optimized inline functions - much faster for the most common usage
6+
2: Support for more boards (including ATTiny85 except for the PWM functionality)
7+
8+
http://www.pjrc.com/teensy/td_libs_TimerOne.html
9+
10+
https://github.com/PaulStoffregen/TimerOne
11+
12+
Original code
13+
14+
http://playground.arduino.cc/Code/Timer1
15+
16+
Open Source License
17+
18+
TimerOne is free software. You can redistribute it and/or modify it under
19+
the terms of Creative Commons Attribution 3.0 United States License.
20+
To view a copy of this license, visit
21+
22+
http://creativecommons.org/licenses/by/3.0/us/
23+
24+
Paul Stoffregen forked this version from an early copy of TimerOne/TimerThree
25+
which was licensed "Creative Commons Attribution 3.0" and has maintained
26+
the original "CC BY 3.0 US" license terms.
27+
28+
Other, separately developed updates to TimerOne have been released by other
29+
authors under the GNU GPLv2 license. Multiple copies of this library, bearing
30+
the same name but distributed under different license terms, is unfortunately
31+
confusing. This copy, with nearly all the code redesigned as inline functions,
32+
is provided under the "CC BY 3.0 US" license terms.
33+

Arduino/TimerOne/TimerOne.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Interrupt and PWM utilities for 16 bit Timer1 on ATmega168/328
3+
* Original code by Jesse Tane for http://labs.ideo.com August 2008
4+
* Modified March 2009 by Jérôme Despatis and Jesse Tane for ATmega328 support
5+
* Modified June 2009 by Michael Polli and Jesse Tane to fix a bug in setPeriod() which caused the timer to stop
6+
* Modified Oct 2009 by Dan Clemens to work with timer1 of the ATMega1280 or Arduino Mega
7+
* Modified April 2012 by Paul Stoffregen
8+
* Modified again, June 2014 by Paul Stoffregen
9+
* Modified July 2017 by Stoyko Dimitrov - added support for ATTiny85 except for the PWM functionality
10+
*
11+
* This is free software. You can redistribute it and/or modify it under
12+
* the terms of Creative Commons Attribution 3.0 United States License.
13+
* To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/us/
14+
* or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
15+
*
16+
*/
17+
18+
#include "TimerOne.h"
19+
20+
TimerOne Timer1; // preinstatiate
21+
22+
unsigned short TimerOne::pwmPeriod = 0;
23+
unsigned char TimerOne::clockSelectBits = 0;
24+
void (*TimerOne::isrCallback)() = TimerOne::isrDefaultUnused;
25+
26+
// interrupt service routine that wraps a user defined function supplied by attachInterrupt
27+
#if defined (__AVR_ATtiny85__)
28+
ISR(TIMER1_COMPA_vect)
29+
{
30+
Timer1.isrCallback();
31+
}
32+
#elif defined(__AVR__)
33+
ISR(TIMER1_OVF_vect)
34+
{
35+
Timer1.isrCallback();
36+
}
37+
#elif defined(__arm__) && defined(TEENSYDUINO) && (defined(KINETISK) || defined(KINETISL))
38+
void ftm1_isr(void)
39+
{
40+
uint32_t sc = FTM1_SC;
41+
#ifdef KINETISL
42+
if (sc & 0x80) FTM1_SC = sc;
43+
#else
44+
if (sc & 0x80) FTM1_SC = sc & 0x7F;
45+
#endif
46+
Timer1.isrCallback();
47+
}
48+
#elif defined(__arm__) && defined(TEENSYDUINO) && (defined(__IMXRT1052__) || defined(__IMXRT1062__))
49+
void TimerOne::isr(void)
50+
{
51+
FLEXPWM1_SM3STS = FLEXPWM_SMSTS_RF;
52+
Timer1.isrCallback();
53+
}
54+
55+
#endif
56+
57+
void TimerOne::isrDefaultUnused()
58+
{
59+
}

0 commit comments

Comments
 (0)