קורס אמבדד – 005 – RB18
MOTOR DRIVER
תכנון מעגל משלוב חומרה ותוכנה -מתנתקים ממיגבלות המעבד \ משדר של כמות IO
(PWM / I/O / SPI / I2C /I2S/ UART ) I/O Expanders
PCF8575 Interface – I/O Expanders Remote 16-Bit I2C & SMBus I/O Expander
PCAL6524HEAZ
UART EXPENDER
TIMER
esp32 80Mhz ==> 8,000,000Hz
TICK :
T.S (HZ) , prescaler=1 ==> 80mhz /1 = 80Mhz
T.S (HZ) , prescaler=80==> 80mhz /80 = 1Mhz
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
// Robotronix.co.il #define LED 32 hw_timer_t *My_timer = NULL; void IRAM_ATTR onTimer(){ digitalWrite(LED, !digitalRead(LED)); } void setup() { pinMode(LED, OUTPUT); My_timer = timerBegin(0, 80, true); // TIMEER 0-3,PRESCALR, COUNER UP ? timerAttachInterrupt(My_timer, &onTimer, true); /* timerAttachInterrupt: pecify the counter value in which the timer interrupt should be generated. So, for this example, we assume that we want to generate an interrupt each second, and thus we pass the value of 1000000 microseconds, which is equal to 1 second. For the third argument, we will pass the value true, so the counter will reload and thus the interrupt will be generated periodically. */ timerAlarmWrite(My_timer, 1000000, true); // enabling the timer interrupt using the function timerAlarmEnable. timerAlarmEnable(My_timer); } void loop() { } |
https://wokwi.com/projects/350706177868300882
הוספת ספרייה לארדואינו \ ESP32
https://github.com/RoboticsBrno/ServoESP32
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#include <Servo.h> static const int servoPin = 4; Servo servo1; void setup() { Serial.begin(115200); servo1.attach(servoPin); } void loop() { for(int posDegrees = 0; posDegrees <= 180; posDegrees++) { servo1.write(posDegrees); Serial.println(posDegrees); delay(20); } for(int posDegrees = 180; posDegrees >= 0; posDegrees--) { servo1.write(posDegrees); Serial.println(posDegrees); delay(20); } } |
SUMMERY
BITWISE OPERATORS
bitwise – mask
נבדוק את ביט מספר 3
תוצאה גדולה מ 0
——————————————————————————————————————————————
נבדוק את BIT מספר 7
תוצאה 0
BIT WIZE SET BIT
מטרה – להציב ערך של ביט אחד או יותר בלי לשנות את שאר הביטים
Clearing Bits
FLIP BIT / TOGGLING
1^1==>0
0^1==>1
FLIP ALL BITS
תרגיל כיתה :
Build a program in emended c that control DJ leds with string commando from rs232 / Bluetooth
https://wokwi.com/projects/350701464616698450
the program get 8 chars string s , like s="0100-1010" in this format
1. SET S , EXMAPLE SET 0000-1000
2. CLEAR S , CLEAR 3 WILL CLEAR BIT 3
3 RAND , SET all 8 leds in random value 1 or 0 ,Example RAND
4 CLEAR BIT , example CLEAR 5 , will clear bit 5 .
5 T BIT , toggle bit number BIT , T 4
6. BLINK will blink all bit in 500 ms
7 shift N will shift all bits in N BITS
8 LEFT N will shift shift all bit in N BITS
all input can be lower , upper or both letters .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
#include <string.h> #include <stdio.h> void run() { for (int i = 4; i <= 13; i++) { digitalWrite(i, HIGH); delay(100); digitalWrite(i, LOW); } for (int i = 12; i > 4; i--) { digitalWrite(i, HIGH); delay(100); digitalWrite(i, LOW); } } char ch; char buf[100]; int c=0; void setup() { Serial.begin(115200); Serial. print("Dj control - The Bits Master\n"); for (int i = 4; i <= 13; i++) { pinMode(i, OUTPUT); } } void loop() { if(Serial.available()) { ch=Serial.read(); Serial.print(ch); if(ch!='\n') { buf[c]=ch; buf[c+1]=0; c++; } else { // Serial.print(buf); c=0; // terminate command if(strstr(buf,"run")>0) { run(); } memset(buf,100,0); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
#include <stdio.h> void showbits( unsigned int x ) { int c1=0; int i; unsigned int temp=0; for (i = (sizeof(int) * 8) - 1; i >= 0;c1++, i--) { // putchar(x & (1 << i) ? '1' : '0'); temp =x & (1 << i); if ( (c1%4)==0 )putchar('-'); if( temp>0) { putchar('1'); } else { putchar('0'); } } printf("\n"); } int main( void ) { int j =1; printf("%d in binary ", j); showbits(j); printf("\n-----------------------------\n"); showbits(j); /* the loop for right shift operation */ for (int m = 0; m <= 5; m++) { int n = j >> m; printf("%d right shift %d gives ", j, m); showbits(n); } return 0; } |
brushless drones motors
Spikes Motor driver