Thread: My new lathe
View Single Post
  #46  
Old 01-06-2020, 11:01 AM
bojan's Avatar
bojan
amateur

bojan is offline
 
Join Date: Jul 2006
Location: Mt Waverley, VIC
Posts: 6,943
Since the issue with seller isn't going anywhere, I decided to modify existing controller by replacing original processor with AtTiny85.
The following "sketch" (arduinian for "source code") does the trick:

****
// HT66F016 application for lathe DC continuous variable speed motor controller
// to run on attiny85 as replacement

const byte pwmPin = 0; // PWM output pin defined
const byte LED = 1; // It is also used for onboard LED
const byte PWM_EN = 3; // PWN enable LOW, no activity from original processor
const byte analogInPin = A2; // input pin defined

// Original HT66F016 PWM frequency is 15kHz. Default ATtiny85 PWM frequency on P0 is 500Hz
// To change that:
// https://digistump.com/wiki/digispark/tricks
// MS_TIMER_TICK_EVERY_X_CYCLES in arduino-1.0x/hardware/digispark/cores/tiny/wiring.c is set to 8 (default is 64)
// resulting in PWM frequency on P0 =4kHz (If set to 1, freq would be 32kHz, possibly too high)
// FAVOR_PHASE_CORRECT_PWM to 0 in arduino-1.0x/hardware/digispark/cores/tiny/core_build_options.h file, it's possible to double the frequency on Pin1
// How to increase this frequency to ~15kHz?

void setup() {
//TCCR2B = TCCR2B & 0b11111000 | 0x01; // This doesn't work

pinMode(pwmPin, OUTPUT);
pinMode(PWM_EN, OUTPUT);
pinMode(LED, OUTPUT);
digitalWrite(LED, HIGH); // LED ON
digitalWrite(PWM_EN, LOW); // another wired-NAND for PWM, no activity observed form original /u processor, so here just in case..
}

void loop() {
int analogIn = analogRead(analogInPin);
analogIn >>= 2;
analogIn=analogIn/1.5;
// Alternative statement is: analogIn = map(analogIn, 0, 1023, 0, 255);
analogWrite(pwmPin, analogIn);
}

***


I will couple the PWM output to the rest of controller electronics with opto-isolator, which will give me the option of using GRBL for spindle speed control in the future.

EDIT: I added enable output (LOW), the same functionality was on Holtek HT66F018 processor (but no activity observed), probably to prevent activation of high voltage output during processor startup.

Last edited by bojan; 10-06-2020 at 08:35 AM.
Reply With Quote