I cant use all of my pwm pins only 8 of them - esp32

Hi im new to all of this and im trying to use servo motor with PWM, so my problem is this out of 16 PWM Pins only 8 of them is working 0-7, 8-15 isnt. i read online PWM is divided to 2 groups. so do I need to do somthing extra to use the 2 groups? maybe somthing i dont know about
im adding a picutre of the setup of my code
#define Servo_0 13
#define Servo_1 12
#define Servo_2 14
#define Servo_3 27
#define Servo_4 26
#define Servo_5 25
#define Servo_6 33
#define Servo_7 15
#define Servo_8 2
#define Servo_9 4
#define PWM_Channel0 0
#define PWM_Channel1 1
#define PWM_Channel2 2
#define PWM_Channel3 3
#define PWM_Channel4 4
#define PWM_Channel5 5
#define PWM_Channel6 6
#define PWM_Channel7 7
#define PWM_Channel8 8
#define PWM_Channel9 9
#define PWM_Resolution 8
#define PWM_Freq 50
String str;
void setup()
{
ledcSetup(PWM_Channel0, PWM_Freq, PWM_Resolution);
ledcSetup(PWM_Channel1, PWM_Freq, PWM_Resolution);
ledcSetup(PWM_Channel2, PWM_Freq, PWM_Resolution);
ledcAttachPin(Servo_0, PWM_Channel0);
ledcAttachPin(Servo_1, PWM_Channel1);
ledcAttachPin(Servo_2, PWM_Channel2);
ledcAttachPin(Servo_3, PWM_Channel3);
ledcAttachPin(Servo_4, PWM_Channel4);
ledcAttachPin(Servo_5, PWM_Channel5);
ledcAttachPin(Servo_6, PWM_Channel6);
ledcAttachPin(Servo_7, PWM_Channel7);
ledcAttachPin(Servo_8, PWM_Channel8);
ledcAttachPin(Servo_9, PWM_Channel9);
}
void colorRGB(byte valRed,byte valGreen,byte valBlue)
{
ledcWrite(PWM_Channel0, valRed);
ledcWrite(PWM_Channel1,valGreen);
ledcWrite(PWM_Channel2, valBlue);
}
void head_End()
{
int vertical = map(100, 0, 180, 10, 35);
int horizontal = map(84, 0, 180, 10, 35);
ledcWrite(PWM_Channel0,vertical);
ledcWrite(PWM_Channel1,horizontal);
}
void head_Move(int angle_h,int angle_v)
{
int h = map(angle_h, 0, 180, 10, 35);
int v = map(angle_v, 0, 180, 10, 35);
ledcWrite(PWM_Channel0,h);
ledcWrite(PWM_Channel1,v);
}
void boxes(int angle1,int angle2)
{
int box1 = map(angle1, 0, 180, 10, 35);
int box2 = map(angle2, 0, 180, 10, 35);
ledcWrite(PWM_Channel8,box1);
ledcWrite(PWM_Channel9,box2);
}
void loop()
{
boxes(0,160);
delay(1000);
boxes(160,0);
delay(1000);
}

Related

Why GPU memory updates are not read?

I have written a program like this and wanted to display in real-time progress of the kernel. I saw How can I check the progress of matrix multiplication?, but wanted not to use such specific CUDA things as cudaDeviceMapHost. The things do not work even if I allocate array bigger than GPU cache. How is this possible?
#include <chrono>
#include "cuda_runtime.h"
#include "device_atomic_functions.h"
#include "device_launch_parameters.h"
#define CUDA_CHECK(err) __cudaSafeCall(err, __FILE__, __LINE__)
inline void __cudaSafeCall(cudaError err, const char *file, const int line)
{
if (err != cudaSuccess)
{
fprintf(stderr, "%s(%i): CUDA error %d (%s)\n",
file, line, int(err), cudaGetErrorString(err));
throw "CUDA error";
}
}
static const int c_dataSize = 4 << 20;
__global__ void progressKernel(int *devP)
{
while (1)
{
for (int i = 9 + threadIdx.x; i < c_dataSize; i += blockDim.x)
devP[i] = i;
}
}
int main()
{
std::vector<int> data(c_dataSize, 1);
int *devP;
auto startTime = std::chrono::system_clock::now();
cudaStream_t stream2, stream3;
CUDA_CHECK(cudaMalloc((void**)&devP, sizeof(int) * c_dataSize));
CUDA_CHECK(cudaStreamCreate(&stream2));
CUDA_CHECK(cudaGetLastError());
printf("Starting...\n");
progressKernel<<<1, 128, 0, stream2>>>(devP);
printf("Started... %llX\n", (__int64)devP);
CUDA_CHECK(cudaGetLastError());
CUDA_CHECK(cudaStreamCreate(&stream3));
CUDA_CHECK(cudaMemcpyAsync(&(data[0]), devP, sizeof(int) * c_dataSize,
cudaMemcpyDeviceToHost, stream3));
CUDA_CHECK(cudaStreamSynchronize(stream3));
while (1)
{
auto currentTime = std::chrono::system_clock::now();
auto transformed = std::chrono::duration_cast<std::chrono::nanoseconds>(currentTime - startTime).count();
printf("%.7f ms: %d, %d, %d\n", (double)transformed / 1000000,
data[10], data[100], data[c_dataSize - 1]);
cudaMemcpyAsync(&(data[0]), devP, sizeof(int) * c_dataSize,
cudaMemcpyDeviceToHost, stream3);
cudaStreamSynchronize(stream3);
}
printf("Done\n");
}
I am getting
Starting...
Started... 505200000
1520.5665000 ms: 0, 0, 0
1526.6487000 ms: 0, 0, 0
1530.3077000 ms: 0, 0, 0
1534.4480000 ms: 0, 0, 0
1538.1516000 ms: 0, 0, 0
1541.7932000 ms: 0, 0, 0
1545.4041000 ms: 0, 0, 0
1549.6127000 ms: 0, 0, 0
1553.5760000 ms: 0, 0, 0
1557.2292000 ms: 0, 0, 0
1560.8776000 ms: 0, 0, 0
1564.6736000 ms: 0, 0, 0
1568.8331000 ms: 0, 0, 0
1572.5332000 ms: 0, 0, 0 ...
Windows 10 x64 Pro 19044.2251, Visual Studio 2019 16.0.2, CUDA Toolkit 10.2

