Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
April 23, 2024, 11:06:10 11:06


Login with username, password and session length


Pages: 1 [2]  All
Print
Author Topic: Motor controller with RPM count  (Read 9604 times)
0 Members and 1 Guest are viewing this topic.
TomJackson69
Active Member
***
Offline Offline

Posts: 218

Thank You
-Given: 26
-Receive: 63


« Reply #25 on: December 13, 2011, 07:17:46 19:17 »

leaveme,

You may have lock the TMR0 interrupt by putting a 20uS delay inside the int routine.

your code
"
#INT_TIMER0
void triggure(){
   set_timer0(period);
   dim_pos++;
   if (dim_pos==intensity){    
      ON(TRIAC);                                  
      delay_us(20);
      OFF(TRIAC);                                
    }            
 }
"

Timer 1 is an 8 bits and 20uS seem too long for me. Please check to see what is your interrupt period.

Tom
« Last Edit: December 13, 2011, 07:21:13 19:21 by TomJackson69 » Logged

Con Rong Chau Tien
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #26 on: December 14, 2011, 07:19:19 19:19 »

Some points:

- what pin for triac gate? RB7 at the code but RB6 at Proteus?
- trigger signal should go to anode of opto led?
- as Tom said, delay in interrupt is not good - turn off the triac somewhere else on the main loop.
- as Solution said, be careful with inductive load of the motor - the triac can be keep turned on where it should be turned off.

If you are trying to use this phase control for your cnc spindle, then you might try to look into Variable Frequency drive - phase controlled motor speed have a very bad torque at low speed.

-ichan
Logged

There is Gray, not only Black or White.
leaveme
Junior Member
**
Offline Offline

Posts: 93

Thank You
-Given: 38
-Receive: 15


« Reply #27 on: December 15, 2011, 11:58:37 11:58 »

Thanks Ichan for the correction.

Anyway, I changed the whole coding...trying to learn the phase control concept...

UPDATE:
Below coding is not working in real HW. Looking for some advice...pls.  Huh


Code:
// Compiler: CCS PCWHD 4.120
// Motor Speed Control - AC220V/50Hz

#include <16F886.H>

#device adc=10;

#fuses HS               //High speed Osc (> 4mhz for PCM/PCH)
#fuses NOWDT            //No Watch Dog Timer
#fuses NOLVP            //No low voltage programing, B3(PIC16)
#fuses NOPROTECT        //Code not protected from reading
//#fuses NOBROWNOUT       //No brownout reset
//#FUSES NOPUT            //No Power Up Timer

#use delay(clock=20M)    //20MHz clock, one instruction=0.2us


#define LCD_DB4    PIN_B1
#define LCD_DB5    PIN_B2
#define LCD_DB6    PIN_B3
#define LCD_DB7    PIN_B4

#define LCD_E      PIN_C5
#define LCD_RS     PIN_C4
#define LCD_RW     PIN_C6

#include <flex_LCD.c>



#define PORT_adc   sAN0    // PIN_A0
#define PORT_zero  PIN_B0
#define GATE       PIN_B6

int16 duty=0;
int16 intensity;                
int16 percent;
float div = 0.1022;


#int_ext
void key_interrupt(void) {
   int phaseangle=10;
   duty=percent;
  
   // force triac off at startup since we do not know the pulse state
   if (duty==0) {
       OUTPUT_LOW(GATE);
   }

   if (input(PORT_zero)) {
       // Here since the input is low,
       // we now need to look for a low to high transition
       ext_int_edge( L_TO_H );
       OUTPUT_LOW(GATE);
       delay_us(phaseangle);
       OUTPUT_HIGH(GATE);
       delay_us(duty);
       OUTPUT_LOW(GATE);
   }
   // else {
      // Here since the input is high,
      // we need to next look for the high to low transition
      //  ext_int_edge( H_TO_L);
      //  OUTPUT_LOW(GATE);
      //  delay_us(phaseangle);
      //  OUTPUT_HIGH(GATE);
      //  delay_us(duty);
      //  OUTPUT_LOW(GATE);
      // }
}
  
void main(void) {
    set_tris_a( 0b00000001 );    
    set_tris_b( 0b00000001 );    

    // Setup the ADC so we can read a value from 0 to 1022
    // as we turn a trimpot which is connected to pin A0.
    // setup_comparator(NC_NC_NC_NC);
    setup_adc_ports(PORT_adc);
    setup_adc(ADC_CLOCK_DIV_32);    // Divisor for 20 MHz oscillator
    set_adc_channel(0);
    delay_us(15);

    lcd_init(); //LCD start
    lcd_putc("\f");  // Clear the LCD
    delay_ms(100);
    lcd_gotoxy(1,1);    //Goto first line
    printf(lcd_putc, "Intensity");

    // Set _one_ active edge.
    // Set it to the next change that can occur
    if (input(PORT_zero)) ext_int_edge( H_TO_L );
     else ext_int_edge(L_TO_H);
    
    clear_interrupt(INT_EXT);
    enable_interrupts(int_ext);
    enable_interrupts(global);
      
    //Must ensure code does not exit.
    while (true) {

      intensity = read_adc();       // Read speed set value from the ADC
      percent = intensity/div ;

      lcd_gotoxy(1,2);    //Goto second line
      printf(lcd_putc, "%lu   ", duty);  //Show intensity for test perpose

    }
}

« Last Edit: December 19, 2011, 04:58:51 16:58 by leaveme » Logged
Pages: 1 [2]  All
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC