PDA

View Full Version : LAB-XUSB Experimenter Board help



ERMEGM
- 10th May 2015, 07:42
Hello,

I bought the following product and am trying to run a sample program on it provided by their website. I have a PIC16F874A installed and can't seem to get the sample programs to work. All I get is a single row of solid blocks on the LCD.

Here is the original code:

' PICBASIC PRO program to display key number on LCD

' Define LOADER_USED to allow use of the boot loader.
' This will not affect normal program operation.
Define LOADER_USED 1

' RESET_ORG can be set to move the BASIC program out of the way
' of any boot loader running from location 0, such as the
' Microchip USB boot loader
'Define RESET_ORG 800h

Define OSC 48 ' Core is running at 48MHz

' Define LCD connections
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1


' Define program variables
col var byte ' Keypad column
row var byte ' Keypad row
key var byte ' Key value


INTCON2.7 = 0 ' Enable PORTB pullups
ADCON1 = 15 ' Make PORTA and PORTE digital
Low PORTE.2 ' LCD R/W low (write)
Pause 100 ' Wait for LCD to start

Lcdout $fe, 1, "Press any key" ' Display sign on message

loop: Gosub getkey ' Get a key from the keypad
Lcdout $fe, 1, #key ' Display ASCII key number
Goto loop ' Do it forever


' Subroutine to get a key from keypad
getkey:
Pause 50 ' Debounce

getkeyu:
' Wait for all keys up
PORTB = 0 ' All output pins low
TRISB = $f0 ' Bottom 4 pins out, top 4 pins in
If ((PORTB >> 4) != $f) Then getkeyu ' If any keys down, loop

Pause 50 ' Debounce

getkeyp:
' Wait for keypress
For col = 0 to 3 ' 4 columns in keypad
PORTB = 0 ' All output pins low
TRISB = (dcd col) ^ $ff ' Set one column pin to output
Pauseus 1
row = PORTB >> 4 ' Read row
If row != $f Then gotkey ' If any keydown, exit
Next col

Goto getkeyp ' No keys down, go look again

gotkey: ' Change row and column to key number 1 - 16
key = (col * 4) + (ncd (row ^ $f))
Return ' Subroutine over

End

Because PBP3 doesn't like it using the instruction Loop as a label, I changed it to Looper. Also changed INTCON2.7 = 0 to OPTION_REG.7 = 0 for the 874A and changed the define osc 48 to define osc 20.

I am new to this type of code and find it difficult to read, so the problem doesn't stand out for me. What I'm left with is this:


;----[16F874A Hardware Configuration]-------------------------------------------
#IF __PROCESSOR__ = "16F874A"
#DEFINE MCU_FOUND 1
#CONFIG
cfg = _XT_OSC ; XT oscillator
cfg&= _WDT_OFF ; WDT disabled
cfg&= _PWRTE_OFF ; PWRT disabled
cfg&= _BODEN_OFF ; BOR disabled
cfg&= _LVP_OFF ; RB3 is digital I/O, HV on MCLR must be used for programming
cfg&= _CPD_OFF ; Data EEPROM code protection off
cfg&= _WRT_OFF ; Write protection off; all program memory may be written to by EECON control
cfg&= _DEBUG_OFF ; In-Circuit Debugger disabled, RB6 and RB7 are general purpose I/O pins
cfg&= _CP_OFF ; Code protection off
__CONFIG cfg

#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

define osc 20 ' Core is running at 20MHz

' Define LCD connections
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1


' Define program variables
col var byte ' Keypad column
row var byte ' Keypad row
key var byte ' Key value


OPTION_REG.7 = 0 ' Enable PORTB pullups
ADCON1 = 15 ' Make PORTA and PORTE digital
Low PORTE.2 ' LCD R/W low (write)
Pause 100 ' Wait for LCD to start

Lcdout $fe, 1, "Press any key" ' Display sign on message

looper: Gosub getkey ' Get a key from the keypad
Lcdout $fe, 1, #key ' Display ASCII key number
Goto looper ' Do it forever


' Subroutine to get a key from keypad
getkey:
Pause 50 ' Debounce

getkeyu:
' Wait for all keys up
PORTB = 0 ' All output pins low
TRISB = $f0 ' Bottom 4 pins out, top 4 pins in
If ((PORTB >> 4) != $f) Then getkeyu ' If any keys down, loop

