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
Contact:

KEYPAD FREQUENCY ADJUSTMENT

Post by siliconchip »

hi all
a question for those with far more knowledge than myself, can a keypad be used as an input to adjust a square wave generated by an interrupt ?? can a timer interrupt be made adjustable to alter frequency ?? I've looked through the old posts and found nothing to answer my question

bob

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

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by medelec35 »

Hi Bob,
What about using a map component along with the frequency generator you required here?
Martin

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

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by siliconchip »

hi martin
as always thanks for the reply, i did originally have a play with this but had trouble opening the FCPX files and couldnt figure out how to incorporate the keypad, i will admit i didnt spend much time on it as my idea was just an idea and i was between projects but now ive completed what i was doing ive started to think again about using a keypad to give me a desired frequency, my ideal range is between about 150hz to 2KHz, the other alternative ive thought is having several different input values and when one is selected there is say five frequency steps for that desired input shown ie

if input is say10 then first set frequency for this input would be
1= 160Hz
2= 210Hz
3 = 320Hz
4 = 440Hz
5 = 590Hz
these five frequencys would be selected in turn automatically staying at the output for the desired frequency for 15 secs before the next one comes then after the 5th one it resets back to 0,

so ive 2 things in mind and wondered if either is possible i dont mind putting in the work as its the only way to learn, id be interested in your thoughts on this, cheers

bob

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

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by medelec35 »

Hi, Bob.
siliconchip wrote:
Wed Aug 04, 2021 5:29 pm
but had trouble opening the FCPX files
The fcpx is not for you to open as its a component file.
The easiest way to use a component file is:
1. Create a new folder for component files.
2. Place the component in the new component folder.
3. Open Flowcode & select View Global Options.
4. Select Locations and the ... icon in the Look for components in.
5. Browse to the new components folder and choose the .fcpx file.
6. Close and reopen Flowcode & the new component should be present.
You can use the search option to find the component.

As for using the keypad.
There is this topic as well to have look at.
If you put together a flowchart, then I can help you further.
Martin

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

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by siliconchip »

hi martin
ive added a program and changed the target device this was done by me from the link you provided and we have already touched on it some time ago as per link but you mentioned it was not viable to use pwm but maybe a timer interupt and thats where it ended so maybe my flowchart is not relevant as its for pwm ??

bob
Attachments
keypad frequency.fcfx
(26.02 KiB) Downloaded 141 times

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

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by medelec35 »

Hi Bob,
Sorry for the delay.
I have deleted unrequired components and changed keyboard pins, so your Flowchart will compile.
I have not tested it on hardware, but with simulation after entering 1600* the PWM does change to 1600Hz and the duty looks correct.
It works for every frequency entered so far.
What a great way of setting PWM frequencies!
Attachments
keypad frequency v1.1.fcfx
(22.57 KiB) Downloaded 136 times
Martin

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

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by siliconchip »

hi martin,
thanks for the reply, has the oscillator speed got to be set at a certain frequency to make this work as id like to run at 8MHz with this particular chip, also in simulation am i right in thinking the lowest value you can pick is 299Hz ?? or is simulation different than hardware when showing results, cheers

bob

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

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by medelec35 »

All you need to do with the microcontroller running at 8MHz is change the Clock Speed within Build options & the ClockFrequencyHz to 8000000.
Martin

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

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by siliconchip »

hi martin
ive made a few changes and tried to measure the output on pin C5 with the oscilloscope but was unable to in simulation do you take it for granted that the PWM box in the 3D display is the indicator that its got something at the output ??

bob

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

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by medelec35 »

siliconchip wrote:
Sat Aug 07, 2021 8:44 pm
do you take it for granted that the PWM box in the 3D display is the indicator that its got something at the output ??
Yes I did as normally if not working the same as sim then could be a pin connection (or a bug) issue.
Can you post your changes and I will take a look.
Martin

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

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by siliconchip »

hi martin
code attached, cheers

bob
Attachments
keypad frequency v1.1.fcfx
(21.59 KiB) Downloaded 135 times

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

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by siliconchip »

Hi martin
Ive used the code on my e blocks board and as far as display and keypad are concerned its working im unsure if the led however is actually flashing at the desired rate tho my hunch is that its just on, also i used the formula 1/ T and with what the pwm box tells me like you said the selected frequency is correct however im still unsure of any output on the actual pwm pin ive tried ICT via my board but no joy

