Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

voltage level right or not?

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
krolikbest

Bascom Member



Joined: 02 Jan 2017
Posts: 66

poland.gif
PostPosted: Sat Mar 10, 2018 7:53 pm    Post subject: voltage level right or not? Reply with quote

Hello,

here i attach my simple code:
Code:

$regfile = "m8adef.dat"
$crystal = 8000000

Config Pinb.1 = Output 'step silnik2
silnik2 Alias Portb.1

config pinc.2=output
kier Alias Portc.2

Dim rozruch2 as Integer, szybko2 as Integer, wolno2 as Integer

$baud = 19200                                               ' baud rate
$hwstack = 32                                               ' default use 32 for the hardware stack
$swstack = 10                                               ' default use 10 for the SW stack
$framesize = 40                                             ' default use 40 for the frame space

Config Timer1 = Timer, Prescale = 64, Compare A = Disconnect, Compare B = Disconnect, Clear Timer = 1

Enable Interrupts

On compare1a run_stepper2
Compare1a = szybko2

szybko2=120
silnik2=0

Do
Loop

run_stepper2:
 Toggle silnik2
Return
 


as you may guess this is for running stepper motor. But on output pin voltage level is only 2.14V while ATMega8 is sourced with 5v connected to VCC(d7) and AVCC(d20), so I expected that output will be ~5v. In the output (pin PB1) i use 1N4148 as a protection.
When I test it with a small lighting diode it works, it means, square wave generator works and diode is blinking all the time. But when I connect atmega's output to stepper's controller as a PULSE signal, it works for a while(1 sec) and then stops. Parallel i've connected oscilloscope 'Hantek' and see that ATmega8 is generating square wave no more! It looks like stepper (or to be more precise) stepper's controller stops ATMega8?
So with lighting diode atmega8 is generating square wave all time, with stepper only for a while. I suppose that either some kind of level shifter should be used or ... Maybe someone has similar experience?

Best regards
Martin

(BASCOM-AVR version : 2.0.7.6 , Latest : 2.0.8.1 )
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1803

blank.gif
PostPosted: Sat Mar 10, 2018 10:00 pm    Post subject: Reply with quote

Beside where it would make sense, I would not use a signed variable to control an unsigned register.
Also this code part makes no sense:
Code:
Compare1a = szybko2

szybko2=120
silnik2=0

Do
Loop
as szybko2 is zero at start, compare1a is and stays thus zero too, because writing szybko2 to 120 has no effect on compare1a.
Compare1a however is timer-top in CTC-mode, surely not intended this way.
Else, it may be a hardware issue of noisy power line, locking up the controller.
Back to top
View user's profile
krolikbest

Bascom Member



Joined: 02 Jan 2017
Posts: 66

poland.gif
PostPosted: Sun Mar 11, 2018 11:38 am    Post subject: Reply with quote

You are right but this piece of code is not exactly what is in uC. This is only few lines copied/pasted (probably there i did mistake during pasteing) from the whole program to demonstarte the problem.

Ok, found the problem. As you may know, AVCC should be connected to VCC and all GND to ground. For AVCC i did but not for one of GND. That was a problem. So many time checked .. Smile
<SOLVED>


Last edited by krolikbest on Sun Mar 11, 2018 12:00 pm; edited 1 time in total
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1803

blank.gif
PostPosted: Sun Mar 11, 2018 11:58 am    Post subject: Reply with quote

Are you joking? You're asking for help and for that purpose you post code, which you do not actually use?
Even after you get aware of that, you still don't post actual code.
Surely the error may be in hardware - something which you also do not show - but it may be a software issue.
It seems you assume the latter, otherwise this is the wrong part of the forum.
Good luck, you surly need it.
Back to top
View user's profile
krolikbest

Bascom Member



Joined: 02 Jan 2017
Posts: 66

poland.gif
PostPosted: Sun Mar 11, 2018 12:03 pm    Post subject: Reply with quote

Ok, sorry. But you were right that problem WAS in hardware. Now it works, i've described in my previous post what was bad. Thank you and good luck too Wink
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum