1. Home
  2. Docs
  3. USB2.0 Camera Shield Rev.E
  4. 7.GPIO&PWM

7.GPIO&PWM

Arducam USB Camera Shield Rev.E has the function of GPIO&PWM.

As is shown in the figure, USB Camera Shield Rev.E has 2*3 pin. Pin3 and pin4(Two Extended IOs) can be configured as GPIO or PWM mode.

Figure1: CPLD register configuration

registeraddressregistertypeValue Meaning
0x12read-writebit[7], Two Extended IOs as PWM or GPIO
0, GPIO; 1, PWM
bit[0], GPIO Direction
0, CPLD input; 1, CPLD output
0x13read-onlybit[1:0], GPIO read-in values
bit[1], GPIO_1 read value
bit[0], GPIO_0 read value
0x14read-writebit[1:0], GPIO write-out values
bit[1], GPIO_1 write value; bit[0]:GPIO_0 write value
for example: If 0x12 writes 0x01, the two extended IO is GPIO, the GPIO_1 and GPIO_0  are both output the 0x14 writes 0x01, the GPIO_1 is low level, and  GPIO_0 is high level
0x15read-writebit[5:4], Selection of pwm_0 Cycle Counting Clock
3:320us, 2:160us; 1:80us; 0:40us
bit[1:0], Clock selection for pwm_0 high-level counting
3, 40us; 2, 20us; 1, 10us; 0, 5us
0x16read-writebit[7:0], Number of High-Level Width Clocks in pwm_0
0x17read-writebit[7:0], Number of pwm_0 Periodic Width Clocks
0x18read-writebit[5:4], Selection of pwm_1 Cycle Counting Clock
3, 320us; 2, 160us; 1, 80us; 0, 40us
bit[1:0], Clock selection for pwm_1 high-level counting
3, 40us; 2, 20us; 1, 10us; 0, 5us
0x19read-writebit[7:0], Number of Clocks with High Level Width in pwm_1
0x1Aread-writebit[7:0], Number of pwm_1 Periodic Width Clocks

1.GPIO Configuration

1.1 Modify register on Arducam USB Camera Demo APP

Download the the latest version Arducam USB Camera Demo APP.

  • Tools->R/W Regs

Support modify I2C device address and read & write register in batches.

  • File->Open->Select the Configuration file->Load->Open(no need Play)->R/W Regs
  • Tools->R/W Regs

GPIO configuration operate example 1

Make the two GPIO pins configured as signal output state (Either all pins are output or input state).
Copy the code to the R/W Regs window and press Write.
//======================
//bit[7],Two Extended IOs as PWM or GPIO。
//0,GPIO;1,PWM。
//bit[0],GPIO Direction。
//0,CPLD input;1,CPLD output。
I2C_8_8, 0x46, 0x12, 0x01
//======================
//bit[1:0],GPIO write-out values。
//bit[1]:GPIO[1] write value;
//bit[0]:GPIO[0] write value。
I2C_8_8, 0x46, 0x14, 0x03
//======================



Note: CPLD I2C device address is 0x46, the access method is 8-bit address + 8-bit data.
Write 0x01 to 0x12 means two extended IOs are all set as GPIO and GPIO_1 & GPIO_1 are all signal output states.
Write 0x01 to 0x14 means that GPIO_1 is Low Level & GPIO_0 is High Level(3.3v).

GPIO configuration operate example 2

Make the two GPIO pins configured as signal input states (Either all pins are output or input states).
Copy the code to the R/W Regs window and press Write.
//======================
//bit[7],Two Extended IOs as PWM or GPIO。
//0,GPIO;1,PWM。
//bit[0],GPIO Direction。
//0,CPLD input;1,CPLD output。
I2C_8_8, 0x46, 0x12, 0x00
//======================



Copy the code to the R/W Regs window and press Read.
//======================
bit[1:0],GPIO read-in values。
bit[1]:GPIO[1] read value;
bit[0]:GPIO[0] read value。
I2C_8_8, 0x46, 0x13
//======================



Writer 0x00 to 0x12 means the extended IO pins are all set as GPIO and GPIO_1 & GPIO_0 are signal input state.
At this time, RegAddr is 0x13 and Value is 0x00. That means GPIO_1 and GPIO_0 values are both 0 in the floating state.

