PDA

View Full Version : Pulsout Pic16F630 @16Mhz problem



zorgloub
- 10th February 2022, 18:39
Hi everyone,

I'm trying to understand a problem with a Pic16F630 equipped with a 16Mhz resonator (3 legs).
The very simple verification code is below.
The pulses delivered are 240msec for a command "PULSOUT PORTC.3, 100"!?
And the pulse result is the same if I delete the "DEFINE OSC 16" line !!?
(But the 200 pause is then reduced to 50 msec !)

I kept the factory OSCCAL value which IC-Prog copies to the right address.

I did not have this problem with a Pic16F84A...
What is my mistake or oversight?

Thank you in advance.

-----------------------------------------------------------
'**** CODE: *****
' TESTPIC16F630.PBP
' TEST PIC16F630 Pulsout Command

' Pic Specifications
@ Device Pic16F630,HS_osc, wdt_off, pwrt_on,protect_off, mclr_off
DEFINE OSC 16

' i/o Definition
'All OUTPUT
TRISA =0
TRISC =0
' All pins at Logic Low
PORTA = 0
PORTC = 0

Loop:
pulsout PORTC.3, 100
pause 200
Goto LOOP

mpgmike
- 10th February 2022, 20:14
Without pulling out a data sheet to check, most PICs have some sort of OSCCON Register where you have to tell it to use the external crystal, oscillator, RC, or use the internal oscillator. I'm betting that by not using the OSCCON Register, it is defaulting to 4 MHz Internal Oscillator. By DEFINEing OSC 16, PBP is counting clock ticks as though you were at 16 MHz using your external resonator, where in reality, you're using the internal 4 MHz clock.

richard
- 10th February 2022, 20:38
The pulses delivered are 240msec for a command "PULSOUT PORTC.3, 100"!?

by 240mS do you mean 240 micro seconds. a more likely result



What is my mistake or oversight?
not reading the manual


5.59 PULSOUT
PULSOUT Pin, Period
Generates a pulse on Pin of specified Period. The pulse is generated by toggling the pin twice, thus the initial state of the pin determines the polarity of the pulse. Pin is automatically made an output. Pin may be a constant, 0 - 15, or a variable that contains a number 0 - 15 (e.g. B0) or a pin name (e.g. PORTA.0).
The resolution of PULSOUT is dependent upon the oscillator frequency. If a 4MHz oscillator is used, the Period of the generated pulse will be in 10us increments. If a 20MHz oscillator is used, Period will have a 2us resolution. Defining an OSC value has no effect on PULSOUT. The resolution always changes with the actual oscillator speed.
' Send a pulse 1mSec long (at 4MHz) to Pin5
PULSOUT PORTB.5,100
PULSOUT is a legacy command that is included for compatibility with other languages.

