PDA

View Full Version : 18f4431 PORT.5 Problem Large automated machine



microcnc05
- 10th April 2020, 17:16
I don't post much but last night I was work on finalizing a hserin interrupt routine for a project I'm working on. I'm using pic18f4431 portb.5 as an output for a buzzer on my main board. I normally just hook my scope to a jumper pin for portb.5 to monitor as a heart beat. Anyway I've used this main board in many projects so I know there are no hardware issues. But for some reason after testing the hserin routine portb.5 stopped working. I've tried everything I know, I wrote a simple program just to toggle portb.5 and portb.6. Portb.5 nothing sitting at zero volts portb.6 10ms square wave. I've tried a new chip as well and I can't seem to get this running. I haven't seen this before but the fact that even a new chip won't work leads me to believe some obscure setting is wrong and can't find it. The crazy thing is that I loaded my original code back to the board and portb.5 no longer works. So it has to be a setting of some sort.

If anyone can help me get this going I'll post a full project and video of a large feed to length automated machine I'm finishing up. Thanks

Little test program:


;----[18F4431 Hardware Configuration]-------------------------------------------
#IF __PROCESSOR__ = "18F4431"
#DEFINE MCU_FOUND 1
#CONFIG
CONFIG OSC=XT, FCMEN=OFF, IESO=OFF, PWRTEN=OFF, BOREN=OFF, BORV=20, WDTEN=OFF
CONFIG WDPS=512, WINEN=OFF, PWMPIN=OFF, LPOL=HIGH, HPOL=HIGH, T1OSCMX=OFF
CONFIG FLTAMX=RC1, SSPMX=RC7, PWM4MX=RD5, EXCLKMX=RC3, MCLRE=ON, STVREN=ON
CONFIG LVP=OFF, DEBUG=OFF, CP0=OFF, CP1=OFF, CP2=OFF, CP3=OFF, CPB=OFF
CONFIG CPD=OFF, WRT0=OFF, WRT1=OFF, WRT2=OFF, WRT3=OFF, WRTC=OFF, WRTB=OFF
CONFIG WRTD=OFF, EBTR0=OFF, EBTR1=OFF, EBTR2=OFF, EBTR3=OFF, EBTRB=OFF
#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



'---[OSCILATORS]----------------------------------------------------------------
DEFINE OSC 8
OSCTUNE = %00000000
OSCCON = %01111000

'---[CAPTURE COMPAIR MODUALS]---------------------------------------------------
CCP1CON = %00000000
CCP2CON = %00000000
'-------------------------------------------------------------------------------
'---[ANALOG CHANELS TO DIGITAL]-------------------------------------------------
ANSEL0 = %00000000
ANSEL1 = %00000000
ADCON0 = %00000000
'---[CONFIGURE PORT]------------------------------------------------------------
TRISB = %00000000
LATB = %00000000
PORTB = %00000000
'-------------------------------------------------------------------------------
'---[ Alias ]-------------------------------------------------------------------
BUZZER VAR PORTB.5
BUZZER2 VAR PORTB.6
'---[ MAIN PROGRAM]-------------------------------------------------------------
MAIN:
TOGGLE BUZZER
TOGGLE BUZZER2
PAUSE 10
GOTO MAIN
END

Dave
- 10th April 2020, 18:21
I'm not sure the config strings are right. After looking at the .INC file in MPLABX it says the config bits are to be constructed such as:

