Log in

View Full Version : PBP3/MPLABX - PIC18F46Q10: The sound function.



DdtWks
- 5th March 2025, 18:17
Hi all, I am a 20+ years user of PBP. I am porting an existing product from a PIC18F4252 (MPLAB8) to PIC18F46Q10 (MPLABX) for now all look ok except the sound function does not work. If I high and low my Piezo pin I have sound. For a reason I don't understand there nothing using the normal function. Any idea ?

Ioannis
- 5th March 2025, 18:33
Many, but all guesses...

Maybe you post the complete code?

Ioannis

DdtWks
- 5th March 2025, 18:38
I will take your guesses, this won't help:

sound piezo,[124,10]

Thanks

DdtWks
- 5th March 2025, 19:42
Hi Ioannis, can tell me if I should just go back from MPLABX 5.35 to a working Pic on MPLAB8 ? Maybe there is other stuff not working normally.

Ioannis
- 6th March 2025, 14:14
You should use 5.35 version. This is the latest PBP supports and needs for the relatively new chips.

Going back will not help.

New chips have lots of functions and you need to do your homework setting up the ports correctly.

If the program worked OK on an older chip it will work on the new one, as long as you set it up correctly.

Since you do not post your code there is no more we can say about it.

Use MCC to set up the chip you are using.

Ioannis

DdtWks
- 6th March 2025, 16:01
So I have checked all registers concerning the Ports and Timers source clocks. Add them to my program.
Here is the setup:


DEFINE OSC 4
DEFINE CHAR_PACING 2000
INCLUDE "modedefs.bas"


#CONFIG
CONFIG FEXTOSC = HS ;HS (crystal oscillator) above 8 MHz; PFM set to high power
CONFIG RSTOSC = EXTOSC ;EXTOSC operating per FEXTOSC bits (device manufacturing default)
CONFIG CLKOUTEN = OFF ;CLKOUT function is disabled
CONFIG CSWEN = ON ;Writing to NOSC and NDIV is allowed
CONFIG FCMEN = ON ;Fail-Safe Clock Monitor enabled
CONFIG MCLRE = EXTMCLR ;MCLR pin (RE3) is MCLR
CONFIG PWRTE = ON ;Power up timer enabled
CONFIG LPBOREN = OFF ;Low power BOR is disabled
CONFIG BOREN = ON ;Brown-out Reset enabled according to SBOREN
CONFIG BORV = VBOR_245 ;Brown-out Reset Voltage (VBOR) set to 2.45V
CONFIG ZCD = OFF ;ZCD disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
CONFIG PPS1WAY = OFF ;PPSLOCK bit can be set and cleared repeatedly (subject to the unlock sequence)
CONFIG STVREN = ON ;Stack full/underflow will cause Reset
CONFIG XINST = OFF ;Extended Instruction Set and Indexed Addressing Mode disabled
CONFIG WDTCPS = WDTCPS_31 ;Divider ratio 1:65536; software control of WDTPS
CONFIG WDTE = SWDTEN ;WDT enabled/disabled by SWDTEN bit
CONFIG WDTCWS = WDTCWS_7 ;window always open (100%); software control; keyed access not required
CONFIG WDTCCS = SC ;Software Control
CONFIG WRT0 = OFF ;Block 0 (000800-001FFFh) not write-protected
CONFIG WRT1 = OFF ;Block 1 (002000-003FFFh) not write-protected
CONFIG WRTC = OFF ;Configuration registers (300000-30000Bh) not write-protected
CONFIG WRTB = OFF ;Boot Block (000000-0007FFh) not write-protected
CONFIG WRTD = OFF ;Data EEPROM not write-protected
CONFIG SCANE = ON ;Scanner module is available for use, SCANMD bit can control the module
CONFIG LVP = OFF ;HV on MCLR/VPP must be used for programming
CONFIG CP = OFF ;UserNVM code protection disabled
CONFIG CPD = OFF ;DataNVM code protection disabled
CONFIG EBTR0 = OFF ;Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
CONFIG EBTR1 = OFF ;Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
CONFIG EBTRB = OFF ;Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
#ENDCONFIG


data @0,0 'Mode tête et pied inversé Rotec
data @1,1 'afficheur 6r pre-compile
data @2,0 'th12 (Permobil et Span) pre-compile relais
data @3,0 'Linak hl70d (Euro) pre-compile
data @4,0 'TC1 (Permobil et Span serial) pre-compile pas fait
data @5,0 'TC14 (Sotec serial) pre-compile
data @6,0 'Umano pre-compile
data @7,0 'Permobil Trost pre-compile
data @8,1 'Permobil Noa TC1 relais pre-compile (Comme Span mais différents boutons/fonctions)
data @9,0 'Bertek 9 pins pre-compile