Pause 50 ' Debounce

getkeyp:
' Wait for keypress
For col = 0 to 3 ' 4 columns in keypad
PORTB = 0 ' All output pins low
TRISB = (dcd col) ^ $ff ' Set one column pin to output
Pauseus 1
row = PORTB >> 4 ' Read row
If row != $f Then gotkey ' If any keydown, exit
Next col

Goto getkeyp ' No keys down, go look again

gotkey: ' Change row and column to key number 1 - 16
key = (col * 4) + (ncd (row ^ $f))
Return ' Subroutine over

End

Does anything jump out to anyone? I'm just playing with this board and am trying to get it to work. It says "PIC18F4550 recommended" but lists the 16F874 as a compatible chip. Thanks in advance.

Tony

Product in question (http://store.melabs.com/prod/boards/LABXUA.html)
Schematic and code links (http://melabs.com/doclist.htm#XUSB)

Demon
- 10th May 2015, 12:32
Lower case DEFINEs?

I can never remember when it's ok to use, so I always use upper case DEFINEs.

Robert

Demon
- 10th May 2015, 12:35
Also, I am not familiar with your chip. It should be good enough as long as you have the ports used in your code, as well as enough code space.

The 4550 is required if you want to use USB.

Robert

Demon
- 10th May 2015, 12:39
I just remembered, I have jumpers on my Lab X1. Have you checked if any on your Lab USB?

Robert

rsocor01
- 10th May 2015, 14:08
I think that you are missing the LCD_BITS and the LCD_LINES defines. Also, how do you have the pin Vo connected in your LCD?

aerostar
- 10th May 2015, 19:04
This
cfg = _XT_OSC ; XT oscillator

Should be
cfg = _HS_OSC

Check this syntax

ERMEGM
- 11th May 2015, 03:08
Well, changing the config did it, but only for the LCD sample program where it just repeats saying Hello World. On this key press program, I am getting mixed results. Sometimes it's a single line of blocks. Other times it's a cursor or 9 characters like arrow symbols and slashes. When I press a button, each one yields a ?. If I hit the reset button, those characters side step off of the lcd.

At one point, when I played with the power up and watchdog timers, I did get the words "press any key" however, several of the letters were missing.

The schematic of the board is available at the links provided. Nothing was changed, or requires to be changed on the jumpers. I have JP2 set to USB power instead of a wall wart.

The chip I have matches the pinout of the 4550 exactly, so the configuration should be the same. I thought buying the completed board and using the sample programs was going to be straight forward. Silly me.

Scampy
- 11th May 2015, 23:23
Well, changing the config did it, but only for the LCD sample program where it just repeats saying Hello World.

this is confusing - from what I can see the crystal on the board is 20 Mhz, but the OSC value in the first bit of code is 48 !

What happens if you change the OSC to 48 or 40 in your code ? - Also, comment out the section of the code that deals with the key pad and make the main loop a simple LCDout "hello world" - once you get that part running then you know you have the config and LCD setting right, and then you can un-comment the switch routines and debug them.

towlerg
- 12th May 2015, 02:04
this is confusing - from what I can see the crystal on the board is 20 Mhz, but the OSC
value in the first bit of code is 48

check out the fuses, PLL etc. 48Hhz is needed for USB

ERMEGM
- 12th May 2015, 05:18
It IS confusing. As I said, I made the change to the LCD program that just says Hello World over and over again, but it doesn't work on the keypad program.

I'm still learning this type of code, so the error could be right in front of me and I won't see it. That's why I'm asking for help deciphering this type of coding.

Thanks,
Tony

AvionicsMaster1
- 12th May 2015, 14:02
Demon hit on an issue that comes up here repeatedly. Writing define osc 20 doesn't do the job but define OSC 20 will. I use his method and write the whole define statement in caps like DEFINE OSC 20. That needs to be addressed first.

Tabsoft
- 12th May 2015, 14:32
Absolutely.

From the PBP manual in the "DEFINEs Defined" section.
For the practical PBP user, there are a couple of fundamental points to consider:
1) DEFINEs are CASE SENSITIVE!

All PBP DEFINE parameters are UPPERCASE.

So when you use "osc"' "Osc" "oSc" "osC" "OSc" "oSC" "OsC", PBP will not recognize these as OSC defines and will use the default OSC setting.

ONLY "OSC" will actually tell PBP you are setting the OSC speed.

The correct statement for your program is:
"DEFINE OSC 20"

The Microcode Studio UI will change the "DEFINE" keyword to lower case when it is displayed I.e. "define" but that is only what is displayed in the UI. It does not actually change the text in the file to lowercase. More importantly it does not change the "OSC" parameter. It will leave it as you typed it.

Scampy
- 13th May 2015, 00:41
check out the fuses, PLL etc. 48Hhz is needed for USB

But how would you get the timing right with a 20mhz crystal. I thought HS setting means that you run at the crystal speed, and the HS_PLL is typically a multiplier (of 4). IE to get 48 Mhz a 12 Mhz crystal is required, OSC is set to 48 and the fuse set to HS_PLL. - From the pictures of this LAB it's not clear if you can interchange the crystals, which is why I found that confusing.

ERMEGM
- 13th May 2015, 01:12
Absolutely.

From the PBP manual in the "DEFINEs Defined" section.
For the practical PBP user, there are a couple of fundamental points to consider:
1) DEFINEs are CASE SENSITIVE!