;----- CONFIG1H Options --------------------------------------------------
_OSC_LP_1H EQU H'F0'; LP oscillator
_OSC_XT_1H EQU H'F1'; XT oscillator
_OSC_HS_1H EQU H'F2'; HS oscillator
_OSC_RC2_1H EQU H'F3'; External RC oscillator, CLKO function on RA6
_OSC_EC_1H EQU H'F4'; EC oscillator, CLKO function on RA6
_OSC_ECIO_1H EQU H'F5'; EC oscillator, port function on RA6
_OSC_HSPLL_1H EQU H'F6'; HS oscillator, PLL enabled (clock frequency = 4 x FOSC1)
_OSC_RCIO_1H EQU H'F7'; External RC oscillator, port function on RA6
_OSC_IRCIO_1H EQU H'F8'; Internal oscillator block, port function on RA6 and port function on RA7
_OSC_IRC_1H EQU H'F9'; Internal oscillator block, CLKO function on RA6 and port function on RA7
_OSC_RC1_1H EQU H'FA'; 101X External RC oscillator, CLKO function on RA6
_OSC_RC_1H EQU H'FC'; 11XX External RC oscillator, CLKO function on RA6

_FCMEN_OFF_1H EQU H'BF'; Fail-Safe Clock Monitor disabled
_FCMEN_ON_1H EQU H'FF'; Fail-Safe Clock Monitor enabled

_IESO_OFF_1H EQU H'7F'; Internal External Switchover mode disabled
_IESO_ON_1H EQU H'FF'; Internal External Switchover mode enabled

;----- CONFIG2L Options --------------------------------------------------
_PWRTEN_ON_2L EQU H'FE'; PWRT enabled
_PWRTEN_OFF_2L EQU H'FF'; PWRT disabled

_BOREN_OFF_2L EQU H'FD'; Brown-out Reset disabled
_BOREN_ON_2L EQU H'FF'; Brown-out Reset enabled

_BORV_45_2L EQU H'F3'; VBOR set to 4.5V
_BORV_42_2L EQU H'F7'; VBOR set to 4.2V
_BORV_27_2L EQU H'FB'; VBOR set to 2.7V
_BORV_20_2L EQU H'FF'; Reserved

;----- CONFIG2H Options --------------------------------------------------
_WDTEN_OFF_2H EQU H'FE'; WDT disabled (control is placed on the SWDTEN bit)
_WDTEN_ON_2H EQU H'FF'; WDT enabled

_WDPS_1_2H EQU H'E1'; 1:1
_WDPS_2_2H EQU H'E3'; 1:2
_WDPS_4_2H EQU H'E5'; 1:4
_WDPS_8_2H EQU H'E7'; 1:8
_WDPS_16_2H EQU H'E9'; 1:16
_WDPS_32_2H EQU H'EB'; 1:32
_WDPS_64_2H EQU H'ED'; 1:64
_WDPS_128_2H EQU H'EF'; 1:128
_WDPS_256_2H EQU H'F1'; 1:256
_WDPS_512_2H EQU H'F3'; 1:512
_WDPS_1024_2H EQU H'F5'; 1:1024
_WDPS_2048_2H EQU H'F7'; 1:2048
_WDPS_4096_2H EQU H'F9'; 1:4096
_WDPS_8192_2H EQU H'FB'; 1:8192
_WDPS_16384_2H EQU H'FD'; 1:16384
_WDPS_32768_2H EQU H'FF'; 1:32768

_WINEN_ON_2H EQU H'DF'; WDT window enabledbled
_WINEN_OFF_2H EQU H'FF'; WDT window disabled

;----- CONFIG3L Options --------------------------------------------------
_PWMPIN_ON_3L EQU H'FB'; PWM outputs drive active states upon Reset
_PWMPIN_OFF_3L EQU H'FF'; PWM outputs disabled upon Reset (default)

_LPOL_LOW_3L EQU H'F7'; PWM0, 2, 4 and 6 are active-low
_LPOL_HIGH_3L EQU H'FF'; PWM0, 2, 4 and 6 are active-high

_HPOL_LOW_3L EQU H'EF'; PWM1, 3, 5 and 7 are active-low
_HPOL_HIGH_3L EQU H'FF'; PWM1, 3, 5 and 7 are active-high

_T1OSCMX_OFF_3L EQU H'DF'; Standard (legacy) Timer1 oscillator operation
_T1OSCMX_ON_3L EQU H'FF'; Low-power Timer1 operation when microcontroller is in Sleep mode

