KEYPAD FREQUENCY ADJUSTMENT

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by siliconchip »

hi martin
after changing the display to 2x16 to match my board display, SUCCESS !!!!! yay, it would seem that the problem as you pointed out lay with the oscillator speed, if i used my E-Blocks crystal and configured the program accordingly it showed a pulse using ICT on both the data recorder and scope, if i used the INTOSC 8MHz oscillator it wouldn't therefore can i presume that when using the ICT function for any chip and program the oscillator should be set for 19660800 MHz ??
also i had done personal tweaks to version 1.1 and did away with a few things before your 1.3 version as i noted when pressing # key to clear it had to be pressed twice etc, ive used multiple frequency's and using the cursor on the data recorder to show time i then did the following to get the frequency to see if it matched that i had picked
1/t = result / 2 and it was pretty damn close, so this leaves another question between version 1.1 and 1.3 MACRO - setfrequencyPWM has been tweaked with what looks like a local variable "P_Overflow" plus FLOAT, now when comparing the 2 there isnt much that i can see to be different with the frequency generated for a given value would you agree ?? would like you thoughts on all the above please cheers

bob

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by medelec35 »

Hi, bob.
siliconchip wrote:
Tue Aug 10, 2021 3:38 pm
after changing the display to 2x16 to match my board display
Sorry, I was playing with two different setups.
Hopefully, the Replace option worked for you as replacing components is instant!
It's nothing to do with the speed, it's only to do with an external oscillator, e.g. crystal or resonator.
They can be any value that is compatible with your chip.
So you can have 4, 8, 16,19.66, 32, 40MHz etc. crystal or resonator.
That depends on the frequencies involved.
siliconchip wrote:
Tue Aug 10, 2021 3:38 pm
so this leaves another question between version 1.1 and 1.3 MACRO - setfrequencyPWM has been tweaked with what looks like a local variable "P_Overflow" plus FLOAT, now when comparing the 2 there isnt much that i can see to be different with the frequency generated for a given value would you agree ??
The version using P_Overflow is going to be more accurate as it uses floats within the frequency calculations at the price of using more memory.
Non-float version:

Code: Select all

Memory Summary:
    Program space        used   864h (  2148) of  8000h words   (  6.6%)
    Data space           used    58h (    88) of   FF0h bytes   (  2.2%)
Float version:

Code: Select all

Program space        used  1193h (  4499) of  2000h words   ( 54.9%)
    Data space           used    9Fh (   159) of   1F0h bytes   ( 32.1%)
I'm not sure if the difference in accuracy is worth the extra memory?
Probably not.
If you want to go back to the non-float version then I can help you with that.
Martin

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by siliconchip »

hi martin
first off thanks for the reply, i feel ive spoken to you more the last few days than i have to the wife lol, but for me this has been interesting and it couldn't of been done without your help thank you, I've tweaked the non float version a while before the 1.2 and 1.3 version from you appeared and this is probably the version i will keep because of changes i made, however if the FLOAT version is more accurate then i may try to substitute the PWM macro over mine but in doing so i don't want to lose what I've done, program space wont be much of an issue as there wont be much more to add other than a fancy title on power up on the display, my next goal is to change the target pic to one of my choice and build a version on strip board to check how well it performs.

i may well take you up on your offer for further help if i run into issues converting to the FLOAT type if the accuracy gain is needed and the last few days have done my head in trying to get the ICT working etc but the results are always worth the hassle. i would hit the thanks button but it seems to have disappeared again, so all i can say at this point is a very big thankyou, and you know you have not heard the last of me lol

cheers Martin :D

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by siliconchip »

Hi martin,
Ive made a hardware version with a pic 16f1825 and it works well ive tried both the float and non float versions but there is no notable difference in accuracy. From 150hz up to 1000hz its nigh on accurate im using a fluke to measure the output, however when the frequency starts to go around the 1400 to the 1900 hz range accuracy starts to drift by several hz at points is there any way to get more accuracy ive tried messing with roll over between these ranges but not made any noteable difference

Bob

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by medelec35 »

Hi, Bob
It's all to do with accuracy percentages.
Its only as accurate as the oscillator circuit.
So you want the most accurate crystal you can get as the frequency drifts with temperature.
If accuracy is vital, don't use internal oscillators.
The lower Parts Per Million (PPM) the better.
Also make sure the correct matching caps are used.
Along with Float version maybe best?
Martin

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by siliconchip »

Hi martin
Thanks for the reply i will try using a crystal instead of the internal oscillator i will let you know cheers

Bob

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by siliconchip »

hi martin,
first i tested the non float version with the internal oscillator and wrote down the results starting from 200Hz and going up in 50Hz steps to 2000Hz

i then changed the program for HS as well as the calc box and used a 4MHz crystal first off with 22pf caps not sure what the crystals ppm is though, i started at 200Hz and went up in steps of 50Hz up to 1000Hz its fairly accurate although the worst was 950 Hz that showed 960Hz on the output to the fluke, just like the internal oscillator all results were the same.

i then fitted an 8MHz crystal and changed the code accordingly exact same results found, did the same with a 16MHz crystal again same results.
i then loaded the float version starting with the 4MHz crystal then the 8 then 16MHz again all results were consistent in all tests, i also typed in a random number for instance when i selected 1800Hz the fluke showed 1811 Hz so i put in 1815Hz this showed 1838Hz again this was done a couple of times with different crystal and no matter what combination of crystal and using FLOAT or Non FLOAT all results found are consistent with each other. as for Cap values ive only 22Pf ceramics but even with these if they are not the correct value i expected to see some sort of change,

bob

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by medelec35 »

Hi, Bob.
Maybe it's no what I thought then and is relying solely on the calculations alone.
In that case perhaps a percentage fudge factor could be introduced?
Alternatively, if required frequency is not too high then timer 2 interrupt could be used instead.
Martin

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by siliconchip »

Hi martin
Ive not heard of percentage fudge factor but as for the timer2. Option would it be that once the keypad number inputed the timer would count the pwm frequency to that point and display it, sorry for the poor description

Bob

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by siliconchip »

Hi martin,
Ive been messing with the program trying to improve accuracy but pwm is beating me, have you any ideas where the accuracy could be improved upon ive tried to research via the net but everything i do is of no change to improve it

Cheers bob

Post Reply