Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

codevision AVR + Proteus problem

Status
Not open for further replies.

huy vo

Newbie level 4
Joined
Apr 8, 2021
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
83
I have a problem with the increase and decrease of the motor speed of the circuit, please help me because this is my graduation thesis.
 

Attachments

  • mophong - Sao chép.rar
    69 KB · Views: 59

Solution
Hi,

I guess A,B,C are hall sensor inputs,
this is block commutation?

for CW and CCW I recommend to use tabels with 8 entires each. (2 entries are redundant)
tableB_CW(0..7): table for port B direction CW
tableC_CW(0..7): table for port C direction CW
tableB_CW(0..7): table for port B direction CCW
tableC_CW(0..7): table for port C direction CCW

Read PINC, AND 0x07 to get the table position. bit position are: 0b0000 0ABC
position 0 = redundant
position 1 = (C==0)&&(B==0)&&(A==1); tableB_CW(1) = 0b0000 0000 for portB = 0b|0|0|C5|C4 | C3|C2|0|0 = 0x08
and so on...

position 1 = (C==0)&&(B==0)&&(A==1); tableC_CW(1) = 0b0000 0000 for portC = 0b|0|0|0|C1 | C0|0|0|0 = 0x08
and so on...

this avoids the annoying long combinations of "IF". Is...
below is my simulation diagram, the dynamic speed reduction function does not work, I have looked at the code but can't solve it, can you help me because this is very important in my graduation thesis...
thanks

1628236313012.png
 

Hi,
the dynamic speed reduction function does not work

I guess the "dynamic speed reduction" is a part of the software. So without showing the software ... how can we help?

The schematic is incomplete --> see Q1. Don´t know how it should work.
A lot of values are not shown.
Some values are very questionable: --> see C1.
Some values I can´t read: Driver type: --> TC4????

If you need help you need to provide complete and useful informations first.

There is a chapter in the forum rules. Please read them.
"Only you know what "doesn't work" means".

Klaus
 
Hi,


I guess the "dynamic speed reduction" is a part of the software. So without showing the software ... how can we help?

The schematic is incomplete --> see Q1. Don´t know how it should work.
A lot of values are not shown.
Some values are very questionable: --> see C1.
Some values I can´t read: Driver type: --> TC4????

If you need help you need to provide complete and useful informations first.

There is a chapter in the forum rules. Please read them.
"Only you know what "doesn't work" means".

Klaus
Thank you for your comment, I have corrected the simulation and removed the code written on codevision AVR, can you review and help me with the problem of speed reduction?



1628263022429.png



Code C - [expand]
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include <mega8.h>
#define  C0 PORTC.3
#define  C1 PORTC.4
#define  C2 PORTB.2
#define  C3 PORTB.3
#define  C4 PORTB.4
#define  C5 PORTB.5
#define  C PINC.0
#define  B PINC.1
#define  A PINC.2
#define  Stop PIND.3
#define  Back PIND.4      
#define  Foward PIND.5
//------------------------------------------------------------------
unsigned char a; int h;
//-------------------------------------------------------------------------
   void CW(void)
{
      //Phase 6: 001 // 010 010
if (((C==0)&&(B==0)&&(A==1))==1){C5=0;C4=0;C3=1; C2=0;C1=0;C0=1;};
      //Phase 4: 010 // 001 001          
if (((C==0)&&(B==1)&&(A==0))==1){C5=0;C4=1;C3=1; C2=0;C1=0;C0=0;};  
      //Phase 5: 011 // 011 000        
  if(((C==0)&&(B==1)&&(A==1))==1){C5=1;C4=0;C3=0; C2=1;C1=0;C0=0;};
      //Phase 2: 100 // 100 100        
if (((C==1)&&(B==0)&&(A==0))==1){C5=0;C4=0;C3=0; C2=1;C1=1;C0=0;};
    //Phase 1: 101 // 000 110        
if (((C==1)&&(B==0)&&(A==1))==1){C5=1;C4=0;C3=0; C2=0;C1=0;C0=1;};
    //Phase 3: 110 // 100 001        
if (((C==1)&&(B==1)&&(A==0))==1){C5=0;C4=1;C3=0; C2=0;C1=1;C0=0;};
}
void CCW(void)
{
      //ccw
      //Phase 6: 001 // 100 001
if (((C==0)&&(B==0)&&(A==1))==1){C5=0;C4=0;C3=0; C2=1;C1=1;C0=0;};
        //Phase 4: 010 // 000 110          
if (((C==0)&&(B==1)&&(A==0))==1){C5=1;C4=0;C3=0; C2=1;C1=0;C0=0;};
                 //Phase 5: 011 // 100 100        
if (((C==0)&&(B==1)&&(A==1))==1){C5=0;C4=1;C3=1; C2=0;C1=0;C0=0;};
    //Phase 2: 100 // 011 000        
        if (((C==1)&&(B==0)&&(A==0))==1){ C5=0;C4=0;C3=1; C2=0;C1=0;C0=1;};
//Phase 1: 101 // 001 001        
if (((C==1)&&(B==0)&&(A==1))==1){C5=0;C4=1;C3=0; C2=0;C1=1;C0=0;};
//Phase 3: 110 // 010 010        
if (((C==1)&&(B==1)&&(A==0))==1){C5=1;C4=0;C3=0; C2=0;C1=0;C0=1;};
    }