;----- CONFIG3H Options --------------------------------------------------
_FLTAMX_RD4_3H EQU H'FE'; FLTA input is multiplexed with RD4
_FLTAMX_RC1_3H EQU H'FF'; FLTA input is multiplexed with RC1

_SSPMX_RD1_3H EQU H'FB'; SCK/SCL clocks and SDA/SDI data are multiplexed with RD3 and RD2, respectively. SDO output is multiplexed with RD1.
_SSPMX_RC7_3H EQU H'FF'; SCK/SCL clocks and SDA/SDI data are multiplexed with RC5 and RC4, respectively. SDO output is multiplexed with RC7.

_PWM4MX_RD5_3H EQU H'F7'; PWM4 output is multiplexed with RD5
_PWM4MX_RB5_3H EQU H'FF'; PWM4 output is multiplexed with RB5

_EXCLKMX_RD0_3H EQU H'EF'; TMR0/T5CKI external clock input is multiplexed with RD0
_EXCLKMX_RC3_3H EQU H'FF'; TMR0/T5CKI external clock input is multiplexed with RC3

_MCLRE_OFF_3H EQU H'7F'; Disabled
_MCLRE_ON_3H EQU H'FF'; Enabled

;----- CONFIG4L Options --------------------------------------------------
_STVREN_OFF_4L EQU H'FE'; Stack full/underflow will not cause Reset
_STVREN_ON_4L EQU H'FF'; Stack full/underflow will cause Reset

_LVP_OFF_4L EQU H'FB'; Low-voltage ICSP disabled
_LVP_ON_4L EQU H'FF'; Low-voltage ICSP enabled

_DEBUG_ON_4L EQU H'7F'; Background debugger enabled; RB6 and RB7 are dedicated to In-Circuit Debug
_DEBUG_OFF_4L EQU H'FF'; Background debugger disabled; RB6 and RB7 configured as general purpose I/O pins

;----- CONFIG5L Options --------------------------------------------------
_CP0_ON_5L EQU H'FE'; Block 0 (000200-000FFFh) code-protected
_CP0_OFF_5L EQU H'FF'; Block 0 (000200-000FFFh) not code-protected

_CP1_ON_5L EQU H'FD'; Block 1 (001000-001FFF) code-protected
_CP1_OFF_5L EQU H'FF'; Block 1 (001000-001FFF) not code-protected

_CP2_ON_5L EQU H'FB'; Block 2 (002000-002FFFh) code-protected
_CP2_OFF_5L EQU H'FF'; Block 2 (002000-002FFFh) not code-protected

_CP3_ON_5L EQU H'F7'; Block 3 (003000-003FFFh) code-protected
_CP3_OFF_5L EQU H'FF'; Block 3 (003000-003FFFh) not code-protected

;----- CONFIG5H Options --------------------------------------------------
_CPB_ON_5H EQU H'BF'; Boot Block (000000-0001FFh) code-protected
_CPB_OFF_5H EQU H'FF'; Boot Block (000000-0001FFh) not code-protected

_CPD_ON_5H EQU H'7F'; Data EEPROM code-protected
_CPD_OFF_5H EQU H'FF'; Data EEPROM not code-protected

;----- CONFIG6L Options --------------------------------------------------
_WRT0_ON_6L EQU H'FE'; Block 0 (000200-000FFFh) write-protected
_WRT0_OFF_6L EQU H'FF'; Block 0 (000200-000FFFh) not write-protected

_WRT1_ON_6L EQU H'FD'; Block 1 (001000-001FFF) write-protected
_WRT1_OFF_6L EQU H'FF'; Block 1 (001000-001FFF) not write-protected

_WRT2_ON_6L EQU H'FB'; Block 2 (002000-002FFFh) write-protected
_WRT2_OFF_6L EQU H'FF'; Block 2 (002000-002FFFh) not write-protected