'************************************************* ***
' Initialisation des modules internes 18F46Q10 *
'************************************************* ***


'Analog to digital converters
ANSELA = 0
ANSELB = 0
ANSELD = 0
ANSELE = 0


'Open Drain (NO)
ODCONA = 0
ODCONB = 0
ODCONC = 0
ODCOND = 0
ODCONE = 0


'Slew rate
SLRCONA = 0
SLRCONB = 0
SLRCONC = 0
SLRCOND = 0
SLRCONE = 0


'Input threshold (TTL)
INLVLA = 0
INLVLB = 0
INLVLC = 0
INLVLD = 0
INLVLE = 0


'Weak Pull-Up
WPUA = 0
WPUB = 0
WPUC = 0
WPUD = 0
WPUE = 0


'Timers
T0CON1 = %01000000 'source Fosc/4
T1CLK = %00000001 'source Fosc/4
T2CLKCON = %00000001 'source Fosc/4
T3CLK = %00000001 'source Fosc/4
T4CLKCON = %00000001 'source Fosc/4
T5CLK = %00000001 'source Fosc/4
T6CLKCON = %00000001 'source Fosc/4


It changed nothing. I always put a blinking led and a "beep" on startup. So I switched my PIEZO for the LED (PORTD.0). So I can see the LED "SOUND"


sound led_1,[124,20]


The led should be ON for about 20x12ms so 240ms. It's ON for exactly 240ms and the period is 400us (2.5Khz) All Ok here. So I "Input' my Piezo pin, place a jumper from my led (removed and 1k res removed) to the piezo. No drive, no PWM, just HIGH and then LOW after 240ms. I must be doing something wrong. I don't know.


The second thing not working is the SERIN function. All rejected after timeout. I did not investigate this one yet.

DdtWks
- 6th March 2025, 16:05
Yes I am using MPLAB X 5.35 compile OK.
Thank you.

Ioannis
- 6th March 2025, 19:58
There seems that you use external crystal. What frequency is this?

Is led_1 defined in your program?

Is the MCLR pin tied to Vdd?

Is TRISD.0=0?

Ioannis

tumbleweed
- 6th March 2025, 22:51
Also, you missed setting PORTC to digital mode (ANSELC), so any sound or serial functions for these pins will likely have issues.

DdtWks
- 7th March 2025, 00:56
Also, you missed setting PORTC to digital mode (ANSELC), so any sound or serial functions for these pins will likely have issues.

I changed it after my post. It was not that. I found out that even if a peripheral is disabled I had to assign a dummy port to it. (xxxPPS registers)
For the SOUND FUNCTION (RC1) it was CCP2PPS (=0 now) same for the SERIN2/SEROUT2 FUNCTION (RB6 RB7) it was RX1PPS (=0 now) CK1PPS (=0 now)

Thank you !

richard
- 7th March 2025, 06:50
i see a code snippets that cannot be compiled.
code snippets not in code tags.
a code snippet that does not demonstrate how you have configured the device
allegations of strange undocumented behavior that cannot be corroborated


why don't you post the code you have tried. if you don't want to post the complete project then
aim to post the simplest compliable program that shows the problem. code snippets generally
don't cut it, we need to see the config settings, osc speed, var declarations, port settings etc....
[use code tags] please, if you don't know how to do that then read the faq






a minimal, complete and verifiable example MCVE is the best way to get help
https://stackoverflow.com/help/minim...ucible-example

DdtWks
- 7th March 2025, 16:12
Update, it's resolved. tumbleweed was wright. I have tried to replicate the problem with the sound function and serin2/serout2 problems and it's only the ANSELC that was not set properly.

To my "excuse" here is a picture of the Datasheet and why I dismiss ANSELC at first. Thank you Ioannis, tumbleweed and Richard. To Richard, I wrote a small program to check for the problem, but there is nothing to check anymore. The PPS registers can be ignored if the peripherals are not enabled (confirmed).

9930

Ioannis
- 7th March 2025, 16:41
Yes, maybe the Data sheet had a miss there. But then on page 251 there is this:

9931

So, Richard stated very well about snippets. I said earlier that only guesses we can make. Once again this was so true!

This one would be resolved on the 2nd post.

Ioannis

DdtWks
- 7th March 2025, 17:12
:wink: I know. Thank you Ioannis.