void STOP(void)
        { C5=0;C4=0;C3=0; C2=0;C1=0;C0=0;}
// External Interrupt 0 service routine
//----------------------------------------------------------
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
// Place your code here
  STOP(); while(Stop==1);
}
#define FIRST_ADC_INPUT 0
#define LAST_ADC_INPUT 5
unsigned char adc_data[LAST_ADC_INPUT-FIRST_ADC_INPUT+1];
#define ADC_VREF_TYPE 0x20
// ADC interrupt service routine
// with auto input scanning
interrupt [ADC_INT] void adc_isr(void)
{
unsigned char input_index=0;
// Read the 8 most significant bits
// of the AD conversion result
adc_data[input_index]=ADCH;
// Select next ADC input
if (++input_index > (LAST_ADC_INPUT-FIRST_ADC_INPUT))
   input_index=0;
ADMUX=(FIRST_ADC_INPUT|ADC_VREF_TYPE)+input_index;
// Start the AD conversion
ADCSRA|=0x40;
}
// Timer 2 overflow interrupt service routine
interrupt [TIM2_OVF] void timer2_ovf_isr(void)
{
// Place your code here
      a=adc_data[5];
      h=a;
      OCR1A=100*h;
}
// Declare your global variables here
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port B initialization
// Func7=In Func6=In Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=In
// State7=T State6=T State5=0 State4=0 State3=0 State2=0 State1=0 State0=T
PORTB=0x00;
DDRB=0x3E;
// Port C initialization
// Func6=In Func5=In Func4=Out Func3=Out Func2=In Func1=In Func0=In
// State6=T State5=T State4=0 State3=0 State2=T State1=T State0=T
PORTC=000;
DDRC=0x18;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0=0x00;
TCNT0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 12000.000 kHz
// Mode: Fast PWM top=ICR1
// OC1A output: Non-Inv.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x82;
TCCR1B=0x19;
TCNT1H=0x00;
TCNT1L=0x00;
//ICR1H=0x00;
//ICR1L=0x00;
ICR1=20000; //T
//OCR1AH=0x00;
//OCR1AL=0x00;
OCR1A=10000; //khoi tao
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: 1500.000 kHz
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x02;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Rising Edge
// INT1: Off
GICR|=0x40;
MCUCR=0x03;
GIFR=0x40;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x40;
// Analog Comparator initializationt
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC Clock frequency: 187.500 kHz
// ADC Voltage Reference: AREF pin
// Only the 8 most significant bits of
// the AD conversion result are used
ADMUX=FIRST_ADC_INPUT|ADC_VREF_TYPE;
ADCSRA=0xCE;
// Global enable interrupts
#asm("sei")
while (1)
      {
      // Place your code here
       if(Foward==1)CW();
       if(Back==1) CCW();
      };
}

 
Last edited by a moderator:

Hi,

I guess A,B,C are hall sensor inputs,
this is block commutation?

for CW and CCW I recommend to use tabels with 8 entires each. (2 entries are redundant)
tableB_CW(0..7): table for port B direction CW
tableC_CW(0..7): table for port C direction CW
tableB_CW(0..7): table for port B direction CCW
tableC_CW(0..7): table for port C direction CCW

Read PINC, AND 0x07 to get the table position. bit position are: 0b0000 0ABC
position 0 = redundant
position 1 = (C==0)&&(B==0)&&(A==1); tableB_CW(1) = 0b0000 0000 for portB = 0b|0|0|C5|C4 | C3|C2|0|0 = 0x08
and so on...

position 1 = (C==0)&&(B==0)&&(A==1); tableC_CW(1) = 0b0000 0000 for portC = 0b|0|0|0|C1 | C0|0|0|0 = 0x08
and so on...

this avoids the annoying long combinations of "IF". Is much faster, constant in time and - in my opinion - better to understand.
**********************

basically you need to measure the RPM. This means the time from one phase to the next.
According this you can increase duty cycle of PWM.
At least this would be my fisrt approach.

But maybe it´s better to read some tutorials how other - with more experience than me - do it.

Braking and switching to opposite direction is somehow difficult because of the rotational energy.
Either you do DC braking. This may cause overvoltage on your bus capasitor.
Or you just let it free run until RPM is zero. Then start inopposite direction.

As already written: Read tutorials.

Klaus
 
Solution
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top