_WRT3_ON_6L EQU H'F7'; Block 3 (003000-003FFFh) write-protected
_WRT3_OFF_6L EQU H'FF'; Block 3 (003000-003FFFh) not write-protected

;----- CONFIG6H Options --------------------------------------------------
_WRTC_ON_6H EQU H'DF'; Configuration registers (300000-3000FFh) write-protected
_WRTC_OFF_6H EQU H'FF'; Configuration registers (300000-3000FFh) not write-protected

_WRTB_ON_6H EQU H'BF'; Boot Block (000000-0001FFh) write-protected
_WRTB_OFF_6H EQU H'FF'; Boot Block (000000-0001FFh) not write-protected

_WRTD_ON_6H EQU H'7F'; Data EEPROM write-protected
_WRTD_OFF_6H EQU H'FF'; Data EEPROM not write-protected

;----- CONFIG7L Options --------------------------------------------------
_EBTR0_ON_7L EQU H'FE'; Block 0 (000200-000FFFh) protected from table reads executed in other blocks
_EBTR0_OFF_7L EQU H'FF'; Block 0 (000200-000FFFh) not protected from table reads executed in other blocks

_EBTR1_ON_7L EQU H'FD'; Block 1 (001000-001FFF) protected from table reads executed in other blocks
_EBTR1_OFF_7L EQU H'FF'; Block 1 (001000-001FFF) not protected from table reads executed in other blocks

_EBTR2_ON_7L EQU H'FB'; Block 2 (002000-002FFFh) protected from table reads executed in other blocks
_EBTR2_OFF_7L EQU H'FF'; Block 2 (002000-002FFFh) not protected from table reads executed in other blocks

_EBTR3_ON_7L EQU H'F7'; Block 3 (003000-003FFFh) protected from table reads executed in other blocks
_EBTR3_OFF_7L EQU H'FF'; Block 3 (003000-003FFFh) not protected from table reads executed in other blocks

;----- CONFIG7H Options --------------------------------------------------
_EBTRB_ON_7H EQU H'BF'; Boot Block (000000-0001FFh) not protected from table reads executed in other blocks
_EBTRB_OFF_7H EQU H'FF'; Boot Block (000000-0001FFh) not protected from table reads executed in other blocks

I'm not sure any of them are being set correctly. Here is an example for a project I did some time ago:

#CONFIG
;----- CONFIG1H Options --------------------------------------------------
__config _CONFIG1H, _FOSC_INTIO7_1H & _PLLCFG_ON_1H & _PRICLKEN_ON_1H & _FCMEN_ON_1H & _IESO_OFF_1H
;----- CONFIG2L Options --------------------------------------------------
__config _CONFIG2L, _PWRTEN_ON_2L & _BOREN_ON_2L & _BORV_190_2L
;----- CONFIG2H Options --------------------------------------------------
__config _CONFIG2H, _WDTEN_OFF_2H & _WDTPS_32768_2H
;----- CONFIG3H Options --------------------------------------------------
__config _CONFIG3H, _CCP2MX_PORTB3_3H & _PBADEN_OFF_3H & _HFOFST_OFF_3H & _T3CMX_PORTB5_3H & _MCLRE_EXTMCLR_3H
;----- CONFIG4L Options --------------------------------------------------
__config _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
#ENDCONFIG

This is the syntax I use ...

microcnc05
- 10th April 2020, 20:14
I usually use meCONFIG.exe just because it's so much faster when I'm writing code and it has the chips in it I use. Here is the long form of the same file. The weird thing is that this program was working just fine. And playing around with HSERIN with and interrupt routine is what messed things up. I had the interrupt working fine and just change a little bit of code and then it stopped working. I've tried the original code without interrupt that's been working for a month just fine and it won't run portb.5 now. Could something have gotten screwed up with the programming software? I"m using the melabs U2 USB programmer. It's just odd, nothing was hooked to the pin but my scope.



