I have a circuit and code that worked fine in testing but now that I have packaged it all I does is burn up teensies both LC and 3.2. The attached PDF shows the connections to the teensy. Sorry I am not good at drawing schematics. The project is a thread winder. It is quite simple. A target is set and the thing winds until it is reached. Motor turns are (still works until teensy burns up) counted by a field effect switch with open collector output. The motor is controlled with an FET switch with PWM input from the Teensy. The display is an IIC OLEDSSD1306.
I have checked everything 50 times and have blown up 5 teensies. Again this worked fine until I packaged it up. My only guess at this point is that the motor leads are generating RFI which is getting into the Hall effect line? I am not sure but I think it only burns up after running the motor. If this could be the case, should I shield the motor leads or the signal and power leads to the hall switch or both?
and here is the full code which I have cleaned up to make it less confusing:
I have checked everything 50 times and have blown up 5 teensies. Again this worked fine until I packaged it up. My only guess at this point is that the motor leads are generating RFI which is getting into the Hall effect line? I am not sure but I think it only burns up after running the motor. If this could be the case, should I shield the motor leads or the signal and power leads to the hall switch or both?
and here is the full code which I have cleaned up to make it less confusing:
Code:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
int pot_position;
int count =0;
int target = 100; // start high so it can be hand runt
int CounterState = 0; // current state of the button
int LastCounterState = 0;
int undershoot;
int final_target;
int volt_out;
int speed_table[] = {// LOG 4 to give fine control at lower speeds 102 entries
0,0,1,1,1,2,2,2,3,3,4,4,5,5,6,6,7,8,9,10,10,11,13,14,15,
15,16,17,19,20,22,24,25,27,29,31,33,36,38,41,43,46,49,52,
55,58,62,65,69,73,77,81,86,90,95,100,105,110,116,122,127,
134,140,146,153,160,168,175,183,191,199,208,216,226,235,
245,245,245,255,255,255,255,255,255,255,255,255,255,255
,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255
}; // add a few extra to be sure
void setup() {
Serial.begin(9600);
delay(1000);
Wire.setSDA(18);
Wire.setSCL(19);;
Serial.println("setup begin");
pinMode(2, INPUT_PULLUP); // count switch input
pinMode(9, INPUT_PULLUP); // restart switch input
pinMode(10, INPUT_PULLUP); // set target switch
pinMode(15, INPUT_PULLUP); // pedal switch input
pinMode(16, INPUT_PULLUP); // switch to choose between on off and continuous pedal
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 Display 0 allocation failed"));
for(;;); // Don't proceed, loop forever
}
delay(1000);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.clearDisplay();
display.setCursor(0, 0);
display.println(count);
display.println(target);
display.display();
} // end setup
void loop(){
if (digitalReadFast(9) == LOW){ // reset switch is low
count = 0;
display.clearDisplay();
display.setCursor(0, 0);
display.println(count);
display.println(target);
display.display();
} // probably should make the next line an else if but it works
if (digitalReadFast(10) == LOW){ // setting target switch is low keep updating target value until switch is off
final_target = count +1;
target = count +1;///check to see if this is right do a few runs with target and see if it stops correctlyfinal_target =
}
else {
// final_target = target - undershoot +1;// not using undershoot right now
final_target = target;
}
check_counter_state();
if (count >= final_target){ // stop if target reached
analogWrite(23, 0);
}
else{
pot_position = analogRead(A0) -1; // read the speed control pot
if (pot_position < 0){
pot_position = 0;
}
volt_out = speed_table[int((pot_position/10))];
if (volt_out < 2){
analogWrite(23, 0);// PWM out pin sw 23 or A9
}
else{
if(digitalReadFast(15) == LOW){
if((target - count < 35 )and(digitalReadFast(10) == HIGH)){ // slow down to not overshoot
analogWrite (23,20);
}
// can add code to ramp in a few brackets here eg
// else if (count < 10){
// analogWrite (23,volt_out/6);// PWM out pin sw 23 or A9
// }
// else if(count < 20){
// analogWrite (23,volt_out/4);// PWM out pin sw 23 or A9
// }
// else if(count < 30){
// analogWrite (23t,volt_out/2);// PWM out pin sw 23 or A9
// }
else{
analogWrite (23,volt_out);// PWM out pin sw 23 or A9
}
}
else{
analogWrite(23, 0);// PWM out pin sw 23 or A9
}
}
}
}
void check_counter_state() {
CounterState = digitalReadFast(2);// output of hall effect switch
if (CounterState != LastCounterState) {
if (CounterState == HIGH) { // try LOW to have it not start at one
count++;
display.clearDisplay();
display.setCursor(0, 0);
display.println(count);
display.println(target);
display.display();
}
LastCounterState = CounterState;
}
}