zorgloub
- 10th February 2022, 21:30
@ Mpgmike,
Now you're confusing me ;)
(I already don't know English very well, thanks to the automatic translators).
Well, actually I was an amateur user of the BS2x BasicStamp and I try to pour some programs into one or the other PIC.
The registers of the PICs and the commands other than the pure Basic of the Stamp, I don't know too much!
So, isn't declaring the High Speed fuse then sufficient for PicBAsicPro Compiler, as I wrote in my program?
So I don't understand your sentence "as if you were at 16 MHz using your external resonator, when in reality you are using the internal 4 MHz clock."
--> So does it work in 4Mhz or 16Mhz?

@Richard
(Yes, 240µsec!)
You say that setting OSC has no effect on PULSOUT but that the resolution depends on the crystal used.
What is the point of defining OSC?
And considering what Mpgmike said above, at what frequency does my Pic equipped with a 16Mhz resonator and high speed fuse indication work?

Here are the pulses I read on a logic analyser:

WITHOUT indicating Define OSC 16 :
PAUSE 200 = 50 msec (Isn't the resolution at 4Mhz 10µsec??)
PULSOUT 100 = 240µsec

Isn't the resolution at 4Mhz 10µsec?

WITH Define OSC 16 :
PAUSE 200 =200 msec
PULSOUT 100 = 240 µsec also

(Theoretical resolution at 16Mhz should be 2.5 µsec I think).
So the PIC would work well here at 16Mhz!

I have to admit that I'm getting confused here with the Pause and Pulsout resolutions and I'm trying to understand ;)

richard
- 10th February 2022, 21:46
So, isn't declaring the High Speed fuse then sufficient for PicBAsicPro Compiler, as I wrote in my program?
for this chip yes

You say that setting OSC has no effect on PULSOUT but that the resolution depends on the crystal used.
?
its a legacy [old ] command, it does not use the OSC define in its operation



What is the point of defining OSC

non legacy commands do use the OSC define in their operations


And considering what Mpgmike said above
is incorrect and out of context for that chip




(Theoretical resolution at 16Mhz should be 2.5 µsec I think).
So the PIC would work well here at 16Mhz


thats it

richard
- 10th February 2022, 21:52
looks like the forum is broken. cannot edit last post


I have to admit that I'm getting confused here with the Pause and Pulsout resolutions and I'm trying to understand

pause uses OSC define to calculate TIME , Pulsout does not

zorgloub
- 10th February 2022, 22:04
I was wondering about the resolutions of the PAUSE command:

With "DEFINE OSC 16", PAUSE 200 gives a delay of 50 msec
The resolution here is therefore 250µsec per "unit".

WITHOUT "DEFINE OSC 16", PAUSE 200 gives a delay of 200 msec
The resolution here is 1msec per "unit".

Right?

--> What are legacy commands, I don't know this term :(

richard
- 10th February 2022, 22:23
i'm not sure what ver of pbp you are using but

@ Device Pic16F630,HS_osc, wdt_off, pwrt_on,protect_off, mclr_off

is old stuff, and probably case sensitive HS_osc looks doubtful
if this line is incorrect then the actual config fuse you are setting is the pbp default not what you think.
the default will be most likely use a 4mhz clock


With "DEFINE OSC 16", PAUSE 200 gives a delay of 50 msec
means the osc is 4mhz not 16, so your config line is incorrect


The resolution here is therefore 250µsec per "unit".
pause is always in mS but the actual osc must march the defined OSC



What are legacy commands, I don't know this term
commands that resemble old basicstamp style commands ,they are not as well integrated in the pbp operating environment

zorgloub
- 10th February 2022, 22:27
Strange, I have a program using pulsin and pulsout that runs perfectly on Pic16F84A/16Mhz and I try to put it on a Pic16F630./16Mhz .. but nothing works ;(
I was using 16Mhz for better accuracy.
I spent the day there, without success.
My neurons are melted.

zorgloub
- 10th February 2022, 22:30
I am using a 20 year old compiler PBP 2.40/2.46.
But I can confirm that when IC-Prog loads the Hex file, the fuse is set to HS.
And the same program ran perfectly on a Pic16F84A

richard
- 10th February 2022, 22:33
if you have pbp3 then a config looks loke this


#CONFIG
__config _HS_OSC & _WDT_ON & _PWRTE_OFF & _MCLRE_ON & _BODEN & _CP_OFF & _CPD_OFF
#ENDCONFIG



@ Device Pic16F630,HS_osc, wdt_off, pwrt_on,protect_off, mclr_off

looks wrong for any version

zorgloub
- 10th February 2022, 22:38
I just tried this command.
It is not recognised on my PBP 2.40 :(
But I guess without this configuration line, setting the fuses in IC-Prog is also valid and sufficient?
"My" command was valid for my Pic16F84A.

richard
- 10th February 2022, 22:39
I am using a 20 year old compiler PBP 2.40/2.46.
But I can confirm that when IC-Prog loads the Hex file, the fuse is set to HS.
And the same program ran perfectly on a Pic16F84A

the chip is running @4mHz so something is not right


you might need to find noah or someone else out of the ark

zorgloub
- 10th February 2022, 22:47
How can you tell it's running at 4Mhz?

richard
- 10th February 2022, 22:53
from this post




With "DEFINE OSC 16", PAUSE 200 gives a delay of 50 msec
The resolution here is therefore 250µsec per "unit".


WITHOUT "DEFINE OSC 16", PAUSE 200 gives a delay of 200 msec
The resolution here is 1msec per "unit".

zorgloub
- 10th February 2022, 23:01
Well, I'll leave it for today.
Thank you for your support.
Have a good evening and a good night.

zorgloub
- 11th February 2022, 08:20
Hi Richard,
(The resolution at 16Mhz is theoretically 2.5µsec.)
So if PULSOUT 100 gives me a pulse of 0.24 msec, the resolution here is 2.4µsec, which would indicate that the Peak is running at 16Mhz.
No ?

richard
- 11th February 2022, 09:09
So if PULSOUT 100 gives me a pulse of 0.24 msec, the resolution here is 2.4µsec, which would indicate that the Peak is running at 16Mhz.
sounds right.

however
if osc = 16mhz and define OSC 16 is set then pause 200 will pause 200mS
if not then something is wrong , PULSOUT would not be my way to test osc speed.


also code snippets are not meaningful in this situation at least until the chip is confirmed configured as intended

do post entire code including config word in code tags to make it easy for anyone one interested in assisting

zorgloub
- 12th February 2022, 12:09
Hello Richard
Well, I solved the problem of the operation of my program on the Pic16F630.
Regardless of the strange problem of the duration of the pauses, I have no problem with the management of Pulsin / Pulsout under 16Mhz.
In fact, I had no Pulsout signal on some outputs because I had not disabled the comparator of this Pic (CMCON = 7).
The duration of the pauses does not impact the progress of my program.
Thanks for your general help.

Translated with www.DeepL.com/Translator (free version)