;----[18F4431 Hardware Configuration]-------------------------------------------
#IF __PROCESSOR__ = "18F4431"
#DEFINE MCU_FOUND 1
#CONFIG
CONFIG OSC = XT ; XT oscillator
CONFIG FCMEN = ON ; Fail-Safe Clock Monitor enabled
CONFIG IESO = ON ; Internal External Switchover mode enabled
CONFIG PWRTEN = OFF ; PWRT disabled
CONFIG BOREN = ON ; Brown-out Reset enabled
CONFIG BORV = 20 ; Reserved
CONFIG WDTEN = ON ; WDT enabled
CONFIG WDPS = 512 ; 1:512
CONFIG WINEN = OFF ; WDT window disabled
CONFIG PWMPIN = OFF ; PWM outputs disabled upon Reset (default)
CONFIG LPOL = HIGH ; PWM0, 2, 4 and 6 are active-high
CONFIG HPOL = HIGH ; PWM1, 3, 5 and 7 are active-high
CONFIG T1OSCMX = ON ; Low-power Timer1 operation when microcontroller is in Sleep mode
CONFIG FLTAMX = RC1 ; FLTA input is multiplexed with RC1
CONFIG SSPMX = RC7 ; SCK/SCL clocks and SDA/SDI data are multiplexed with RC5 and RC4, respectively. SDO output is multiplexed with RC7.
CONFIG PWM4MX = RB5 ; PWM4 output is multiplexed with RB5
CONFIG EXCLKMX = RC3 ; TMR0/T5CKI external clock input is multiplexed with RC3
CONFIG MCLRE = ON ; Enabled
CONFIG STVREN = ON ; Stack full/underflow will cause Reset
CONFIG LVP = OFF ; Low-voltage ICSP disabled
CONFIG DEBUG = OFF ; Background debugger disabled; RB6 and RB7 configured as general purpose I/O pins
CONFIG CP0 = OFF ; Block 0 (000200-000FFFh) not code-protected
CONFIG CP1 = OFF ; Block 1 (001000-001FFF) not code-protected
CONFIG CP2 = OFF ; Block 2 (002000-002FFFh) not code-protected
CONFIG CP3 = OFF ; Block 3 (003000-003FFFh) not code-protected
CONFIG CPB = OFF ; Boot Block (000000-0001FFh) not code-protected
CONFIG CPD = OFF ; Data EEPROM not code-protected
CONFIG WRT0 = OFF ; Block 0 (000200-000FFFh) not write-protected
CONFIG WRT1 = OFF ; Block 1 (001000-001FFF) not write-protected
CONFIG WRT2 = OFF ; Block 2 (002000-002FFFh) not write-protected
CONFIG WRT3 = OFF ; Block 3 (003000-003FFFh) not write-protected
CONFIG WRTC = OFF ; Configuration registers (300000-3000FFh) not write-protected
CONFIG WRTB = OFF ; Boot Block (000000-0001FFh) not write-protected
CONFIG WRTD = OFF ; Data EEPROM not write-protected
CONFIG EBTR0 = OFF ; Block 0 (000200-000FFFh) not protected from table reads executed in other blocks
CONFIG EBTR1 = OFF ; Block 1 (001000-001FFF) not protected from table reads executed in other blocks
CONFIG EBTR2 = OFF ; Block 2 (002000-002FFFh) not protected from table reads executed in other blocks
CONFIG EBTR3 = OFF ; Block 3 (003000-003FFFh) not protected from table reads executed in other blocks
CONFIG EBTRB = OFF ; Boot Block (000000-0001FFh) not protected from table reads executed in other blocks
#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

tumbleweed
- 10th April 2020, 23:54
CONFIG PWM4MX = RB5 ; PWM4 output is multiplexed with RB5

microcnc05
- 11th April 2020, 01:03
Yep I tried that as well. My first post shows CONFIG PWM4MX = RD5 The second post I was just showing the output for meConfig one line of code. Still stumped. Tomorrow I'll try another board with a fresh pic, unless there is something setup in the programming software I'm unaware of.

