|
글쓴이 :
관리자
작성일 : 18-04-18 13:54
조회 : 5,251
|
ex_dcmotor_pwm.zip (40.2K) [7] DATE : 2018-04-18 13:54:17 |
안녕하세요? 고객님,
저희 뉴티씨 제품을 이용하여 주셔서 감사합니다.
소스를 보니, 아마도 첨부드린 소스를 변경하여 쓰시는 것 같습니다.
이 안에, 정역제어 및 PWM 속도제어가 모두 들어 있으므로,
참고하여 프로그래밍 하시는 것이 좋겠습니다.
이 소스는 AM-TS8 스위치 모듈을 포트A에 AM-DC2-2D 모터는 포트C에 꽂아서 쓰시면 됩니다.
감사합니다.
>
>
> 컴파일 환경을 설정하여 겨우 컴파일 성공하였습니다.
>
> 아래 정. 역회전 소스에 더하여 회전방향을 바꿀때
> 모터를 설정한 시간동안 정지시키고 싶습니다.
>
> while 문에 BREAK1_ON; 을 사용하였더니 모터가 정지하는데
> delay() 문을 써서 일정시간에 모터를 재가동 시키려 해봐도 모터가 기동을 하지 않습니다.
>
> (최종목적은 PWM 기능과 PID 제어로 모터를 자유자재로 제어하고 싶습니다.)
>
> 조언을 부탁 드립니다.
>
> 감사합니다.
>
> ==========================<Source>=========================
>
> #include <iom128v.h>
> #include <macros.h>
> #include <stdio.h>
>
> #define MOTOR_PORT PORTC
> #define PWM_PORT 0x00
> #define PWM1_ON (MOTOR_PORT|=0x01)
> #define PWM1_OFF (MOTOR_PORT&=0xFE)
> #define DIR1_ON (MOTOR_PORT|=0x02)
> #define DIR1_OFF (MOTOR_PORT&=0xFD)
> #define ENABLE1_OFF (MOTOR_PORT|=0x04)
> #define ENABLE1_ON (MOTOR_PORT&=0xFB)
> #define BREAK1_ON (MOTOR_PORT|=0x08)
> #define BREAK1_OFF (MOTOR_PORT&=0xF7)
>
> volatile unsigned int DCMOTOR[8], Tcount=0, motor_speed,sw_state[8]={0,0,0,0,0,0,0,0};
>
> // printf 함수 사용시 추가할 것.
> int putchar(char c)
> {
> while (((UCSR0A>>UDRE0)&0x01) == 0) ; // UDRE, data register empty
>
> UDR0 = c;
> return c;
> }
>
> // scanf 함수 사용시 추가할 것.
> int getchar(void)
> {
> while ((UCSR0A & 0x80) == 0);
> return UDR0;
> }
>
>
> void port_init(void)
> {
> PORTA = 0x00;
> DDRA = 0x00;
> PORTB = 0x00;
> DDRB = 0x00;
> PORTC = 0x00; //m103 output only
> DDRC = 0xFF;
> PORTD = 0x00;
> DDRD = 0x00;
> PORTE = 0x00;
> DDRE = 0x00;
> PORTF = 0x00;
> DDRF = 0x00;
> PORTG = 0x00;
> DDRG = 0x1F;
> }
>
> //UART0 initialize
> // desired baud rate: 9600
> // actual: baud rate:9615 (0.2%)
> // char size: 8 bit
> // parity: Disabled
> void uart0_init(void)
> {
> UCSR0B = 0x00; //disable while setting baud rate
> UCSR0A = 0x00;
> UCSR0C = 0x06;
> UBRR0L = 0x67; //set baud rate lo
> UBRR0H = 0x00; //set baud rate hi
> UCSR0B = 0x18;
> }
>
> //call this routine to initialize all peripherals
> void init_devices(void)
> {
> //stop errant interrupts until set up
> CLI(); //disable all interrupts
> XDIV = 0x00; //xtal divider
> XMCRA = 0x00; //external memory
> port_init();
> uart0_init();
>
> MCUCR = 0x00;
> EICRA = 0x00; //extended ext ints
> EICRB = 0x00; //extended ext ints
> EIMSK = 0x00;
> TIMSK = 0x00; //timer interrupt sources
> ETIMSK = 0x00; //extended timer interrupt sources
> SEI(); //re-enable interrupts
> //all peripherals are now initialized
> }
>
> void delay(int delaytime){
> int i,j;
> for(i=0;i<1000;i++){
> for(j=0;j<delaytime;j++){
> }
> }
> }
>
> void Motor_bt(int breaktime){
> int i,j;
> for(i-0;i<1000;i++){
> for(j=0;j<breaktime;j++) {
> if (j=breaktime
> }
> }
> }
> //
> void main(void)
> {
> init_devices();
> //insert your functional code here...
> ENABLE1_ON;
> PWM1_ON;
> BREAK1_OFF;
> printf("Motor Control V01W\r\n");
>
> while(1){
> DCMOTOR[PWM_PORT] = 100;
> DIR1_ON;
> delay(12000);
> PORTG = 0x01;
> printf("CW\r\n");
>
>
> DCMOTOR[PWM_PORT] = 100;
> DIR1_OFF;
> delay(12000);
> PORTG = 0x02;
> printf("CCW\r\n");
>
> }
> }
>
|
|