ATmega32 Problem

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
dawladin
Posts: 13
Joined: Mon Feb 04, 2013 12:05 pm
Has thanked: 4 times
Been thanked: 1 time

ATmega32 Problem

Post by dawladin »

Hello :)

I have one problem with my flowcodechart done in Flowcode v4.

My flowchart has 4 major functions.

It controls a servo, A HC SR04, 2 dc motors and 2 internal PWMS to adjust the motors so that is can turn and keep a straight line.

My problem is that when i use the PWMS to control the dc motors, my servos movement becomes highly irregular.

I am useing a H-bridge to deliver the power to the dc motors and my microchip is an ATmega32.

Conections:
Motor1: D4 and D6
Motor2: D5 and D3
Servo: B3
HC SR04: B7 trig and B6 Echo

I've attached the program to the post

Michael Steffensen
Attachments
Afstandsmler michael.fcf_avr
(14.95 KiB) Downloaded 268 times

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 474 times
Been thanked: 458 times

Re: ATmega32 Problem

Post by dazz »

Hi
Firstly can you sign up to relevant forum based on your version of flowcode (follow the link in my sig)
if you look at your servo macro, you arn't using the servo component,instead you are using channel one of your pwms so when the motor gets called to move your servo (this was also called in main to move a motor )
i have reassigned PWM 2 and 3. (look at the name on the pwm components in your panel (renamed them to the Pwm channel and associated PORT) .
Try the flowchart i have attached as the motors should both now move without the servo, doing its own thing.
Have a look at your Servo macro ,replace the pwm calls with the servos macros

Regards
Dazz
Afstandsmler michael2.fcf_avr
(24.45 KiB) Downloaded 264 times
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

dawladin
Posts: 13
Joined: Mon Feb 04, 2013 12:05 pm
Has thanked: 4 times
Been thanked: 1 time

Re: ATmega32 Problem

Post by dawladin »

Thank you for the reply :D

I'm wondering if the name of the pwm crucial to where the output goes or is it just for cosmetic reasons?

And again thank you so much

Kindest regards Michael

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 474 times
Been thanked: 458 times

Re: ATmega32 Problem

Post by dazz »

Hi
The PWM channel assignment follows Atmel practise, there are 2 ways of working it out, one is look at the datsasheet ,the other is to open the chips fcd file and look at the pwm section this will tell you what pin corresponds to what channel see below( this is from the flowcode fcd for your chip.

Code: Select all


Define45=#define MX_PWM_1_PORT PORTB
Define46=#define MX_PWM_1_TRIS DDRB
Define47=#define MX_PWM_1_PIN 3
Define48=#define MX_PWM_2_PORT PORTD
Define49=#define MX_PWM_2_TRIS DDRD
Define50=#define MX_PWM_2_PIN 5
Define51=#define MX_PWM_3_PORT PORTD
Define52=#define MX_PWM_3_TRIS DDRD
Define53=#define MX_PWM_3_PIN 4

Regards
Dazz
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

dawladin
Posts: 13
Joined: Mon Feb 04, 2013 12:05 pm
Has thanked: 4 times
Been thanked: 1 time

Re: ATmega32 Problem

Post by dawladin »

Thanks for your help but there is one last thing the file you sent me was for v5, so i was wondering if you had a v4 file instead :)

From a grateful student :)

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 474 times
Been thanked: 458 times

Re: ATmega32 Problem

Post by dazz »

Hi
Attached is a V4 file, I've removed the outputs on the pwms as if you programmed the pic the pwm would do its own thing, sim the flowchart at 100 and watch the pwms and servo, i've changed the servo macro to move to pos 254 and return to main, when it renters the macro it moves to position 10 then 0 and then counts up to 254 etc.

When it exits the servo macro and goes into the srfo4 loop, ive added a switch , set the switch wait a while then unset the switch , this then displays the distance on the lcd, leave the switch set for different times to get different results etc
Also you dont need to add an output in your flowchart for the pwm's as the pins are assigned automatically, however the servo does need to be connected to a pin in the panel
Regards
Dazz
Attachments
Afstandsmler michaelv4(changed).fcf_avr
(17.24 KiB) Downloaded 251 times
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

Post Reply