This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
I am scanning a keypad of 8 rows x 6 columns (48 keys)
Some questions:
When a column is active (scanned), is the signal low or high? Is this logic selectable? Is it driven as push-pull or open-drain?
What is the preferred arrangement of pullup, pulldown, or no-pull resistors on rows and columns? (The example shows pull downs on Y, Pull ups on X)
An example configuration and script for the PWM would be great. Using them to drive some LED indicators and a piezo element (for sound - chirps)
Can the PWM generate a 1 kHz square wave?
I can read and write to registers at this point. Any hints on configuring and general use of this device would be greatly appreciated.
Thanks,
Jonathan,
Thank you and I look forward to hearing from the Application Engineer.
Doug
Hi Randy,
If KPY pins are open-drain, why are they also configured with pull-downs? There could be no change in the logic state. Am I missing something?
Do you have an example script to drive a PWM at 1 kHz? Or any example script of any PWM action? Just need to get started.
Thanks,
Doug
P.S. Since I now know that KPY pins are open drain, if I set the pins to have pull ups and start the scanning, I should be able to see the scan pulses with an oscilloscope, right?
Hi Doug
The KPY pull-down ensures that the pin is low. When a key is pressed the KPX pull-up is connected to the KPY pull-down which wakes up the scanning process (KPY input pulled-up). After the device wakes up it starts driving KPY pin low one at a time to detect which KPX pin is connected. You can see the scan activity by pressing a key connected between any KPX and KPY combination and observe on a scope.
I will send out a pwm example tomorrow.
Randy
Hi Doug
There are two examples below. PWM 1 sets fixed duty cycle pwm that remains on. PWM2 will ramp up then down and then turn off.
The PWM frequency is fixed at 125 Hz (32 kHz OSC/255).
// Enable PWM clock and Keyscan clock
0x8a, 0x05
// ***** Configure PWM 1 *****
// PWM1 Fixed 25% duty cycle
0x7d, 0x20 // PWM1 Pointer
0x7e, 0x40, 0x40 // Set PWM1 to 25% Duty Cycle
0x7e, 0x01, 0x02 // Ramp increment 1, step 2
0x7e, 0x02, 0xa0 // Loop to Addr 02 (fixed duty cycle, ramp not repeated)
delay(40);
// ***** Configure PWM 2 *****
// PWM2 ramp up then back down and halt
0x7d, 0x40 // PWM2 Pointer
0x7e, 0x80, 0x40 // Set PWM2 to 50% Duty Cycle
0x7e, 0x01, 0x08 // Ramp increment 1, step 8
0x7e, 0x81, 0xbf // Repeat Loop to Addr 01 63 times
0x7e, 0x01, 0x08 // Ramp increment 1, step 8
0x7e, 0x83, 0xbf // Repeat Loop to Addr 03 63 times
0x7e, 0x01, 0x08 // Ramp increment 1, step 8
0x7e, 0x85, 0xbf // Repeat Loop to Addr 05 63 times
0x7e, 0x01, 0x08 // Ramp increment 1, step 8
0x7e, 0x87, 0xbf // Repeat Loop to Addr 07 63 times
0x7e, 0x81, 0x08 // Ramp decrement 1, step 8
0x7e, 0x89, 0xbf // Repeat Loop to Addr 09 63 times
0x7e, 0x81, 0x08 // Ramp decrement 1, step 8
0x7e, 0x8b, 0xbf // Repeat Loop to Addr 11 63 times
0x7e, 0x81, 0x08 // Ramp decrement 1, step 8
0x7e, 0x8d, 0xbf // Repeat Loop to Addr 13 63 times
0x7e, 0x81, 0x08 // Ramp decrement 1, step 8
0x7e, 0x8f, 0xbf // Repeat Loop to Addr 15 63 times
0x7e, 0x00, 0xd8 // Halt PWM
0x69, 0x0f // Start PWM1 Command
0x71, 0x0f // Start PWM2 Command
Let me know if you have any other questions.
Best regards,
Randy
Hi Doug
It looks like you are getting a SF key press detected, change KBDIC for 03 to 83 (disable SF keys).
When enabled the key scan sequence is executed which takes a few milliseconds.
This was a typo, no need for the delay.
Randy
Hi Doug
I have pasted in your sequence below with corrections highlighted.
This sequence will enable the key scan and pwm and should clear up the dedicated key press you were getting on row 0.
Here is an extract of my code:
//1 byte: RSTINTCLR 0x84
test_data_tx[0] = 0x01;
keypad_write(KBD_RSTINTCLR, 1);
//5 bytes:
test_data_tx[0] = 0x80; //KBDSETTLE (0x01). Set settle time to 12 msec
test_data_tx[1] = 0x80; //KBDBOUNCE (0x02). Set debounce time to 12 msec
test_data_tx[2] = 0x34; //KBDSIZE (0x03). 7:4 # of rows (2-8), 3:0 # of columns (2-12)
test_data_tx[3] = 0xFF; //KBDDEDCFG (0x04). X[7:2], Y[11:10]. USE 3 Rows: X2:0
test_data_tx[4] = 0xFF; //KBDDEDCFG (0x05). Y[9:2]. USE 4 Cols: Y3:0
keypad_write(KBD_KBDSETTLE, 5);
//1 byte:
test_data_tx[0] = 0x11; //IOCFG (0xA7). Enable PWM0,1,2. Enable KPY11 as IRQN output.
keypad_write(KBD_IOCFG, 1);
//4 bytes:
test_data_tx[0] = 0x00; //IOPC0 (0xAA). '10' = Pullup resistors for KPX[7:4]. UNUSED
test_data_tx[1] = 0x2a; //IOPC0 (0xAB). Pullup resistors for KPX[3:0]. USE 3 Rows: X2:0
test_data_tx[2] = 0x00; //IOPC1 (0xAC). No Pull resistors for KPY[7:4]. UNUSED
test_data_tx[3] = 0x55; //IOPC1 (0xAD). '01' = Pulldown resistors for KPY[3:0]. USE 4 Cols: Y3:0
keypad_write(KBD_IOPC0, 4);
//2 bytes:
test_data_tx[0] = 0x03; //KBDIC (0x08). Clear any pending interrupts
test_data_tx[1] = 0x03; //KBDMSK (0x09). Enable keyboard interrupts
keypad_write(KBD_KBDIC, 2);
//1 byte: CLKEN 0x8A
test_data_tx[0] = 0x01; //CLKEN (0x8A). Enable keyscan clock. set bit 0
keypad_write(KBD_CLKEN, 1);
//RED LED on KPY9 (PWM1)
//Fixed 25% duty cycle
//PWMCFG1
test_data_tx[0] = 0x06;//Pattern Gen Enabled, PWM enabled, LOW when PWM is OFF
keypad_write(KBD_PWMCFG1, 1); --- MOVE to last command after clearing interrupts
//GPIOPDIR2
test_data_tx[0] = 0x0f; //KPY[11:8] all output
keypad_write(KBD_GPIOPDIR2, 1); NOT NEEDED
//PWM1 Pointer
test_data_tx[0] = 0x20;
keypad_write(KBD_PWMWP, 1);
//Set PWM1 to 25% Duty Cycle
test_data_tx[0] = 0x40;
test_data_tx[1] = 0x40;
keypad_write(KBD_PWMCFG, 2);
//Ramp increment 1, step 2
test_data_tx[0] = 0x01;
test_data_tx[1] = 0x02;
keypad_write(KBD_PWMCFG, 2);
//Loop to Addr 02 (fixed duty cycle, ramp not repeated)
test_data_tx[0] = 0x02;
test_data_tx[1] = 0xa0;
keypad_write(KBD_PWMCFG, 2);
//IOCFG: CAUTION! is this correct?!
test_data_tx[0] = 0x02; //configure KPY[10:8} as PWM0,1,2.
keypad_write(KBD_IOCFG, 1); NOT NEEDED
//CLKEN
test_data_tx[0] = 0x04; //Enable PWM
keypad_write(KBD_CLKEN, 1);
//TIMIC
test_data_tx[0] = 0x3f; //TIMIC: Clear any pending interrupts
keypad_write(KBD_TIMIC, 1);
Let me know if you need anything else.
Randy
Hi Randy,
I am adding support for special function keys to this product and need some assistance. First KPY0-KPY5 are used for column scanning. This is working fine. KPY6 and KPY7 are to be used for SF keys (one on each KPY line).
What is the circuit for a SF key? Is it a switch that when closed pulls up through a resistor to Vdd? What would be an appropriate value for this resistor?
In this case I am setting
KBDDEDCFG to 0xFFCF
(Note that KBDSIZE is 0x86)
Presently I can't get an interrupt when pulling KPY6 (or KPY7) high through a 10k resistor.
Are there other registers that need to be configured to support this functionality?
Is the SF scan part of the Matrix scan process? Can the SF scan be seen on an oscilloscope?
Thanks,