Author Topic: TimerOne library port to Digispark Pro available?  (Read 4177 times)

robmack

  • Newbie
  • *
  • Posts: 13
TimerOne library port to Digispark Pro available?
« on: January 17, 2015, 06:33:02 pm »
Through my research, I can see that this topic of TimerOne has surfaced in the past for the original Digispark, and has been answered before as well.  I'm new to the ATTiny world and have been trying to port my Arduino code to the Pro platform (from an Uno development platform).

My code uses the TimerOne library to implement timer1 in CTC mode and invoke a simple interrupt routine. The main loop refreshes LEDs attached to ports 0-7, and the interrupt fires off every 50mS.  Within the ISR, the code reads an external switch status to change which LEDs are illuminated or extinguished.  It's pretty straight forward.

The code fails to compile with the following error (I'm linking to the hardware extended version of TimerOne):
Code: [Select]
Arduino: 1.5.8 (Mac OS X), Board: "Digispark Pro (Default 16 Mhz)"

In file included from TGPI_sketch_v21.ino:16:0:
/Users/robert/Documents/Arduino/libraries/TimerOne/TimerOne.h: In member function 'void TimerOne::setPwmDuty(char, unsigned int)':
/Users/robert/Documents/Arduino/libraries/TimerOne/TimerOne.h:105:13: error: 'TIMER1_A_PIN' was not declared in this scope
  if (pin == TIMER1_A_PIN) OCR1A = dutyCycle;
             ^
/Users/robert/Documents/Arduino/libraries/TimerOne/TimerOne.h: In member function 'void TimerOne::pwm(char, unsigned int)':
/Users/robert/Documents/Arduino/libraries/TimerOne/TimerOne.h:114:13: error: 'TIMER1_A_PIN' was not declared in this scope
  if (pin == TIMER1_A_PIN) { pinMode(TIMER1_A_PIN, OUTPUT); TCCR1A |= _BV(COM1A1); }
             ^
/Users/robert/Documents/Arduino/libraries/TimerOne/TimerOne.h: In member function 'void TimerOne::disablePwm(char)':
/Users/robert/Documents/Arduino/libraries/TimerOne/TimerOne.h:129:13: error: 'TIMER1_A_PIN' was not declared in this scope
  if (pin == TIMER1_A_PIN) TCCR1A &= ~_BV(COM1A1);
             ^
Error compiling.

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

The Pro platform differs from the ATTIny85-based Digispark and from the ATmega328-based platforms so I'm wondering if a TimerOne-equivalent library for the Digispark Pro exists?

If not, I can't believe that my problem hasn't been solved before and whether anyone can point me to a good example of how to achieve interrupting the processor every 50mS to read some digital ports.  I've honestly searched for a library everywhere with no success.
« Last Edit: January 17, 2015, 11:04:08 pm by robmack »

defragster

  • Sr. Member
  • ****
  • Posts: 467
Re: TimerOne library port to Digispark Pro available?
« Reply #1 on: January 18, 2015, 02:13:44 am »
There may be a better example, but this came out during the Pro Beta and shows a library hooking a timer interrupt.  This example drives an array of 64 LED's to eight shades through a multiplex LED driver to get them.  It worked in that application so yours with direct pins should be easier.

Re: What are you doing with your Beta Shield?
Binary Angle Modulation to actually drive the 8x8 array with multiple simultaneous shades of red
http://digistump.com/board/index.php/topic,1457.msg6789.html#msg6789
« Last Edit: January 18, 2015, 04:46:08 pm by defragster »

robmack

  • Newbie
  • *
  • Posts: 13
Re: TimerOne library port to Digispark Pro available?
« Reply #2 on: January 18, 2015, 06:26:19 am »
Hi Defragster,

Thanks for the reference.  You've given me a lot to research in a different direction.  I presume that you pointed me to the BetaSketcher code and specifically the BAM library.  I see the following fragment of code:
Code: [Select]
void BAMClass::begin() {
  memset((void*)frames, 0, sizeof(frames));
  initLED();
  tickpos = 0;
  TCCR1A = 0;
  TCCR1B = 0;
  TCCR1B |= (1 << WGM12); // CTC
  TCCR1B |= (1 << CS12) | (1 << CS10); // 1024 prescaler
  TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt
  TCNT1 = 0;
}
This provided me with different search terms that netted me several other web tutorials on interrupt code, most helpful being this one.  Now, through these examples, I can wean my code off TimerOne and get it working.  Thanks.

defragster

  • Sr. Member
  • ****
  • Posts: 467
Re: TimerOne library port to Digispark Pro available?
« Reply #3 on: January 18, 2015, 12:29:58 pm »
Yes, that post link was the BAM code, it was effective and impressive turning 64 leds into color intensity matrix. I scanned the cpp file and saw the interrupt code later after that timer setup. It should have everything in it to pull out and swap in your code