ATTiny1614 support
Hello,
I note under supported platforms the ATTiny 1 series isn't supported due to lack of standardised timers.
Do you have more information on "standardised"?
The ATTiny1614 has 2 16-bit timers and I was wondering what you need for New Ping to work?
Amadeus
Comments (9)
-
-
repo owner And does this work?
I believe the problem with the ATTiny 1 series is that it uses a totally different method of addressing the timers. This makes it “not standardized”. Therefore, you can't just say the processor is compatible, you would need to totally rework ALL of the timer commands to specifically work for this microcontroller.
So again, are you submitting code which have tested as working, or are you just guessing this would work? Only tested code should be submitted to a repo.
Further, I hope you know that you do NOT need timers at all for NewPing to work with the non-timer methods like ping(), ping_cm() and ping_median(). There seems to be this misconception that you need timers when you only need timers if you're using an event-driven programming paradigm, which almost no one uses. Most Arduino programmers use a blocking-mode programming paradigm, in which case you absolutely shouldn't be using timers at all or your code probaby won't do what you want.
So 2 questions: Why do you think you need timers for NewPing and have you tested the commit you submitted to this repo? As I don't have a ATTiny 1 series microcontroller, I'll need to wait for your answer.
-
- No need for timers, just curious about the phrasing “standardised”
- Yes, added a link in the PR to working code
-
repo owner What sketch did you use to test the PR?
-
repo owner By the looks of the documentation, the ATTiny 1 series doesn’t use these ATMega standardized registers used for timers:
OCR2A
TIMSK2
ASSR
TCCR2A
TCCR2B
TCNT2
So I’m not sure how it would work, unless the library for the ATTiny 1 series re-addresses everything. But still, the values may be different if the bits or options have changed. It just doesn’t seem that timer methods would work on this microcontroller without hard-coding new timer code specific to this microcontroller (like what has been done with the
ATmega32U4
). -
https://github.com/amadeuspzs/TinyTX/blob/main/software/HC-SR04/HC-SR04.ino
Can confirm the
ping_median
() method works.In the sketch I add the following caveat:
/* For the ATTiny1614 the following methods are unavailable: ping_timer(), check_timer(), timer_us(), timer_ms() & timer_stop() */
-
repo owner ping_median() doesn't use timers.
-
Yes; and New Ping doesn’t compile on ATTiny1614 without
#define TIMER_ENABLED false
The PR is to enable support for ATTiny1614, not of the timer functions, but of the non-timer functions.
Without setting
#define TIMER_ENABLED false
on the ATTiny1614, when trying to useping_median()
you get:
/Users/amadeus/Documents/Arduino/libraries/RFM69/RFM69_OTA.cpp: In function 'uint8_t sendHEXPacket(RFM69&, uint16_t, uint8_t*, uint8_t, uint16_t, uint16_t, uint16_t, uint8_t)': /Users/amadeus/Documents/Arduino/libraries/RFM69/RFM69_OTA.cpp:513:59: warning: format '%hu' expects argument of type 'short unsigned int*', but argument 3 has type 'uint16_t* {aka unsigned int*}' [-Wformat=] sscanf((const char*)radio.DATA, "FLX:%hu:OK", &tmp); ~~~~^ /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp: In static member function 'static void NewPing::timer_us(unsigned int, void (*)())': /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp:254:3: error: 'OCR2A' was not declared in this scope OCR2A = min((frequency>>2) - 1, 255); // Every count is 4uS, so divide by 4 (bitwise shift right 2) subtract one, then make sure we don't go over 255 limit. ^~~~~ In file included from /Users/amadeus/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.5.11/cores/megatinycore/api/ArduinoAPI.h:52:0, from /Users/amadeus/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.5.11/cores/megatinycore/Arduino.h:23, from /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.h:152, from /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp:7: /Users/amadeus/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.5.11/cores/megatinycore/api/Common.h:35:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] _a < _b ? _a : _b; }) ~~~^~~ /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp:254:11: note: in expansion of macro 'min' OCR2A = min((frequency>>2) - 1, 255); // Every count is 4uS, so divide by 4 (bitwise shift right 2) subtract one, then make sure we don't go over 255 limit. ^~~ /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp:255:3: error: 'TIMSK2' was not declared in this scope TIMSK2 |= (1<<OCIE2A); // Enable Timer2 interrupt. ^~~~~~ /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp:255:3: note: suggested alternative: 'TIMERB2' TIMSK2 |= (1<<OCIE2A); // Enable Timer2 interrupt. ^~~~~~ TIMERB2 /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp:255:17: error: 'OCIE2A' was not declared in this scope TIMSK2 |= (1<<OCIE2A); // Enable Timer2 interrupt. ^~~~~~ /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp: In static member function 'static void NewPing::timer_ms(long unsigned int, void (*)())': /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp:274:3: error: 'OCR2A' was not declared in this scope OCR2A = 249; // Every count is 4uS, so 1ms = 250 counts - 1. ^~~~~ /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp:275:3: error: 'TIMSK2' was not declared in this scope TIMSK2 |= (1<<OCIE2A); // Enable Timer2 interrupt. ^~~~~~ /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp:275:3: note: suggested alternative: 'TIMERB2' TIMSK2 |= (1<<OCIE2A); // Enable Timer2 interrupt. ^~~~~~ TIMERB2 /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp:275:17: error: 'OCIE2A' was not declared in this scope TIMSK2 |= (1<<OCIE2A); // Enable Timer2 interrupt. ^~~~~~ /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp: In static member function 'static void NewPing::timer_stop()': /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp:286:3: error: 'TIMSK2' was not declared in this scope TIMSK2 &= ~(1<<OCIE2A); ^~~~~~ /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp:286:3: note: suggested alternative: 'TIMERB2' TIMSK2 &= ~(1<<OCIE2A); ^~~~~~ TIMERB2 /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp:286:18: error: 'OCIE2A' was not declared in this scope TIMSK2 &= ~(1<<OCIE2A); ^~~~~~ /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp: In static member function 'static void NewPing::timer_setup()': /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp:311:3: error: 'ASSR' was not declared in this scope ASSR &= ~(1<<AS2); // Set clock, not pin. ^~~~ /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp:311:3: note: suggested alternative: 'SS' ASSR &= ~(1<<AS2); // Set clock, not pin. ^~~~ SS /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp:311:16: error: 'AS2' was not declared in this scope ASSR &= ~(1<<AS2); // Set clock, not pin. ^~~ /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp:311:16: note: suggested alternative: 'A2' ASSR &= ~(1<<AS2); // Set clock, not pin. ^~~ A2 /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp:312:3: error: 'TCCR2A' was not declared in this scope TCCR2A = (1<<WGM21); // Set Timer2 to CTC mode. ^~~~~~ /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp:312:16: error: 'WGM21' was not declared in this scope TCCR2A = (1<<WGM21); // Set Timer2 to CTC mode. ^~~~~ /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp:313:3: error: 'TCCR2B' was not declared in this scope TCCR2B = (1<<CS22); // Set Timer2 prescaler to 64 (4uS/count, 4uS-1020uS range). ^~~~~~ /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp:313:16: error: 'CS22' was not declared in this scope TCCR2B = (1<<CS22); // Set Timer2 prescaler to 64 (4uS/count, 4uS-1020uS range). ^~~~ /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp:314:3: error: 'TCNT2' was not declared in this scope TCNT2 = 0; // Reset Timer2 counter. ^~~~~ In file included from /Users/amadeus/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.5.11/cores/megatinycore/Arduino.h:26:0, from /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.h:152, from /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp:7: /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp: In function 'void TIMER2_COMPA_vect()': /Users/amadeus/Documents/Arduino/libraries/NewPing/src/NewPing.cpp:337:6: warning: 'TIMER2_COMPA_vect' appears to be a misspelled 'signal' handler, missing '__vector' prefix [-Wmisspelled-isr] ISR(TIMER2_COMPA_vect) { ^ exit status 1 Error compiling for board ATtiny3224/1624/1614/1604/824/814/804/424/414/404/214/204.
-
repo owner - changed status to resolved
PR merged
- Log in to comment
I have tried adding
to https://bitbucket.org/teckel12/arduino-new-ping/src/10899d084c83a6096872b68e8f4e6a8e2d5ed3a8/src/NewPing.h#lines-209