Atmega16a assembly PWM problem

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

Iam trying to generate a pwm wave on PINB.3 of my atmega16a but my code doesn't work. I am getting 0 volts when I check the PINB.3 of my atmega16a with a multimeter. I have added my code below. Can you tell me if something is wrong with my code?

 

.include "m16adef.inc"

.def temp1 = R19

.def temp2 = r20

.def dummy = r22

 

.cseg

.org 0

 

RJMP RESET

;set portb as output

RESET:

LDI dummy,0b11111111

OUT DDRB, dummy

 

START:

;fast pwm mode, non inverted, no prescaling

LDI temp1,0b01011010

sts TCCR0, temp1

;50% duty cycle

LDI temp2,127

sts OCR0,temp2

 

mainloop:

RJMP mainloop

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

STS -> OUT

Stefan Ernst

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

I replaced STS with OUT but my code still doesn't work. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
;0000 0026 // Port B initialization
;0000 0027 // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=Out Bit2=In Bit1=In Bit0=In
;0000 0028 DDRB=(0<<DDB7) | (0<<DDB6) | (0<<DDB5) | (0<<DDB4) | (1<<DDB3) | (0<<DDB2) | (0<<DDB1) | (0<<DDB0);
	LDI  R30,LOW(8)
	OUT  0x17,R30
	
;0000 0038 // Timer/Counter 0 initialization
;0000 0039 // Clock source: System Clock
;0000 003A // Clock value: 16000.000 kHz
;0000 003B // Mode: Fast PWM top=0xFF
;0000 003C // OC0 output: Non-Inverted PWM
;0000 003D // Timer Period: 0.016 ms
;0000 003E // Output Pulse(s):
;0000 003F // OC0 Period: 0.016 ms Width: 7.9686 us
;0000 0040 TCCR0=(1<<WGM00) | (1<<COM01) | (0<<COM00) | (1<<WGM01) | (0<<CS02) | (0<<CS01) | (1<<CS00);
	LDI  R30,LOW(105)
	OUT  0x33,R30
;0000 0041 TCNT0=0x00;
	LDI  R30,LOW(0)
	OUT  0x32,R30
;0000 0042 OCR0=0x7F;
	LDI  R30,LOW(127)
	OUT  0x3C,R30

 

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

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

Ok it works now. I had to make COM01 "1" and COM00 "0". 

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

sitkitanseltunc wrote:
LDI temp1,0b01011010
sitkitanseltunc wrote:
COM01 "1" and COM00 "0".
That's the problem with uncommented magic numbers...

David (aka frog_jr)