Did a detailed analysis of how MIBAM affects pause and general code execution at PIC16F1936 running at 32mhz and with 13 BAM outputs.
This is the simple code, and output is monitored with scope.
Code:
;----[16F1937 Hardware Configuration]-------------------------------------------
#IF __PROCESSOR__ = "16F1936"
#DEFINE MCU_FOUND 1
#CONFIG
cfg1 = _FOSC_INTOSC ; INTOSC oscillator: I/O function on CLKIN pin
cfg1&= _WDTE_OFF ; WDT disabled
cfg1&= _PWRTE_OFF ; PWRT disabled
cfg1&= _MCLRE_OFF ; MCLR/VPP pin function is digital input
cfg1&= _CP_ON ; Program memory code protection is enabled
cfg1&= _CPD_OFF ; Data memory code protection is disabled
cfg1&= _BOREN_OFF ; Brown-out Reset disabled
cfg1&= _CLKOUTEN_OFF ; CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
cfg1&= _IESO_ON ; Internal/External Switchover mode is enabled
cfg1&= _FCMEN_ON ; Fail-Safe Clock Monitor is enabled
__CONFIG _CONFIG1, cfg1
cfg2 = _WRT_OFF ; Write protection off
cfg2&= _VCAPEN_OFF ; All VCAP pin functionality is disabled
cfg2&= _PLLEN_ON ; 4x PLL disabled
cfg2&= _STVREN_ON ; Stack Overflow or Underflow will cause a Reset
cfg2&= _BORV_19 ; Brown-out Reset Voltage (Vbor), low trip point selected.
cfg2&= _LVP_OFF ; High-voltage on MCLR/VPP must be used for programming
__CONFIG _CONFIG2, cfg2
#ENDCONFIG
#ENDIF
;----[Verify Configs have been specified for Selected Processor]----------------
; Note: Only include this routine once, after all #CONFIG blocks
#IFNDEF MCU_FOUND
#ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
#ENDIF
ADCON1=%11110011 'enable adc internal reference and justify
FVRCON=%11001111 'set internal reference to 4.096V
'OSCCON=%01111000 'SET INTOSC TO 16MHZ
OSCCON=%11110000 'SET INTOSC TO 16MHZ
ANSELA=%00000000 'disable ADC on A
ANSELB=%00000000 'disable ADC on B
TRISC=%00000000 'set PORTC as output all
TRISB=%00000000 'set PORTB as output all
TRISA=%00000000 'set PORTA 2 as input, others as output
TRISE=%00000000 'set PORTE as output all
WPUB=%00000000 'DISABLE B PULL UPS
OPTION_REG=%100000000
LCDCON=%00000000 'disable LCD controller pins
LCDSE0=%00000000
LCDSE1=%00000000
;____[ For 12F/16F only - Interrupt Context save locations]_________________
wsave var byte $20 SYSTEM ' location for W if in bank0
'wsave var byte $70 SYSTEM ' Alternate save location for W
' if using $70, comment out wsave1-3
' --- IF any of these next three lines cause an error ?? -------------------
' Comment them out to fix the problem ----
' -- The chip being used determines which variables are needed -------------
wsave1 VAR BYTE $A0 SYSTEM ' location for W if in bank1
wsave2 VAR BYTE $120 SYSTEM ' location for W if in bank2
wsave3 VAR BYTE $1A0 SYSTEM ' location for W if in bank3
'---DO NOT change these-----------------------------------------------------
ssave VAR BYTE BANK0 SYSTEM ' location for STATUS register
psave VAR BYTE BANK0 SYSTEM ' location for PCLATH register
;----[ MIBAM Setup ]--------------------------------------------------------
BAM_COUNT CON 13 ; How many BAM Pins are used?
INCLUDE "MIBAM.pbp" ; Mirror Image BAM module
DEFINE OSC 32 'set oscillator speed
'DIGIT PINS
D0 VAR BYTE
D1 VAR BYTE
D2 VAR BYTE
D3 VAR BYTE
D4 VAR BYTE
D5 VAR BYTE
D6 VAR BYTE
D7 VAR BYTE
D8 VAR BYTE
D9 VAR BYTE
DF VAR BYTE 'TEMPERATURE SIGN
DT1 VAR BYTE 'DOTS
DT2 VAR BYTE
eval var byte 'eeprom reader
ELOC VAR BYTE 'EEPROM LOCATION
ASM
BAM_LIST macro ; Define PIN's to use for BAM
BAM_PIN (PORTB,3, D0)
BAM_PIN (PORTA,0, D1)
BAM_PIN (PORTB,4, D2)
BAM_PIN (PORTC,4, D3)
BAM_PIN (PORTB,5, D4)
BAM_PIN (PORTC,7, D5)
BAM_PIN (PORTB,2, D6)
BAM_PIN (PORTC,5, D7)
BAM_PIN (PORTB,1, D8)
BAM_PIN (PORTB,0, D9)
BAM_PIN (PORTC,6, DF)
BAM_PIN (PORTA,3, DT1)
BAM_PIN (PORTA,2, DT2)
endm
BAM_INIT BAM_LIST ; Initialize the Pins
ENDASM
D0=10: D1=10: D2=10: D3=0: D4=10: D5=10: D6=10: D7=10: D8=10: D9=10: DF=10 'set bam ports
mama:
high portc.3
pause 1
low portc.3
pause 1
goto mama
The above code should generate square wave output with 1ms high and 1ms low frequency. It does, but the "high" period slowly increases from 1ms to 1.3ms in several iterations of the loop, while "low" period remains the same. The jitter remains almost the same, and on values of PAUSE 20 and above, becomes almost non-existent.
Based on, that, I've developed a simple "protocol" which appears to be working, and is based on pulse with measurement:
Code:
receiver:
if portc.3=1 then
xcount=xcount+1 'increase counter while pin is high
else
gosub dcder 'go to decoder when it is low
xcount=0 'reset counter
endif
pauseus 1
goto receiver
dcder:
if xcount>10 and xcount<50 then rxvalue=0
if xcount>60 and xcount<100 then rxvalue=1
if xcount>110 and xcount<150 then rxvalue=2
if xcount>160 and xcount<200 then rxvalue=3
if xcount>210 and xcount<250 then rxvalue=4
if xcount>260 and xcount<300 then rxvalue=5
if xcount>310 and xcount<350 then rxvalue=6
if xcount>360 and xcount<400 then rxvalue=7
if rxvalue<>oldvalue then
gosub deco 'send to display
endif
oldvalue=rxvalue
return
This works quite reliably and no issues so far, but it is very slow and is only good as a temporal solution.
So I'm going to redesign PCB and use hardware serial ports on both transmitter and receiver, but will it 100% work? won't be it also affected by MIBAM?
Bookmarks