sensor error help me

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

working right zero cross , But its setting doesn't work properly  OCR1A = map(deger, 22, 1023, 100, 0);    I installed here doesn't work properly the pin output  and not responding  what to do now :(üzgün

 

 

Code;

#include <avr/io.h>
#include <avr/interrupt.h>
#include <math.h>
#define DETECT 2      //zero cross detect, interrupt 0, is physical pin 7
#define GATE 1        //triac gate is physical pin 2 pourrait etre 0 (pin5)
#define PULSE 2       //trigger pulse width 4 if 512 (counts)
#define sensorPin 4

void setup() {
  // set up pins
  pinMode(DETECT, INPUT);      //zero cross giriş
  digitalWrite(DETECT, HIGH);  //enable pull-up resistor
  pinMode(GATE, OUTPUT);       //triac çıkış sinyali
   pinMode(sensorPin, INPUT);

  TCCR1 = 0;
  OCR1A = 100;
  TIMSK = _BV(OCIE1A) | _BV(TOIE1);
  sei();

  attachInterrupt(0, zeroCrossingInterrupt, FALLING);
}

//Interrupt Service Routines
void zeroCrossingInterrupt() {
  TCNT1 = 0;
  TCCR1 = B00001000;
}

ISR(TIMER1_COMPA_vect) {
    digitalWrite(GATE, HIGH);
  TCNT1 = 255 - PULSE;
}

ISR(TIMER1_OVF_vect) {
  digitalWrite(GATE, LOW);
  TCCR1 = 0;
}

void loop() {

  int deger = analogRead(sensorPin);
     
OCR1A = map(deger, 22, 1023, 100, 0); 
 
 

}

Last Edited: Fri. Jan 31, 2020 - 11:03 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You've not given us much to work from.

 

My guess is: TCNT1 = 255 - PULSE; what do you want this to do?

 

When I've done triac phase control, I use the timer input capture for the zero crossing and the compare feature to time the triac firing. I don't use overflow.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is arduino code...

was there not a timer claimed by the arduino platform to generate internal ticks?

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yes i bought it from the library, the code I wrote is not working anttny but is works arduino ,I want to visualize my finishing project and want to get a study and  I made fan design with mechanical engineer ansys but I want a module that changes with temperature but it doesn't

Last Edited: Fri. Jan 31, 2020 - 11:08 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't know how to change there , I control speed with this OC1A  but I want speed control that changes with temperature but it doesn't work