what is wrong with the bpf_csum_diff function call?

I want to somehow redirect packets using ebpf. Took an example from the Cilium documentation: Implementation: proxy via bpf
here is an example of my macro in bpf_helpers:
...
static int (*bpf_csum_diff)(void *from, __u64 from_size, void *to, __u64 to_size, __u64 seed) = (void*) // NOLINT
BPF_FUNC_csum_diff;
...
here is the code of the proxy script itself:
#include <linux/bpf.h>
#include "../main/bpf_helpers.h"
#include "../main/bpf_endian.h"
#include <linux/in.h>
#include <linux/if_ether.h>
#include <linux/if_packet.h>
#include <linux/if_vlan.h>
#include <linux/ip.h>
#include <linux/ipv6.h>
#include <linux/types.h>
#include <linux/tcp.h>
#include <linux/udp.h>
#include <stdlib.h>
#include "../main/utils_helpers.h"
#include <stddef.h>
#include <linux/pkt_cls.h>
SEC("socket_filter")
int proxy(struct __sk_buff *skb)
{
const __be32 cluster_ip = 0x846F070A; // 10.7.111.132
const __be32 pod_ip = 0x0529050A; // 10.5.41.5
const int l3_off = ETH_HLEN; // IP header offset
const int l4_off = l3_off + 20; // TCP header offset: l3_off + sizeof(struct iphdr)
__be32 sum; // IP checksum
void *data = (void *)(long)skb->data;
void *data_end = (void *)(long)skb->data_end;
if (data_end < data + l4_off) { // not our packet
return TC_ACT_OK;
}
struct iphdr *ip4 = (struct iphdr *)(data + l3_off);
if (ip4->daddr != cluster_ip || ip4->protocol != IPPROTO_TCP /* || tcp->dport == 80 */) {
return TC_ACT_OK;
}
// DNAT: cluster_ip -> pod_ip, then update L3 and L4 checksum
sum = bpf_csum_diff((void *)&ip4->daddr, 4, (void *)&pod_ip, 4, 0);
bpf_csum_diff((void *)&ip4->daddr, 4, (void *)&pod_ip, 4, 0);
bpf_skb_store_bytes(skb, l3_off + offsetof(struct iphdr, daddr), (void *)&pod_ip, 4, 0);
bpf_l3_csum_replace(skb, l3_off + offsetof(struct iphdr, check), 0, sum, 0);
bpf_l4_csum_replace(skb, l4_off + offsetof(struct tcphdr, check), 0, sum, BPF_F_PSEUDO_HDR);
return TC_ACT_OK;
}
char __license[] SEC("license") = "GPL";
Here is the code of the proxy script itself:
...
2020/06/02 21:58:17 sf.Load(): %vebpf_prog_load() failed: 0: (b7) r2 = 86574346
1: (63) *(u32 *)(r10 -4) = r2
2: (61) r2 = *(u32 *)(r1 +80)
invalid bpf_context access off=80 size=4
processed 3 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
...
Tell me how to correctly proxy packets to another port and another ip in docker?

Math calculations in arduino

