Fantastisch Bruno! Chapeau!
Dan zijn we eruit
Dan zijn we eruit

Follow along with the video below to see how to install our site as a web app on your home screen.
Nota: This feature may not be available in some browsers.
Ik wil het je met alle plezier een keer stap voor stap uitleggen, maar op dit moment vliegt de tijd me door de vingers.....Voor alsnog is het maken van een sketch en het goed begrijpen van alle termen voor mij een brug te ver, maar ik probeer toch wat op te steken van jullie exercities, Dus als het kan zo duidelijk mogelijk uitleg geven en vooral: DOORGAAN.![]()
/*
A switch to propo channel conversion for ATTiny.
************************************************
This converter will take a 3-position switched channel and change it to an increase-stop-decrease channel.
2 potmeters will adjust the end points of the servo output.
The PWM from the receiver is captured with interrupts, based on Phil Green's Digispark V-tail mixer.
ATTiny TOP VIEW:
_____
1-| U |-8
2-| |-7
3-| |-6
4-|_____|-5
*/
#define Rxch 0 // receiver channel connected to P0 (ATTiny physical pin 5)
#define led 1 // DigiSpark internal LED on P1 (ATTiny physical pin 6)
#define potmin 2 // minimum throttle setting from potmeter on P2 (ATTiny physical pin 7)
#define potmax 3. // maximum throttle setting from potmeter on P3 (ATTiny physical pin 2)
#define servo 4 // servo output from P4 (ATTiny physical pin 3)
volatile unsigned long timer_ch; // all timer variables are unsigned long
volatile int pulse_time = 1500;
volatile byte chWas = 0, sync = 0;
int RXpulse, Minpulse, Maxpulse, Outpulse = 1500;
void setup()
{
pinMode(led, OUTPUT);
pinMode(servo, OUTPUT);
pinMode (potmin, INPUT);
pinMode (potmax, INPUT);
pinMode(Rxch, INPUT);
timer_ch = 0;
GIMSK = (1 << PCIE); // Enable Pin Change Interrupts
PCMSK = (1 << Rxch); // Enable interrupts for rx channel inputs
sei();
}
void loop()
{
while (sync == 0);
sync = 0;
delay(6); // do the o/p pulses mid-frame, reduces jitter...
cli();
RXpulse = pulse_time; // do an atomic copy in the quickest way
sei();
if (RXpulse <= 1200) Outpulse = Outpulse - 5;
if (RXpulse >= 1800) Outpulse = Outpulse + 5;
Minpulse = 1000 + map(analogRead(potmin), 0, 1023, 0, 500); // Minpulse: 1000 > 1500
Maxpulse = 2000 - map(analogRead(potmax), 0, 1023, 0, 500); // Maxpulse: 1500 > 2000
constrain (Outpulse, Minpulse, Maxpulse);
digitalWrite(servo, 1); delayMicroseconds(Outpulse); digitalWrite(servo, 0); // servo out
}
ISR(PCINT0_vect)
{
if (PINB & 0b00000001) { // read the Rx pulse on P0
if (chWas == 0) {
timer_ch = micros();
chWas = 1;
}
} else {
if (chWas == 1) {
pulse_time = (micros() - timer_ch);
chWas = 0;
sync = 1;
}
}
}
Video, or it didn't happen....Gisteravond Bruno’s sketch laten lopen
/*
A switch to propo channel conversion for ATTiny.
************************************************
This converter will take a 3-position switched channel and change it to an increase-stop-decrease channel.
2 potmeters will adjust the end points of the servo output.
The PWM from the receiver is captured with interrupts, based on Phil Green's Digispark V-tail mixer.
ATTiny TOP VIEW:
_____
1-| U |-8
2-| |-7
3-| |-6
4-|_____|-5
*/
#define Rxch 0 // receiver channel connected to P0 (ATTiny physical pin 5)
#define led 1 // DigiSpark internal LED on P1 (ATTiny physical pin 6)
#define potmin 2 // minimum throttle setting from potmeter on P2 (ATTiny physical pin 7)
#define potmax 3. // maximum throttle setting from potmeter on P3 (ATTiny physical pin 2)
#define servo 4 // servo output from P4 (ATTiny physical pin 3)
volatile unsigned long timer_ch; // all timer variables are unsigned long
volatile int pulse_time = 1000;
volatile byte chWas = 0, sync = 0;
int RXpulse, Minpulse, Maxpulse, Outpulse = 1500;
void setup()
{
pinMode(led, OUTPUT);
pinMode(servo, OUTPUT);
pinMode (potmin, INPUT);
pinMode (potmax, INPUT);
pinMode(Rxch, INPUT);
timer_ch = 0;
GIMSK = (1 << PCIE); // Enable Pin Change Interrupts
PCMSK = (1 << Rxch); // Enable interrupts for rx channel inputs
sei();
}
void loop()
{
while (sync == 0);
sync = 0;
delay(6); // do the o/p pulses mid-frame, reduces jitter...
cli();
RXpulse = pulse_time; // do an atomic copy in the quickest way
sei();
if (RXpulse <= 1200) Outpulse = Outpulse - 5;
if (RXpulse >= 1800) Outpulse = Outpulse + 5;
Minpulse = 1000 + map(analogRead(potmin), 0, 1023, 0, 500); // Minpulse: 1000 > 1500
Maxpulse = 2000 - map(analogRead(potmax), 0, 1023, 0, 500); // Maxpulse: 1500 > 2000
// constrain Outpulse between Minpulse and Maxpulse:
if (Outpulse < Minpulse) Outpulse = Minpulse;
if (Outpulse > Maxpulse) Outpulse = Maxpulse;
digitalWrite(servo, 1); delayMicroseconds(Outpulse); digitalWrite(servo, 0); // servo out
}
ISR(PCINT0_vect)
{
if (PINB & 0b00000001) { // read the Rx pulse on P0
if (chWas == 0) {
timer_ch = micros();
chWas = 1;
}
} else {
if (chWas == 1) {
pulse_time = (micros() - timer_ch);
chWas = 0;
sync = 1;
}
}
}
Ik zou dat zeker veranderen. In hoeverre een hogere input spanning dan de Vcc fataal voor de chip is weet ik niet, maar in ieder geval gaat de nauwkeurigheid van de pots naar beneden. De A/D converters zijn berekend op maximaal Vcc aan de input (0V - 5V / 0 - 1023) . Maar als je de voeding van een ontvanger krijgt is er niet zoveel aan de hand (aangenomen dat je die met maximaal 5V voed), je mist dan alleen de spanningsval over de spanningsregelaar.Deze loopt op Vin, misschien beter om de potmeters op de uiteindelijke versie op 5V te solderen.
Ik zorg er voor dat alles wat ik publiceer éérst getest wordt op compileren, dus ja. Ik gebruik de IDE 2.3.3. (op de Mac), maar ik heb het bestand met enige moeite op mijn oude Mac overgezet en geopend met IDE 1.8.13, en ook daar compileert het bestand zonder problemen.Compileert de skech?
Maar werkt het ook zoals je je het voorstelde? Bruno vond de servo bij mijn versie nogal langzaam bewegen.........Maar dat is simpel aan te passen, gewoon de stapgrootte van +/- 5 microseconden wat groter maken (al wordt het herprogrammeren nogal lastig nadat alles er al aangesoldeerd is...)En alles werkt,