microcnc05
- 11th April 2020, 12:47
Plot thickens . I went to my shop today and programmed this simple code to the board and it works fine. I then try and program the same code from my laptop even after uninstalling and reinstalling U2 programming software. Nothing now it won't work. It's got to be some setting that got messed up. I need to be able to program it from my laptop though in the field. Any thoughts?




DEFINE OSC 8 ' DEFINE OSCILATOR SPEED
OSCCON = %01111000

'---[CAPTURE COMPAIR MODUALS]---------------------------------------------------
CCP1CON = %00000000
CCP2CON = %00000000
'-------------------------------------------------------------------------------
'---[ANALOG CHANELS TO DIGITAL]-------------------------------------------------
ANSEL0 = %00000000
ANSEL1 = %00000000
ADCON0 = %00000000


MAIN:
SOUND PORTB.5,[100,20]
PAUSE 1000
GOTO MAIN
END

microcnc05
- 11th April 2020, 13:01
Ok I found it, there were a couple of configuration bits that for some reason the config setting I originally had didn't work when I launched the programmer. I changed them with the U2 software before programming and now all is well. I guess this is one of those moments where you've been staring at the screen for hours and you mind is starting to get tunnel vision. Thanks for you help

microcnc05
- 12th April 2020, 02:30
Oh yeah as soon as I get the machine done I'll post some pictures and video of the project as well.

microcnc05
- 29th May 2020, 22:21
Well I finished up the machine and delivered it. My client is thrilled and has more automated machines he wants me to get started on. But like I said I'd post a little about this project. This machine is for a very progressive framing company that is automating every aspect of their business. This machine will except window and door water proofing seal from 4" to 30" wide and interface with their software over USB. They have an in house software engineer that writes all their custom software to break a job down and minimize waist. Every aspect of their framing is maximized through automation. I worked with him over the internet interfacing my control with his software and after a handful of emails and a couple calls we had it debugged and running. Minus my original post here which was a late night, frustration and a wrong configuration bit. :) It bites us all at some point. So here is the youtube video of the project in front of my shop.

https://youtu.be/-SRK0NL9KIM

Also the main PCB and secondary interface PCB for using the DYN4 AC servo drive and all inputs and outputs. I'm using a pic18f4431 on the main board because it's a handy controller with and easy to use quadrature encoder. It's one of my basic boards I always use designed in diptrace. Here are some pictures.
8881
8882

amgen
- 29th May 2020, 23:05
Really neat electro mechanical electronic stuff !

Ioannis
- 30th May 2020, 11:39
Good work!

I wonder why is it necessary for the roll tape to travel through almost right angles?

Ioannis

microcnc05
- 31st May 2020, 01:40
The machine had to be built to take many different types of tape of width and thickness. So for small tape it looks a little silly for the large stuff it really helps to run it though multiple rolls like this for tracking. I've done several other machines similar to this and the more rolls you run though it keeps the material tracking in the center. It's especially important as you can see in the video I have a capacitive proximity sensor that triggers an interrupt that stops the machine saving the position and allowing the operator to splice in a new roll. This company is big on not wasting material. Their custom software breaks down an entire house plan and organizes all the cutting on automated chop saws. They can run all day cutting lumber and making an entire house and maybe loose 1.5 linear foot of wood total. It blew me away to see it. I was contacted over the net by the owner to build a machine that would automate tap cutting and integrate it with their software engineer's software. The owner has all kinds of ideas he wants to automate and has no problem spending money because he makes it up quickly in cost savings. This maybe just the first step to this project as well, next I need to add a line printer to it and possibly design a re-roll machine on the out feed of this one to roll the cut parts back onto a roll. This way his crews can just go window to window and unroll the tape, every thing is labeled and it goes together like Lego's. I love designing these machines from the ground up and building them, and it pays for my shop as I do it on the side. :)

Ioannis
- 1st June 2020, 06:22
Great! Glad you do such things and get paid as well. Well done!

Ioannis