Unwanted fast switching on ATTINY85 output

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MBelow is a simple T85 assembler program to raise Pin3 (PB3). Looking at pin3 with a logic analyser I see a square wave signal switching at around 8uS period. If I change the program to force pin3 low, it goes low as expected. I replaced the assembler with a simple (Arduino) C program and that works as expected. Why am I seeing a switching waveform is it something to do with the way my main loop is executing? Spent most of the day trying to track this down so have tried may things on the way and the code below is now reduced from it's original down to the bare bones. It looks as though setting the pin when it is already set causes it to reset in some way.

.INCLUDE "tn85def.inc" ; Port definitions
.LIST ; Output to list file on
.CSEG
.ORG 0
	rjmp Init

.ORG 52
;
; Define Registers
;
.def TEMP = R16 ;
.equ LED = PB3
.equ CS = PB4

; Program start
;
Init:

	;set pin directions
	sbi DDRB,LED ; output
	cbi DDRB,CS ;input
	sbi PORTB,CS; set pull-up

; Program loop
;
Loop:
	sbi PINB,LED
	rjmp Loop

;
; End

 

This topic has a solution.
Last Edited: Tue. Jul 14, 2020 - 07:20 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Writing to PINB toggles the output.

Please reread the data sheet.
Here's what your code would look like.

 

	sbi PORTB,LED

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I guess you missed this new enhanced feature in newer AVR's!

10.2.2 Toggling the Pin
Writing a logic one to PINxn toggles the value of PORTxn, independent on the value of DDRxn. Note that the SBI
instruction can be used to toggle one single bit in a port.

 

 

Jim

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

*zap* - others can type faster than me.

Last Edited: Tue. Jul 14, 2020 - 07:11 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Must have read over that 10 times today. On its own the first sentence in the para is pretty clear (in retrospect). The second is less so.

 

Anyway, found it. Thank you everyone.