Go Down

Topic: what input pin is it using? (Read 19208 times) previous topic - next topic


if im using a hall sensor it is high or low
i no there will be 6 triggers a revolution
we no what short of speeds we are looking at
what else we looking at apart from the mechanical side?


Hall switch operates ON/OFF.

Hall sensor linear type is analog -but- digital read pin triggers ON/OFF when voltage passes the switch points so you can use the linear type either way.

6 triggers per revolution... not 60?
With 60 the triggers per second is same as rpm, with 6 it is rpm/10.

I think that you could get by polling all 3 sensors at once by Port read and process the 3 bits at 10,000, maybe more triggers per second continuous if you don't do heavy processing.

If you don't do continuous reads, say capture and store 100 to 500 reads in an array and then process those while not reading then you could capture higher rates, possibly over 50,000 triggers per second and still sample and control more than 10x a second.

My ultrasonic sensor code has a while loop that does a digital read, unsigned long increment and unsigned long compare that runs just about 1 million times a second. I am being conservative in my estimates above because I can't be sure what your processing entails.
Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts


It does occur to me that you could write test programs reading the pins in a loop just to see how fast you can do it --- as long as the data doesn't matter. You can set them INPUT HIGH or pull them down through a 10k or higher (better) resistor or just let them float. Do all the things you would do with real data except run the car, you can get a good idea of what's possible.

Read all the pins at once for best results. Well, using AVR code in the sketch may save more cycles but I'm not the person to say those steps -- I do what I need without.

Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts


yes the 60 trigger was with the old sensor i was thinkthing of putting the new sensor somewhere else hence now 6 trigger
here is the code i have at mo:
i no there is delays in it but when they are active the hall will not be being used
i would like to put all what we have been talking about in where it says (auto mod)

Code: [Select]

#include <AH_EasyDriver.h>

//AH_EasyDriver(int RES, int DIR, int STEP, int MS1, int MS2, int SLP);
AH_EasyDriver stepper(200,2,3,4,5,6);    // init w/o "enable" and "reset" functions

int tempsensor     = A1;
int brack          = 12;
int pump           = 13;
int automanual     = 11;
int overtempled    = 10;

int previous = 0;                       // the previous reading from the analog input
bool DoneInitialization = false;

void setup() {
  stepper.resetDriver();                  // reset driver
  stepper.enableDriver();                 // enable driver
  stepper.setMicrostepping(3);            // 0 -> Full Step                               
                                          // 1 -> 1/2 microstepping
                                          // 2 -> 1/4 microstepping
                                          // 3 -> 1/8 microstepping
  stepper.setSpeedRPM(50);                // set speed in RPM, rotations per minute
  pinMode(brack      , INPUT) ;           // brack
  pinMode(pump       , OUTPUT);           // hydraulis pump
  pinMode(automanual , INPUT) ;           // auto / manual swicth
  pinMode(overtempled, OUTPUT);           // over temp LED

void loop() {
                                            // get the sensor value
  int potVal = analogRead(0);
  int stpPos = map(potVal, 0, 1023, 0, 152);
  //                                         ----------------------
  int val = analogRead(tempsensor);          // temp sensor high
  if (val <970) {
    digitalWrite(pump,        HIGH);         // hydraulis pump high
    digitalWrite(overtempled,    LOW);          // over temp LED
    //                                      ----------------------- 
    if (digitalRead(brack) == LOW) {        // brack swicth
    if (digitalRead(automanual) == HIGH) {  // auto / manual swicth
    //                                    -------------------------------------------
        if (!DoneInitialization) {
    stepper.sleepON();                     // set Sleep mode ON
        DoneInitialization=true;           // Initialization is done, don't run it again until it has been reset
    } //                                ---------------------------------------------
      stepper.sleepOFF();                  // set Sleep mode OFF
      stepper.rotate(stpPos - previous);

      previous = stpPos;                   // remember the previous value of the sensor
//                                      ---------------------------------------------
  else {                                              // -- AUTO mod -- //
  //                                      ---------------------------------------------------------
  else {                                   // brack swicth when HIGH
                                           // reset the previous value to zero
      previous = 0;
  //                                      ---------------------------------------------------------
  else {                                   // temp sensor HIGH
    previous = 0;                          // reset the previous value to zero
    DoneInitialization=false;              // resetting the count
    digitalWrite(overtempled,    HIGH);    // over temp LED
    stepper.sleepON();                     // set Sleep mode ON
    digitalWrite(pump,          LOW);      // hydraulis pump high
  //                                     --------------------------------------------     


Oh no. You have to use timing based (Real Time) code to get this to work, even using interrupts.
The stepper moves like a glacier compared to Arduino. Loop has to finish very fast to get enough reads per second for... I forget how many rpm but it's for a car wheel.

If you read 10x as often as triggers then you will be sure to catch every one a few times in a row. That lets you be sure you don't get false positives, a good thing.

Also be real careful to debug and test this insanely much before going out on any road. If someone gets hurt there will be lawyers who will do anything to make it your fault. Facts won't matter, they are trained to steer around such trivialities as facts.

Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

Go Up