Show Posts
Pages: 1 [2] 3 4 ... 23
16  Using Arduino / Programming Questions / 8bit variable and struct to represent a Register & its bits on: August 09, 2013, 09:19:33 pm
Basically what i want is something along these lines
pseudo code

uint8_T  =  8_bits_in_register    <-- this would be the variable that would hold the 8 bits for the register

struct  ADMUX               <-- i know  i cannot call it ADMUX but for the sake of making this easier to explain lets say its called admux
{
     some_variable_type       left_Adjust ;
   
    some_variable_type       ref_Voltage_Avcc ;

    some_variable_type       ref_Voltage_1v ;

};


then i  would use it :   
ADMUX.left_Adjust = true ;
ADMUX.ref_Voltage_1v = false ;
ADMUX.ref_Voltage_AVCC = true ;

and as i set these up they get appended to the 8 bit variable (which would be a binary number)
in the proper order so that when that variable is passed to the register all my setting match

so it would look like

8_bit_variable  = 0b00101101  and i would pass that on to the real admux ,


is this feasible?  or is there a more efficient way to write a generic way of setting up something such as ADC or PWM for that matter
basically use a structure to set all the bits in  a port
17  Using Arduino / Programming Questions / Re: setting PWM Counter and registers yields odd behavior on: August 08, 2013, 01:24:56 am
sorry i didnt include the preprocessor code in my post

but i have pwm set as a global since its used all over the place
Code:
double  pwm = 0;
int cycle = 0;
18  Using Arduino / Programming Questions / Re: setting PWM Counter and registers yields odd behavior on: August 08, 2013, 12:03:23 am
interesting..i think its because of delay but then again it would happen every 10ms if it was indeed delay

its goes
0...255
0...255
0...255
255...0
255...0
255...0

not at all what it want
any ideas?
19  Using Arduino / Programming Questions / setting PWM Counter and registers yields odd behavior on: August 07, 2013, 10:19:37 pm
tonights issue is the following ,
when trying to set up counter 0 which is an 8 bit counter
to fastPwM
 i use the following code
 now before you read
understand i have tried the following
Change the interrupt to overflow , on compare match

also tried having no interrupt and just updating  the compare register everytime i update pwm


but the strange behavior is this..
it does what  i want it to do but...wrong
i want it to fade in and out out

instead it fades from 0 to 255 THREE TIMES
and then from 255 to 0  THREE TIMES...
 where in the code am i telling it do it three times in between transitions ????
 
i want  one fade up and one fade down nice smooth transition..

unless i have a misunderstanding of how the timer works
Code:
int main(void)
{

        sei(); //global interrupts
DDRD |=(1<<PIND6); // set pin d6  OC0A to output



TCCR0A |= ((1<<WGM01) | (1<<WGM00)); // enable fast pwm

TCCR0A |= (1<<COM0A1); // clear on compare math , set at bottom
TIMSK0 |= (1<<OCIE0A);// compare match interrupt
      

OCR0A = ((pwm / 100) * 255.0 ) ;//value to compare to timer , aka pwm dudty cycle
TCCR0B |= (1<<CS00) ); // no prescale


while(1)
{
_delay_ms(10);
//just fade in and out , 8 bit mode
if (pwm >=255)
cycle = 0;


if(pwm <=1 )  
cycle = 1;

if(cycle == 0 )
pwm --;

if (cycle == 1)
pwm++;


}

}
ISR (TIMER0_COMPA_vect)
{
OCR0A =  ((pwm / 100) * 255.0 ); // update  duty cycle again since it changes everytime around main loop


}
20  Using Arduino / Programming Questions / need a global variable defined that constantly changes on: August 06, 2013, 10:50:22 pm
ok i have a feeling this might be simple but i cannot get my head around it
 i am trying to make a simple pwm file which , for learning purposes will only use the 8 bit timer
along with PIN D6 (OCOA)...the code for that looks like thislooks like this
Code:
#ifndef fastPWM
#define fastPWM

