Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Attiny841 strange behaviour in Bascom
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
Meister

Bascom Member



Joined: 27 May 2010
Posts: 319

blank.gif
PostPosted: Mon Apr 28, 2014 9:46 am    Post subject: Attiny841 strange behaviour in Bascom Reply with quote

Hi,
I am now trying to get an Attiny841 application working. Because of the many Timers and Port options I hoped that might replace two other Tinys that are used presently.
Since examples are rare and rather written in C (but working) I started with programming in C and using CodevisionAVR (eval). With that I could get the timers (CTC and PWM modes) working as they should. Then I converted the Port and Register settings to Bascom directives and got that:
Code:
$regfile = "attiny841.dat"
$crystal = 8000000
$hwstack = 40
$swstack = 16
$framesize = 32
'$baud = 57600

'Disable Interrupts
Puea = 0
Porta = 0
Tocpmcoe = &B0011_1110
Ddra = &B0011_1100
Tccr0a = &B0101_0010
Tccr0b = &B0000_0001
Set Tccr0b.6
Tcnt0 = 0
Ocr0a = &H03
Ocr0b = Ocr0a
Tocpmsa0 = 0
Tocpmsa1 = &B0000_1010
'Do

'Loop
'End

That program is not doing right. The most interesting feature is that the high-frequency pulse outputs are chopped with a 29Hz frequency. Using the C-code the HF-pulses are continous.

The core of the problem seems to be related to this:
Commenting out anything but the DDRA= line there is a continous output of that 29Hz.
So just setting the DDR register causes a pulsed output of 29Hz.
Maybe somebody has a suggestion on what is going wrong.
Regards, Meister

(BASCOM-AVR version : 2.0.7.7 )
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Mon Apr 28, 2014 10:02 am    Post subject: Reply with quote

this is a new supported chip. i did not even received the samples from atmel. you should do 2 things :
- check if programming works (use verify). it could be a setting for your programmer is not right.
- if it works with C, check the registers that are set. and also, try if setting DDRA in your C code gives the same problem!

_________________
Mark
Back to top
View user's profile Visit poster's website
Meister

Bascom Member



Joined: 27 May 2010
Posts: 319

blank.gif
PostPosted: Mon Apr 28, 2014 11:46 am    Post subject: Reply with quote

Hi, thanks.
Quote:
- check if programming works (use verify). it could be a setting for your programmer is not right.
- if it works with C, check the registers that are set. and also, try if setting DDRA in your C code gives the same problem!

Programming always verifies (Studio6.2) and is ok.
This Bascom Code gives 29Hz on PA3 and PA4:
The same in C-code puts out nothing (0) as it should be.
Code:
$regfile = "attiny841.dat"
$crystal = 8000000
$hwstack = 40
$swstack = 16
$framesize = 32
Disable Interrupts
Ddra = &B1111_1111


Strange 29Hz.
Regards, Meister
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Mon Apr 28, 2014 12:19 pm    Post subject: Reply with quote

the code you show here is simple :
Cli ; disable global interrupts

Ldi R23,$FF
Out $001A,R23

that can never be the problem.

_________________
Mark
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Mon Apr 28, 2014 12:20 pm    Post subject: Reply with quote

of course you need to insert an END but i guess you did.
_________________
Mark
Back to top
View user's profile Visit poster's website
Meister

Bascom Member



Joined: 27 May 2010
Posts: 319

blank.gif
PostPosted: Mon Apr 28, 2014 12:30 pm    Post subject: Reply with quote

Right, there was an "End". Just had stopped selcting above that line.
But my previous tests showed that there is no difference with End or not with End.
I agree, that assembler code won't be harmful.
So there should be happening something more...
Regards, Meister
Back to top
View user's profile
Meister

Bascom Member



Joined: 27 May 2010
Posts: 319

blank.gif
PostPosted: Mon Apr 28, 2014 12:34 pm    Post subject: Reply with quote

Without the DDRA= ... the outputs are quiet.
In this Chip the outputs are muxed to several pins. Maybe the problem comes from that.
Regards, Meister


Last edited by Meister on Mon Apr 28, 2014 12:37 pm; edited 1 time in total
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Mon Apr 28, 2014 12:37 pm    Post subject: Reply with quote

there is not much more.

stack is set up
watchdog is disabled
ram is cleared. (try $noramclear)

that is it.

_________________
Mark
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Mon Apr 28, 2014 12:40 pm    Post subject: Reply with quote

like i said :
;##### DDRA = &B1111_1111
Ldi R23,$FF
Out $001A,R23

I can not imagine that is wrong. But as i asked before : if you do that in C , you do not get the problem?
show the C code. and possible the asm it create for setting ddr.
beside from the register i can not imagine it can be done otherwise.

atmel inc file : .equ DDRA = 0x1A ;
so the address is right.

maybe the code also set the PORT ?

_________________
Mark
Back to top
View user's profile Visit poster's website
Meister

Bascom Member



Joined: 27 May 2010
Posts: 319

blank.gif
PostPosted: Mon Apr 28, 2014 12:42 pm    Post subject: Reply with quote

