This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Voltage and current monitor for lab supply | |
* | |
* LCD and analog input pin assignments as shown below | |
* | |
* Matt Godfrey, 2015 | |
*/ | |
#include <LiquidCrystal.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
8 bit up-down counter. | |
Based on code from Mojo tutorial | |
https://embeddedmicro.com/tutorials/mojo/pulse-width-modulation | |
/\ /\ | |
/ \ / \ | |
/ \/ \ | |
The CRT_LEN determines the period of the resulting counter | |
*/ | |
module counter #(parameter CTR_LEN = 27) ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
servo controller | |
Based on code from Mojo tutorial | |
https://embeddedmicro.com/tutorials/mojo/servos | |
Takes an 8-bit position as an input | |
Output a single pwm signal with period of ~20ms | |
Pulse width = 1ms -> 2ms full scale. 1.5ms is center position | |
*/ | |
module servo_controller ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Servo motor control demo module | |
Four servos swing back and forth with different speeds. | |
*/ | |
module mojo_top( | |
input clk, // 50MHz clock input | |
//remaining default inputs/outputs omitted | |
output [3:0] servo_out //PWM output lines for each servo | |
); | |
//Usual setup code omitted (setting SPI lines, reset, etc. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void loop() { | |
//poll the timers | |
//if any of these have expired then their callback will automatically run. | |
conversionTimer.run(); | |
measTimer.run(); | |
display_timeout.run(); | |
//... | |
//reset the display timeout timer if a button was pressed | |
if(button_up.pushed() || button_down.pushed() || button_select.pushed()){ | |
display_timeout.restart(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void measure_temps(){ | |
DateTime t = rtc.now(); //get the current timestamp | |
datetime2str(t, date_str); | |
//trigger a temperature measurement | |
sensors.begin(); | |
sensors.setWaitForConversion(false); | |
sensors.requestTemperatures(); | |
conversionTimer.restart(); //Set up timer for temperature conversion to complete | |
return; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Logs current temperature data to SD card. | |
* Note that the global variable "filename" must be initialised | |
* File format is: | |
* datestring,sensor0_name,temp0,sensor1_name,temp1,sensor2_name,temp2 | |
* datestring,sensor0_name,temp0,sensor1_name,temp1,sensor2_name,temp2 | |
*/ | |
byte log_temps(char *date_str){ | |
File f = SD.open(filename, FILE_WRITE); | |
if(f) { |