Bob

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

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by medelec35 »

Hi Bob,
I have to agree with you.
As coon as change period is used the PWM fails to work.
I will see if I can find out why.
Martin

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

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by siliconchip »

Hi Martin,
thanks that would be great if you could find the issue it's a neat little project, look forward to your reply cheers

Bob

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

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by medelec35 »

Hi Bob.
Can you see if this works any better please?
Attachments
keypad frequency v1.2.fcfx
(24.99 KiB) Downloaded 115 times
Martin

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

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by siliconchip »

hi martin,
still cant find a pulse on the output using the ICT Function on my board I've changed the target to the 16f 1937 for board testing which allows me to use the e blocks keypad i have, maybe I'm doing something wrong ??, I've checked I've got the OSCCON settings correct with a 1Hz flash test which i have, failing this i may have to dismantle my board so i can get on the output pin with a scope or order a keypad and build a bread board version which i feel i shouldn't need to do as im using the E-block board, ive tried using the flowcode scope as well but again nothing in simulation, ive also deleted the led as i think its pretty much redundant

bob

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

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by siliconchip »

hi
quick update i was not using the debug system correctly however when i got it working im unable to use the ICD/ICT function due to the error message that the 1937 which came with the board does not support it, even tried to recompile as it suggests, if this is so why provide a chip that isnt supported by ghost ??? ggggrrrrrr :( :(

bob

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

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by medelec35 »

Hi Bob.
I was posting about it seems to be working for meI set the PWM to 800Hz via the keypad:
Set for 800Hz.png
Set for 800Hz.png (11.8 KiB) Viewed 8252 times
I have the EB006 & Flowkit.
I can see if I can it it to work for me.
Martin

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

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by siliconchip »

Hi Martin
excellent can you run through how you got it to work please

Bob

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

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by medelec35 »

Using the latest flowchart I posted along with 16F18877 target device.
I will try with 16F1937 and let you know how it goes as there could be an issue with your target device?
Won't know until I test it.
Martin

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

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by siliconchip »

Hi Martin
that would be great I'd appreciate it thanks

Bob

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

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by medelec35 »

Hi Bob,
Tried attached Flowchart for the 16F1937.
The correct frequency is outputted on pin C2.
Keypad is plugged in port D
LCD is plugged in port B
Works with or without ghost.
Display needs a tickle but I used the flowchart for testing.
Attachments
keypad frequency 16f1937 v1.2 .fcfx
(21.34 KiB) Downloaded 104 times
Martin

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

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by siliconchip »

hi martin
can you run through how you tested it in simulation i still cant find a pulse, either with scope or data recorder but when testing the 1Hz flasher both scope and data recorder work ?? :oops: :oops: :oops: :oops: :oops:

bob

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

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by medelec35 »

Hi Bob,
I have noticed that the frequency does not look correct on the PWM scope within the simulator if the simulation is running at full speed.
I have noticed this when changing from 2000 to 900Hz for example.
This requires reporting as PWM scope only updates to the correct values if the simulation is stopped and restared.
Therefore move the simulator speed slider one notch from the left.
It then displays ok:
Freq Gen Sim1.png
Freq Gen Sim1.png (72.07 KiB) Viewed 8199 times
Is that the issue you are facing?
siliconchip wrote:
Mon Aug 09, 2021 3:32 pm
I've checked I've got the OSCCON settings correct
Tesing with ICD/ICT you will need to run the board using the external 19660800 crystal and not using the internal oscillator.
This is because the oscillator needs to run at the correct speed before Ghost is active.
I have got rid of the extra char on the display and rearranged the panel so it's easier to use.
The data recorder via ITC with freq set to 900Hz:
Data Recorder.png
Data Recorder.png (55.98 KiB) Viewed 8196 times
Try with the 19.6MHz crystal and let me know how you get on.
Attachments
keypad frequency 16f1937 v1.3 .fcfx
(21.72 KiB) Downloaded 104 times
Martin

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

Re: KEYPAD FREQUENCY ADJUSTMENT

Post by siliconchip »

hi martin
thanks for the reply and being patient i will try what youve suggested and will let you know cheers

bob

Post Reply