I wrote a code to do a basic calculations with arduino uno. but it returns me a wrong answer for filledPercentage. It is always -1. what is the problem with this?
//include the library code:
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 13, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int lowLevelDistance =112;
int highLevelDistance = 47;
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
Serial.begin(9600);
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
int currentLevel = 101;
int filledLevel = (lowLevelDistance - currentLevel);
int fullLevel = (lowLevelDistance - highLevelDistance);
int filledPercentage = filledLevel / (fullLevel / 100);
Serial.println(lowLevelDistance);
Serial.println(highLevelDistance);
Serial.println(currentLevel);
Serial.println(filledLevel);
Serial.println(fullLevel);
Serial.println(filledPercentage);
delay(1000);
}
You shouldn't use an integer for the division, your fulllevel / 100 returns 0.65 but then is converted into an integer (truncating it into a 0).
Dividing by 0 throws an error (-1).

AVR GCC Error initializer element is not constant

I am using Atmel Studio 6.2, the chip xmega64D3, and I have a problem with intitializing some fields of a structure:
typedef struct
{
uint32_t val;
uint32_t inv;
uint32_t xor;
}SPROTU32;
typedef struct
{
SPROTU32 SerialNr;
SPROTU32 SwVersion;
SPROTU32 HwVersion;
SPROTU32 ProdCode;
SPROTU32 ProdDate;
SPROTU32 PartNum;
}BasicData;
#define sw_high 02
#define sw_low 12
#define sw_ver ((sw_high << 16) + sw_low)
#define hw_high 01
#define hw_low 06
#define hw_ver ((hw_high << 16) + hw_low)
#define DEFAULT_SERIAL 0
#define DEFAULT_SW_VERSION sw_ver
#define DEFAULT_HW_VERSION hw_ver
#define DEFAULT_PROD_CODE 0
#define DEFAULT_PROD_DATE 0
#define DEFAULT_PART_NUM 05545410
EEMEM BasicData eeBasicData =
{
{DEFAULT_SERIAL,~DEFAULT_SERIAL,DEFAULT_SERIAL^0x55555555},
{DEFAULT_SW_VERSION,~DEFAULT_SW_VERSION,DEFAULT_SW_VERSION^0x55555555},
{DEFAULT_HW_VERSION,~DEFAULT_HW_VERSION,DEFAULT_HW_VERSION^0x55555555},
{DEFAULT_PROD_CODE,~DEFAULT_PROD_CODE,DEFAULT_PROD_CODE^0x55555555},
{DEFAULT_PROD_DATE,~DEFAULT_PROD_DATE,DEFAULT_PROD_DATE^0x55555555},
{DEFAULT_PART_NUM,~DEFAULT_PART_NUM,DEFAULT_PART_NUM^0x55555555}
};
Compile output image
The compiler says always initilizer is not constant. So, how can I do to initialize my structure with what I want?
try to use multiply operation instead << operation
#define _VERSION(h,l) ((h * 65536) | l)
#define DEFAULT_SW_VERSION _VERSION(sw_high, sw_low)

Delay time when exposing in Xlib

I'm trying to work out a time-delay to display steady flickering. I didn't get it to work with sleep() or time.h, what seems to be logically.
How could I achieve something like, displaying a white rectangle for 10 seconds, then clear this area (also for 10 sec), in a loop.
In this question, a socket of the X11 connection is mentioned to do things like that. But where to dig in, in this matter?
Thanks
The file descriptor is in the Display structure and can be obtained with the macro ConnectionNumber(dis).
You could then use poll with a timeout to wait for an event to arrive or a timeout to occur.
As mentioned in the other questions, XPending will let you see if there are any events, so you don't actually need to check the file descriptor, you could do something like this:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <time.h>
#include <unistd.h>
int main()
{
XEvent ev;
Display *dis = XOpenDisplay(NULL);
Window win = XCreateSimpleWindow(dis, RootWindow(dis, 0), 1, 1, 500, 500, 0, BlackPixel (dis, 0), WhitePixel(dis, 0));
XMapWindow(dis, win);
GC gc = XCreateGC(dis, win, 0, 0);
int draw = 1;
time_t t = time(NULL) + 10;
XMapWindow(dis, win);
XSelectInput(dis, win, ExposureMask | KeyPressMask);
while (1)
{
if (XPending(dis) > 0)
{
XNextEvent(dis, &ev);
switch (ev.type)
{
case Expose:
printf("Exposed.\n");
if (draw > 0)
{
XFillRectangle(dis, win, gc, 100, 100, 300, 300);
}
break;
case KeyPress:
printf("KeyPress\n");
/* Close the program if q is pressed.*/
if (XLookupKeysym(&ev.xkey, 0) == XK_q)
{
exit(0);
}
break;
}
}
else
{
printf("Pending\n");
sleep(1);
if (time(NULL) >= t)
{
/* Force an exposure */
XClearArea(dis, win, 100, 100, 300, 300, True);
t += 10;
draw = 1 - draw;
}
}
}
return 0;
}
Note: you might want to use something like usleep to get a finer timer granularity.

Resources