void iniPWM()
{
TCCR0A |= ((1<<COM0A1) | (1<<WGM01) | (1<<WGM00)) ; //set to use pin d6 and set to fast pwm
TCCR0B |= ((1<<CS02) | (1<<CS00)) ; //set the prescaler
TIMSK0 |= ((1<<TOIE0));// set timer overflow interrupt .. not sure if its is propper to use interrupts in files outside of main program
}

void startPWM (  )
{
   
OCR0A  =((pulseWidth / 100) * 255.0); // set  output compare to a percentage of 255
}


ISR (TIMER0_OVF_vect)
{
OCR0A  =((pulseWidth / 100) * 255.0); //after the first interrupt this should just keep going and going

}

#endif

now my problem is i need to pass a pulsewidth in my main code if i use #define pulsewidth then i cant change the pulse width
and if  i use a regular deffinition then its not seen by the pwm library...
my main code looks like this
Code:
#define F_CPU 16000000L
#include <avr/io.h>
#include <eddie/fastPWM.h>
#include <avr/interrupt.h>
int pulseWidth = 50;  // <--here is the problem
int main(void)
{
sei();
iniPWM();

    while(1)
    {
       
startPWM();

    }
}

i know  i can set the start pwm function to accept a parameter but then how do i  get the ISR routine to also see that parameter if ISR accepts no parameters , only way would be to have a global variable , but then i cant change it....feels like a catch 22 , but im sure its just lack of knowledge..
can anyone enlighten me

furthermore is malpractice to use interrupts inside a .h file?
i know .h files are for definitions only , i will soon be attempting to learn about libraries . i just want to test  out what can be done in an .h file
21  Using Arduino / Programming Questions / *pointer PINB1 ... is there a way? on: August 05, 2013, 11:39:17 pm
is there a way to assign the address of a pin to a pointer?
works perfectly with data direction registers.

if not how does one make a function that asks for a pin number , with out having to resort to
if x ==1 then PINB1
if x = 2 then PINB2

one more question when  compiling this line gives me a warning, it still works as desired but im just wondering what the warning means
Code:
int *test = &PORTB ;

"Warning   1   initialization from incompatible pointer type [enabled by default]"

what data type are the ports?? and where does one learn such things...? aside from trial and error
22  Using Arduino / General Electronics / cell phone jammer using house Mains ground as antenna on: August 04, 2013, 02:09:13 am
would that be possible? i saw somewhere someone use their houses ground connection through a wall socket to extend the rang of his wireless headphones, fo course this creates a huge antenna as well as noise and might disrupt the neighbors devices on the same frequency , theoretically could you make a cell phone jammer and use your mains ground as the antenna ? I am not planning to make this nor am i asking for details on how , its just an idea that came to mind
23  Using Arduino / General Electronics / bypass caps proper routing? on: August 03, 2013, 01:23:17 am
Quick question guys, when using bypass caps as you can see here in the image , one side is going to a ground plane then the other side is a power trace , should the power trace enter through the cap to have the coupling effect or can i just route it straight  to the pad and the cap will still do its job , its is still connected ...

24  Using Arduino / Programming Questions / Re: Arduino stops when using Interrupts() - Serial freezes on: August 01, 2013, 01:18:05 am
sharing the knowledge..
You cannot use delays in an interrupt.

•Don't attempt to delay, eg: delay (100);

•You can get the time from a call to millis, however it won't increment, so don't attempt to delay by waiting for it to increase.

•Don't do serial prints (eg. Serial.println ("ISR entered"); )

•Don't try to do serial reading.

See:
http://www.gammon.com.au/forum/?id=11488
25  Using Arduino / Programming Questions / Re: adding delay in interrupt does not work on: August 01, 2013, 12:35:59 am
Very well explained guys and good link there to Gammon's site. I did not know the whole interrupts are disabled when an interrupt occurs , but then again I am to blame when it is right there , first sentence on page 14  of the datasheet

Quote
When an interrupt occurs, the Global Interrupt Enable I-bit is cleared and all interrupts are disabled. The user software
can write logic one to the I-bit to enable nested interrupts. All enabled interrupts can then interrupt the current
interrupt routine. The I-bit is automatically set when a Return from Interrupt instruction – RETI – is executed
26  Using Arduino / Programming Questions / adding delay in interrupt does not work on: July 31, 2013, 11:11:29 pm
i was just hoping to get an explanation as to why when i add the _delay_ms
in an interrupt it cause it to not work.
i was trying to add it to the ISR call as oppose to the while loop, for no real reason i figured it would work the same , i imagine since its "haniging" there it misses there interupt next time around...everytime around??
Code:
/*
* PWM_experiment.c
*
* Created: 7/16/2013 9:43:52 PM
*  Author: eddiea6987
*/

