mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-22 23:56:13 +01:00
Motor drivers tested
This commit is contained in:
parent
7a4fcd228d
commit
da7275d9a4
|
@ -89,7 +89,18 @@ int inline analogReadFast(uint8_t ADCpin)
|
|||
return adc;
|
||||
}
|
||||
|
||||
#elif defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY)
|
||||
|
||||
int inline analogReadFast(uint8_t ADCpin)
|
||||
{ byte ADC0CTRLCoriginal = ADC0.CTRLC;
|
||||
ADC0.CTRLC = (ADC0CTRLCoriginal & 0b00110000) + 0b01000011;
|
||||
int adc = analogRead(ADCpin);
|
||||
ADC0.CTRLC = ADC0CTRLCoriginal;
|
||||
return adc;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int inline analogReadFast(uint8_t ADCpin)
|
||||
{ byte ADCSRAoriginal = ADCSRA;
|
||||
ADCSRA = (ADCSRA & B11111000) | 4;
|
||||
|
|
34
CVReader.ino
34
CVReader.ino
|
@ -24,6 +24,14 @@
|
|||
#include "DCCEXParser.h"
|
||||
#include "WifiInterface.h"
|
||||
|
||||
#ifdef ARDUINO_AVR_UNO
|
||||
#include <SoftwareSerial.h>
|
||||
SoftwareSerial Serial1(15,16); // YOU must get thee pins correct to use Wifi on a UNO
|
||||
#define WIFI_BAUD 9600
|
||||
#else
|
||||
#define WIFI_BAUD 115200
|
||||
#endif
|
||||
|
||||
// this code is here to demonstrate use of the DCC API and other techniques
|
||||
|
||||
// myFilter is an example of an OPTIONAL command filter used to intercept < > commands from
|
||||
|
@ -74,9 +82,9 @@ void setup() {
|
|||
|
||||
// Responsibility 1: Start the usb connection for diagnostics and possible JMRI input
|
||||
// DIAGSERAL is normally Serial but uses SerialUSB on a SAMD processor
|
||||
DIAGSERIAL.begin(115200);
|
||||
while(!DIAGSERIAL);
|
||||
|
||||
DIAGSERIAL.begin(115200);
|
||||
while(!DIAGSERIAL);
|
||||
|
||||
// Responsibility 2: Start the DCC engine.
|
||||
// Note: this provides DCC with two motor drivers, main and prog, which handle the motor shield(s)
|
||||
// Standard supported devices have pre-configured macros but custome hardware installations require
|
||||
|
@ -84,16 +92,16 @@ void setup() {
|
|||
|
||||
DCC::begin(STANDARD_MOTOR_SHIELD);
|
||||
|
||||
// Responsibility 3: Optionally Start the WiFi interface if required.
|
||||
// Responsibility 3: **Optionally** Start the WiFi interface if required.
|
||||
// NOTE: On a Uno you will have to provide a SoftwareSerial
|
||||
// configured for the pins connected to the Wifi card
|
||||
// and a 9600 baud rate.
|
||||
// setup(serial, F(router name), F(password) , port)
|
||||
//
|
||||
#ifdef WIFI
|
||||
Serial1.begin(115200);
|
||||
WifiInterface::setup(Serial1, F(WIFI_CONNECT_TO_SSID), F(WIFI_CONNECT_PASSWORD),F("DCCEX"),F("CVReader"),3532); // (3532 is 0xDCC decimal... )
|
||||
#endif
|
||||
// (port 3532 is 0xDCC decimal.)
|
||||
|
||||
|
||||
Serial1.begin(WIFI_BAUD);
|
||||
WifiInterface::setup(Serial1, F("BTHub5-M6PT"), F("49de8d4862"),F("DCCEX"),F("CVReader"),3532);
|
||||
|
||||
// This is just for demonstration purposes
|
||||
DIAG(F("\n===== CVReader demonstrating DCC::getLocoId() call ==========\n"));
|
||||
|
@ -102,7 +110,7 @@ void setup() {
|
|||
|
||||
// Optionally tell the command parser to use my example filter.
|
||||
// This will intercept JMRI commands from both USB and Wifi
|
||||
DCCEXParser::setFilter(myFilter);
|
||||
DCCEXParser::setFilter(myFilter);
|
||||
|
||||
DIAG(F("\nReady for JMRI commands\n"));
|
||||
|
||||
|
@ -119,13 +127,11 @@ void loop() {
|
|||
serialParser.loop(DIAGSERIAL);
|
||||
|
||||
// Responsibility 3: Optionally handle any incoming WiFi traffic
|
||||
#ifdef WIFI
|
||||
WifiInterface::loop();
|
||||
#endif
|
||||
|
||||
// Your additional code
|
||||
// Your additional loop code
|
||||
|
||||
// OPtionally report any decrease in memory (will automatically trigger on first call)
|
||||
// Optionally report any decrease in memory (will automatically trigger on first call)
|
||||
int freeNow=freeMemory();
|
||||
if (freeNow<ramLowWatermark) {
|
||||
ramLowWatermark=freeNow;
|
||||
|
|
21
Config.h
21
Config.h
|
@ -9,23 +9,28 @@
|
|||
// A custom hardware setup will require your sketch to create MotorDriver instances
|
||||
// similar to those defined here, WITHOUT editing this file.
|
||||
|
||||
// Define these if you have a WiFi board on Serial1
|
||||
#define WIFI
|
||||
#define WIFI_CONNECT_TO_SSID "RPi-JMRI"
|
||||
#define WIFI_CONNECT_PASSWORD "rpI-jmri"
|
||||
|
||||
const byte UNUSED_PIN = 255;
|
||||
|
||||
// MotorDriver(byte power_pin, byte signal_pin, byte signal_pin2, byte brake_pin, byte current_pin, float senseFactor, unsigned int tripMilliamps, byte faultPin);
|
||||
// MotorDriver(byte power_pin, byte signal_pin, byte signal_pin2, byte brake_pin, byte current_pin,
|
||||
// float senseFactor, unsigned int tripMilliamps, byte faultPin);
|
||||
|
||||
// Arduino standard Motor Shield
|
||||
#define STANDARD_MOTOR_SHIELD \
|
||||
new MotorDriver(3 , 12, UNUSED_PIN, 9, A0, 2.99, 2000, UNUSED_PIN), \
|
||||
new MotorDriver(11, 13, UNUSED_PIN, 8, A1, 2.99, 250 , UNUSED_PIN)
|
||||
new MotorDriver(3 , 12, UNUSED_PIN, UNUSED_PIN, A0, 2.99, 2000, UNUSED_PIN), \
|
||||
new MotorDriver(11, 13, UNUSED_PIN, UNUSED_PIN, A1, 2.99, 250 , UNUSED_PIN)
|
||||
|
||||
// Pololu Motor Shield
|
||||
#define POLOLU_MOTOR_SHIELD \
|
||||
new MotorDriver(4, 7, UNUSED_PIN, 9 , A0, 18, 2000, 12), \
|
||||
new MotorDriver(2, 8, UNUSED_PIN, 10, A1, 18, 250 , UNUSED_PIN)
|
||||
|
||||
// Allocations with memory implications..!
|
||||
// Base system takes approx 900 bytes + 8 per loco. Turnouts, Sensors etc are dynamically created
|
||||
const byte MAX_LOCOS=50;
|
||||
#ifdef ARDUINO_AVR_UNO
|
||||
const byte MAX_LOCOS=20;
|
||||
#else
|
||||
const byte MAX_LOCOS=50;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
2
DCC.cpp
2
DCC.cpp
|
@ -44,7 +44,7 @@ const byte FN_GROUP_5=0x10;
|
|||
|
||||
void DCC::begin(MotorDriver * mainDriver, MotorDriver* progDriver) {
|
||||
debugMode=false;
|
||||
DCCWaveform::begin(mainDriver,progDriver);
|
||||
DCCWaveform::begin(mainDriver,progDriver);
|
||||
}
|
||||
|
||||
void DCC::setThrottle( uint16_t cab, uint8_t tSpeed, bool tDirection) {
|
||||
|
|
|
@ -26,17 +26,19 @@
|
|||
DCCWaveform DCCWaveform::mainTrack(PREAMBLE_BITS_MAIN, true);
|
||||
DCCWaveform DCCWaveform::progTrack(PREAMBLE_BITS_PROG, false);
|
||||
|
||||
//const int ACK_MIN_PULSE_RAW=65 / PROG_SENSE_FACTOR;
|
||||
|
||||
bool DCCWaveform::progTrackSyncMain=false;
|
||||
|
||||
void DCCWaveform::begin(MotorDriver * mainDriver, MotorDriver * progDriver) {
|
||||
mainTrack.motorDriver=mainDriver;
|
||||
progTrack.motorDriver=progDriver;
|
||||
|
||||
TimerA.initialize();
|
||||
TimerA.setPeriod(58);
|
||||
TimerA.attachInterrupt(interruptHandler);
|
||||
TimerA.start();
|
||||
mainTrack.setPowerMode(POWERMODE::ON);
|
||||
progTrack.setPowerMode(POWERMODE::ON);
|
||||
|
||||
}
|
||||
|
||||
|
@ -85,7 +87,6 @@ DCCWaveform::DCCWaveform( byte preambleBits, bool isMain) {
|
|||
sampleDelay = 0;
|
||||
lastSampleTaken = millis();
|
||||
ackPending=false;
|
||||
setPowerMode(POWERMODE::ON);
|
||||
}
|
||||
|
||||
POWERMODE DCCWaveform::getPowerMode() {
|
||||
|
|
|
@ -25,7 +25,7 @@ const int POWER_SAMPLE_ON_WAIT = 100;
|
|||
const int POWER_SAMPLE_OFF_WAIT = 1000;
|
||||
const int POWER_SAMPLE_OVERLOAD_WAIT = 20;
|
||||
|
||||
const int MIN_ACK_PULSE_DURATION = 3000;
|
||||
const int MIN_ACK_PULSE_DURATION = 2000;
|
||||
const int MAX_ACK_PULSE_DURATION = 8500;
|
||||
|
||||
|
||||
|
|
|
@ -22,13 +22,16 @@
|
|||
#include "DIAG.h"
|
||||
|
||||
|
||||
#if defined(ARDUINO_ARCH_AVR)
|
||||
|
||||
#if defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAMC) || defined(ARDUINO_ARCH_MEGAAVR)
|
||||
#define WritePin digitalWrite
|
||||
#define ReadPin digitalRead
|
||||
#else
|
||||
// use the DIO2 libraray for much faster pin access
|
||||
#define GPIO2_PREFER_SPEED 1
|
||||
#include <DIO2.h> // use IDE menu Tools..Manage Libraries to locate and install DIO2
|
||||
#define WritePin digitalWrite2
|
||||
#define ReadPin digitalRead2
|
||||
#else
|
||||
#define WritePin digitalWrite
|
||||
#define ReadPin digitalRead
|
||||
#endif
|
||||
|
||||
MotorDriver::MotorDriver(byte power_pin, byte signal_pin, byte signal_pin2, byte brake_pin,
|
||||
|
|
|
@ -26,6 +26,9 @@
|
|||
#define DIAGSERIAL SerialUSB
|
||||
#elif defined(ARDUINO_ARCH_AVR)
|
||||
#define DIAGSERIAL Serial
|
||||
#elif defined(ARDUINO_ARCH_MEGAAVR)
|
||||
#define DIAGSERIAL Serial
|
||||
#define __FlashStringHelper char
|
||||
#endif
|
||||
|
||||
class StringFormatter
|
||||
|
|
Loading…
Reference in New Issue
Block a user