TinkerKit LCD (Leonardo) PWM Fan Control Timer Setup

Hi Guys,

I recently discovered the Arduino system when trying to find a way to build PWM controller for a 4-wire computer fan. Once I saw how cool these boards were, I immediately ordered up an UNO R3 online. I’ve only had it for a few days, but I’ve found a method to change the PWM timing on pins 3/11 and I can now adust the fan speed with a potentiometer. I only needed to connect the fan PWM line to pin 3 on the UNO and the ground to GND.

  pinMode(PWMPin, OUTPUT);   // OCR2B sets duty cycle

// Set up Fast PWM on Pin 3
  TCCR2A = 0x23;    // COM2B1, WGM21, WGM20
// Set prescaler 
  TCCR2B = 0x0A;  // WGM21, Prescaler = /8
// Set TOP and initialize duty cycle to zero(0)
  OCR2A = 79;    // TOP DO NOT CHANGE, SETS PWM PULSE RATE
  OCR2B = 0;    // duty cycle for Pin 3 (0-79) generates 1 500nS pulse even when 0 :frowning:
}

void loop() {
  unsigned int x;
  // ramp up fan speed by increasing duty cycle every 200mS, takes 16 seconds
  for(x = 0; x < 80; x++) {
    OCR2B = x;    // set duty cycle
    delay(200);
  } 
}




Source Post: http://forum.arduino.cc/index.php?topic=155089.msg1176136#msg1176136

Next thing you know, I happened into Radio Shack the other day and noticed that they were blowing out heaps of different kits. I picked up a TinkerKit Base for $30 and five TinkerKit LCDs for $15 each! They were also clearning out Arduino Proto Boards and Motor Shields for $2.50, Ethernet Shields for $7.50, Parallax GPS for $10 and LCD for $5, and many others. If you have a Radio Shack nearby check the website and go find some deals!

Anyways, to continue, I now discovered that the TinkerKit LCD contains an ATMega32U4 / Leonardo chip and can act as a standalone device. I’ve done goofing around with it and have had some success interfacing with the TinkerKit modules but have been unable to replicate the timing changes like the UNO. I’ve read a few tutorials concerning the timers and interrupts, how to set the bits and I’ve had a glance at the datasheet for the ATMega32U4. I’ve been able to blink an LED on D5 by adjusting Timer1 but when I tried to translate over the UNO timer settings I bricked the LCD. Luckily, I found a trick to un-brick the LCD by starting a sketch to compile and resetting the device just before it uploads.

Is there anyone out there that can help me properly setup a timer to get my PWM fan to work on the TK LCD? I have the fan PWM line connected to the middle pin on the D5 connector (I believe this is just pin 5, I’m not certain what the outside pins are, +5V or GND I guess,) and the fan ground connected to the GND pin on the serial connector. Here is what the back of the TinkerKit LCD looks like for those who are not familiar.

Any insights you may be able to give would be most appreciated.

Cheers,

Smart-Aleck

OK, I took another long look at the datasheets for both the UNO and Leonardo. It definitely appears to me that the 8-bit Timer2 on the UNO is equivalent to the 8-bit Timer0 on the Leonardo, all the registers appear to be exactly the same. The code unfortunately does not run after changing the references from Timer2 to Timer0 and I'm wondering if some extra components need to be added to interface with the TKLCD??

I'm continuing to research the device and have made some comments in the TinkerKit LCD tutorials section, hopefully they will know a bit more about the issue. I see a lot of units popping up on eBay when there were none before, I'm sure it's RS stock. Maybe some more TKLCD users will come along soon!