#define F_CPU 16000000L
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>

double  pwm = 0;
int cycle = 0;
int main(void)
{
DDRD |=(1<<PIND6); // set pin d6  "OC0A" to output

TCCR0A |= ((1<<WGM01) | (1<<WGM00)); //set form generation mode to  fast pwm

TCCR0A |= (1<<COM0A1); // clear on compare match
TIMSK0 |= (1<<TOIE0);// overflow interrupt enable
sei(); //enable global interrupts

OCR0A = ((pwm / 100) * 255.0 ) ;//value to compare to timer ,  pwm dudty cycle
TCCR0B |= (1<<CS00) | (1<<CS02); // set prescaler to 1024 , once set timer will start

while(1)
{
_delay_ms(10);
pwm++; //increment dutyCycle PWM
if(pwm > 100)
{
pwm = 0;
}

}

}
ISR (TIMER0_OVF_vect)
{
OCR0A =  ((pwm / 100) * 255.0 ); // give it a new dutycycle " since it was changed i while loop main

//_delay_ms(50); // adding a delay in the isr will cause it not work
}
27  Using Arduino / General Electronics / AVR dev board , 2 MCUs , 2Power sources..? on: July 24, 2013, 10:04:12 am
Hey guys,
 I'm trying to make an Avr development board
 with an external lcd to use for debugging purposes
One chip will be programmed in a zif socket
I will break out the ports as well as separate place for SPI ICSP UART and TWI

How ever I do not want that lcd wired up to the MCU I'm programming because even in 4bit mode its using up the pins not to mention the avr programmer is also using up pins

So I want to have a separate chip probably a 328p or p-au driving the LCD and communicating with the chip being programmed via UART at most just listening which is just one wire and a com. Ground.
And i am going to have that lcd and the chip driving it running off an external power supply (not icsp) ..so my question is as follows:

Since the ICSP is going to give the chip being programmed power then the only thing I need between the two would be a common ground?

Or can I drive the them both off external power supply and just not connects the ICSP vcc to anything ..I don't think leaving that pin floating will be a good and I'm not sure if grounding it is right either. .I was hoping if I didn't have to power one of the microcontrollers  via icsp then I can just program it then unplug the programer and it'll still be powered.

i am at work so here's a sketch of the idea..mind the penmanship and picaso like drawing .

28  Community / Bar Sport / Re: Your latest purchase on: July 18, 2013, 11:44:14 pm
Atmel Capacitive Touch Sensors , these are the one channel , i also purchased a couple 7 Channel .

29  Using Arduino / Programming Questions / Re: Setting up ADC ..am i setting the right bits? on: July 18, 2013, 03:01:55 pm
okay i have it working its that the 0-255 resolution sucks i hardly turn the pot and the led goes on i guess ill have to read both bytes to get that 10bit. Appreciate the help guys , if Coding Badly had not mentioned the ADATE bit i wouldnt have noticed it and that was an issue as well.
30  Using Arduino / Programming Questions / Re: Setting up ADC ..am i setting the right bits? on: July 18, 2013, 02:49:15 pm
okay this part confuses me....

in the data sheet picture above, under  "ADC AUTO TRIGGER SOURCE"
the last sentence says:

"IF ADEN in ADCSRA is set (meaning if  the ADC is enabled) , this will start a conversion.
Switching to  Free Running mode (ADTS2-0) will not cause a trigger event, even if the ADC interrupt flag is set "

ok correct me if i am wrong...but by "trigger event" im assuming they mean trigger a new conversion ,
so when they say  free running mode will not cause a trigger event , then what does "free running" mode mean?
i thought it meant it just keeps "running"  in other words reading the analog input and setting the data registers with out the need for
an interrupt such as timer/counter compare match
Pages: 1 [2] 3 4 ... 23