Short circuit PIN3 and PIN2 using Dupont Line and GPIO_0 switch to the high level.

Read register and Adress is 0x13 & Value is 0x01

1.2 Modify register using the configuration file

Writer the register data to the configuration file(Automatic configuration at initialization).

Copy the code to [board parameter]

//--------------------------------------------------------//
//bit[7],Two Extended IOs as PWM or GPIO。
//0,GPIO;1,PWM。

//bit[0],GPIO Direction。
//0,CPLD input;1,CPLD output。
VRCMD = 0xD7, 0x4600, 0x1200, 1, 0x01   


//bit[1:0],GPIO write-out values。
//bit[1]:GPIO[1] write value;
//bit[0]:GPIO[0] write value。
VRCMD = 0xD7, 0x4600, 0x1400, 1, 0x03
//--------------------------------------------------------//

Note:

  • The format is different in modify register on Arducam USB Camera Demo.
  • You can only write the register.

You can refer to the configuration file.

2.PWM Configuration

2.1 Modify register on Arducam USB Camera Demo APP

Download the the latest version Arducam USB Camera Dem

Tools->R/W Regs

File->Open->Select the Configuration file->Load->Open(no need Play)->R/W Regs

Tools->R/W Regs

PWM configuration operate example 1–PWM_0

Copy the following code to the R/W Reg window and press Write.
//======================
//bit[7],Two Extended IOs as PWM or GPIO。
//0,GPIO;1,PWM。
//bit[0],GPIO Direction。
//0,CPLD input;1,CPLD output。
I2C_8_8, 0x46, 0x12, 0x80
//======================
//bit[5:4], Selection of pwm_0 Cycle Counting Clock
//3:320us
//2:160us
//1:80us
//0:40us
//bit[1:0], Clock selection for pwm_0 high-level counting
//3:40us
//2:20us
//1:10us
//0:5us
I2C_8_8, 0x46, 0x15, 0x11
//======================
//bit[7:0],Number of High Level Width Clocks in pwm_0
I2C_8_8, 0x46, 0x16, 0x96
//======================
//bit[7:0],Number of pwm_0 Periodic Width Clocks
I2C_8_8, 0x46, 0x17, 0xFA
//======================

Set up the four register: 0x12, 0x15, 0x16, 0x17

Due to the setup :
The clock is 80us
The number of clocks is 250
High-Level Width Clocks is 10us
The Number of High-Level Width Clock is 150

PWM_0 Period = 80us x 250 = 20ms
PWM High-Level = 10us x 150 =1.5ms

Observe the waveform with a logic analyzer or oscilloscope


PWM configuration operate example 1–PWM_1

Same as PWM_0, only different in register

2.2 Modify register using the Configuration files

Writer the register data to the configuration file(Automatic configuration at initialization).

Copy the following code to [board parameter]

//--------------------------------------------------------//
//bit[7],Two Extended IOs as PWM or GPIO。
//0,GPIO;1,PWM。

//bit[0],GPIO Direction。
//0,CPLD input;1,CPLD output。

VRCMD = 0xD7, 0x4600, 0x1200, 1, 0x80   
//--------------------------------------------------------//
//bit[5:4], Selection of pwm_0 Cycle Counting Clock
//3:320us
//2:160us
//1:80us
//0:40us

//bit[1:0], Clock selection for pwm_0 high-level counting
//3:40us
//2:20us
//1:10us
//0:5us

VRCMD = 0xD7, 0x4600, 0x1500, 1, 0x11
//--------------------------------------------------------//
//bit[7:0],Number of High Level Width Clocks in pwm_0

VRCMD = 0xD7, 0x4600, 0x1600, 1, 0x96
//--------------------------------------------------------//
//bit[7:0],Number of pwm_0 Periodic Width Clocks

VRCMD = 0xD7, 0x4600, 0x1700, 1, 0xFA
//--------------------------------------------------------//

Note:

  • The format is different in modify register on Arducam USB Camera Demo.
  • You can only write the register.

You can also refer to the configuration file.

Was this article helpful to you? Yes No