??? 06/24/08 04:00 Read: times |
#156140 - Could use some help with LPC983 PWM code |
Hi All,
I've spent way too much time trying to figure out how to program the P89LPC938 PWM hardware and could use some help from someone with experience. The code below results in a continuous string of "f" characters being sent out the serial port OK and the LED flashes OK but the PWM output pins P1.6 and P1.7 never wiggle and are both at ZERO. I've read the user manual destructions and data sheet untill I'm blue in the face, tried several new chips and double checked the wiring. Must be nmissing something :-) AGC_PWM EQU P1.7 XMITV_PWM EQU P1.6 LED EQU P2.0 MOV P0M1,#00101110b ;x,x,CMP_Ref,x,CMP_V,Sonar_SigV,W_Temp,Tx_Pin MOV P0M2,#00000001b MOV P1M1,#00000000b ;AGC_PWM,XMITV_PWM,x,DE,x,x,RxD,TxD MOV P1M2,#11000001b ;p1.2,p1.3 open drain (must have ext. pullups) clr a MOV P2M1,a ;Port2, mode Quasi Bi-directional MOV P2M2,a MOV P3M1,a ;Port3, mode Quasi Bi-directional MOV P3M2,a dec a ;acc now=0ffh mov p3,a mov p2,a mov p1,a mov p0,a clr Tx_Pin ;xmit OFF clr XMITV_PWM ;XmitPwr 0 vdc clr DE ;Set linea A/B to receive RS485 mov SCON,#01010000b ;8 bit uart, REN=1 rcv enabled mov PCON,#10000000b ;SMOD=1 MOV TCON,#01010101b ;TF1,TR1,TF0,TR0,IntEdge1,IntType1,IE0,IT0 MOV IE,#00000000b ;Global,-,T2,Serial,T1,X1,T0,X0 mov BRGCON,#00000010b ;UART set to use Baud Rate Generator mov BRGR1,#0 ;0,48=115200, 2,240=9600, 5,240=4800 mov BRGR0,#48 ;1,112=19200, 0,176=38400 ;with 7.373Mhz clock mov BRGCON,#00000011b ;enable Baud Rate Generator clr RI MOV SP,#EndVarList-1;Initialize stack pointer into RAM mov a,WDCON clr acc.2 ;Stop Watchdog timer mov WDCON,a MOV WFEED1,#0A5h ;do watchdog feed part 1 MOV WFEED2,#05Ah ;do watchdog feed part 2 setb AGC_PWM ;P1.7 setb XMITV_PWM ;P1.6 mov TPCR2H,#00000000b ;Prescaler mov TPCR2L,#01100011b mov TCR21,#00000110b ;PLLDV=PLL divisor, N. ;PLLFreq=PCLK/(N+1) mov CCCRB,#00000001b ;Enable PWM channel B mov CCCRC,#00000001b ;Enable PWN channel C mov TCR20,#10000000b ;Enable PLL setb AGC_PWM ;P1.7 setb XMITV_PWM ;P1.6 call Dly50mS ;Wait for PLL to lock up mov TOR2H,#00h ;16 bit timer reload value for PWM (Hi Byte) mov TOR2L,#0ffh ;16 bit timer reload value for PWM (Lo Byte) mov TCR21,#10000000b ;Latch in the TOR2H/L values mov OCRBH,#00h ;CCU channel B Compare value (Hi byte) mov OCRBL,#0fh ;CCU channel B Compare value (Lo byte) mov TCR21,#10000000b ;Update duty cycle mov OCRCH,#00h ;CCU channel C Compare value (Hi byte) mov OCRCL,#0fh ;CCU channel C Compare value (Lo byte) mov TCR21,#10000000b ;Update duty cycle mov TCR20,#10000010b ;Asymmetrical PWM setb p1.0 setb p1.1 setb es STAAA: clr TI mov sbuf,#'f' ;Send string of "f"'s to see if HW running jnb TI,$ djnz r0,STAAA call Dly50mS cpl LED jmp STAAA Dly50mS: ;50ms at 7.373Mhz push 2 push 1 push 0 mov r2,#3 DySc: mov r1,#240 DySf: mov r0,#0 djnz r0,$ djnz r1,DySf djnz r2,DySc pop 0 pop 1 pop 2 ret |
Topic | Author | Date |
Could use some help with LPC983 PWM code | 01/01/70 00:00 | |
have you tried CodeArchitect? | 01/01/70 00:00 | |
http://www.codearchitect.org/ | 01/01/70 00:00 | |
Code Architect![]() | 01/01/70 00:00 | |
Code Architect | 01/01/70 00:00 |