All PBP DEFINE parameters are UPPERCASE.

So when you use "osc"' "Osc" "oSc" "osC" "OSc" "oSC" "OsC", PBP will not recognize these as OSC defines and will use the default OSC setting.

ONLY "OSC" will actually tell PBP you are setting the OSC speed.

The correct statement for your program is:
"DEFINE OSC 20"

The Microcode Studio UI will change the "DEFINE" keyword to lower case when it is displayed I.e. "define" but that is only what is displayed in the UI. It does not actually change the text in the file to lowercase. More importantly it does not change the "OSC" parameter. It will leave it as you typed it.

Well, that was it. I tried changing the case of define to uppercase, but PBP kept changing it back to lowercase. Never did anything with the OSC. Not sure if it's a programming flaw or done intentionally, but that makes no sense to auto-correct some things that don't matter, but not auto-correct the things that do matter.

Two days I've been working on this, and all for something as simple as case size. I thought it was the other code as I am not familiar with it and was trying to decipher it.

Thanks for everyone's input. Much appreciated.

Tony

Tabsoft
- 13th May 2015, 01:37
Malc,

ERMEGM is not using a 18F4550 in the board. He is using a 16F874A.
It's max rate is 20MHz using HS mode.

The 18F4550 is a bit of a different animal as far as I can tell looking at the DS.

It can take a 20MHz input in HSPLL mode that then gets divided by 5 to drive a 4MHz input into the PLL to get a 96MHz PLL clock. You can then select to divided down to 48MHz for the MCU clock. This allows the USB and MCU to run from a common source but at different rates.

Tabsoft
- 13th May 2015, 01:52
ERMEGM,

Glad that got you going.
Yes, the MCS (MicroCode Studio) editor does have a few things that are undesirable, including the one you pointed out about case changing. However, you can configure this behavior in MCS. Go to View-> Editor Options-> Highlighter tab.
At the bottom you will see Reserved Word Formatting.
There you can change the option from "Lowercase All" (default setting) to "Default" which will leave the text as it was entered by the user.

HenrikOlsson
- 13th May 2015, 06:02
Just to reiterate, possibly for future reference:
The reserved word DEFINE can be written any way you like, lower case, upper case, mixed case, whatever. It's WHAT you define (OSC on this case) that's case sensitive. It doesn't automatically mean everything should be UPPER CASE, it means it must match the case of the assembly code constant you're trying to "set". Thankfully all PBP assemnly code constants ARE all upper case.

/Henrik.

Scampy
- 13th May 2015, 19:07
Malc,

ERMEGM is not using a 18F4550 in the board. He is using a 16F874A.
It's max rate is 20MHz using HS mode.

The 18F4550 is a bit of a different animal as far as I can tell looking at the DS.

It can take a 20MHz input in HSPLL mode that then gets divided by 5 to drive a 4MHz input into the PLL to get a 96MHz PLL clock. You can then select to divided down to 48MHz for the MCU clock. This allows the USB and MCU to run from a common source but at different rates.

Thanks for the explanation... learning something new every day :)

Tabsoft
- 13th May 2015, 20:03
For me too.
Had to take a look at the 4550 DS to get an understanding of it.

ERMEGM
- 14th May 2015, 07:32
Thank you for the insight.

Tony