PWM issue

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

I've been trying to get this code to work. I'm trying to setup PWM so that it triggers at 75, goes to the TOP which is 100, and counts back down and toggles once again at 75. Everything works, save for the fact that instead of going up to 100 and then decrementing, it just clears and restarts at 00 as if it was in the regular compare mode. Please be kind in your help, I'm a bit new at this. Thank you guys for your response :)

;************************************************
;*			Toggle Lights		12/21/07	V1	*
;************************************************


;DESCRIPTION
;
;This program's purpose is to toggle an LED based on a PWM timer.
;
;
;
;
;
;
;DEFINITIONS

.device ATtiny861
.include "C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes\tn861def.inc"
	
.org	$0000	;RESET
	rjmp	RESET


;**** INITIALIZATION **** 

RESET:

	ldi		r16,high(RAMEND);Initialize Stack
	out		SPH,r16			;High Byte
	ldi		r16,low(RAMEND)	;
	out		SPL,r16			;Low Byte


;**** TIMER SETUP **** ;PWM Mode

	ldi		r16,0b01000010	;OC1A Toggle on Compare Match, PWM based on OC1R1A
	out		TCCR1A,r16		;

	ldi		r16,100			;TOP value
	out		OCR1C,r16		;

	ldi		r16,75			;OCR1A PWM value
	out		OCR1A,r16		;

	ldi		r16,0b00000001	;PWM Mode
	out		TCCR1D,r16		;

	ldi		r16,0b00000001	;Prescaler set to 1x
	out		TCCR1B,r16		;

	ser		r16
	out		DDRB,r16		;Set PORTB to OUTPUT


;**** MAIN PROGRAM **** 

MAIN:

	rjmp	MAIN			;Loop forever

NOTE: I'm confident I followed the datasheet exactly, have read the thing over quite a few times, but for some reason its not working. I am simulating this program in Studio 4.

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

Quote:

Everything works, save for the fact that instead of going up to 100 and then decrementing, it just clears and restarts at 00 as if it was in the regular compare mode.

Tell how you know that this is happening. Note that AVRStudio simulator does NOT do all timer modes.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

While I run the simulator in single step mode I view the TIMER1 registers. The output pin toggles when TCNT1 is equal to $4B (100) and $00 (when it resets instead of counts downward). I really hope I haven't been wasting all this time trouble shooting something that never was supported to begin with. The reason why I'm depending on the simulator is because I don't receive my STK500 for another 2 days :\. Is there a list out there that tells what Studio 4 Simulator supports?

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

The is a list of the supported funtions, but there are still some functions that only work partially. Then there is a new simulator for a few of the newer devices that is paned to be more accurate, but so far only supporting a limited number of devices.

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

I ended up programming for the other micro I'm buying and the PWM mode worked great for it (ATmega644). Thanks a ton for the heads up on lack of support for some of the devices.