The full code with $noramclear (doesn't help).
Code:
$regfile = "attiny841.dat"
$crystal = 8000000
$hwstack = 40
$swstack = 16
$framesize = 32
'$baud = 57600
 $noramclear
Disable Interrupts
'Puea = 0
'Porta = 0
'Tocpmcoe = &B0000_0000
Ddra = &B1111_1111
'Tccr0a = &B0101_0010
'Tccr0b = &B0000_0001
'Set Tccr0b.6
'Tcnt0 = 0
'Ocr0a = &H03
'Ocr0b = Ocr0a
'Tocpmsa0 = 0
'Tocpmsa1 = &B0000_1010
'Do

'Loop
End

Regards, Meister
Back to top
View user's profile
Meister

Bascom Member



Joined: 27 May 2010
Posts: 319

blank.gif
PostPosted: Mon Apr 28, 2014 1:18 pm    Post subject: Reply with quote

Very strange. I have a Logicanalyser connected to PA3 and PA4. Then I get the 29Hz pulses when using the Bascom Code. I do not get those pulses when using the equivalent C-Code.
Now, I disconnect the Logicanalyzer. Then (on oscilloscope) the pulses disappear -and come back when reconnecting. The LA-Input disconnected outputs 3V. So probably those are working against eachother. But a LA is legitimate to be connected, its impedance should not be low.

So the Port settings must be different between the Bascom and the C-Program.

Any further help appreciated, Meister
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Mon Apr 28, 2014 1:27 pm    Post subject: Reply with quote

the real strange thing is that i asked for the C code and the asm but still did not get it. how can i compare it than?
are you aware that this tiny uses the PUD for pull up?

_________________
Mark
Back to top
View user's profile Visit poster's website
Meister

Bascom Member



Joined: 27 May 2010
Posts: 319

blank.gif
PostPosted: Mon Apr 28, 2014 1:28 pm    Post subject: Reply with quote

The C-program:
Code:

#include <tiny841.h>
//#include <io.h>

void main(void)
{
DDRA=0xff ;


while (1)
    {
    // Please write your application code here

    }
}
 

Assembler attached.
Regards, Meister
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Mon Apr 28, 2014 1:38 pm    Post subject: Reply with quote

that code does not do a thing.
better load it in studio and have a look there at the asm.
the text you sent is all remarked. so it is the same as doing in bascom

' DDRA=&HFF
^ notice the remark. this will give the same effect in bascom

_________________
Mark
Back to top
View user's profile Visit poster's website
Meister

Bascom Member



Joined: 27 May 2010
Posts: 319

blank.gif
PostPosted: Mon Apr 28, 2014 2:43 pm    Post subject: Reply with quote

Hi Mark,
I try to summerize up to this point:
In my first post I had posted a code that produced those 29Hz chopped HF pulse trains.
That was line by line translated from C, including the PUE register.
Unlike the C-program, only the Bascom output was chopped.
However, the PUE register setting can be omitted in the C-program and everything still works.

Then I stripped down the code to just the DDRA=.. line (so, doing "nothing").
But already with that we have different results with the C and Bascom (getting 29Hz pulses when the LA is connected to the pins, with Bascom-code, not with C).

Here is the Assembler code from the C-code obtained from Studio.
Code:
--- No source file -------------------------------------------------------------
0000001E  RJMP PC-0x001E                Relative jump
0000001F  CLI           Global Interrupt Disable
00000020  CLR R30               Clear Register
00000021  OUT 0x1C,R30          Out to I/O location
00000022  OUT 0x35,R30          Out to I/O location
00000023  LDI R24,0x0D          Load immediate
00000024  LDI R26,0x02          Load immediate
00000025  CLR R27               Clear Register
00000026  ST X+,R30             Store indirect and postincrement
00000027  DEC R24               Decrement
00000028  BRNE PC-0x02          Branch if not equal
00000029  LDI R24,0x00          Load immediate
0000002A  LDI R25,0x02          Load immediate
0000002B  LDI R26,0x00          Load immediate
0000002C  LDI R27,0x01          Load immediate
0000002D  ST X+,R30             Store indirect and postincrement
0000002E  SBIW R24,0x01         Subtract immediate from word
0000002F  BRNE PC-0x02          Branch if not equal
00000030  LDI R30,0x00          Load immediate
00000031  OUT 0x13,R30          Out to I/O location
00000032  OUT 0x14,R30          Out to I/O location
00000033  OUT 0x15,R30          Out to I/O location
00000034  SER R30               Set Register
00000035  OUT 0x3D,R30          Out to I/O location
00000036  LDI R30,0x02          Load immediate
00000037  OUT 0x3E,R30          Out to I/O location
00000038  LDI R28,0x80          Load immediate
00000039  LDI R29,0x01          Load immediate
0000003A  RJMP PC+0x0001                Relative jump
--- D:\cvavreval\Attiny841\Attiny841baretest.c ---------------------------------
DDRA=0xff ;
0000003B  SER R30               Set Register
--- D:\cvavreval\Attiny841\Attiny841baretest.c ---------------------------------
0000003C  OUT 0x1A,R30          Out to I/O location
    {
0000003D  RJMP PC-0x0000                Relative jump


Thank you for help. Regards, Meister
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum