I am working on a project and am having a little difficulty with it. What the below section of code does is fill up a block of SRAM (32k) with a repeating pattern of 16bit values representing a sine wave. (Example The pattern 1, 2, 3, 4 is put into the ram like: 1, 2, 3, 4, 1, 2, 3, 4, 1, 2.)
I suspect most of my confusion is with the internal locations needing to be multiplied by 2 which I don’t really understand fully yet.
It currently causes the microcontroller to freeze.
I’m wondering if anyone could help me figure this out,
;Parameters used: ;X: High and low data ;Y: SRAM Address and Address+1 ;Z: Program memory pointer Init_SRAM: clr YH clr YL Restart: ldi ZL, LOW(2*Sine_Data) ldi ZH, HIGH(2*Sine_Data) Repeat: lpm XH, Z+ lpm XL, Z rcall Write_SRAM adiw R30, 0x01 cpi YH, 0x7F ;SRAM end check brne Cont cpi YH, 0xFE breq Sub_done Cont: cpi XH, 0x00 ;Data block end check brne Repeat cpi XL, 0x00 brne Repeat rjmp Restart Sub_Done: rjmp Done Sine_Data: .dw 286, 572, 858, 1144, 1429, 1715, 2000, 2286, 2571, 2856, 3141, 3425, 3709, 3993, 4277, 4560, 4843, 5126, 5408, 5690 .....(lots of values) .dw -5408, -5126, -4843, -4560, -4277, -3993, -3709, -3425, -3141, -2856, -2571, -2286, -2000, -1715, -1429, -1144, -858, -572, -286, 0 A few notes on the program: The Sub_Done label and jump is used because the breq instruction cannot jump the distance required. Writing the SRAM involves a routine called Write_SRAM. This routine works because I have been using it quite extensively over the past few months. It uses the values contained in X and Y to function as well as arranging the 16bit values in the way I require.