<<<

abstract

Circuit design

List of components

Making the board

Code

First test

desired operation

interruptions

pwm

Tests

unloaded

with load



abstract

Work this week at the fabacademy is to build an actuator circuit and the control with microcontrollers.

I wish to make a / flashing headlights Central for my velomobile.

To operate a little more the possibilities of tiny (because otherwise I could have fair all without microcontroller),

I'll create features like code / headlights (PWM) and signal / warnings.

Because it's a mosfet board, it's also a multipurpose device for activating motors or solenoids.


Circuit design

I use FabModules to draw the circuit: make_cad_png

This is a ATTINY44 piloted by three switches, for operating 3 mosfets.

The card is provided with a voltage regulator, and the lights may be powered at different voltages.

According to the datasheet of mosfet (N), and the regulator may supply the circuit until 30V

File: Light.central.44.cad

I add leds to the outputs to get adicators for activations of mosfets

the board
WARNING there is no diode controller input! if you plug the PSU upside down, it burns!
tracescut & holes
I combine holes and cut to do the mill in the same operation

List of components

id
component amount
D1, D2, D3 Red leds 1206 smd 3
R1 Resistance 1206 cms 10KB 1
R2, R3, R4 1206 cms Resistance 100 Ohms 3
C1 1206 cms capacitor 1uF 1
IC1 ATtiny44SSU 1
IC2 regulator 5V/100mA LM3480IM3-5.0 1
T1, T2, T3 Mosfets N 30V 1.7A 3
J1 6-pin ISP connector 1
J2, J3, J4, J5 screw terminals not 3.5mm 4


Making the board

during milling, I was unsure of the horizontality of the work plan, I settled in fabmodules a slightly larger than normal depth: 0.12mm instead of 0.1

milled

We see the difference because the inter-tracks are much more hollow, then tracks and fine patterns are more fragile:
this is particularly evident for the text, but it will be careful when soldering, because the fine tracks can be tendency to come off.

soldered

Although I'm getting better every time, I think I still have some progress soldering technique ;)

Screw terminals, through, are soldered to the back of the circuit.


I used the small code below to test the circuit: I had me try several times to correct any small errors in welding.



Code

I'm coding in C, starting from examples of the course

First test

To validate the circuit

I made a simple code that flashes the outputs

File: Hello.blink.3.44.zip

I stourted with a switching power supply recovery, but the microcontroller does not respond well. It seems that the power dropped much voltage under load, yet not so huge ...

Finally, I put a 9V battery and it works well.


desired operation

input

3 switches are wired to the ISP connector inputs PA4, PA5 and PA6 settled pullup


1 button (PA4): each button release mode is changed for the headlights: low> high> off

during the button pushed, it is full headlights (to the headlight flasher)


2 switchs monostable (PA5 and PA6): flashing (left and right)

if it triggers a flashing button while the headlights button is turned on, it goes into warnings.


output

PA0 PA1 PA2 pins are wired to the mosfets



interruptions

Flashing ... flash, so it will be wise to use interrupts to detect changes even during the delay buttons blink.

some resources about the tiny interruptions:

http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=105493

http://www.nongnu.org/avr-libc/user-manual/group__avr__interrupts.html


in the datasheet can be seen that all three inputs of the buttons are positioned on the same interrupt port


I have not yet implemented the warning function.

To put into action the interruptions, I informed the ISR function (PCINT0_vect) that is called when you stop on concerned pins .

You must write in this function tests and actions to take when  a monitored pin is changing.



  1.  
  2. ISR(PCINT0_vect) // interrupt service routine
  3. { // called when PCINT0 changes state
  4.  
  5.  
  6.  
  7. /////////////BLINKERS
  8. if((!(button_pins & LeftBton_pin)) && blink_mode==0 ){
  9. blink_mode=1;
  10. }
  11.  
  12. if((!(button_pins & RightBton_pin)) && blink_mode==0 ){
  13. blink_mode=2;
  14. }
  15.  
  16. if((button_pins & RightBton_pin) && blink_mode==2){
  17. blink_mode=0;
  18. }
  19.  
  20. if((button_pins & LeftBton_pin) && blink_mode==1){
  21. blink_mode=0;
  22. }
  23.  
  24.  
  25. /////////////////LIGHT
  26. if(!(button_pins & LightBton_pin) && btonLightState==0){
  27. //LightBton_pin rise up
  28. //
  29. btonLightState=1;
  30. }
  31. if((button_pins & LightBton_pin) && btonLightState==1){
  32.  
  33. //LightBton_pin rise down
  34. btonLightState=0;
  35. //change light mode
  36. if(light_mode<2) {
  37. light_mode+=1;
  38. }else{
  39. light_mode=0;
  40. }
  41. }
  42.  
  43.  
  44. return;
  45. }
  46.  
  47.  

Then, in the beginning of the program, I enabled the interrupt port connected to pins 0-7 or PCIE0

Then set the watch mask on pins that I whant   (to not the routine triggers when the outputs are enabled)

Finally, I enabled the interrupt method:


  1.  
  2. GIMSK |= (1<<PCIE0); // enable PCIE0 interrupt
  3. PCMSK0 = (1<<PCINT4)|(1<<PCINT5)|(1<<PCINT6); // pin change mask: listen to portA 4, 5 and 6
  4. sei(); //Enable Global Interrupt
  5.  
  6.  




PWM

to adjust the intensity of the lights I intend to use the PWM

Unfortunately, the outputs I used dont have pwm hardware function

Fortunately, you can make a soft pwm :

http://www.kobakant.at/DIY/?p=3393

The challenge is to make the PWM on the headlights without losing the timing of the flashing

the principle is the following:

Blink_delay corresponds to the flash duration flashing


my poorman PWM function is like that :



  1.  
  2. void poormanPWM(){//for lights
  3. int i;
  4. for (i=0; i<10; i++) {
  5. if(light_mode!=0){
  6. set(Lights_port,Light_pin); // Turn light on if necessary
  7. }else{
  8. clear(Lights_port,Light_pin);//else shut it
  9. }
  10. long_delay_ms(blink_delay/20);
  11. if(light_mode==1) clear(Lights_port,Light_pin); // Turn light off half time in low mode
  12. long_delay_ms(blink_delay/20);
  13.  
  14. }
  15.  
  16. }
  17.  
  18.  

the final code is available here: File: Light.control.44.c.zip



Tests



unloaded

As I put LED indicator on the circuit, I could encode the entire program without putting load on the mosfets.

I also mounted a small dashboard fortune to wire switches.

The behavior is completely consistent with my expectations:

with load

ok

I wired a small ribbon LED 12V test. It is a bit underpowered, but it will do for now.

The mosfet headlights works well

Alas, when I activate a flashing, it does not work.

Testing mosfets flashing, I see that they do not work. There must be a welding problem but I'm not lab. I should fix that later.

Diagnosis (temporary)

my circuit or otherwise disrupts the trigger mosfet, it would then set the indication LEDs downstream of mosfet (with resistors dimensioned to the supply voltage)


To be continued...