??? 11/22/06 09:18 Read: times |
#128405 - This Code Works ! Responding to: ???'s previous message |
Dear Russell,
No harm done like mentioned earlier. It's water under the bridge, and life must go on. I've attached a new set of codes which has produced the ultimate solution desired, since you was the kindest in giving a helping hand. With this code, I've managed to get a linear ramp-up frequency which is fed into a panasonic servo amplifier. My only problem now is that the ramp is so steep & changing the number of pulses does not reduce the steep. This code is posted as soon result materialized. Now I'm looking at whats causing the steep ramp-up from 1Khz ~ 10Khz ( same even if frequency is higher )& which cannot be reduced despite attempt to increase the number of pulses per Khz. MAIN: ACALL PCA_INIT SJMP $ ; Only for testing PCA_INIT: ;Initializa PCA Timer MOV CMOD,#02H ; Input to PCA Timer = 1/4 * Fosc MOV CH,#00 MOV CL,#00 MOV CCAPM0,#04DH ; HSO with Interrupt Enabled MOV CCAP0L,#.LOW(1000) ; Not sure what this does !!!!! MOV CCAP0H,#.HIGH(1000) ; Not sure what this does !!!!! CLR P1.3 SETB EC ; Enable PCA Interrupt SETB EA SETB CR MOV PULSE_COUNTER,#0 ; ACTUAL PULSES PRODUCED MOV PULSES,#250 ; PULSES DESIRED MOV A,PULSES MOV B,#02H ; PCA TIMESOUT EVERY 500us ( HOWEVER two 500uS timeouts makes 1 pulse ) MUL AB MOV .LOW(PULSES),A MOV .HIGH(PULSES),B ; Now Pulse Counter Holds correct pulses needed MOV TABLE_POINTER,#0 RET PCA_INTERRUPT: CLR CCF0 CONT_INIT: PUSH ACC PUSH PSW PUSH DPH PUSH DPL PUSH B MOV A,TABLE_POINTER ; POINT TO DESIRED FREQ VALUE CLR C RL A mov dptr,#FREQ_TABLE movc a,@a+dptr ;get low byte mov b,a ;save low into B mov a,TABLE_POINTER clr c rl a inc a ;+1 movc a,@a+dptr ;get high byte CLR EA ADD A,CCAP0L ; ---- MOV CCAP0L,A ; | MOV A,B ; > generated the actual pulse ADDC A,CCAP0H ; | MOV CCAP0H,A ; ---- ISR_1: DJNZ PULSES,DONE INC TABLE_POINTER ; collect next freq MOV A,TABLE_POINTER CJNE A,#10,FREQ_RAMP SJMP KILL_PCA ; 10 FREQ REACHED - END OF FREQ TABLE, KILL PCA FREQ_RAMP: MOV PULSES,#250 ; PULSES DESIRED MOV A,PULSES MOV B,#02H ; PCA TIMESOUT EVERY 500us ( HOWEVER two 500uS timeouts makes 1 pulse ) MUL AB MOV .LOW(PULSES),A MOV .HIGH(PULSES),B ; Now Pulse Counter Holds correct pulses needed MOV A,PULSES CJNE A,#0,DONE KILL_PCA: MOV CCAPM0,#00H DONE: INC PULSE_COUNTER BIT_HIGH: SETB EA POP B POP DPL POP DPH POP PSW POP ACC RETI FREQ_TABLE: .DCW 3125,1563,1042,781, 625,521 ,446,391,343,313 ; 1 ~ 10Khz ; .DCW 284,260,240,223,208,195,184,174,164,156 ; 11~ 20Khz ; .DCW 142,136,130,125,120,116,112,108,104,101 ; 21~ 30KHZ .aseg __data,data .org 20H TABLE_POINTER .DSB PULSES .DSB GENERATOR .DSB PULSE_COUNTER .DSB .end |