picbasic e interrupt su dimmer 16f873a

ciao a tutti

sto cercando di creare un dimmer a due canali comandabile sia da pulsante che da 485

per farlo sto usando un pic16f873a e il picbasic

ho praticamente finito ma ho un piccolo problema... riesco a fare le rampe di salita e discesa correttamente usando portb.0 per per lo "zero crossing" e il tmr0 e tmr1 per il conteggio per l'accensione e funzionano. appena però comunico con la la luce sfarfalla. come se non agganciasse un interrupt correttamente. ovviamente ho fatto tutta la gestione degli interrupt in assembler ma non cambia nulla

vi allego il sorgente così magari mi aiutate...

'Variables for saving state in interrupt handler wsave VAR BYTE $70 system ' Saves W ssave VAR BYTE bank0 system ' Saves STATUS psave VAR BYTE bank0 system ' Saves PCLATH fsave VAR BYTE bank0 system ' Saves FSR

PROTBUFFER_SIZE CON 30

PROTREAD0 VAR BYTE[30] PROTOUT0 VAR BYTE[30] PROTOUTLEN var word PROTINDEX VAR BYTE bank0 PROTINDEX_OUT VAR BYTE bank0 BUFFRECEIVE VAR BYTE bank0

errflag VAR BYTE bank0 ' Error flag

'' Define interrupt handler 'DEFINE INTHAND myint

GoTo EndInterrupt ' Skip around interrupt handler

' Assembly language INTERRUPT handler MY_INT_HANDLER: Asm myint

; Save the FSR value for later

movf FSR, W ; Move FSR to W movwf fsave ; Save FSR

btfss pir1,5 GoTo TESTLAMP

comm ; Find in which bank the compiler put buffer, and set IRP IF (_PROTREAD0 > 0FFh) ; Find the bank where buffer is located bsf STATUS,IRP ; If bank 2 or 3 set IRP Else bcf STATUS,IRP ; If bank 0 or 1 clear IRP EndIF

; Check for hardware overrun error btfsc RCSTA,OERR ; Check for usart overrun GoTo usart_err ; jump to assembly error routine ; Test for buffer overrun clrf _BUFFRECEIVE; clrf _PROTTIMEOUT; incf _PROTINDEX, W ; Increment index_in to W subwf _PROTBUFFER_SIZE-1, W ; Subtract indexes to test for buffer overrun btfsc STATUS,Z ; check for zero (index_in = index_out) GoTo buffer_err ; jump to error routine if zero

; Increment the index_in pointer and reset it if it's outside the ring buffer incf _PROTINDEX, F ; Increment index_in to index_in movf _PROTINDEX, W ; Move new index_in to W sublw _PROTBUFFER_SIZE-1 ; Subtract index_in from buffer_size-1

; Set FSR with the location of the next empty location in buffer movlw Low _PROTREAD0 ; Get the location of buffer[0] addwf _PROTINDEX, W ; Add index_in to point to next empty slot movwf FSR ; Store pointer in FSR

; Read and store the character from the USART movf RCREG, W ; Read the received character movwf INDF ; Put the received character in FSR location

bcf pir1,5 bsf _BUFFRECEIVE,1

movf fsave, W ; retrieve FSR value movwf FSR ; Restore it to FSR

goto finished

TESTLAMP btfss intcon,1 GoTo TESTLAMP0

bcf pir1,0 bsf intcon,5 bsf intcon,6 bcf Intcon,1 bcf Intcon,2

movf _DIMM0VAL,W movwf TMR0

movf _DIMM1VALL,W movwf TMR1L movf _DIMM1VALH,W movwf TMR1H

bcf _DIMM0 bcf _DIMM1

goto finished

TESTLAMP0

btfss intcon,2 GoTo TESTLAMP1

bcf Intcon,2 btfss _DIMM_ENABLED,0 GoTo finished

bsf _DIMM0 goto finished TESTLAMP1

bcf pir1,0 btfss _DIMM_ENABLED,1 GoTo finished

bsf _DIMM1 goto finished

; Restore FSR, PCLATH, STATUS and W registers finished

;btfsc pir1,5 ;GoTo comm

btfsc intcon,1 GoTo TESTLAMP

btfsc intcon,2 GoTo TESTLAMP0

btfsc pir1,0 GoTo TESTLAMP1

;bsf intcon,7 retfie ; Return from the interrupt ; Error routines buffer_err ; Jump here on buffer error bsf _errflag,1 ; Set the buffer flag usart_err ; Jump here on USART error bsf _errflag,0 ; Set the USART flag movf RCREG, W ; Trash the received character GoTo finished ; Restore state and return to program

EndAsm

vi ringrazio e se avete dubbi chiedete pure. grazie ciao Marco

Reply to
marco
Loading thread data ...

Darti una mano senza tutto l'ambaradan in mano non è facile.. ma..." l'istruzione IF (_PROTREAD0 > 0FFh)" è all'interno dell' interrupt service routine ?

Mi sembra evidente se comunichi con la luce probabilmente qualcosa fa saltare i timing della routine di interrupt...mentre se fai tutto con un pulsante diretto funziona bene vero ? io proverei a cambiare il baudrate della seriale magari rallentandola e vedere se cambia qualcosa... X La gestione della seriale, anche se 485, hai usato hserin (o serin) o hai fatto un protocollo tu ? Ciao, Riccardo.

"marco" ha scritto nel messaggio news:171Kf.3161$ snipped-for-privacy@twister2.libero.it...

per

e

overrun

Reply to
68000 Riccardo

io sto comunicando a 19200 e ho usato un protocollo mio in asm. una pARTE DEL CODICE MEMORIZZA I BYTE CHE ARRIVANO IN UN ARRAY CHE PROCESSO IN SEGUITO.

MANCAVA IL SALVATAGGIO E RIPRISTINO DELLE VARIABILI:

SALVATAGGIO: movf FSR, W ; Move FSR to W movwf fsave ; Save FSR

RIPRISTINO: MOVF fsave,W ; Restore the FSR reg MOVWF FSR

Movf psave,w ; Restore the PCLATH reg Movwf PCLATH swapf ssave,w ; Restore the STATUS reg movwf STATUS swapf wsave,f swapf wsave,w ; Restore W reg Retfie ; Exit the interrupt routine

NON è CHE MANCA QUALCHE COSA DA SALVARE?

"68000 Riccardo" ha scritto nel messaggio news:De2Kf.185085$ snipped-for-privacy@twister1.libero.it...

hai

pulsante

l'accensione

non

Reply to
marco

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.