View previous topic :: View next topic |
Author |
Message |
KaiT
Joined: 20 Nov 2016 Posts: 2
|
Posted: Mon Nov 21, 2016 7:09 pm Post subject: Waitms doesn't work on ATtiny20 |
|
|
Hi,
For some reason I can't get Waitms, Wait or Delay to work on ATtiny20. No matter what I do, the MCU gets stuck on Waitms (or Wait or Delay) command. Here is a small example code:
$regfile = "ATtiny20.DAT"
$crystal = 8000000
Config Portb.1 = Output
Reset Portb.1
Do
Set Portb.1
Waitms 1
Reset Portb.1
Waitms 1
Loop
End
With this code the MCU gets stuck on the first Waitms command. It doesn't matter if the variable is 1 or 1000 or something in between.
If I remove both Waitms commands, then the code flows nicely and I can see the pin pulsing with an oscilloscope.
Can anyone see something wrong with the code example? Is there something I have forgot to put in there? Or could the problem lay perhaps in the ATtiny20.DAT file?
I am using the demo version (2.0.7.5). Could this be the reason?
(BASCOM-AVR version : 2.0.7.5 , Latest : 2.0.7.8 ) |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Mon Nov 21, 2016 8:42 pm Post subject: |
|
|
These sort of Tinys have a reduced register- and instruction-set, the attiny20.dat will allow some fundamental code, but the compiler seems not to be adapted to this controller.
To adapt it - at least I assume that - makes no sense in regards of cost effectiveness, too much efforts and too little use.
The reason why Waitms won't work: it uses the SBIW opcode, which the ATTiny doesn't know. It can be fixed by rewriting the _waitms routine, include it in a lib and such replace the failing waitms.
But - there is more trouble ahead, for example the read-command, it uses processor registers R8/R9, which simply do not exist in ATTiny20. And so it goes...
Translated: forget it or use Bascom only as framework to program the chip in assembler. |
|
Back to top |
|
|
KaiT
Joined: 20 Nov 2016 Posts: 2
|
Posted: Tue Nov 22, 2016 6:07 am Post subject: |
|
|
Thanks so much for the quick answer. That's a real drag having to change the MCU because most probably I will have to change the PCB layout as well.
Would you have a suggestion for the next MCU? I'm looking for something very small and cheap from Atmel. It needs to have only 5-6 GPIOs and two PWM channels. And most importantly it would have to be 100% compatible with Bascom.
Do you know if ATtiny13A or ATtiny24A/44A would have all the necessary registers? I tried to find registers R8 and R9 from the Register Summary but there were nothing named liked that. |
|
Back to top |
|
|
Visovian
Joined: 31 Oct 2007 Posts: 584 Location: Czech
|
Posted: Tue Nov 22, 2016 8:01 am Post subject: |
|
|
Quote: | I tried to find registers R8 and R9 from the Register Summary but there were nothing named liked that. |
In the Register sumary there are only IO registers.
R0, R1 ... R31 are General purpose working registers.
Attiny 20 has only R16 to R31. See Figure 4-2. AVR CPU General Purpose Working Registers in the datasheet. |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Tue Nov 22, 2016 10:18 am Post subject: |
|
|
KaiT wrote: |
Would you have a suggestion for the next MCU? I'm looking for something very small and cheap from Atmel. |
Attiny 24/44/84 are pin compatible.
They have the SBIW opcode and 32 general registers.
For pwm, IO and Bascom compatibility, read the datasheet to be sure. _________________ www.evertdekker.com Bascom code vault |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
Posted: Tue Nov 22, 2016 10:42 am Post subject: |
|
|
hi,
take care to the fuse bits
it can be set to "clock divide by 8" by default !
JP |
|
Back to top |
|
|
|